lua-users home
lua-l archive

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


I want to create a 2-D table (array) in C to return to a lua script. In other words, a={} and b = {}, then a[1] = b, a[2] = b, etc., for each new b. I can't figure out how to assign each "column" table to an element of the "row" table, like a[1] = b. My gut tells me to do something like the following, but this code hits a dead end:

lua_newtable( L );  // push a Row Table (the main table) onto the stack
for ( int j = 1; j <= nRows; j++ )
{
   lua_newtable( L ); // push a Column Table onto the stack
   for ( int i = 1; i <= nCols; i++ )
   {
       lua_pushnumber( L, i );
       lua_pushstring( L, sValue );
       lua_settable( L, -3 );
   }

   // Now stack looks like  -2: RowTable,   -1: ColumnTable
   // How do I do the equivalent of RT[ j ] = CT?
}

Any help would be greatly appreciated.

Michael