我是 Lua 的新手,很困惑。我见过这个,但我不确定它是否适用于 5.2。
我已经阅读了 _ENV table(?) 但再次不确定这是否与它有关。
那么问题来了:我如何在 C/C++ 中重定向 Lua 5.2 的内置打印函数来调用我自己的 C/C++ 函数?
来自Lua 5.2 手册:
Lua keeps a distinguished environment called the global environment.
This value is kept at a special index in the C registry (see §4.5).
In Lua, the variable _G is initialized with this same value.
因此,如果您将呼叫替换为呼叫,则您链接的问题的这个答案将起作用。luaL_register
luaL_setfuncs