Lua 5.2重定向打印功能

Lua 5.2 redirecting the print function

本文关键字:打印 功能 重定向 Lua      更新时间:2023-10-16

可能重复:
重定向/重新定义嵌入式Lua 的打印()

我是卢阿的新手,相当困惑。我看过这个,但我不确定它是否适用于5.2。

我读过_ENV表(?),但再次不确定这是否与它有关。

那么问题来了:在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的调用,那么您链接的问题的答案将有效。