简体   繁体   English

为什么C ++看不到我的lua脚本文件?

[英]Why C++ can't see my lua script file?

I have a simple problem with integrating Lua with c++. 我在将Lua与c ++集成时遇到一个简单的问题。 I have my project in Visual Studio : http://i.stack.imgur.com/nNw6H.png 我在Visual Studio中有我的项目: http : //i.stack.imgur.com/nNw6H.png

and I run my lua_init() function : 然后运行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;

} }

but don't know I get the "Cannot find / open lua script file:" error 但不知道我得到“找不到/打开lua脚本文件:”错误

should I point somehow my script.lua to the Visual Studio ? 我应该以某种方式将我的script.lua指向Visual Studio吗? the file is located in the project directory. 该文件位于项目目录中。

Your code will exectue where the binary is, or in the target directory in Debugging Mode. 您的代码将显示二进制文件所在的位置,或在调试模式下的目标目录中。 So check that your lua file is accessible to your binary when you execute it. 因此,在执行二进制文件时,请检查您的lua文件是否可被二进制文件访问。 If it's with your source files, sure, it's not accessible. 如果与您的源文件一起使用,请确保该文件不可访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM