tech-userlevel archive

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

Re: proplib and the jet age



On 01/04/13 17:46, Marc Balmer wrote:
[---]
>> Let me add another option here:  Lua could be used just for that.  Lua has 
>> been designed as a data description language, a fact that is obvious when 
>> you look at it's fine syntax for defining tables and structuring data in 
>> general.   Its easy to generate and easy to process and has far less 
>> overhead that e.g. XML.
> 
> I have, in the meantime, described what it would be like to use Lua as a 
> language for configuration files or to exchange data.  Lua is already used 
> for this purpose, actually it emerged from a language called Sol which was 
> created specifically as a data description language.

   I somewhat recently migrated one of my own projects to use lua
scripts as configuration files rather than a custom "key=value"-pair
type configuration.

   I encountered a few minor annoyances, mostly due to my old format
having a few shortcuts. For instance:

   myproj.max_elements=64K
   myproj.max_store=8G

   ..and in this particular project that syntax happens a lot. As a
workaround, I added support for passing strings; "64K", etc, and have
the application automatically treat them as integers. Not very pretty,
but I doubt it's an issue for most cases/users. And there's also 64*1024
etc of one prefers it.

   There are a few of those types of mini-annoyances. (Oh, I much prefer
having a '#' as first character on the line to denote a comment).
However the gain in being able to probe the system for variables (in
some cases using external lua libraries) and write procedures to
calculate certain values far outweighs any small annoyances I have
encountered.

   Before I started the conversion I was a little worried about the
configuration files rapidly turning into beasts which aren't easily
grep/sed/awk:able. With my limited experience (only one project so far),
this hasn't turned out to be a big problem. The only issue is that
sometimes I want to check what the current *effective* setting is, and
since I sometimes use procedures to set them. The workaround for this
was to write a small "expander" (brutally trivial to do). It's almost
like a preprocessor, which dumps expanded variables:

   $ ./dumpconfvars config.lua | grep max_elements
   max_elements=65536


   Lua is not a perfect solution in all regards. But then again, if
there were one, there wouldn't be much point in having this discussion. :)

   My experiences with "Lua as config" is good enough for me so far that
I'm considering migrating other projects with custom configuration
formats to Lua-based configuration files.


   Just my 2 öre.

-- 
Kind regards,
Jan Danielsson


Attachment: signature.asc
Description: OpenPGP digital signature



Home | Main Index | Thread Index | Old Index