From: "Peter Prade" <[email protected]>
Reply-To: [email protected]
To: Multiple recipients of list <[email protected]>
Subject: RE: Lua Tables from 'C'
Date: Mon, 15 Oct 2001 03:03:57 +0200
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: [email protected]
[mailto:[email protected]]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