为什么C++看不到我的 lua 脚本文件?
Why C++ can't see my lua script file?
我在集成Lua和c++时有一个简单的问题。我有我的项目在Visual Studio:https://i.stack.imgur.com/nNw6H.png
,然后运行lua_init()函数:
bool lua_init(std::string &luaScriptName){
// Create the Lua state. Explanation from Lua 5.1 Ref. Manual:
globalL = luaL_newstate(); // 5.1 OK - Lua 5.0 or lower will probably require different commands
if( globalL == NULL )
return false;
// Loads all Lua standard libraries
luaL_openlibs(globalL); // 5.1 OK - Lua 5.0 or lower will require different commands
// This lot below could be replaced with luaL_dofile, but that just does: luaL_loadfile(..) || lua_pcall(..), which gives no reporting of error messages etc.
int initError = luaL_loadfile(globalL,luaScriptName.c_str());
switch( initError )
{
case 0:
// The file loaded okay, so call it as a protected function - to stop fatal errors from exiting the program
lua_pcall(globalL,0,0,0);
break;
case LUA_ERRFILE:
std::cerr<<"Cannot find / open lua script file: "<<luaScriptName<<std::endl<<"Skipping Lua init."<<std::endl;
break;
case LUA_ERRSYNTAX:
std::cerr<<"Syntax error during pre-compilation of script file: " <<luaScriptName<<std::endl<<"Skipping Lua init."<<std::endl;
break;
case LUA_ERRMEM:
// Treating this as fatal, since it means other Lua calls are unlikely to work either
std::cerr<<"Fatal memory allocation error during processing of script file: " <<luaScriptName<<std::endl;
return false;
}
return true;
}
但不知道我得到"无法找到/打开lua脚本文件:"错误
应该指向我的脚本吗?如何使用Visual Studio ?文件位于项目目录
您的代码将在二进制文件所在的位置执行,或者在调试模式下的目标目录中执行。因此,在执行二进制文件时,请检查lua文件是否可以访问。如果它与源文件在一起,当然,它是不可访问的。
相关文章:
- "configure"脚本如何检测我的系统是否支持某些头文件或 cpp 功能?
- 将数据从 c++ 文件连续发送到 Python 脚本以进行进一步处理
- 在使用PyInstaller冻结Python脚本时包含一个C++可执行文件
- 生成库失败:无法识别文件格式;作为链接器脚本处理
- Python 脚本到 c .obj 文件
- 当 PHP、C++ 和 shell 脚本尝试访问同一个文件时,如何避免错误?
- 嵌入批处理脚本文件并在C 控制台项目中运行
- C 正则是从脚本文件中提取变量
- 将参数从 Qt 传递到 shell 脚本文件
- 如何编写运行MingW的脚本文件
- 使用多个类对象将文本写入后脚本文件
- 如何在 c++ 中运行.sql脚本文件
- 如何在BB10级联中将数据传递到java脚本文件
- 在嵌入式八度C++中如何执行脚本文件?( "error: invalid call to script" )
- C++将字符数组解析为脚本文件(语法)
- 在资源编译器脚本文件中添加注释
- 如何加载一个脚本文件
- 如何在自定义shell中检测脚本文件与可执行文件
- '$OutDir'在Visual Studio的脚本文件中定义在哪里?
- 为什么C++看不到我的 lua 脚本文件?