Skip to main content
GameDev.net gamedev.net
🔒 Locked

lua_gettable problem

Started by luasitdown Jul 25, 2005 at 7:11 PM 5 replies 6.9k views
Original Post
luasitdown
luasitdown
lua_gettable pops a key from the stack and returns (on the stack) the contents of the table at that key. The table is left where it was in the stack. I think gettable should return a value. but I cannot do v = lua_gettabel(...) as int i = lua_tonumber(...) where is the value it return?
Sneftel
Sneftel
Er, you just told us where it returns the value. It returns it on the stack. It pops the key off the top of the stack, looks up the corresponding value, and puts the value on the stack.
luasitdown
luasitdown
void lua_gettable (lua_State *L, int index);

but where is key ? just index is supplied.
luasitdown
luasitdown
I know the key is on top of stack.

but I wonder what does "left" mean in the sentence The table is left where it was in the stack.?



void lua_settable (lua_State *L, int index);

where index points to the table. lua_settable pops from the stack both the key and the value. The table is left where it was in the stack.

and when lua_settable executed,what happen in stack.

I think settable need a existed table in stack and put key/value on top of stack
into table index points to.and some element in this stack must shift.
The manual of lua is so ambiguity.

so I am right?



Sneftel
Sneftel
Quote:
Original post by luasitdown
I know the key is on top of stack.

but I wonder what does "left" mean in the sentence The table is left where it was in the stack.?

I think there are language barriers here. The sentence means, basically, "The table's position before lua_gettable is the same as the table's position after lua_gettable".

Here's an example: suppose you have a table in stack position 1 and a key in stack position 2. Now you call lua_gettable(L, 1). Afterwards, the table is still in stack position 1, and the value is in stack position 2.
luasitdown
luasitdown
thank
but for lua_settable , any element in the stack do not shift after settable??

Sneftel
Sneftel
No. Other than lua_insert and lua_remove, all Lua functions which operate on the stack change only the topmost positions.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.