table.insert(t, 1, 5) --> {1,2,3} => {5,1,2,3}
t = {}
for line in io.lines() do
table.insert(t, line) --> append line to ending of t
--> but t[#t+1] = line is recommended in lua5.1
end
print (#t)
table.delete()
will delete the last item in array t by default.
table.insert()
and table.delete()
can be used to simulate stack.
t = {} --> initialize stack
table.insert(t, xx) --> push
table.delete(t) --> pop
ipairs
uses array order, while pairs
uses table's order.
this extended (and recursive) version of concat
is able to handle nested table.
function rconcat(l)
if type(l) ~= "table" then return l end
local res = {}
for i = 1, #l do
res[i] = rconcat(l[i])
end
return table.concat(res)
end