Lua中的string.len、string.lower或其他任何字符串函数无法工作。

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

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

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

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

它不起作用;如果注释了使用lower的那一行,"other code"会很好地运行,但是如果那一行被执行,它就不会被执行。

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

同样的问题...

我还发现,当我调用例如string.len(txt)或类似于此的任何内容时,同样的问题(之后的代码不被执行)也会出现...

我不知道是什么原因导致了我的问题,谷歌/搜索Stackkoverflow也没有帮助我,遗憾...

提前感谢任何回复!

点赞
用户1283954
用户1283954

你从 C++ 中打开了 Lua 的标准库吗?

void luaL_openlibs (lua_State *L);

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

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

编辑

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

2013-03-19 11:13:14