Jump to content




[Lua][Question] Table.insert


  • You cannot reply to this topic
1 reply to this topic

#1 darkroom

  • Members
  • 70 posts

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})


#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

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")





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users