1
私はLuaをC++と統合するのに簡単な問題があります。 私は、Visual Studioでの私のプロジェクトがあります。 http://i.stack.imgur.com/nNw6H.pngC++で私のluaスクリプトファイルが見えないのはなぜですか?
を、私は私の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に指しておく必要がありますか?ファイルはプロジェクトディレクトリにあります。
お返事ありがとうございます。私はVisual Studioのワーキングディレクトリを変更して、そこにスクリプトを挿入しました。ファイルが見つからないというエラーは出ませんが、スクリプトは実行されません。コンソールにはHelloWorldが表示されません。 – Patryk
だから私の答えは正しかった、それをチェック! 2.私はあなたのスクリプトが何をすべきか分からない! 3.あなたのスクリプトがhello worldを印刷することになっているなら、あなたのlua vmの出力がコンソールであることを確認してください。私は本当にあなたのVM出力をあなたの標準出力に疑っていますが、自分で確認する必要があります。とにかく、エラーがなければ、スクリプトはロードされます(実行されますか?ロードするだけで十分かどうかは分かりません)ので、luaコードを見てください。 – Klaim
さて、私のスクリプトはちょうど 'print(" hello world ");' secondly:私はVSで新しいプロジェクトを作成しましたが(ogreAppWizardではなく普通のC++プロジェクトです)、同じファイルをコピーしてすべて実行しますちょうど良い。私は問題がより奇妙であると思う - あなたがルアのVMについて何か言ったように - どうすれば確認できますか? – Patryk