table.insert

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

table.insert

Hugo <Nabble>
This code works with standard Lua, but doesn't work with Luan:
t = {}
table.insert(t, "text")
print(t[1])
I know we can use the line below to insert an element, but shouldn't table.insert also work?
t[#t+1] = "text"
Reply | Threaded
Open this post in threaded view
|

Re: table.insert

fschmidt
Administrator
This works:
t = {}
table.insert(t, 1, "text")
print(t[1])
In Lua, the second parameter to table.insert() is optional.  I think optional parameters that aren't at the end of the parameter list are confusing, so I require the "pos" parameter.
Woe to those who call bad good and good bad -- Isaiah 5:20
Following the Old Testament, not evil modern culture
Reply | Threaded
Open this post in threaded view
|

Re: table.insert

Hugo <Nabble>
Okay, your version works and it is not a big issue. Closing thread.