Lua as configuration language

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Lua as configuration language

Marc Balmer
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


Reply | Threaded
Open this post in threaded view
|

Re: Lua as configuration language

Peter Cawley
I seem to be mentioned as [4] in the References, but I don't see [4] anywhere in the text - is the reference due to text which you've edited out of the article?

On Fri, Jan 4, 2013 at 4:47 PM, Marc Balmer <[hidden email]> 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



Reply | Threaded
Open this post in threaded view
|

Re: Lua as configuration language

Alexander Gladysh
In reply to this post by Marc Balmer
On Fri, Jan 4, 2013 at 8:47 PM, Marc Balmer <[hidden email]> 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

>From a first cursory glance: I'd add some information on "constructor
functions" (or how they are properly called — foo { a = 42 }), a.b.c =
5 syntax with automagic tables (where sub-tables are created
automatically) and config format validation.

§2 probably should reference http://lua-users.org/wiki/SandBoxes.

Also, Roberto's name is spelled incorrectly in the second footnote on
the first page.

HTH,
Alexander.

Reply | Threaded
Open this post in threaded view
|

Re: Lua as configuration language

Alexander Gladysh
On Fri, Jan 4, 2013 at 8:58 PM, Alexander Gladysh <[hidden email]> wrote:
> On Fri, Jan 4, 2013 at 8:47 PM, Marc Balmer <[hidden email]> 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

BTW:

> Lua chunks have even be used as protocol messages for client-server protocols over the network,
see [3] for details.

While they have been used, it is not a sound practice, IMO. (1) Both
client and server must trust each other (or pay heavy sandboxing
toll), and (2) data deserialization is itself quite costly, when
compared with existing specialized alternatives.

Alexander.

Reply | Threaded
Open this post in threaded view
|

Re: Lua as configuration language

Marc Balmer

Am 04.01.2013 um 18:00 schrieb Alexander Gladysh <[hidden email]>:

> On Fri, Jan 4, 2013 at 8:58 PM, Alexander Gladysh <[hidden email]> wrote:
>> On Fri, Jan 4, 2013 at 8:47 PM, Marc Balmer <[hidden email]> 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
>
> BTW:
>
>> Lua chunks have even be used as protocol messages for client-server protocols over the network,
> see [3] for details.
>
> While they have been used, it is not a sound practice, IMO. (1) Both
> client and server must trust each other (or pay heavy sandboxing
> toll), and (2) data deserialization is itself quite costly, when
> compared with existing specialized alternatives.

I agree.  I just mentioned it because I found it an interesting use case.

And many thanks for you other comments!

- Marc


Reply | Threaded
Open this post in threaded view
|

Re: Lua as configuration language

Tomás Guisasola-2
  Hi Marc

  Have you checked ALua?

ALua: flexibility for parallel programming, by C. Ururahy, N. Rodriguez, and R. Ierusalimschy. Computer Languages 28 #2 (2002) 155-180.

ALua: an event-driven communication mechanism for parallel and distributed programming, by C. Ururahy and N. Rodriguez. Proceedings of ISCA 12th International Conference on Parallel and Distributed Computing Systems (PDCS-99), Fort Lauderdale, USA, August 1999, pages 108-113.

  The references come from Lua site's Papers and theses:

http://www.lua.org/papers.html

  Regards,
  Tomás

On Fri, 4 Jan 2013, Marc Balmer wrote:

>
> Am 04.01.2013 um 18:00 schrieb Alexander Gladysh <[hidden email]>:
>
>> On Fri, Jan 4, 2013 at 8:58 PM, Alexander Gladysh <[hidden email]> wrote:
>>> On Fri, Jan 4, 2013 at 8:47 PM, Marc Balmer <[hidden email]> 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
>>
>> BTW:
>>
>>> Lua chunks have even be used as protocol messages for client-server protocols over the network,
>> see [3] for details.
>>
>> While they have been used, it is not a sound practice, IMO. (1) Both
>> client and server must trust each other (or pay heavy sandboxing
>> toll), and (2) data deserialization is itself quite costly, when
>> compared with existing specialized alternatives.
>
> I agree.  I just mentioned it because I found it an interesting use case.
>
> And many thanks for you other comments!
>
> - Marc
>
>
>
--
Reply | Threaded
Open this post in threaded view
|

Re: Lua as configuration language

Thijs Schreijer
In reply to this post by Marc Balmer
Nice article. Typo; 'sanboxes' page 3 iirc


Marc Balmer <[hidden email]> schreef:
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


Reply | Threaded
Open this post in threaded view
|

Re: Lua as configuration language

Marc Balmer
In reply to this post by Peter Cawley

Am 04.01.2013 um 17:52 schrieb Peter Cawley <[hidden email]>:

> I seem to be mentioned as [4] in the References, but I don't see [4] anywhere in the text - is the reference due to text which you've edited out of the article?

Oh, indeed.  Your reference sneaked in from another article on Lua in the NetBSD kernel (where protection against malicious bytecode actually matters).  I'll remove the reference here.


Reply | Threaded
Open this post in threaded view
|

Re: Lua as configuration language

Alexander Nasonov
In reply to this post by Marc Balmer
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

Alex

Reply | Threaded
Open this post in threaded view
|

Re: Lua as configuration language

Marc Balmer
Good idea.  How would the Section function look like?


> 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
>
> Alex
>

Reply | Threaded
Open this post in threaded view
|

Re: Lua as configuration language

Alexander Gladysh
On Sat, Jan 5, 2013 at 3:06 AM, Marc Balmer <[hidden email]> 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.

Reply | Threaded
Open this post in threaded view
|

Re: Lua as configuration language

Rapin Patrick
In reply to this post by Marc Balmer

Comments welcome.

I have some small remarks. First, as a general rule, I think you should describe mainly Lua 5.2 release and not 5.1.
This is because if you convince NetBSD to use Lua as a configuration language, they will use the latest version, won't they?
While you don't mention the actual Lua version in your text, the way you describe _G indicates this.

- Section 1.1: "Global variables in Lua are actually entries in a table named G,", replace _G by _ENV and the phrase becomes true. Otherwise, this is not always the case, _G is not guaranteed to match the current environment (being _ENV of 5.2 or getenv() of 5.1 )
- Section 1.2: same remark, gsub("_G", "_ENV")
- Section 1.3: "if, then, for": typeset these keywords like code with a fixed font. I will note this as <code> afterwards, as in DocBook (*).
- Section 1.4: explicetely -> explicitly
- Section 2: replace all _G by _ENV and explain this is the *current* environment
- Section 3.1 and 3.2: <code> missing at numerous places
- Section 3.2: This section is essentially wrong !
  - Loading and compiling are the exact same thing, check what you meant. 
  - luaL_dofile and luaL_dostring also _executes_ the result
  - but since the chunk is already executed, you don't call lua_call or lua_pcall afterwards.
  - I think you want to replace mention of luaL_dofile and luaL_dostring in the first list by lua_load, luaL_loadstring and luaL_loadfilex, with their Lua 5.2 signature.
- Section 4: Thanks for citing a paper of mine in your article. This does not happen often and is a pleasure.

I hope this helps.

(*) in case you are actually using DocBook, I have written a Lua syntax highlight add-on that could enhance your document.

--
-- Patrick Rapin
-- coauthor of "Le guide de Lua et ses applications", D-BookeR