luabindを使用してLuaにバインドしたC++プログラムがあります。私は現在、luaスクリプトのデバッグを支援するためにluaとluabindが提供しなければならないエラー処理方法をテストしています。目的は、構文エラーやプログラミングミスが発生したときにluabindまたはluaに例外をスローさせて、それらをデバッグおよび修正できるようにすることです。
現在のところ、問題は、エラーメッセージや例外がスローされることなく、以下のスクリプトの実行が停止することです。したがって、より大きなプログラムでは、問題がどこにあるのか、そもそも問題があったとしてもわかりません。
関連するスニペットは次のとおりです。
Lua:(start.lua)
--complete file shown, this is meant to test the error handling of the C++ program
print("This is valid")
print(1234)
bad_function()
a = "meow"
b = 7
c = a + b
C ++:
Engine *callbackEngine;
int theCallback(lua_State *L) //This is so I can use my own function as an
//exception handler, pcall_log()
{
return callbackEngine->pcall_log(L);
}
void Engine::Run()
{
luabind::set_pcall_callback(&theCallback); //my own callback function,
//redirects to
//pcall_log() below
try {
luaL_dofile(L, "scripts/start.lua");
}
catch(luabind::error &sError) { //This never gets executed, noted by breakpoints
theCallback(L);
}
//etc...code not shown
int Engine::pcall_log(lua_State *L)
{
lua_Debug d;
lua_getstack( L,1,&d);
lua_getinfo( L, "Sln", &d);
lua_pop(L, 1);
stringstream ss;
ss.clear();
ss.str("");
ss << d.short_src;
ss << ": ";
ss << d.currentline;
ss << ": ";
if ( d.name != 0)
{
ss << d.namewhat;
ss << " ";
ss << d.name;
ss << ") ";
}
ss << lua_tostring(L, -1);
logger->log(ss.str().c_str(),ELL_ERROR);
return 1;
}
実行時の出力は次のとおりです。
This is valid
1234
予想どおりに例外をスローする代わりに、スクリプトの実行が停止します。luaがいつ例外をスローするかを制御する方法や、エラーを処理する別の方法はありますか?デバッグ情報を生成するようにロギング関数を設定していますが、ブレークポイントにより、上記のcatchステートメントが実行されていないことがわかります。
ありがとうございました!