我有一个Lua解释器,只要我在代码中发生语法错误,返回的错误信息就是attempted to call a string value
,而不是有意义的错误消息。例如,如果我运行这个Lua代码:Lua语法错误的描述性错误信息
for a= 1,10
print(a)
end
而不是返回有意义'do' expected near 'print'
和行号的它只会返回错误attempted to call a string value
。
我的C++代码如下:提前
void LuaInterpreter::run(std::string script) {
luaL_openlibs(m_mainState);
// Adds all functions for calling in lua code
addFunctions(m_mainState);
// Loading the script string into lua
luaL_loadstring(m_mainState, script.c_str());
// Calls the script
int error =lua_pcall(m_mainState, 0, 0, 0);
if (error) {
std::cout << lua_tostring(m_mainState, -1) << std::endl;
lua_pop(m_mainState, 1);
}
}
谢谢!