lua-users home
lua-l archive

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


Brian Hook wrote:
> Does this make sense?

Of course that makes sense. I was thinking of doing something like that.
Everybody says that lua is good as a data description language, and that it
could be used to replace xml, but actually the lua api is not designed for
that, and doing something simple like accessing "foo.x.y" or traversion
nested tables is not that easy.

It seems to me that that's wha you want to do, right?

Ok, the answer of your question:

You cannot get a table a in C. Instead of that you have to keep that
reference inside lua, in a safe place like the registry. For example, you
could store your current table in the registry table as 'current_table'. In
that case, you would do the following to get the global table and asign it
to current_table.

lua_pushstring(lua, "current_table");    // push key
lua_pushvalue(lua, LUA_GLOBALSINDEX);    // push global table
lua_settable(lua, LUA_REGISTRYINDEX);    // set key-value in the registry

After that, when you want to get a value from your current table, you do:

lua_pushstring(lua, "current_table");    // push key
lua_gettable(lua, LUA_REGISTRYINDEX);    // get value

and that leaves the value on the top of the stack.


Ignacio Castaño
castanyo@yahoo.es


___________________________________________________
Yahoo! Móviles
Personaliza tu móvil con tu logo y melodía favorito 
en http://moviles.yahoo.es