Jump to content
  • Advertisement
Sign in to follow this  
luasitdown

lua_gettable problem

This topic is 4771 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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?



Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
No. Other than lua_insert and lua_remove, all Lua functions which operate on the stack change only the topmost positions.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!