2

可能重复:
为嵌入式 Lua 重定向/重新定义 print()

我是 Lua 的新手,很困惑。我见过这个,但我不确定它是否适用于 5.2。

我已经阅读了 _ENV table(?) 但再次不确定这是否与它有关。

那么问题来了:我如何在 C/C++ 中重定向 Lua 5.2 的内置打印函数来调用我自己的 C/C++ 函数?

4

1 回答 1

2

来自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_registerluaL_setfuncs

于 2012-09-07T08:49:01.153 回答