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
+10 -4
View File
@@ -45,7 +45,7 @@ int w_newImageData(lua_State *L)
return luaL_error(L, "Invalid image size.");
ImageData *t = nullptr;
EXCEPT_GUARD(t = instance->newImageData(w, h);)
luax_catchexcept(L, [&](){ t = instance->newImageData(w, h); });
luax_pushtype(L, "ImageData", IMAGE_IMAGE_DATA_T, t);
return 1;
@@ -55,7 +55,10 @@ int w_newImageData(lua_State *L)
love::filesystem::FileData *data = love::filesystem::luax_getFileData(L, 1);
ImageData *t = nullptr;
EXCEPT_GUARD_FINALLY(t = instance->newImageData(data);, data->release();)
luax_catchexcept(L,
[&]() { t = instance->newImageData(data); },
[&]() { data->release(); }
);
luax_pushtype(L, "ImageData", IMAGE_IMAGE_DATA_T, t);
return 1;
@@ -66,7 +69,10 @@ int w_newCompressedData(lua_State *L)
love::filesystem::FileData *data = love::filesystem::luax_getFileData(L, 1);
CompressedData *t = nullptr;
EXCEPT_GUARD_FINALLY(t = instance->newCompressedData(data);, data->release();)
luax_catchexcept(L,
[&]() { t = instance->newCompressedData(data); },
[&]() { data->release(); }
);
luax_pushtype(L, "CompressedData", IMAGE_COMPRESSED_DATA_T, t);
return 1;
@@ -102,7 +108,7 @@ extern "C" int luaopen_love_image(lua_State *L)
{
if (instance == nullptr)
{
EXCEPT_GUARD(instance = new love::image::magpie::Image();)
luax_catchexcept(L, [&](){ instance = new love::image::magpie::Image(); });
}
else
instance->retain();