问题描述
我有一个函数嵌套在一组表中相对较深.C/C++ 中有没有办法在我需要使用它时获得对该函数的引用"并将其(和参数)推入堆栈?
I have a functions nested relatively deeply in a set of tables. Is there a way in C/C++ to get a "reference" to that function and push that (and args) onto the stack when I need to use it?
推荐答案
这就是 参考系统是为了.函数调用 r = luaL_ref(L, LUA_REGISTRYINDEX)
将值存储在注册表中的栈顶并返回一个整数,该整数可以存储在 C 端并用于检索该值函数调用lua_rawgeti(L, LUA_REGISTRYINDEX, r)
.
This is what the reference system is for. The function call r = luaL_ref(L, LUA_REGISTRYINDEX)
stores the value on the top of the stack in the registry and returns an integer that can be stored on the C side and used to retrieve the value with the function call lua_rawgeti(L, LUA_REGISTRYINDEX, r)
.
请参阅PiL 章节,以及luaL_ref()
, lua_rawgeti()
和 luaL_unref()
了解完整故事.
See the PiL chapter, as well as the documentation of luaL_ref()
, lua_rawgeti()
, and luaL_unref()
for the full story.
这篇关于在 C/C++ 中引用 Lua 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!