我正在使用 C++ 中的 lua 编写一个基本的脚本系统。我的一个胶水函数是从这里调用的:
lua_register(luaVM, "openFile", l_dial.l_specifyF);
并且编码如下:
static int l_specifyF(lua_State* luaVM) {
const char* c = lua_tostring(luaVM, -1);
cDialogManager::getSingletonPtr()->clearVector();
try{
luaL_dofile(luaVM, c);
}
catch(...) {
cout << "Unable to open file" << endl;
luaL_dofile(luaVM, "startup.lua");
}
return 1;
}
当我在我的应用程序中调用它时,如果我从本地目录调用文件,如 openFile("somefile.lua")
或 openFile("someotherfile.lua ")
,但在调用位于外部文件夹中的文件时会崩溃,例如 openFile("scripts/ohdear.lua")
。
请注意,这确实在某些情况下确实有效,这只会增加困惑。这有什么原因吗? 如何补救我的应用程序以使用外部目录中的文件?
最佳答案
根据您的描述,我严重怀疑它与文件夹结构有关。我的猜测是,您正在观察早期错误的后期 react ...
关于c++ - 在 C++ 中使用嵌入式 lua 从外部目录加载文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4052698/