2
我在磁盤上有一個純文本lua表。它看起來是這樣的:如何使用Lua語言從磁盤加載Lua表?
rootTable = {
name="myTable",
settings = {
setting1="some stuff",
setting2="some more stuff"
},
parameters = {
{ name="paramName", values={x=1.0,y=1.0,z=0.0,w=0.0} },
{ name="paramName2", values={x=0.0,y=3.0,z=1.0,w=0.0} }
}
}
我試圖在使用下面的代碼(在C++)LUA打開這個表:
const char *filename = "path/file.txt"
lua_State *state = luaL_newstate();
luaL_openlibs(state);
int error = luaL_loadfile(state, filename);
if (error == 0) {
error = lua_pcall(_state, 0, 0, 0);
}
if(error != 0)
{
std::string errorMessage = lua_tostring(_state, -1);
fprintf(stderr, "%s\n", _errorMessage.c_str());
}
然而,每當我嘗試運行此,我得到以下錯誤消息:
附近意外符號 '{'
我不知道這意味着什麼,或者我可以如何解決它。任何幫助,將不勝感激。