Reference to Lua function in C/C++(在 C/C++ 中引用 Lua 函数)
问题描述
我有一个函数嵌套在一组表中相对较深.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 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 C/C++ 中引用 Lua 函数


- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 静态初始化顺序失败 2022-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 从python回调到c++的选项 2022-11-16
- 如何对自定义类的向量使用std::find()? 2022-11-07
- C++ 协变模板 2021-01-01
- 近似搜索的工作原理 2021-01-01