lua-users home
lua-l archive

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


Hi Denis,

try lua_gettable(L, -2)

the table is not #2 on the stack, but the second from the top!
(positive numbers indicate absolute position from the bottom of the stack,
negative a position relative to the top)
see also Chapter "5.2 - The Stack and Indices" in the manual:
http://www.lua.org/manual/manual.html#5.2

Cheers,
Peter.

-----Original Message-----
From: owner-lua-l@tecgraf.puc-rio.br
[mailto:owner-lua-l@tecgraf.puc-rio.br]On Behalf Of Denis Lamarche
Sent: Monday, October 15, 2001 2:15 AM
To: Multiple recipients of list
Subject: Lua Tables from 'C'


I am trying to get the value in a table passed to 'C' from lua.

[LUA]
names={car="red", house="brick"}
doit(names)

[C]
static int doit(lua_State *L)
{
char *text;

lua_pushstring(L, "house");
lua_gettable(L, 2)  //because the table is at 2 in the stack right?
text=(char *)lua_tostring(L, 1);

}


but for some strange reason, text is NULL.  I am assuming that the table
names was passed on the stack as index 1 and then I pushed a string on the
stack, so the table is now index 2, right??  but the string "brick" does not
get pushed onto the stack.

I tried to lua_getglobal before the pushstring to try to get the table, but
I dont know how to getglobal the table that is being sent by lua.

any thoughts?

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp