View Single Post
Old 11-20-2009, 11:21 AM   #128
Iņigo
Guru
Iņigo did not drink the Kool Aid.Iņigo did not drink the Kool Aid.Iņigo did not drink the Kool Aid.Iņigo did not drink the Kool Aid.Iņigo did not drink the Kool Aid.Iņigo did not drink the Kool Aid.Iņigo did not drink the Kool Aid.Iņigo did not drink the Kool Aid.Iņigo did not drink the Kool Aid.Iņigo did not drink the Kool Aid.Iņigo did not drink the Kool Aid.
 
Posts: 730
Karma: 72743
Join Date: Feb 2008
Location: Here or there
Device: iRex iLiad, iRex DR800S. K4NT. Kobo Aura, Aura One, Libra 2.
Excuse me for the silence, too much work these days...

Quote:
Originally Posted by hansel View Post
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.
Iņigo is offline   Reply With Quote