lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Thanks, Ashwin,
It works!!! 
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:
 
lua_getglobal(L, "global_objects");
lua_pushstring(L, "effecttype");
lua_gettable(L, -2);
lua_pushstring(L, "water");
lua_gettable(L, -2);
 
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?
 
Thanks again!
Nelson

Ashwin Hirschi <deery@operamail.com> wrote:

[snip<]
> 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.

Ashwin.
--
no signature is a signature.



Post your free ad now! Yahoo! Canada Personals