lua-users home
lua-l archive

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


Grellier, Thierry a écrit :
So one would have to do something like:
lua_dostring(L, "local pushed = a.b.c[1].d");
lua_to<mytype>(L, -1);
lua_pop(L, 1);
and eventually catch error? (what if b is nil for example?)
It is just that my configuration shall be a valid lua expression, so I
don't really feel like I shall tokenize and interpret it myself.

No, you can access any table member in C without using this syntax.
I can't give you code here right now, because I am a bit rusty on the C side of the API, but there are example around (mailing list, Wiki, PiL aka. Programming in Lua, etc.)

Side note: I had an old unfinished project to improve existing table dump routines by indenting nicely the output. I recently took it back, and rewrote it entirely, making it somehow usable. It is the opportunity to share it, I give the DumpObject.lua and its companion TestDumpObject.lua, trying to explore most of the aspects of table building...

I don't manage user-data (depending on the implementation) nor functions: I discovered later that I can dump and reread the functions, perhaps wrapping the dump with a conversion to Ascii (Base64, Ascii85, to hex, with escapes, whatever), but I feel lazy here... Another limitation is that I transform implicit array numbers to explicit ones, it would add some complexity to do otherwise.

On the other hand, it handles loops and makes its output using the real Lua syntax with some optimizations (using literal string when needed), unlike a previous version which was merely a debug dump.

The main issue, for somebody used to Windows' .INI files, is that comments are lost, and initial order of key/value pairs too. That's the limits of Lua as configuration language, to do otherwise would need to re-parse the initial file and update the values in place...

The strong point is that it supports expressions and even functions, good and clean hierarchy, references, etc.
I suppose we can't get the best of the two worlds (or it will be hard).

We have the same problem with the SciTE .properties files: they are quite flexible, but read-only, it is hard to add a configuration dialog to allow friendly option editing and automatically update the properties on disk, and even then, we would loose lines like keywords4.$(file.patterns.lua)=$(keywordclass4.lua5).

--
Philippe Lhoste
--  (near) Paris -- France
--  http://Phi.Lho.free.fr
--  --  --  --  --  --  --  --  --  --  --  --  --  --