Allow for failed function calls from lua.

This commit is contained in:
ThePhD 2015-10-22 06:49:53 -04:00
parent 93fe7443f0
commit 7f4d8d8f89

View File

@ -120,7 +120,31 @@ private:
function_result invoke(indices<>, types<>, std::ptrdiff_t n) const { function_result invoke(indices<>, types<>, std::ptrdiff_t n) const {
const int stacksize = lua_gettop(state()); const int stacksize = lua_gettop(state());
const int firstreturn = std::max(0, stacksize - static_cast<int>(n) - 1); const int firstreturn = std::max(0, stacksize - static_cast<int>(n) - 1);
int code = luacodecall(n, LUA_MULTRET); int code = LUA_OK;
try {
code = luacodecall( n, LUA_MULTRET );
}
// Handle C++ errors thrown from C++ functions bound inside of lua
catch ( const std::exception& error ) {
code = LUA_ERRRUN;
stack::push( state(), error.what() );
}
// TODO: handle idiots?
/*catch ( const char* error ) {
code = LUA_ERRRUN;
stack::push( state(), error );
}
catch ( const std::string& error ) {
code = LUA_ERRRUN;
stack::push( state(), error );
}
catch ( ... ) {
code = LUA_ERRRUN;
stack::push( state(), "[sol] an unknownable runtime exception occurred" );
}*/
catch ( ... ) {
throw;
}
const int poststacksize = lua_gettop(state()); const int poststacksize = lua_gettop(state());
const int returncount = poststacksize - firstreturn; const int returncount = poststacksize - firstreturn;
return function_result(state(), firstreturn + 1, returncount, code); return function_result(state(), firstreturn + 1, returncount, code);