[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Lua Tables from 'C'
- From: Diego Fernandes Nehab <diego@...>
- Date: Mon, 15 Oct 2001 16:50:49 -0200 (BRST)
Hi,
> When I do a lua_tostring or lua_tonumber, do these values get poped off of
> the stack? Cause when I pass values from lua to 'C' using functions. I
> always use index 1 to retreive the values and it always returns the correct
> one. for example:
>
> [LUA]
> doit(21, 34, "I was here")
>
> [C]
> static int doit(lua_State *L)
> {
> int a, b;
> char *text;
>
> a=(int)lua_tonumber(L, 1);
> b=(int)lua_tonumber(L, 2);
> text=(char *)lua_tostring(L, 3);
>
> printf("A=%d, B=%d, Text=%s\n", a, b, text);
> //prints out: A=21, B=34, Text=I was here <------------
> }
>
> so 21 gets pushed into index #1 and 34 into #2 and "I was here" into #3.
> So the top is at 3 (or -1??) and the bottom is at #1 right??
> So a table would be pushed onto the stack at index #4 (after doit() is
> called).
Your example is correct. I am not sure if you understood that each
function is called with a "private" stack, so that even if you do not
pop your stuff off inside doit(), a new call to doit() will still use
the same indexes.
Some functions pop values from the stack, others do not. Check the manual.
After a while, it starts making sense that some functions should pop and
others should not.
[]s,
Diego.