[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Accessing Table's table value from C++
- From: Initial-N <neruson_newsletter@...>
- Date: Wed, 2 Feb 2005 10:31:49 -0500 (EST)
After getting the global_objects table, I need to push a string (effecttype), then do a lua_gettable(L, -2) in order to get the effecttype table.
Therefore, entrie sequence is:
One thing I have not yet clear is, what exactly are happening in the stack when calling the sequence above.
I know calling lua_getglobal give me a table which live in the lua global environment, but I wonder if the entire table STRUCTURE is push on the top of the stack, or any magic tag is being pushed so that the stack is able to give me the next table when do the pushstring and gettable.
Sorry for the newbie question, but I am fairly confused how the lua stack work. Any tips can help me to monitor the stack?
Ashwin Hirschi <firstname.lastname@example.org> wrote:
> I have no idea why my C++ code does not evaluate global_objects.effectype.water
> as a table. Should I actauly need to separate global_objects effectype and water
> and explicitly do the table traverse?
I don't think lua_getglobal handles the entire 'path' for you.
You need to do a lua_getglobal on "global_objects" and then access the result table using lua_gettable. This way you'll find the "effectype" [only 1 't'?] table and can call lua_gettable again to get to the "water" table.
Best check the reference manual for more details.
Also, doing type-checking on results is good, but it looks like checking for nil after you've ensured it's a table is a bit redundant.
I hope this helps.
no signature is a signature.
Post your free ad now! Yahoo! Canada Personals