[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua as a configuration file
- From: RLake@...
- Date: Fri, 27 Sep 2002 15:38:09 -0500
> I'd like to start using Lua for configuration file uses (which I
> understand was its original purpose). The straightforward approach that
> I would normally do with a simpler language is just to load the file and
> then parse it directly -- items that need to be created are determined
> by the parser, not by the language.
> For example, in a general scripting language you would have something
> like:
> window a = { x = 100, y = 10 };
> It would hit "window", and then have context for the parsing afterwards.
Doesn't that mean writing a parser for every datatype? I'm just asking...
What I do in Lua is create a function called Window, whose single argument
is a table. It can return a userdata or a table with metamethods, whichever
seems appropriate. Lua conveniently allows the parentheses to be omitted in
a function call whose argument is a table, so the following works fine:
a = Window{ x = 100, y = 10}
Probably you were looking to give the Window a name, and assuming that
the name and the variable would be the same. But I would prefer to
put the Window's label as a separate attribute:
a = Window{ label = "My Window", x = 100, y = 10 }
because I would probably have wanted to allow for localisation of the
user-visible string:
a = Window{ label = _X"My Window", x = 100, y = 10 }
(Here _X is another function -- translate would be more
readable but _X is easier to type -- which takes advantage of Lua
not requiring parentheses when the argument is a string either.)
Don't know if that helps you at all....