lua-users home
lua-l archive

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

Thanks, Ashwin,
It works!!!

Glad to hear it.

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);

Yes, this is the smallest sequence.

Of course, having a little error-checking in there wouldn't hurt [unless you're absolutely sure all your data is always available]. For instance, if the 2nd table would somehow be missing, Lua would (quite correctly) throw an alert during your last lua_gettable call. Depending on circumstances, that could be a bit embarrassing, I think.

One thing I have not yet clear is, what exactly are happening in the stack when calling the sequence above.

The reference manual clearly describes how particular Lua API functions change the stack [i.e. what is popped off and pushed onto it]. And you don't need anything else to properly interact with Lua. So, really, don't worry about it too much! [:-)]

Then again, if you're just curious about what actually happens: use the source! I think Lua is very well-written, and it doesn't take too much effort to get somewhat familiar with it.

Obviously, it helps if your development environment has some sort of code-navigation support. That way you don't spend an inordinate amount of time hunting for scraps of code. Many IDEs provide tools to help you. But I use ctags, since I do all of my programming using Vim.

Last but not least, the Lua team provides a nice way to navigate the source by browser:

This is always an enjoyable way to spend a lazy Sunday afternoon [;-)].

Have fun!

no signature is a signature.