Lua -- unpack

Lua -- unpack

unpack它接受一个数组(table)作为参数,并默认从下标1开始返回数组的所有元素

do    arrayData = {"a","b","c","d","e"}    print(arrayData) -- print the address of the arrayData     print(table.unpack(arrayData)) -- print all the elements of the arrayData    print(table.unpack(arrayData, 2)) -- print the second to end elements of the arrayData    print(table.unpack(arrayData, 1, 3)) -- print between first to third elements of the arrayDataend

注意:在Lua5.1中,unpack是全局函数,可以直接使用,但是在Lua5.2中,unpack被移到table.unpack,所以在Lua5.2以后要用table.unpack替代unpack。

推荐阅读