lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Sat, Jan 5, 2013 at 3:06 AM, Marc Balmer <marc@msys.ch> wrote:
>
>
>> Marc Balmer wrote:
>>> I posted a short article on how to use Lua as a configuration and data exchange language.
>>>
>>> Comments welcome.
>>>
>>> http://www.netbsd.org/~mbalmer/lua/lua_config.pdf
>>
>> It's worth adding an explanation of multiline comments and strings.
>>
>> It's also possible to implement something like this:
>>
>> Iface "lo0" {
>>    ip="127.0.0.1",
>>    mask="255.0.0.0"
>> }
>>
>> and build a framework to register sections and define validation
>> rules. For instance:
>>
>> local Iface = Section { ip="string", mask="string" }
>>
>> The simplest version of Iface is below.
>>
>> function Iface(name)
>>        return
>>                function(content)
>>                        _G[name] = content
>>                end
>> end

> Good idea.  How would the Section function look like?

I described something along these lines at previous Lua workshop:

http://www.slideshare.net/agladysh/declarative-internal-dsls-in-lua-a-game-changing-experience

Basically you construct a walker for your data tree.

Here is some code that we still have to release as a proper library
that implements such validator:

https://github.com/logiceditor-com/codebase/blob/master/pk-core/pk-core/tree_walker_with_checker.lua
https://github.com/logiceditor-com/codebase/blob/master/pk-core/pk-core/walk_data_with_schema.lua

Example data format description:

https://github.com/logiceditor-com/codebase/blob/master/pk-core/pk-core/walk_data_with_schema.lua#L715-L722

Example data:

https://github.com/logiceditor-com/codebase/blob/master/pk-core/pk-core/walk_data_with_schema.lua#L715-L722

Config file validator:

https://github.com/logiceditor-com/codebase/blob/master/pk-core/pk-core/config_dsl.lua

And an example of config format:

https://github.com/logiceditor-com/codebase/blob/master/pk-tools/src/lua/db-changes/project-config/schema.lua#L25

If someone is interested in this to be released as a reusable and
documented library, please say so.

Also, if there is some interest, I may try to write some introductory
text for this approach — I see that my talk probably did not include
enough information about how to implement what it describes.

Alexander.