利用table的pack与unpack进行数据打包与解包,测试代码如下:
print("Test table.pack()----------------"); function printTable ( t ) if type(t) == "table" then for k,v in pairs(t) do printTable(v); end else print(t); end end local packData =function( ... ) local arg = table.pack(...); --arg.n 得到可变部分的参数的个数 -- print("arg.n:", arg.n) for k,v in pairs(arg) do print("----------------"); print(k,v); printTable(v); print("----------------"); end return arg; end packData({type=100,param={"param1", "param2", "param3"}}); -- packData("param1", "param2", "param3","param4","param5"); print("\nTest table.unpack()----------------"); local data = {"AA", "BB", "CC", "DD"} print(table.unpack(data)) print(table.unpack(data, 2)) print(table.unpack(data, 2, 3))
打印数据:
原文:http://blog.csdn.net/zz7zz7zz/article/details/38021259