簡體   English   中英

為什么C ++看不到我的lua腳本文件?

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

我在將Lua與c ++集成時遇到一個簡單的問題。 我在Visual Studio中有我的項目: http : //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腳本文件:”錯誤

我應該以某種方式將我的script.lua指向Visual Studio嗎? 該文件位於項目目錄中。

您的代碼將顯示二進制文件所在的位置,或在調試模式下的目標目錄中。 因此,在執行二進制文件時,請檢查您的lua文件是否可被二進制文件訪問。 如果與您的源文件一起使用,請確保該文件不可訪問。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM