lua读写表数据

时间:2013-04-15 04:44:34

标签: lua lua-table

我使用以下lua脚本来访问和读取外部lua文件:

FileStr = "lariatData-sgeT-2012-05-31.lua"
Hnd, ErrStr = io.open(FileStr, "r")
if Hnd then
    dofile(FileStr)
    for Str in Hnd:lines() do
        print(Str, "\n")
        for exec, val in pairs(sgeT) do
            print(exec.." "..val, "\n")
        end
    end
    Hnd.close()
else
    print(ErrStr, "\n")
end

但是,当返回exec键的值时,我得到一个十六进制的内存位置。例如,一行输出如下:

table: 07x7fdc5b2538f0

1 个答案:

答案 0 :(得分:1)

我回答你上一个问题;你需要递归调用函数。存在示例程序here

function DeepPrint (e)
    -- if e is a table, we should iterate over its elements
    if type(e) == "table" then
        for k,v in pairs(e) do -- for every element in the table
            print(k)
            DeepPrint(v)       -- recursively repeat the same procedure
        end
    else -- if not, we can just print it
        print(e)
    end
end