local t1 = {
t0 = "valt0",
t1 = "valt1",
t2 = 42,
tN = {t0key = "t0var",
t1key = "t1var"}
}
local function convert(t)
local arr = {}
local cyclic = {}
local function convert_subtable(t, prefix)
assert(not cyclic[t], 'Cannot convert: cyclic reference detected')
cyclic[t] = true
for k, v in pairs(t) do
k = prefix..tostring(k)
if type(v) == 'number' or type(v) == 'boolean' then
table.insert(arr, k..'='..tostring(v))
elseif type(v) == 'table' then
convert_subtable(v, prefix..k..'_')
else
table.insert(arr, k..'='..string.format('%q', tostring(v)))
end
end
cyclic[t] = nil
end
convert_subtable(t, '')
table.sort(arr)
return table.concat(arr, ', ')
end
print(convert(t1)) --> t0="valt0", t1="valt1", t2=42, tN_t0key="t0var", tN_t1key="t1var"
なぜ単にjsonダンプを使用しないのですか? – hjpotter92
本当に正確にその出力が必要ですか?いくつかのLua/JSONシリアライザを入手したり作成したりしてください。 – FareakyGnome
私が言ったように、「私は必要です...」では、jSONログをLEEF形式に変換します。 –