How to access nested Lua tables from C -
Assume that I want to set a value (such as function) inside the nested table with lava-c API.
- lua.lua glob = {nest = {- set value here}}
How do I set up a heap to reach the inner table?
Is it just calling gettable
many times and then a settop
, like in the following code?
Lua_pushstring (state, "globe"); Lua_gettable (state, -1); Lua_pushstring (state, "nest"); Lua_gettable (state, -1); Lua_pushcclosure (state, and func, 0); Lua_settop (state, "fun"); Lu_pop (state, 2);
This code sets glob.nest.name
C function:
lua_glockGlobal (state, "globe"); Lua_getfield (state, -1, "nest"); Lua_pushcclosure (state, and func, 0); Lua_setfield (state, -1, "name"); To add other fields to glob.nest
, just keep going:
... lua_pushcclosure (state, &) ; Second, 0); Lua_setfield (state, -1, "second name");
Comments
Post a Comment