lua-users home
lua-l archive

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


Hi Peter,

Thank you very much for the help. That solved my problem!

Michael

----- Original Message ----- From: "Peter Cawley" <lua@corsix.org>
To: "Lua list" <lua@bazar2.conectiva.com.br>
Sent: Monday, August 10, 2009 5:15 PM
Subject: Re: How to create multi-dimensional table in C?


On Tue, Aug 11, 2009 at 1:11 AM, Michael
Newberry<mnewberry@mirametrics.com> wrote:
// Now stack looks like -2: RowTable, -1: ColumnTable
// How do I do the equivalent of RT[ j ] = CT?

lua_rawseti(L, -2, j);

That'll set the item on the top of the stack (CT) to index j of the
table at -2 (RT).

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

 lua_rawseti(L, -2, j); // RT[j] = CT
}