2

我在从 C++ 调用的库中使用 Lua (5.2.1)。

例如,在 C++ 中,我调用函数 OnHear 并传递听到的文本。

然而,在我的 Lua 文件中,我检查了一些奇怪的东西:

function OnHear(_Text)
    txt = _Text;
    txt = string.lower(txt); -- comment this line to make the code below run
-- other code
end

这没用; 当注释低的行时,“其他代码”运行良好,但如果正在执行,则不会。

function OnHear(_Text)
    txt = string.lower(_Text);
-- other code 
end

同样的问题...

我还发现,当我调用例如 string.len(txt) 或类似的东西时,会发生同样的问题(之后的代码没有被执行)......

我不知道什么可能导致我的问题,谷歌搜索/搜索 Stackkoverflow 并没有帮助我,遗憾的是......

感谢您提前回复!

4

1 回答 1

3

您是否从 C++ 打开了 Lua 标准库?

void luaL_openlibs (lua_State *L);

将所有标准 Lua 库打开到给定状态。

来自http://www.lua.org/manual/5.2/manual.html#luaL_openlibs

编辑

二进制文件默认打开库,lua但有时,当嵌入解释器时,库可能是多余的。

于 2013-03-19T11:13:14.953 回答