This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
darkroom's profile picture

[Lua][Question] Table.insert

Started by darkroom, 03 January 2013 - 04:57 AM
darkroom #1
Posted 03 January 2013 - 05:57 AM
I am making my first OS! Or some kinda file manger thingy… anyway I am basing it all in tables that store information about the icons in a large object table problem is I have no idea how to use table.insert and I need that function :P/> anyway this is just a little of the code. Thanks for your time :)/>

--Table Int--
local Apps = {
[1] = {name = "NPaintPro", author = "Nitrogenfingers", handler = function() end},
[2] = {name = "FireWolf", author = "Gravityscore", handler = function() end},
[3] = {name = "Taco", author = "Da404lewZer", handler = function() end},
}
--Testing add Icon to Table--
local tArgs = {...}
table.insert(Apps,[#Apps+1] = {name = tArgs[1], author = tArgs[2], handler = function() tArgs[3] end})
Lyqyd #2
Posted 03 January 2013 - 06:32 AM
Take out the "[#Apps + 1] = " part; it will automatically place the new entry at the end of the table. You only need to specify a new index if you want it elsewhere than the end of the table. The position (when necessary) is specified as an argument. To insert a new value at the beginning of a table, for example:

table.insert(tab, 1, "new value")