【发布时间】:2014-04-28 21:02:30
【问题描述】:
假设我想通过 Lua C API 在嵌套表中设置一个值(例如一个函数)。
-- lua.lua
glob = {
nest = {
-- set value in here
}
}
我必须如何设置堆栈才能访问内表?
是否只是多次调用gettable,然后调用settop,如以下代码所示?
lua_pushstring(state, "glob");
lua_gettable(state, -1);
lua_pushstring(state, "nest");
lua_gettable(state, -1);
lua_pushcclosure(state, &func, 0);
lua_settop(state, "funkyfunc");
lua_pop(state, 2);
【问题讨论】:
-
你需要
lua_getglobal,然后是lua_gettable -
你打算用
lua_settop(state, "funkyfunc")做什么?