首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么C++看不到我的lua脚本文件?

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

Stack Overflow用户
提问于 2011-04-17 02:54:37
回答 1查看 1.6K关注 0票数 2

我在集成Lua和c++时遇到了一个简单的问题。我在Visual Studio中有一个项目:http://i.stack.imgur.com/nNw6H.png

然后运行我的lua_init()函数:

代码语言:javascript
复制
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脚本文件:”错误

我应该以某种方式将script.lua指向Visual Studio吗?该文件位于项目目录中。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-04-17 03:52:12

您的代码将在二进制文件所在的位置执行,或者在调试模式下的目标目录中执行。因此,在执行lua文件时,请检查二进制文件是否可以访问它。如果它和你的源文件在一起,当然,它是不可访问的。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5688781

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档