2013-03-19 69 views
2

我使用Lua(5.2.1),在一个库中,从C++调用。Lua string.len,string.lower或任何其他字符串函数不工作

例如,从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没有帮助我,黯然......

感谢提前任何答复!

回答

3

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

void luaL_openlibs (lua_State *L); 

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

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

EDIT

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

+0

非常感谢你,这解决了这个问题:)我不知道这个功能呢...(我觉得哑巴^^) – userrr3 2013-03-19 11:40:33

相关问题