Tabletolua
From OpenEUO
Calling Pattern
Call
local b = sl.tabletolua(a)
Args
a is a table
Results
b is a string, compatible with the lua parser
Usage Example
local a = {[3.14] = 0.7071, [' una ']=1, test='Some "random" string.'} local b = sl.tabletolua(a) local c = dostring('return '..b) print(b,'\013\010') print(sl.keyvalstr(c))
--> {[" una "] = 1,["test"] = "Some \"random\" string.",[3.14] = 0.7071,} table keys:values = { una :1, test:Some "random" string., 3.14:0.7071, }
Description
Encodes a table as a sequence of characters compatible with the lua dostring command. Table keys and values may be composed of boolean,numeric,string, and table types. Does not encode any associated metatables. Uses string.format on string values to ensure proper encoding of escape characters (though may not have desired effect on non-visible control characters).
Upon Error
Tabletolua fails silently. Improper types are encoded as strings of value 'ERROR'. If tabletolua receives no argument or a non-table argument, then '' (an empty string) is returned.