打印lua中全局变量的一段代码

function printTableItem(k, v, level)
    for i = 1, level do
        io.write("    ")
    end
    io.write(tostring(k), " = ", tostring(v), "\n")
    if type(v) == "table" then
        if not tablePrinted[v] then
            tablePrinted[v] = true
            for k, v in pairs(v) do
                printTableItem(k, v, level + 1)
            end
        end
    end
end
printTableItem("_G", _G, 0)

 

posted @ 2017-11-01 13:59  大明湖畔的守望者  阅读(947)  评论(0编辑  收藏  举报