Nesting – ShiVa Engine

Nesting

You can nest ShiVa tables into each other. When working with nested tables/hashtables, you have to be careful about when adding a table into another table, it creates a copy of the table. Just updating the nested table will not update the table you stored in the “master table”. You have to copy it first and then get the handle of the copied table.

------- Nesting Tables
-- this.myTable ( ) is a table
-- defined in the aimodel as
-- member variable
-- part 1
-- storing
-- doing it WRONG:
local tTable = table.newInstance ( )
table.setAt ( this.myTable ( ), i, tTable )
table.add ( tTable, 3 )
-- but this is CORRECT:
local tTable = table.newInstance ( )
table.setAt ( this.myTable ( ), i, tTable )
tTable = table.getAt ( this.myTable ( ), i )
table.add ( tTable, 3 )
-- part 2
-- retrieving
table.getAt ( table.getAt ( this.myTable ( ), x ), y )



Need more answers?

  • slackBanner