lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> Firstly, is this correct? Can I then reference the people within the room
from
> the script? Along a more advanced line, how can I then define these
"people" as
> tables themselves, a table within a table so to speak?
>

A table within a table would be something like this: (untested code)

// Make new outer table. Put an identifier and an empty table
// on the stack
lua_newtable (L);

// Push the key for the sub-table, then the sub table itself,
// and then set the key into the outer table
lua_pushstring (L , "subtable");
lua_newtable (L);
lua_settable (L , -3);

// Now we can set a global for the outer table
lua_setglobal (L , "OuterTable");

This would set up a global variable named OuterTable, which has a key inside
it named "subtable" that is a second table. You can manipulate the
table/subtable from lua just as if you had created them in the script
itself. From code, you would use lua_getglobal to get at the outer table,
and lua_gettable to get at the keys inside it.