[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: How to create tables in C and reference in scripts?
- From: "Terence Martin" <odat@...>
- Date: Mon, 1 Oct 2001 23:19:58 -0700
> Firstly, is this correct? Can I then reference the people within the room
> the script? Along a more advanced line, how can I then define these
> 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
// 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_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.