打印table中的内容
function print_lua_table (lua_table, indent)
indent = indent or 0
for k, v in pairs(lua_table) do
if type(k) == "string" then
k = string.format("%q", k)
end
local szSuffix = ""
if type(v) == "table" then
szSuffix = "{"
end
local szPrefix = string.rep(" ", indent)
formatting = szPrefix.."["..k.."]".." = "..szSuffix
if type(v) == "table" then
print(formatting)
print_lua_table(v, indent + 1)
print(szPrefix.."},")
else
local szValue = ""
if type(v) == "string" then
szValue = string.format("%q", v)
else
szValue = tostring(v)
end
print(formatting..szValue..",")
end
end
end
测试代码:
local vb = {promotion_code="__Ohs6Ir__",channelId="__46__",chn="bilibili"}
print_lua_table (vb)
输出结果:
["promotion_code"] = "__Ohs6Ir__",
["chn"] = "bilibili",
["channelId"] = "__46__",