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:
@@ -47,13 +47,16 @@ int w_newRasterizer(lua_State *L)
|
||||
love::image::ImageData *d = luax_checktype<love::image::ImageData>(L, 1, "ImageData", IMAGE_IMAGE_DATA_T);
|
||||
const char *g = luaL_checkstring(L, 2);
|
||||
std::string glyphs(g);
|
||||
EXCEPT_GUARD(t = instance->newRasterizer(d, glyphs);)
|
||||
luax_catchexcept(L, [&](){ t = instance->newRasterizer(d, glyphs); });
|
||||
}
|
||||
else if (lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_T) || luax_istype(L, 1, FILESYSTEM_FILE_DATA_T))
|
||||
{
|
||||
love::filesystem::FileData *d = love::filesystem::luax_getFileData(L, 1);
|
||||
int size = luaL_checkint(L, 2);
|
||||
EXCEPT_GUARD_FINALLY(t = instance->newRasterizer(d, size);, d->release();)
|
||||
luax_catchexcept(L,
|
||||
[&]() { t = instance->newRasterizer(d, size); },
|
||||
[&]() { d->release(); }
|
||||
);
|
||||
}
|
||||
|
||||
luax_pushtype(L, "Rasterizer", FONT_RASTERIZER_T, t);
|
||||
@@ -69,7 +72,7 @@ int w_newGlyphData(lua_State *L)
|
||||
if (lua_type(L, 2) == LUA_TSTRING)
|
||||
{
|
||||
std::string glyph = luax_checkstring(L, 2);
|
||||
EXCEPT_GUARD(t = instance->newGlyphData(r, glyph);)
|
||||
luax_catchexcept(L, [&](){ t = instance->newGlyphData(r, glyph); });
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -100,7 +103,7 @@ extern "C" int luaopen_love_font(lua_State *L)
|
||||
{
|
||||
if (instance == nullptr)
|
||||
{
|
||||
EXCEPT_GUARD(instance = new Font();)
|
||||
luax_catchexcept(L, [](){ instance = new Font(); });
|
||||
}
|
||||
else
|
||||
instance->retain();
|
||||
|
||||
@@ -64,7 +64,7 @@ int w_GlyphData_getGlyphString(lua_State *L)
|
||||
{
|
||||
GlyphData *t = luax_checkglyphdata(L, 1);
|
||||
|
||||
EXCEPT_GUARD(luax_pushstring(L, t->getGlyphString());)
|
||||
luax_catchexcept(L, [&](){ luax_pushstring(L, t->getGlyphString()); });
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ int w_Rasterizer_getGlyphData(lua_State *L)
|
||||
Rasterizer *t = luax_checkrasterizer(L, 1);
|
||||
GlyphData *g = 0;
|
||||
|
||||
EXCEPT_GUARD(
|
||||
luax_catchexcept(L, [&]() {
|
||||
// getGlyphData accepts a unicode character or a codepoint number.
|
||||
if (lua_type(L, 2) == LUA_TSTRING)
|
||||
{
|
||||
@@ -84,7 +84,7 @@ int w_Rasterizer_getGlyphData(lua_State *L)
|
||||
uint32 glyph = (uint32) luaL_checknumber(L, 2);
|
||||
g = t->getGlyphData(glyph);
|
||||
}
|
||||
)
|
||||
});
|
||||
|
||||
luax_pushtype(L, "GlyphData", FONT_GLYPH_DATA_T, g);
|
||||
return 1;
|
||||
@@ -106,7 +106,7 @@ int w_Rasterizer_hasGlyphs(lua_State *L)
|
||||
int count = lua_gettop(L) - 1;
|
||||
count = count < 1 ? 1 : count;
|
||||
|
||||
EXCEPT_GUARD(
|
||||
luax_catchexcept(L, [&]() {
|
||||
for (int i = 2; i < count + 2; i++)
|
||||
{
|
||||
if (lua_type(L, i) == LUA_TSTRING)
|
||||
@@ -117,7 +117,7 @@ int w_Rasterizer_hasGlyphs(lua_State *L)
|
||||
if (!hasglyph)
|
||||
break;
|
||||
}
|
||||
)
|
||||
});
|
||||
|
||||
luax_pushboolean(L, hasglyph);
|
||||
return 1;
|
||||
|
||||
Reference in New Issue
Block a user