Excuse me for the silence, too much work these days...
Quote:
Originally Posted by hansel
Those are cool functions, but they are not in Lgob (yet)
Personally I prefer to store settings in xml file (that's what always do at work). If you choose to store values in attributs (not in tags) (like <Opts option1='true' option2='false'/>), then converting Lua (nested) hashes to and from xml is quite simple...
|
Well, I don't like XML so much, I usually prefer simpler solutions, like =pair values or JSON.
For the record, here you have the code I'm finally using:
Code:
local buf = "OPT1 = 1,OPT2 = 2"
local txt = "{\n"
for k, v in buf:gfind("([^%s]+)%s*=%s*([^\n]+)") do txt = txt .. k .. " = " .. v .. ",\n" end
txt = txt:sub(1, -3) .. "\n}"
print(txt)
print("***************************************************************************")
r = assert(loadstring("return " .. txt))
pr(r())
A simple loadstring should also work, but I prefer this implementation in order to catch malformed configuration file.