Replaced the EXCEPT_GUARD macro for converting love exceptions into Lua errors with the new luax_catchexcept function, which takes lambda function arguments.

This commit is contained in:
Alex Szpakowski
2014-06-03 19:27:00 -03:00
parent 724bdbd296
commit dfa319e01a
45 changed files with 315 additions and 227 deletions
+27 -1
View File
@@ -68,8 +68,34 @@ int w_setTextInput(lua_State *L)
return 0;
}
template <typename T>
static int throwExcept(lua_State *L, const T& func)
{
bool should_error = false;
try
{
func();
}
catch (love::Exception &e)
{
should_error = true;
lua_pushstring(L, e.what());
}
if (should_error)
return luaL_error(L, lua_tostring(L, -1));
return 0;
}
int w_hasTextInput(lua_State *L)
{
bool asdf = true;
throwExcept(L, [&](){ instance->setTextInput(asdf); });
// throwExcept(L, L);
luax_pushboolean(L, instance->hasTextInput());
return 1;
}
@@ -89,7 +115,7 @@ extern "C" int luaopen_love_keyboard(lua_State *L)
{
if (instance == nullptr)
{
EXCEPT_GUARD(instance = new love::keyboard::sdl::Keyboard();)
luax_catchexcept(L, [&](){ instance = new love::keyboard::sdl::Keyboard(); });
}
else
instance->retain();