mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user