Sommaire: Cours declarative internal DSLs in Lua a game-changing experience
Introduction
Ad-hoc approach
A case study
The « proper » solution
Where do we use DSLs ourselves?
Why game-changing?
Questions?
Extrait du cours declarative internal DSLs in Lua a game-changing experience
Introduction
Internal Declarative DSL in Lua
namespace:method « title »
{
data = « here »;
}
…Without sugar
_G[« namespace »]:method(
« title »
) ({
[« data »] = « here »;
})
Nave implementation
namespace = { }
namespace.method = function(self, name)
return function(data)
— …do something
— …with name and data
end
end
Ad-hoc approach
Hypothetical UI description language
ui:dialog « alert »
{
ui:label « message »;
ui:button « OK »
{
on_click = function(self)
self:close()
end;
};
}
UI description language « implementation », I
function ui:label(title)
return function(data)
return GUI.Label:new(title, data)
end
end
function ui:button(title)
return function(data)
return GUI.Button:new(title, data)
end
end
UI description language « implementation », II
function ui:dialog(title)
return function(data)
local dialog = GUI.Dialog:new(title)
for i = 1, #data do
dialog:add_child(data)
end
return dialog
end
end
………
Cours declarative internal DSLs in Lua a game-changing experience ( 919 KO) (Cours PDF)