Browse Source

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

Alex Szpakowski 11 years ago
parent
commit
dfa319e01a
45 changed files with 315 additions and 227 deletions
  1. 46 24
      src/common/runtime.h
  2. 1 1
      src/modules/audio/wrap_Source.cpp
  3. 1 1
      src/modules/event/sdl/wrap_Event.cpp
  4. 1 1
      src/modules/filesystem/wrap_File.cpp
  5. 7 23
      src/modules/filesystem/wrap_Filesystem.cpp
  6. 7 4
      src/modules/font/freetype/wrap_Font.cpp
  7. 1 1
      src/modules/font/wrap_GlyphData.cpp
  8. 4 4
      src/modules/font/wrap_Rasterizer.cpp
  9. 2 2
      src/modules/graphics/opengl/wrap_Canvas.cpp
  10. 6 6
      src/modules/graphics/opengl/wrap_Font.cpp
  11. 46 26
      src/modules/graphics/opengl/wrap_Graphics.cpp
  12. 2 2
      src/modules/graphics/opengl/wrap_Image.cpp
  13. 6 6
      src/modules/graphics/opengl/wrap_Mesh.cpp
  14. 3 3
      src/modules/graphics/opengl/wrap_ParticleSystem.cpp
  15. 5 5
      src/modules/graphics/opengl/wrap_Shader.cpp
  16. 6 6
      src/modules/graphics/opengl/wrap_SpriteBatch.cpp
  17. 1 1
      src/modules/graphics/opengl/wrap_Texture.cpp
  18. 1 1
      src/modules/image/CompressedData.cpp
  19. 7 6
      src/modules/image/wrap_CompressedData.cpp
  20. 10 4
      src/modules/image/wrap_Image.cpp
  21. 3 3
      src/modules/image/wrap_ImageData.cpp
  22. 3 3
      src/modules/joystick/sdl/wrap_JoystickModule.cpp
  23. 27 1
      src/modules/keyboard/wrap_Keyboard.cpp
  24. 7 7
      src/modules/math/wrap_BezierCurve.cpp
  25. 4 4
      src/modules/math/wrap_Math.cpp
  26. 2 2
      src/modules/math/wrap_RandomGenerator.cpp
  27. 3 3
      src/modules/mouse/wrap_Mouse.cpp
  28. 2 2
      src/modules/physics/box2d/Physics.cpp
  29. 13 13
      src/modules/physics/box2d/wrap_Body.cpp
  30. 4 4
      src/modules/physics/box2d/wrap_ChainShape.cpp
  31. 3 3
      src/modules/physics/box2d/wrap_Fixture.cpp
  32. 2 2
      src/modules/physics/box2d/wrap_FrictionJoint.cpp
  33. 1 1
      src/modules/physics/box2d/wrap_GearJoint.cpp
  34. 1 1
      src/modules/physics/box2d/wrap_Joint.cpp
  35. 3 3
      src/modules/physics/box2d/wrap_MotorJoint.cpp
  36. 44 24
      src/modules/physics/box2d/wrap_Physics.cpp
  37. 3 3
      src/modules/physics/box2d/wrap_PrismaticJoint.cpp
  38. 3 3
      src/modules/physics/box2d/wrap_RevoluteJoint.cpp
  39. 1 1
      src/modules/physics/box2d/wrap_Shape.cpp
  40. 7 7
      src/modules/physics/box2d/wrap_World.cpp
  41. 7 4
      src/modules/sound/wrap_Sound.cpp
  42. 2 2
      src/modules/sound/wrap_SoundData.cpp
  43. 1 1
      src/modules/thread/wrap_ThreadModule.cpp
  44. 1 1
      src/modules/timer/wrap_Timer.cpp
  45. 5 2
      src/modules/window/wrap_Window.cpp

+ 46 - 24
src/common/runtime.h

@@ -33,6 +33,9 @@ extern "C" {
 	#include <lauxlib.h>
 	#include <lauxlib.h>
 }
 }
 
 
+// C++
+#include <exception>
+
 namespace love
 namespace love
 {
 {
 
 
@@ -471,36 +474,55 @@ T *luax_totype(lua_State *L, int idx, const char * /* name */, love::bits /* typ
 Type luax_type(lua_State *L, int idx);
 Type luax_type(lua_State *L, int idx);
 
 
 /**
 /**
- * Macro for converting a LOVE exception into a Lua error.
+ * Converts any exceptions thrown by the passed lambda function into a Lua error.
  * lua_error (and luaL_error) cannot be called from inside the exception handler
  * lua_error (and luaL_error) cannot be called from inside the exception handler
  * because they use longjmp, which causes undefined behaviour when the
  * because they use longjmp, which causes undefined behaviour when the
  * destructor of the exception would have been called.
  * destructor of the exception would have been called.
  **/
  **/
-#define EXCEPT_GUARD(A) \
-{ \
-	bool should_error = false; \
-	try { A } \
-	catch (love::Exception &e) \
-	{ \
-		should_error = true; \
-		lua_pushstring(L, e.what()); \
-	} \
-	if (should_error) \
-		return luaL_error(L, "%s", lua_tostring(L, -1)); \
+template <typename T>
+int luax_catchexcept(lua_State *L, const T& func)
+{
+	bool should_error = false;
+
+	try
+	{
+		func();
+	}
+	catch (const std::exception &e)
+	{
+		should_error = true;
+		lua_pushstring(L, e.what());
+	}
+
+	if (should_error)
+		return luaL_error(L, "%s", lua_tostring(L, -1));
+
+	return 0;
+
 }
 }
 
 
-#define EXCEPT_GUARD_FINALLY(A, B) \
-{ \
-	bool should_error = false; \
-	try { A } \
-	catch (love::Exception &e) \
-	{ \
-		should_error = true; \
-		lua_pushstring(L, e.what()); \
-	} \
-	{ B } \
-	if (should_error) \
-		return luaL_error(L, "%s", lua_tostring(L, -1)); \
+template <typename T, typename F>
+int luax_catchexcept(lua_State *L, const T& func, const F& finallyfunc)
+{
+	bool should_error = false;
+
+	try
+	{
+		func();
+	}
+	catch (const std::exception &e)
+	{
+		should_error = true;
+		lua_pushstring(L, e.what());
+	}
+
+	finallyfunc();
+
+	if (should_error)
+		return luaL_error(L, "%s", lua_tostring(L, -1));
+	
+	return 0;
+	
 }
 }
 
 
 } // love
 } // love

+ 1 - 1
src/modules/audio/wrap_Source.cpp

@@ -36,7 +36,7 @@ int w_Source_clone(lua_State *L)
 {
 {
 	Source *t = luax_checksource(L, 1);
 	Source *t = luax_checksource(L, 1);
 	Source *clone = nullptr;
 	Source *clone = nullptr;
-	EXCEPT_GUARD(clone = t->clone();)
+	luax_catchexcept(L, [&](){ clone = t->clone(); });
 	luax_pushtype(L, "Source", AUDIO_SOURCE_T, clone);
 	luax_pushtype(L, "Source", AUDIO_SOURCE_T, clone);
 	return 1;
 	return 1;
 }
 }

+ 1 - 1
src/modules/event/sdl/wrap_Event.cpp

@@ -123,7 +123,7 @@ extern "C" int luaopen_love_event(lua_State *L)
 {
 {
 	if (instance == 0)
 	if (instance == 0)
 	{
 	{
-		EXCEPT_GUARD(instance = new Event();)
+		luax_catchexcept(L, [&](){ instance = new Event(); });
 	}
 	}
 	else
 	else
 		instance->retain();
 		instance->retain();

+ 1 - 1
src/modules/filesystem/wrap_File.cpp

@@ -236,7 +236,7 @@ int w_File_lines(lua_State *L)
 			file->close();
 			file->close();
 
 
 		bool success = false;
 		bool success = false;
-		EXCEPT_GUARD(success = file->open(File::READ);)
+		luax_catchexcept(L, [&](){ success = file->open(File::READ); });
 
 
 		if (!success)
 		if (!success)
 			return luaL_error(L, "Could not open file.");
 			return luaL_error(L, "Could not open file.");

+ 7 - 23
src/modules/filesystem/wrap_Filesystem.cpp

@@ -45,7 +45,7 @@ bool hack_setupWriteDirectory()
 int w_init(lua_State *L)
 int w_init(lua_State *L)
 {
 {
 	const char *arg0 = luaL_checkstring(L, 1);
 	const char *arg0 = luaL_checkstring(L, 1);
-	EXCEPT_GUARD(instance->init(arg0);)
+	luax_catchexcept(L, [&](){ instance->init(arg0); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -177,26 +177,10 @@ FileData *luax_getFileData(lua_State *L, int idx)
 
 
 	if (file)
 	if (file)
 	{
 	{
-		bool should_error = false;
-
-		// We don't use EXCEPT_GUARD_FINALLY because it returns int.
-		try
-		{
-			data = file->read();
-		}
-		catch (love::Exception &e)
-		{
-			should_error = true;
-			lua_pushstring(L, e.what());
-		}
-
-		file->release();
-
-		if (should_error)
-		{
-			luaL_error(L, "%s", lua_tostring(L, -1));
-			return nullptr; // Never reached.
-		}
+		luax_catchexcept(L,
+			[&]() { data = file->read(); },
+			[&]() { file->release(); }
+		);
 	}
 	}
 
 
 	return data;
 	return data;
@@ -416,7 +400,7 @@ int w_lines(lua_State *L)
 		file = instance->newFile(lua_tostring(L, 1));
 		file = instance->newFile(lua_tostring(L, 1));
 		bool success = false;
 		bool success = false;
 
 
-		EXCEPT_GUARD(success = file->open(File::READ);)
+		luax_catchexcept(L, [&](){ success = file->open(File::READ); });
 
 
 		if (!success)
 		if (!success)
 			return luaL_error(L, "Could not open file.");
 			return luaL_error(L, "Could not open file.");
@@ -676,7 +660,7 @@ extern "C" int luaopen_love_filesystem(lua_State *L)
 {
 {
 	if (instance == 0)
 	if (instance == 0)
 	{
 	{
-		EXCEPT_GUARD(instance = new physfs::Filesystem();)
+		luax_catchexcept(L, [&](){ instance = new physfs::Filesystem(); });
 	}
 	}
 	else
 	else
 		instance->retain();
 		instance->retain();

+ 7 - 4
src/modules/font/freetype/wrap_Font.cpp

@@ -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);
 		love::image::ImageData *d = luax_checktype<love::image::ImageData>(L, 1, "ImageData", IMAGE_IMAGE_DATA_T);
 		const char *g = luaL_checkstring(L, 2);
 		const char *g = luaL_checkstring(L, 2);
 		std::string glyphs(g);
 		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))
 	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);
 		love::filesystem::FileData *d = love::filesystem::luax_getFileData(L, 1);
 		int size = luaL_checkint(L, 2);
 		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);
 	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)
 	if (lua_type(L, 2) == LUA_TSTRING)
 	{
 	{
 		std::string glyph = luax_checkstring(L, 2);
 		std::string glyph = luax_checkstring(L, 2);
-		EXCEPT_GUARD(t = instance->newGlyphData(r, glyph);)
+		luax_catchexcept(L, [&](){ t = instance->newGlyphData(r, glyph); });
 	}
 	}
 	else
 	else
 	{
 	{
@@ -100,7 +103,7 @@ extern "C" int luaopen_love_font(lua_State *L)
 {
 {
 	if (instance == nullptr)
 	if (instance == nullptr)
 	{
 	{
-		EXCEPT_GUARD(instance = new Font();)
+		luax_catchexcept(L, [](){ instance = new Font(); });
 	}
 	}
 	else
 	else
 		instance->retain();
 		instance->retain();

+ 1 - 1
src/modules/font/wrap_GlyphData.cpp

@@ -64,7 +64,7 @@ int w_GlyphData_getGlyphString(lua_State *L)
 {
 {
 	GlyphData *t = luax_checkglyphdata(L, 1);
 	GlyphData *t = luax_checkglyphdata(L, 1);
 
 
-	EXCEPT_GUARD(luax_pushstring(L, t->getGlyphString());)
+	luax_catchexcept(L, [&](){ luax_pushstring(L, t->getGlyphString()); });
 	return 1;
 	return 1;
 }
 }
 
 

+ 4 - 4
src/modules/font/wrap_Rasterizer.cpp

@@ -72,7 +72,7 @@ int w_Rasterizer_getGlyphData(lua_State *L)
 	Rasterizer *t = luax_checkrasterizer(L, 1);
 	Rasterizer *t = luax_checkrasterizer(L, 1);
 	GlyphData *g = 0;
 	GlyphData *g = 0;
 
 
-	EXCEPT_GUARD(
+	luax_catchexcept(L, [&]() {
 		// getGlyphData accepts a unicode character or a codepoint number.
 		// getGlyphData accepts a unicode character or a codepoint number.
 		if (lua_type(L, 2) == LUA_TSTRING)
 		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);
 			uint32 glyph = (uint32) luaL_checknumber(L, 2);
 			g = t->getGlyphData(glyph);
 			g = t->getGlyphData(glyph);
 		}
 		}
-	)
+	});
 
 
 	luax_pushtype(L, "GlyphData", FONT_GLYPH_DATA_T, g);
 	luax_pushtype(L, "GlyphData", FONT_GLYPH_DATA_T, g);
 	return 1;
 	return 1;
@@ -106,7 +106,7 @@ int w_Rasterizer_hasGlyphs(lua_State *L)
 	int count = lua_gettop(L) - 1;
 	int count = lua_gettop(L) - 1;
 	count = count < 1 ? 1 : count;
 	count = count < 1 ? 1 : count;
 
 
-	EXCEPT_GUARD(
+	luax_catchexcept(L, [&]() {
 		for (int i = 2; i < count + 2; i++)
 		for (int i = 2; i < count + 2; i++)
 		{
 		{
 			if (lua_type(L, i) == LUA_TSTRING)
 			if (lua_type(L, i) == LUA_TSTRING)
@@ -117,7 +117,7 @@ int w_Rasterizer_hasGlyphs(lua_State *L)
 			if (!hasglyph)
 			if (!hasglyph)
 				break;
 				break;
 		}
 		}
-	)
+	});
 
 
 	luax_pushboolean(L, hasglyph);
 	luax_pushboolean(L, hasglyph);
 	return 1;
 	return 1;

+ 2 - 2
src/modules/graphics/opengl/wrap_Canvas.cpp

@@ -40,7 +40,7 @@ int w_Canvas_renderTo(lua_State *L)
 	// Save the current Canvas so we can restore it when we're done.
 	// Save the current Canvas so we can restore it when we're done.
 	Canvas *oldcanvas = Canvas::current;
 	Canvas *oldcanvas = Canvas::current;
 
 
-	EXCEPT_GUARD(canvas->startGrab();)
+	luax_catchexcept(L, [&](){ canvas->startGrab(); });
 
 
 	lua_settop(L, 2); // make sure the function is on top of the stack
 	lua_settop(L, 2); // make sure the function is on top of the stack
 	lua_call(L, 0, 0);
 	lua_call(L, 0, 0);
@@ -69,7 +69,7 @@ int w_Canvas_getPixel(lua_State * L)
 	int y = luaL_checkint(L, 3);
 	int y = luaL_checkint(L, 3);
 	unsigned char c[4];
 	unsigned char c[4];
 
 
-	EXCEPT_GUARD(canvas->getPixel(c, x, y);)
+	luax_catchexcept(L, [&](){ canvas->getPixel(c, x, y); });
 
 
 	lua_pushnumber(L, c[0]);
 	lua_pushnumber(L, c[0]);
 	lua_pushnumber(L, c[1]);
 	lua_pushnumber(L, c[1]);

+ 6 - 6
src/modules/graphics/opengl/wrap_Font.cpp

@@ -45,7 +45,7 @@ int w_Font_getWidth(lua_State *L)
 	Font *t = luax_checkfont(L, 1);
 	Font *t = luax_checkfont(L, 1);
 	const char *str = luaL_checkstring(L, 2);
 	const char *str = luaL_checkstring(L, 2);
 
 
-	EXCEPT_GUARD(lua_pushinteger(L, t->getWidth(str));)
+	luax_catchexcept(L, [&](){ lua_pushinteger(L, t->getWidth(str)); });
 	return 1;
 	return 1;
 }
 }
 
 
@@ -56,10 +56,10 @@ int w_Font_getWrap(lua_State *L)
 	float wrap = (float) luaL_checknumber(L, 3);
 	float wrap = (float) luaL_checknumber(L, 3);
 	int max_width = 0, numlines = 0;
 	int max_width = 0, numlines = 0;
 
 
-	EXCEPT_GUARD(
+	luax_catchexcept(L, [&]() {
 		std::vector<std::string> lines = t->getWrap(str, wrap, &max_width);
 		std::vector<std::string> lines = t->getWrap(str, wrap, &max_width);
 		numlines = lines.size();
 		numlines = lines.size();
-	)
+	});
 
 
 	lua_pushinteger(L, max_width);
 	lua_pushinteger(L, max_width);
 	lua_pushinteger(L, numlines);
 	lua_pushinteger(L, numlines);
@@ -96,7 +96,7 @@ int w_Font_setFilter(lua_State *L)
 
 
 	f.anisotropy = (float) luaL_optnumber(L, 4, 1.0);
 	f.anisotropy = (float) luaL_optnumber(L, 4, 1.0);
 
 
-	EXCEPT_GUARD(t->setFilter(f);)
+	luax_catchexcept(L, [&](){ t->setFilter(f); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -143,7 +143,7 @@ int w_Font_hasGlyphs(lua_State *L)
 	int count = lua_gettop(L) - 1;
 	int count = lua_gettop(L) - 1;
 	count = count < 1 ? 1 : count;
 	count = count < 1 ? 1 : count;
 
 
-	EXCEPT_GUARD(
+	luax_catchexcept(L, [&]() {
 		 for (int i = 2; i < count + 2; i++)
 		 for (int i = 2; i < count + 2; i++)
 		 {
 		 {
 			 if (lua_type(L, i) == LUA_TSTRING)
 			 if (lua_type(L, i) == LUA_TSTRING)
@@ -154,7 +154,7 @@ int w_Font_hasGlyphs(lua_State *L)
 			 if (!hasglyph)
 			 if (!hasglyph)
 				 break;
 				 break;
 		 }
 		 }
-	 )
+	});
 
 
 	luax_pushboolean(L, hasglyph);
 	luax_pushboolean(L, hasglyph);
 	return 1;
 	return 1;

+ 46 - 26
src/modules/graphics/opengl/wrap_Graphics.cpp

@@ -176,11 +176,17 @@ int w_newImage(lua_State *L)
 
 
 		if (image->isCompressed(fdata))
 		if (image->isCompressed(fdata))
 		{
 		{
-			EXCEPT_GUARD_FINALLY(cdata = image->newCompressedData(fdata);, fdata->release();)
+			luax_catchexcept(L,
+				[&]() { cdata = image->newCompressedData(fdata); },
+				[&]() { fdata->release(); }
+			);
 		}
 		}
 		else
 		else
 		{
 		{
-			EXCEPT_GUARD_FINALLY(data = image->newImageData(fdata);, fdata->release();)
+			luax_catchexcept(L,
+				[&]() { data = image->newImageData(fdata); },
+				[&]() { fdata->release(); }
+			);
 		}
 		}
 
 
 		// Lua's GC won't release the image data, so we should do it ourselves.
 		// Lua's GC won't release the image data, so we should do it ourselves.
@@ -196,20 +202,20 @@ int w_newImage(lua_State *L)
 
 
 	// Create the image.
 	// Create the image.
 	Image *image = nullptr;
 	Image *image = nullptr;
-	EXCEPT_GUARD_FINALLY(
-		{
+	luax_catchexcept(L,
+		[&]() {
 			if (cdata)
 			if (cdata)
 				image = instance->newImage(cdata, format);
 				image = instance->newImage(cdata, format);
 			else if (data)
 			else if (data)
 				image = instance->newImage(data, format);
 				image = instance->newImage(data, format);
 		},
 		},
-		{
+		[&]() {
 			if (releasedata && data)
 			if (releasedata && data)
 				data->release();
 				data->release();
 			else if (releasedata && cdata)
 			else if (releasedata && cdata)
 				cdata->release();
 				cdata->release();
 		}
 		}
-	)
+	);
 
 
 	if (image == nullptr)
 	if (image == nullptr)
 		return luaL_error(L, "Could not load image.");
 		return luaL_error(L, "Could not load image.");
@@ -247,7 +253,9 @@ int w_newFont(lua_State *L)
 	love::font::Rasterizer *rasterizer = luax_checktype<love::font::Rasterizer>(L, 1, "Rasterizer", FONT_RASTERIZER_T);
 	love::font::Rasterizer *rasterizer = luax_checktype<love::font::Rasterizer>(L, 1, "Rasterizer", FONT_RASTERIZER_T);
 
 
 	Font *font = 0;
 	Font *font = 0;
-	EXCEPT_GUARD(font = instance->newFont(rasterizer, instance->getDefaultFilter());)
+	luax_catchexcept(L, [&]() {
+		font = instance->newFont(rasterizer, instance->getDefaultFilter()); }
+	);
 
 
 	if (font == 0)
 	if (font == 0)
 		return luaL_error(L, "Could not load font.");
 		return luaL_error(L, "Could not load font.");
@@ -311,7 +319,9 @@ int w_newSpriteBatch(lua_State *L)
 	}
 	}
 
 
 	SpriteBatch *t = nullptr;
 	SpriteBatch *t = nullptr;
-	EXCEPT_GUARD(t = instance->newSpriteBatch(texture, size, usage);)
+	luax_catchexcept(L,
+		[&](){ t = instance->newSpriteBatch(texture, size, usage); }
+	);
 
 
 	luax_pushtype(L, "SpriteBatch", GRAPHICS_SPRITE_BATCH_T, t);
 	luax_pushtype(L, "SpriteBatch", GRAPHICS_SPRITE_BATCH_T, t);
 	return 1;
 	return 1;
@@ -325,7 +335,9 @@ int w_newParticleSystem(lua_State *L)
 	if (size < 1.0 || size > ParticleSystem::MAX_PARTICLES)
 	if (size < 1.0 || size > ParticleSystem::MAX_PARTICLES)
 		return luaL_error(L, "Invalid ParticleSystem size");	
 		return luaL_error(L, "Invalid ParticleSystem size");	
 
 
-	EXCEPT_GUARD(t = instance->newParticleSystem(texture, int(size));)
+	luax_catchexcept(L,
+		[&](){ t = instance->newParticleSystem(texture, int(size)); }
+	);
 
 
 	luax_pushtype(L, "ParticleSystem", GRAPHICS_PARTICLE_SYSTEM_T, t);
 	luax_pushtype(L, "ParticleSystem", GRAPHICS_PARTICLE_SYSTEM_T, t);
 	return 1;
 	return 1;
@@ -344,7 +356,9 @@ int w_newCanvas(lua_State *L)
 		return luaL_error(L, "Invalid Canvas format: %s", str);
 		return luaL_error(L, "Invalid Canvas format: %s", str);
 
 
 	Canvas *canvas = nullptr;
 	Canvas *canvas = nullptr;
-	EXCEPT_GUARD(canvas = instance->newCanvas(width, height, format, fsaa);)
+	luax_catchexcept(L,
+		[&](){ canvas = instance->newCanvas(width, height, format, fsaa); }
+	);
 
 
 	if (canvas == nullptr)
 	if (canvas == nullptr)
 		return luaL_error(L, "Canvas not created, but no error thrown. I don't even...");
 		return luaL_error(L, "Canvas not created, but no error thrown. I don't even...");
@@ -515,13 +529,13 @@ int w_newMesh(lua_State *L)
 			vertices.push_back(v);
 			vertices.push_back(v);
 		}
 		}
 
 
-		EXCEPT_GUARD(t = instance->newMesh(vertices, mode);)
+		luax_catchexcept(L, [&](){ t = instance->newMesh(vertices, mode); });
 		t->setVertexColors(use_colors);
 		t->setVertexColors(use_colors);
 	}
 	}
 	else
 	else
 	{
 	{
 		int count = luaL_checkint(L, 1);
 		int count = luaL_checkint(L, 1);
-		EXCEPT_GUARD(t = instance->newMesh(count, mode);)
+		luax_catchexcept(L, [&](){ t = instance->newMesh(count, mode); });
 	}
 	}
 
 
 	if (tex)
 	if (tex)
@@ -660,7 +674,7 @@ int w_setBlendMode(lua_State *L)
 	if (!Graphics::getConstant(str, mode))
 	if (!Graphics::getConstant(str, mode))
 		return luaL_error(L, "Invalid blend mode: %s", str);
 		return luaL_error(L, "Invalid blend mode: %s", str);
 
 
-	EXCEPT_GUARD(instance->setBlendMode(mode);)
+	luax_catchexcept(L, [&](){ instance->setBlendMode(mode); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -669,7 +683,7 @@ int w_getBlendMode(lua_State *L)
 	const char *str;
 	const char *str;
 	Graphics::BlendMode mode;
 	Graphics::BlendMode mode;
 
 
-	EXCEPT_GUARD(mode = instance->getBlendMode();)
+	luax_catchexcept(L, [&](){ mode = instance->getBlendMode(); });
 
 
 	if (!Graphics::getConstant(mode, str))
 	if (!Graphics::getConstant(mode, str))
 		return luaL_error(L, "Unknown blend mode");
 		return luaL_error(L, "Unknown blend mode");
@@ -867,7 +881,7 @@ int w_newScreenshot(lua_State *L)
 	bool copyAlpha = luax_optboolean(L, 1, false);
 	bool copyAlpha = luax_optboolean(L, 1, false);
 	love::image::ImageData *i = 0;
 	love::image::ImageData *i = 0;
 
 
-	EXCEPT_GUARD(i = instance->newScreenshot(image, copyAlpha);)
+	luax_catchexcept(L, [&](){ i = instance->newScreenshot(image, copyAlpha); });
 
 
 	luax_pushtype(L, "ImageData", IMAGE_IMAGE_DATA_T, i);
 	luax_pushtype(L, "ImageData", IMAGE_IMAGE_DATA_T, i);
 	return 1;
 	return 1;
@@ -911,12 +925,12 @@ int w_setCanvas(lua_State *L)
 			attachments.push_back(luax_checkcanvas(L, i));
 			attachments.push_back(luax_checkcanvas(L, i));
 	}
 	}
 
 
-	EXCEPT_GUARD(
+	luax_catchexcept(L, [&]() {
 		if (attachments.size() > 0)
 		if (attachments.size() > 0)
 			canvas->startGrab(attachments);
 			canvas->startGrab(attachments);
 		else
 		else
 			canvas->startGrab();
 			canvas->startGrab();
-	)
+	});
 
 
 	return 0;
 	return 0;
 }
 }
@@ -1055,10 +1069,12 @@ int w_getRendererInfo(lua_State *L)
 {
 {
 	std::string name, version, vendor, device;
 	std::string name, version, vendor, device;
 
 
-	EXCEPT_GUARD(name = instance->getRendererInfo(Graphics::RENDERER_INFO_NAME);)
-	EXCEPT_GUARD(version = instance->getRendererInfo(Graphics::RENDERER_INFO_VERSION);)
-	EXCEPT_GUARD(vendor = instance->getRendererInfo(Graphics::RENDERER_INFO_VENDOR);)
-	EXCEPT_GUARD(device = instance->getRendererInfo(Graphics::RENDERER_INFO_DEVICE);)
+	luax_catchexcept(L, [&]() {
+		name = instance->getRendererInfo(Graphics::RENDERER_INFO_NAME);
+		version = instance->getRendererInfo(Graphics::RENDERER_INFO_VERSION);
+		vendor = instance->getRendererInfo(Graphics::RENDERER_INFO_VENDOR);
+		device = instance->getRendererInfo(Graphics::RENDERER_INFO_DEVICE);
+	});
 
 
 	luax_pushstring(L, name);
 	luax_pushstring(L, name);
 	luax_pushstring(L, version);
 	luax_pushstring(L, version);
@@ -1134,7 +1150,9 @@ int w_print(lua_State *L)
 	float kx = (float)luaL_optnumber(L, 9, 0.0f);
 	float kx = (float)luaL_optnumber(L, 9, 0.0f);
 	float ky = (float)luaL_optnumber(L, 10, 0.0f);
 	float ky = (float)luaL_optnumber(L, 10, 0.0f);
 
 
-	EXCEPT_GUARD(instance->print(str, x, y, angle, sx, sy, ox, oy, kx,ky);)
+	luax_catchexcept(L,
+		[&](){ instance->print(str, x, y, angle, sx, sy, ox, oy, kx,ky); }
+	);
 	return 0;
 	return 0;
 }
 }
 
 
@@ -1170,7 +1188,9 @@ int w_printf(lua_State *L)
 		ky = (float) luaL_optnumber(L, 12, 0.0f);
 		ky = (float) luaL_optnumber(L, 12, 0.0f);
 	}
 	}
 
 
-	EXCEPT_GUARD(instance->printf(str, x, y, wrap, align, angle, sx, sy, ox, oy, kx, ky);)
+	luax_catchexcept(L,
+		[&](){ instance->printf(str, x, y, wrap, align, angle, sx, sy, ox, oy, kx, ky); }
+	);
 	return 0;
 	return 0;
 }
 }
 
 
@@ -1326,13 +1346,13 @@ int w_polygon(lua_State *L)
 
 
 int w_push(lua_State *L)
 int w_push(lua_State *L)
 {
 {
-	EXCEPT_GUARD(instance->push();)
+	luax_catchexcept(L, [&](){ instance->push(); });
 	return 0;
 	return 0;
 }
 }
 
 
 int w_pop(lua_State *L)
 int w_pop(lua_State *L)
 {
 {
-	EXCEPT_GUARD(instance->pop();)
+	luax_catchexcept(L, [&](){ instance->pop(); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -1488,7 +1508,7 @@ extern "C" int luaopen_love_graphics(lua_State *L)
 {
 {
 	if (instance == 0)
 	if (instance == 0)
 	{
 	{
-		EXCEPT_GUARD(instance = new Graphics();)
+		luax_catchexcept(L, [&](){ instance = new Graphics(); });
 	}
 	}
 	else
 	else
 		instance->retain();
 		instance->retain();

+ 2 - 2
src/modules/graphics/opengl/wrap_Image.cpp

@@ -47,7 +47,7 @@ int w_Image_setMipmapFilter(lua_State *L)
 			return luaL_error(L, "Invalid filter mode: %s", mipmapstr);
 			return luaL_error(L, "Invalid filter mode: %s", mipmapstr);
 	}
 	}
 
 
-	EXCEPT_GUARD(t->setFilter(f);)
+	luax_catchexcept(L, [&](){ t->setFilter(f); });
 
 
 	float sharpness = (float) luaL_optnumber(L, 3, 0);
 	float sharpness = (float) luaL_optnumber(L, 3, 0);
 	t->setMipmapSharpness(sharpness);
 	t->setMipmapSharpness(sharpness);
@@ -81,7 +81,7 @@ int w_Image_isCompressed(lua_State *L)
 int w_Image_refresh(lua_State *L)
 int w_Image_refresh(lua_State *L)
 {
 {
 	Image *i = luax_checkimage(L, 1);
 	Image *i = luax_checkimage(L, 1);
-	EXCEPT_GUARD(i->refresh();)
+	luax_catchexcept(L, [&](){ i->refresh(); });
 	return 0;
 	return 0;
 }
 }
 
 

+ 6 - 6
src/modules/graphics/opengl/wrap_Mesh.cpp

@@ -74,7 +74,7 @@ int w_Mesh_setVertex(lua_State *L)
 		v.a = luaL_optinteger(L, 10, 255);
 		v.a = luaL_optinteger(L, 10, 255);
 	}
 	}
 
 
-	EXCEPT_GUARD(t->setVertex(i, v);)
+	luax_catchexcept(L, [&](){ t->setVertex(i, v); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -84,7 +84,7 @@ int w_Mesh_getVertex(lua_State *L)
 	size_t i = (size_t) (luaL_checkinteger(L, 2) - 1);
 	size_t i = (size_t) (luaL_checkinteger(L, 2) - 1);
 
 
 	Vertex v;
 	Vertex v;
-	EXCEPT_GUARD(v = t->getVertex(i);)
+	luax_catchexcept(L, [&](){ v = t->getVertex(i); });
 
 
 	lua_pushnumber(L, v.x);
 	lua_pushnumber(L, v.x);
 	lua_pushnumber(L, v.y);
 	lua_pushnumber(L, v.y);
@@ -134,7 +134,7 @@ int w_Mesh_setVertices(lua_State *L)
 		vertices.push_back(v);
 		vertices.push_back(v);
 	}
 	}
 
 
-	EXCEPT_GUARD(t->setVertices(vertices);)
+	luax_catchexcept(L, [&](){ t->setVertices(vertices); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -216,7 +216,7 @@ int w_Mesh_setVertexMap(lua_State *L)
 			vertexmap.push_back(uint32(luaL_checkinteger(L, i + 2) - 1));
 			vertexmap.push_back(uint32(luaL_checkinteger(L, i + 2) - 1));
 	}
 	}
 
 
-	EXCEPT_GUARD(t->setVertexMap(vertexmap);)
+	luax_catchexcept(L, [&](){ t->setVertexMap(vertexmap); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -225,7 +225,7 @@ int w_Mesh_getVertexMap(lua_State *L)
 	Mesh *t = luax_checkmesh(L, 1);
 	Mesh *t = luax_checkmesh(L, 1);
 
 
 	std::vector<uint32> vertex_map;
 	std::vector<uint32> vertex_map;
-	EXCEPT_GUARD(t->getVertexMap(vertex_map);)
+	luax_catchexcept(L, [&](){ t->getVertexMap(vertex_map); });
 
 
 	size_t element_count = vertex_map.size();
 	size_t element_count = vertex_map.size();
 
 
@@ -315,7 +315,7 @@ int w_Mesh_setDrawRange(lua_State *L)
 	{
 	{
 		int rangemin = luaL_checkint(L, 2) - 1;
 		int rangemin = luaL_checkint(L, 2) - 1;
 		int rangemax = luaL_checkint(L, 3) - 1;
 		int rangemax = luaL_checkint(L, 3) - 1;
-		EXCEPT_GUARD(t->setDrawRange(rangemin, rangemax);)
+		luax_catchexcept(L, [&](){ t->setDrawRange(rangemin, rangemax); });
 	}
 	}
 
 
 	return 0;
 	return 0;

+ 3 - 3
src/modules/graphics/opengl/wrap_ParticleSystem.cpp

@@ -49,7 +49,7 @@ int w_ParticleSystem_clone(lua_State *L)
 	ParticleSystem *t = luax_checkparticlesystem(L, 1);
 	ParticleSystem *t = luax_checkparticlesystem(L, 1);
 
 
 	ParticleSystem *clone = nullptr;
 	ParticleSystem *clone = nullptr;
-	EXCEPT_GUARD(clone = t->clone();)
+	luax_catchexcept(L, [&](){ clone = t->clone(); });
 
 
 	luax_pushtype(L, "ParticleSystem", GRAPHICS_PARTICLE_SYSTEM_T, clone);
 	luax_pushtype(L, "ParticleSystem", GRAPHICS_PARTICLE_SYSTEM_T, clone);
 	return 1;
 	return 1;
@@ -90,7 +90,7 @@ int w_ParticleSystem_setBufferSize(lua_State *L)
 	if (arg1 < 1.0 || arg1 > ParticleSystem::MAX_PARTICLES)
 	if (arg1 < 1.0 || arg1 > ParticleSystem::MAX_PARTICLES)
 		return luaL_error(L, "Invalid buffer size");
 		return luaL_error(L, "Invalid buffer size");
 
 
-	EXCEPT_GUARD(t->setBufferSize((uint32) arg1);)
+	luax_catchexcept(L, [&](){ t->setBufferSize((uint32) arg1); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -128,7 +128,7 @@ int w_ParticleSystem_setEmissionRate(lua_State *L)
 {
 {
 	ParticleSystem *t = luax_checkparticlesystem(L, 1);
 	ParticleSystem *t = luax_checkparticlesystem(L, 1);
 	float arg1 = (float) luaL_checknumber(L, 2);
 	float arg1 = (float) luaL_checknumber(L, 2);
-	EXCEPT_GUARD(t->setEmissionRate(arg1);)
+	luax_catchexcept(L, [&](){ t->setEmissionRate(arg1); });
 	return 0;
 	return 0;
 }
 }
 
 

+ 5 - 5
src/modules/graphics/opengl/wrap_Shader.cpp

@@ -232,10 +232,10 @@ int w_Shader_sendMatrix(lua_State *L)
 		lua_pop(L, 1 + dimension);
 		lua_pop(L, 1 + dimension);
 	}
 	}
 
 
-	EXCEPT_GUARD_FINALLY(
-		{ shader->sendMatrix(name, dimension, values, count); },
-		{ delete[] values; }
-	)
+	luax_catchexcept(L,
+		[&]() { shader->sendMatrix(name, dimension, values, count); },
+		[&]() { delete[] values; }
+	);
 
 
 	return 0;
 	return 0;
 }
 }
@@ -246,7 +246,7 @@ int w_Shader_sendTexture(lua_State *L)
 	const char *name = luaL_checkstring(L, 2);
 	const char *name = luaL_checkstring(L, 2);
 	Texture *texture = luax_checktexture(L, 3);
 	Texture *texture = luax_checktexture(L, 3);
 
 
-	EXCEPT_GUARD(shader->sendTexture(name, texture);)
+	luax_catchexcept(L, [&](){ shader->sendTexture(name, texture); });
 	return 0;
 	return 0;
 }
 }
 
 

+ 6 - 6
src/modules/graphics/opengl/wrap_SpriteBatch.cpp

@@ -64,12 +64,12 @@ int w_SpriteBatch_add(lua_State *L)
 	float ky = (float) luaL_optnumber(L, startidx + 8, 0.0);
 	float ky = (float) luaL_optnumber(L, startidx + 8, 0.0);
 
 
 	int id = 0;
 	int id = 0;
-	EXCEPT_GUARD(
+	luax_catchexcept(L, [&]() {
 		if (quad)
 		if (quad)
 			id = t->addq(quad, x, y, a, sx, sy, ox, oy, kx, ky);
 			id = t->addq(quad, x, y, a, sx, sy, ox, oy, kx, ky);
 		else
 		else
 			id = t->add(x, y, a, sx, sy, ox, oy, kx, ky);
 			id = t->add(x, y, a, sx, sy, ox, oy, kx, ky);
-	)
+	});
 
 
 	lua_pushinteger(L, id);
 	lua_pushinteger(L, id);
 	return 1;
 	return 1;
@@ -101,12 +101,12 @@ int w_SpriteBatch_set(lua_State *L)
 	float kx = (float) luaL_optnumber(L, startidx + 7, 0.0);
 	float kx = (float) luaL_optnumber(L, startidx + 7, 0.0);
 	float ky = (float) luaL_optnumber(L, startidx + 8, 0.0);
 	float ky = (float) luaL_optnumber(L, startidx + 8, 0.0);
 
 
-	EXCEPT_GUARD(
+	luax_catchexcept(L, [&]() {
 		if (quad)
 		if (quad)
 			t->addq(quad, x, y, a, sx, sy, ox, oy, kx, ky, id);
 			t->addq(quad, x, y, a, sx, sy, ox, oy, kx, ky, id);
 		else
 		else
 			t->add(x, y, a, sx, sy, ox, oy, kx, ky, id);
 			t->add(x, y, a, sx, sy, ox, oy, kx, ky, id);
-	)
+	});
 
 
 	return 0;
 	return 0;
 }
 }
@@ -121,7 +121,7 @@ int w_SpriteBatch_clear(lua_State *L)
 int w_SpriteBatch_bind(lua_State *L)
 int w_SpriteBatch_bind(lua_State *L)
 {
 {
 	SpriteBatch *t = luax_checkspritebatch(L, 1);
 	SpriteBatch *t = luax_checkspritebatch(L, 1);
-	EXCEPT_GUARD(t->lock();)
+	luax_catchexcept(L, [&](){ t->lock(); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -223,7 +223,7 @@ int w_SpriteBatch_setBufferSize(lua_State *L)
 {
 {
 	SpriteBatch *t = luax_checkspritebatch(L, 1);
 	SpriteBatch *t = luax_checkspritebatch(L, 1);
 	int size = luaL_checkint(L, 2);
 	int size = luaL_checkint(L, 2);
-	EXCEPT_GUARD(t->setBufferSize(size);)
+	luax_catchexcept(L, [&]() {t->setBufferSize(size); });
 	return 0;
 	return 0;
 }
 }
 
 

+ 1 - 1
src/modules/graphics/opengl/wrap_Texture.cpp

@@ -69,7 +69,7 @@ int w_Texture_setFilter(lua_State *L)
 
 
 	f.anisotropy = (float) luaL_optnumber(L, 4, 1.0);
 	f.anisotropy = (float) luaL_optnumber(L, 4, 1.0);
 
 
-	EXCEPT_GUARD(t->setFilter(f);)
+	luax_catchexcept(L, [&](){ t->setFilter(f); });
 	return 0;
 	return 0;
 }
 }
 
 

+ 1 - 1
src/modules/image/CompressedData.cpp

@@ -87,7 +87,7 @@ CompressedData::Format CompressedData::getFormat() const
 void CompressedData::checkMipmapLevelExists(int miplevel) const
 void CompressedData::checkMipmapLevelExists(int miplevel) const
 {
 {
 	if (miplevel < 0 || miplevel >= (int) dataImages.size())
 	if (miplevel < 0 || miplevel >= (int) dataImages.size())
-		throw love::Exception("Mipmap level %d does not exist", miplevel);
+		throw love::Exception("Mipmap level %d does not exist", miplevel + 1);
 }
 }
 
 
 bool CompressedData::getConstant(const char *in, CompressedData::Format &out)
 bool CompressedData::getConstant(const char *in, CompressedData::Format &out)

+ 7 - 6
src/modules/image/wrap_CompressedData.cpp

@@ -37,7 +37,7 @@ int w_CompressedData_getWidth(lua_State *L)
 	int miplevel = luaL_optinteger(L, 2, 1);
 	int miplevel = luaL_optinteger(L, 2, 1);
 	int width = 0;
 	int width = 0;
 
 
-	EXCEPT_GUARD(width = t->getWidth(miplevel >= 1 ? miplevel - 1 : 0);)
+	luax_catchexcept(L, [&](){ width = t->getWidth(miplevel - 1); });
 
 
 	lua_pushinteger(L, width);
 	lua_pushinteger(L, width);
 	return 1;
 	return 1;
@@ -49,7 +49,7 @@ int w_CompressedData_getHeight(lua_State *L)
 	int miplevel = luaL_optinteger(L, 2, 1);
 	int miplevel = luaL_optinteger(L, 2, 1);
 	int height = 0;
 	int height = 0;
 
 
-	EXCEPT_GUARD(height = t->getHeight(miplevel >= 1 ? miplevel - 1 : 0);)
+	luax_catchexcept(L, [&](){ height = t->getHeight(miplevel - 1); });
 
 
 	lua_pushinteger(L, height);
 	lua_pushinteger(L, height);
 	return 1;
 	return 1;
@@ -61,10 +61,11 @@ int w_CompressedData_getDimensions(lua_State *L)
 	int miplevel = luaL_optinteger(L, 2, 1);
 	int miplevel = luaL_optinteger(L, 2, 1);
 	int width = 0, height = 0;
 	int width = 0, height = 0;
 
 
-	EXCEPT_GUARD(
-		width = t->getWidth(miplevel >= 1 ? miplevel - 1 : 0);
-		height = t->getHeight(miplevel >= 1 ? miplevel - 1 : 0);
-	)
+	luax_catchexcept(L, [&]()
+	{
+		width = t->getWidth(miplevel - 1);
+		height = t->getHeight(miplevel - 1);
+	});
 
 
 	lua_pushinteger(L, width);
 	lua_pushinteger(L, width);
 	lua_pushinteger(L, height);
 	lua_pushinteger(L, height);

+ 10 - 4
src/modules/image/wrap_Image.cpp

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

+ 3 - 3
src/modules/image/wrap_ImageData.cpp

@@ -62,7 +62,7 @@ int w_ImageData_getPixel(lua_State *L)
 	int y = luaL_checkint(L, 3);
 	int y = luaL_checkint(L, 3);
 	pixel c;
 	pixel c;
 
 
-	EXCEPT_GUARD(c = t->getPixel(x, y);)
+	luax_catchexcept(L, [&](){ c = t->getPixel(x, y); });
 
 
 	lua_pushnumber(L, c.r);
 	lua_pushnumber(L, c.r);
 	lua_pushnumber(L, c.g);
 	lua_pushnumber(L, c.g);
@@ -98,7 +98,7 @@ int w_ImageData_setPixel(lua_State *L)
 		c.a = (unsigned char)luaL_optinteger(L, 7, 255);
 		c.a = (unsigned char)luaL_optinteger(L, 7, 255);
 	}
 	}
 
 
-	EXCEPT_GUARD(t->setPixel(x, y, c);)
+	luax_catchexcept(L, [&](){ t->setPixel(x, y, c); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -261,7 +261,7 @@ int w_ImageData_encode(lua_State *L)
 			return luaL_error(L, "Invalid image format '%s'.", fmt);
 			return luaL_error(L, "Invalid image format '%s'.", fmt);
 	}
 	}
 
 
-	EXCEPT_GUARD(t->encode(file, format);)
+	luax_catchexcept(L, [&](){ t->encode(file, format); });
 	return 0;
 	return 0;
 }
 }
 
 

+ 3 - 3
src/modules/joystick/sdl/wrap_JoystickModule.cpp

@@ -107,7 +107,7 @@ int w_setGamepadMapping(lua_State *L)
 	}
 	}
 
 
 	bool success = false;
 	bool success = false;
-	EXCEPT_GUARD(success = instance->setGamepadMapping(guid, gpinput, jinput);)
+	luax_catchexcept(L, [&](){ success = instance->setGamepadMapping(guid, gpinput, jinput); });
 
 
 	luax_pushboolean(L, success);
 	luax_pushboolean(L, success);
 	return 1;
 	return 1;
@@ -140,7 +140,7 @@ int w_getGamepadMapping(lua_State *L)
 	Joystick::JoystickInput jinput;
 	Joystick::JoystickInput jinput;
 	jinput.type = Joystick::INPUT_TYPE_MAX_ENUM;
 	jinput.type = Joystick::INPUT_TYPE_MAX_ENUM;
 
 
-	EXCEPT_GUARD(jinput = instance->getGamepadMapping(guid, gpinput);)
+	luax_catchexcept(L, [&](){ jinput = instance->getGamepadMapping(guid, gpinput); });
 
 
 	if (jinput.type == Joystick::INPUT_TYPE_MAX_ENUM)
 	if (jinput.type == Joystick::INPUT_TYPE_MAX_ENUM)
 		return 0;
 		return 0;
@@ -196,7 +196,7 @@ extern "C" int luaopen_love_joystick(lua_State *L)
 {
 {
 	if (instance == nullptr)
 	if (instance == nullptr)
 	{
 	{
-		EXCEPT_GUARD(instance = new JoystickModule();)
+		luax_catchexcept(L, [&](){ instance = new JoystickModule(); });
 	}
 	}
 	else
 	else
 		instance->retain();
 		instance->retain();

+ 27 - 1
src/modules/keyboard/wrap_Keyboard.cpp

@@ -68,8 +68,34 @@ int w_setTextInput(lua_State *L)
 	return 0;
 	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)
 int w_hasTextInput(lua_State *L)
 {
 {
+	bool asdf = true;
+	throwExcept(L, [&](){ instance->setTextInput(asdf); });
+
+//	throwExcept(L, L);
+
 	luax_pushboolean(L, instance->hasTextInput());
 	luax_pushboolean(L, instance->hasTextInput());
 	return 1;
 	return 1;
 }
 }
@@ -89,7 +115,7 @@ extern "C" int luaopen_love_keyboard(lua_State *L)
 {
 {
 	if (instance == nullptr)
 	if (instance == nullptr)
 	{
 	{
-		EXCEPT_GUARD(instance = new love::keyboard::sdl::Keyboard();)
+		luax_catchexcept(L, [&](){ instance = new love::keyboard::sdl::Keyboard(); });
 	}
 	}
 	else
 	else
 		instance->retain();
 		instance->retain();

+ 7 - 7
src/modules/math/wrap_BezierCurve.cpp

@@ -56,11 +56,11 @@ int w_BezierCurve_getControlPoint(lua_State *L)
 	if (idx > 0) // 1-indexing
 	if (idx > 0) // 1-indexing
 		idx--;
 		idx--;
 
 
-	EXCEPT_GUARD(
+	luax_catchexcept(L, [&]() {
 		Vector v = curve->getControlPoint(idx);
 		Vector v = curve->getControlPoint(idx);
 		lua_pushnumber(L, v.x);
 		lua_pushnumber(L, v.x);
 		lua_pushnumber(L, v.y);
 		lua_pushnumber(L, v.y);
-	)
+	});
 
 
 	return 2;
 	return 2;
 }
 }
@@ -75,7 +75,7 @@ int w_BezierCurve_setControlPoint(lua_State *L)
 	if (idx > 0) // 1-indexing
 	if (idx > 0) // 1-indexing
 		idx--;
 		idx--;
 
 
-	EXCEPT_GUARD(curve->setControlPoint(idx, Vector(vx,vy));)
+	luax_catchexcept(L, [&](){ curve->setControlPoint(idx, Vector(vx,vy)); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -89,7 +89,7 @@ int w_BezierCurve_insertControlPoint(lua_State *L)
 	if (idx > 0) // 1-indexing
 	if (idx > 0) // 1-indexing
 		idx--;
 		idx--;
 
 
-	EXCEPT_GUARD(curve->insertControlPoint(Vector(vx,vy), idx);)
+	luax_catchexcept(L, [&](){ curve->insertControlPoint(Vector(vx,vy), idx); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -134,11 +134,11 @@ int w_BezierCurve_evaluate(lua_State *L)
 	BezierCurve *curve = luax_checkbeziercurve(L, 1);
 	BezierCurve *curve = luax_checkbeziercurve(L, 1);
 	double t = luaL_checknumber(L, 2);
 	double t = luaL_checknumber(L, 2);
 
 
-	EXCEPT_GUARD(
+	luax_catchexcept(L, [&]() {
 		Vector v = curve->evaluate(t);
 		Vector v = curve->evaluate(t);
 		lua_pushnumber(L, v.x);
 		lua_pushnumber(L, v.x);
 		lua_pushnumber(L, v.y);
 		lua_pushnumber(L, v.y);
-	)
+	});
 
 
 	return 2;
 	return 2;
 
 
@@ -150,7 +150,7 @@ int w_BezierCurve_render(lua_State *L)
 	int accuracy = luaL_optinteger(L, 2, 5);
 	int accuracy = luaL_optinteger(L, 2, 5);
 
 
 	std::vector<Vector> points;
 	std::vector<Vector> points;
-	EXCEPT_GUARD(points = curve->render(accuracy);)
+	luax_catchexcept(L, [&](){ points = curve->render(accuracy); });
 
 
 	lua_createtable(L, points.size()*2, 0);
 	lua_createtable(L, points.size()*2, 0);
 	for (size_t i = 0; i < points.size(); ++i)
 	for (size_t i = 0; i < points.size(); ++i)

+ 4 - 4
src/modules/math/wrap_Math.cpp

@@ -49,7 +49,7 @@ int w_randomNormal(lua_State *L)
 
 
 int w_setRandomSeed(lua_State *L)
 int w_setRandomSeed(lua_State *L)
 {
 {
-	EXCEPT_GUARD(Math::instance.setRandomSeed(luax_checkrandomseed(L, 1));)
+	luax_catchexcept(L, [&](){ Math::instance.setRandomSeed(luax_checkrandomseed(L, 1)); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -63,7 +63,7 @@ int w_getRandomSeed(lua_State *L)
 
 
 int w_setRandomState(lua_State *L)
 int w_setRandomState(lua_State *L)
 {
 {
-	EXCEPT_GUARD(Math::instance.setRandomState(luax_checkstring(L, 1));)
+	luax_catchexcept(L, [&](){ Math::instance.setRandomState(luax_checkstring(L, 1)); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -180,12 +180,12 @@ int w_triangulate(lua_State *L)
 
 
 	std::vector<Triangle> triangles;
 	std::vector<Triangle> triangles;
 
 
-	EXCEPT_GUARD(
+	luax_catchexcept(L, [&]() {
 		if (vertices.size() == 3)
 		if (vertices.size() == 3)
 			triangles.push_back(Triangle(vertices[0], vertices[1], vertices[2]));
 			triangles.push_back(Triangle(vertices[0], vertices[1], vertices[2]));
 		else
 		else
 			triangles = Math::instance.triangulate(vertices);
 			triangles = Math::instance.triangulate(vertices);
-	)
+	});
 
 
 	lua_createtable(L, triangles.size(), 0);
 	lua_createtable(L, triangles.size(), 0);
 	for (size_t i = 0; i < triangles.size(); ++i)
 	for (size_t i = 0; i < triangles.size(); ++i)

+ 2 - 2
src/modules/math/wrap_RandomGenerator.cpp

@@ -108,7 +108,7 @@ int w_RandomGenerator_randomNormal(lua_State *L)
 int w_RandomGenerator_setSeed(lua_State *L)
 int w_RandomGenerator_setSeed(lua_State *L)
 {
 {
 	RandomGenerator *rng = luax_checkrandomgenerator(L, 1);
 	RandomGenerator *rng = luax_checkrandomgenerator(L, 1);
-	EXCEPT_GUARD(rng->setSeed(luax_checkrandomseed(L, 2));)
+	luax_catchexcept(L, [&](){ rng->setSeed(luax_checkrandomseed(L, 2)); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -124,7 +124,7 @@ int w_RandomGenerator_getSeed(lua_State *L)
 int w_RandomGenerator_setState(lua_State *L)
 int w_RandomGenerator_setState(lua_State *L)
 {
 {
 	RandomGenerator *rng = luax_checkrandomgenerator(L, 1);
 	RandomGenerator *rng = luax_checkrandomgenerator(L, 1);
-	EXCEPT_GUARD(rng->setState(luax_checkstring(L, 2));)
+	luax_catchexcept(L, [&](){ rng->setState(luax_checkstring(L, 2)); });
 	return 0;
 	return 0;
 }
 }
 
 

+ 3 - 3
src/modules/mouse/wrap_Mouse.cpp

@@ -43,7 +43,7 @@ int w_newCursor(lua_State *L)
 	int hotx = luaL_optint(L, 2, 0);
 	int hotx = luaL_optint(L, 2, 0);
 	int hoty = luaL_optint(L, 3, 0);
 	int hoty = luaL_optint(L, 3, 0);
 
 
-	EXCEPT_GUARD(cursor = instance->newCursor(data, hotx, hoty);)
+	luax_catchexcept(L, [&](){ cursor = instance->newCursor(data, hotx, hoty); });
 
 
 	luax_pushtype(L, "Cursor", MOUSE_CURSOR_T, cursor);
 	luax_pushtype(L, "Cursor", MOUSE_CURSOR_T, cursor);
 	return 1;
 	return 1;
@@ -58,7 +58,7 @@ int w_getSystemCursor(lua_State *L)
 		return luaL_error(L, "Invalid system cursor type: %s", str);
 		return luaL_error(L, "Invalid system cursor type: %s", str);
 
 
 	Cursor *cursor = 0;
 	Cursor *cursor = 0;
-	EXCEPT_GUARD(cursor = instance->getSystemCursor(systemCursor);)
+	luax_catchexcept(L, [&](){ cursor = instance->getSystemCursor(systemCursor); });
 
 
 	cursor->retain();
 	cursor->retain();
 	luax_pushtype(L, "Cursor", MOUSE_CURSOR_T, cursor);
 	luax_pushtype(L, "Cursor", MOUSE_CURSOR_T, cursor);
@@ -214,7 +214,7 @@ extern "C" int luaopen_love_mouse(lua_State *L)
 {
 {
 	if (instance == nullptr)
 	if (instance == nullptr)
 	{
 	{
-		EXCEPT_GUARD(instance = new love::mouse::sdl::Mouse();)
+		luax_catchexcept(L, [&](){ instance = new love::mouse::sdl::Mouse(); });
 	}
 	}
 	else
 	else
 		instance->retain();
 		instance->retain();

+ 2 - 2
src/modules/physics/box2d/Physics.cpp

@@ -246,7 +246,7 @@ int Physics::getDistance(lua_State *L)
 	b2SimplexCache c;
 	b2SimplexCache c;
 	c.count = 0;
 	c.count = 0;
 
 
-	EXCEPT_GUARD(
+	luax_catchexcept(L, [&]() {
 		pA.Set(fixtureA->fixture->GetShape(), 0);
 		pA.Set(fixtureA->fixture->GetShape(), 0);
 		pB.Set(fixtureB->fixture->GetShape(), 0);
 		pB.Set(fixtureB->fixture->GetShape(), 0);
 		i.proxyA = pA;
 		i.proxyA = pA;
@@ -255,7 +255,7 @@ int Physics::getDistance(lua_State *L)
 		i.transformB = fixtureB->fixture->GetBody()->GetTransform();
 		i.transformB = fixtureB->fixture->GetBody()->GetTransform();
 		i.useRadii = true;
 		i.useRadii = true;
 		b2Distance(&o, &c, &i);
 		b2Distance(&o, &c, &i);
-	)
+	});
 
 
 	lua_pushnumber(L, Physics::scaleUp(o.distance));
 	lua_pushnumber(L, Physics::scaleUp(o.distance));
 	lua_pushnumber(L, Physics::scaleUp(o.pointA.x));
 	lua_pushnumber(L, Physics::scaleUp(o.pointA.x));

+ 13 - 13
src/modules/physics/box2d/wrap_Body.cpp

@@ -241,7 +241,7 @@ int w_Body_setX(lua_State *L)
 {
 {
 	Body *t = luax_checkbody(L, 1);
 	Body *t = luax_checkbody(L, 1);
 	float arg1 = (float)luaL_checknumber(L, 2);
 	float arg1 = (float)luaL_checknumber(L, 2);
-	EXCEPT_GUARD(t->setX(arg1);)
+	luax_catchexcept(L, [&](){ t->setX(arg1); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -249,7 +249,7 @@ int w_Body_setY(lua_State *L)
 {
 {
 	Body *t = luax_checkbody(L, 1);
 	Body *t = luax_checkbody(L, 1);
 	float arg1 = (float)luaL_checknumber(L, 2);
 	float arg1 = (float)luaL_checknumber(L, 2);
-	EXCEPT_GUARD(t->setY(arg1);)
+	luax_catchexcept(L, [&](){ t->setY(arg1); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -266,7 +266,7 @@ int w_Body_setAngle(lua_State *L)
 {
 {
 	Body *t = luax_checkbody(L, 1);
 	Body *t = luax_checkbody(L, 1);
 	float arg1 = (float)luaL_checknumber(L, 2);
 	float arg1 = (float)luaL_checknumber(L, 2);
-	EXCEPT_GUARD(t->setAngle(arg1);)
+	luax_catchexcept(L, [&](){ t->setAngle(arg1); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -283,14 +283,14 @@ int w_Body_setPosition(lua_State *L)
 	Body *t = luax_checkbody(L, 1);
 	Body *t = luax_checkbody(L, 1);
 	float arg1 = (float)luaL_checknumber(L, 2);
 	float arg1 = (float)luaL_checknumber(L, 2);
 	float arg2 = (float)luaL_checknumber(L, 3);
 	float arg2 = (float)luaL_checknumber(L, 3);
-	EXCEPT_GUARD(t->setPosition(arg1, arg2);)
+	luax_catchexcept(L, [&](){ t->setPosition(arg1, arg2); });
 	return 0;
 	return 0;
 }
 }
 
 
 int w_Body_resetMassData(lua_State *L)
 int w_Body_resetMassData(lua_State *L)
 {
 {
 	Body *t = luax_checkbody(L, 1);
 	Body *t = luax_checkbody(L, 1);
-	EXCEPT_GUARD(t->resetMassData();)
+	luax_catchexcept(L, [&](){ t->resetMassData(); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -301,7 +301,7 @@ int w_Body_setMassData(lua_State *L)
 	float y = (float)luaL_checknumber(L, 3);
 	float y = (float)luaL_checknumber(L, 3);
 	float m = (float)luaL_checknumber(L, 4);
 	float m = (float)luaL_checknumber(L, 4);
 	float i = (float)luaL_checknumber(L, 5);
 	float i = (float)luaL_checknumber(L, 5);
-	EXCEPT_GUARD(t->setMassData(x, y, m, i);)
+	luax_catchexcept(L, [&](){ t->setMassData(x, y, m, i); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -309,7 +309,7 @@ int w_Body_setMass(lua_State *L)
 {
 {
 	Body *t = luax_checkbody(L, 1);
 	Body *t = luax_checkbody(L, 1);
 	float m = (float)luaL_checknumber(L, 2);
 	float m = (float)luaL_checknumber(L, 2);
-	EXCEPT_GUARD(t->setMass(m);)
+	luax_catchexcept(L, [&](){ t->setMass(m); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -317,7 +317,7 @@ int w_Body_setInertia(lua_State *L)
 {
 {
 	Body *t = luax_checkbody(L, 1);
 	Body *t = luax_checkbody(L, 1);
 	float i = (float)luaL_checknumber(L, 2);
 	float i = (float)luaL_checknumber(L, 2);
-	EXCEPT_GUARD(t->setInertia(i);)
+	luax_catchexcept(L, [&](){ t->setInertia(i); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -351,7 +351,7 @@ int w_Body_setType(lua_State *L)
 	const char *typeStr = luaL_checkstring(L, 2);
 	const char *typeStr = luaL_checkstring(L, 2);
 	Body::Type type;
 	Body::Type type;
 	Body::getConstant(typeStr, type);
 	Body::getConstant(typeStr, type);
-	EXCEPT_GUARD(t->setType(type);)
+	luax_catchexcept(L, [&](){ t->setType(type); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -494,7 +494,7 @@ int w_Body_setActive(lua_State *L)
 {
 {
 	Body *t = luax_checkbody(L, 1);
 	Body *t = luax_checkbody(L, 1);
 	bool b = luax_toboolean(L, 2);
 	bool b = luax_toboolean(L, 2);
-	EXCEPT_GUARD(t->setActive(b);)
+	luax_catchexcept(L, [&](){ t->setActive(b); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -510,7 +510,7 @@ int w_Body_setFixedRotation(lua_State *L)
 {
 {
 	Body *t = luax_checkbody(L, 1);
 	Body *t = luax_checkbody(L, 1);
 	bool b = luax_toboolean(L, 2);
 	bool b = luax_toboolean(L, 2);
-	EXCEPT_GUARD(t->setFixedRotation(b);)
+	luax_catchexcept(L, [&](){ t->setFixedRotation(b); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -527,14 +527,14 @@ int w_Body_getFixtureList(lua_State *L)
 	Body *t = luax_checkbody(L, 1);
 	Body *t = luax_checkbody(L, 1);
 	lua_remove(L, 1);
 	lua_remove(L, 1);
 	int n = 0;
 	int n = 0;
-	EXCEPT_GUARD(n = t->getFixtureList(L);)
+	luax_catchexcept(L, [&](){ n = t->getFixtureList(L); });
 	return n;
 	return n;
 }
 }
 
 
 int w_Body_destroy(lua_State *L)
 int w_Body_destroy(lua_State *L)
 {
 {
 	Body *t = luax_checkbody(L, 1);
 	Body *t = luax_checkbody(L, 1);
-	EXCEPT_GUARD(t->destroy();)
+	luax_catchexcept(L, [&](){ t->destroy(); });
 	return 0;
 	return 0;
 }
 }
 
 

+ 4 - 4
src/modules/physics/box2d/wrap_ChainShape.cpp

@@ -39,7 +39,7 @@ int w_ChainShape_setNextVertex(lua_State *L)
 	ChainShape *c = luax_checkchainshape(L, 1);
 	ChainShape *c = luax_checkchainshape(L, 1);
 	float x = (float)luaL_checknumber(L, 2);
 	float x = (float)luaL_checknumber(L, 2);
 	float y = (float)luaL_checknumber(L, 3);
 	float y = (float)luaL_checknumber(L, 3);
-	EXCEPT_GUARD(c->setNextVertex(x, y);)
+	luax_catchexcept(L, [&](){ c->setNextVertex(x, y); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -48,7 +48,7 @@ int w_ChainShape_setPreviousVertex(lua_State *L)
 	ChainShape *c = luax_checkchainshape(L, 1);
 	ChainShape *c = luax_checkchainshape(L, 1);
 	float x = (float)luaL_checknumber(L, 2);
 	float x = (float)luaL_checknumber(L, 2);
 	float y = (float)luaL_checknumber(L, 3);
 	float y = (float)luaL_checknumber(L, 3);
-	EXCEPT_GUARD(c->setPreviousVertex(x, y);)
+	luax_catchexcept(L, [&](){ c->setPreviousVertex(x, y); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -64,7 +64,7 @@ int w_ChainShape_getChildEdge(lua_State *L)
 	ChainShape *c = luax_checkchainshape(L, 1);
 	ChainShape *c = luax_checkchainshape(L, 1);
 	int index = luaL_checkint(L, 2) - 1; // Convert from 1-based index
 	int index = luaL_checkint(L, 2) - 1; // Convert from 1-based index
 	EdgeShape *e = 0;
 	EdgeShape *e = 0;
-	EXCEPT_GUARD(e = c->getChildEdge(index);)
+	luax_catchexcept(L, [&](){ e = c->getChildEdge(index); });
 	luax_pushtype(L, "EdgeShape", PHYSICS_EDGE_SHAPE_T, e);
 	luax_pushtype(L, "EdgeShape", PHYSICS_EDGE_SHAPE_T, e);
 	return 1;
 	return 1;
 }
 }
@@ -82,7 +82,7 @@ int w_ChainShape_getPoint(lua_State *L)
 	ChainShape *c = luax_checkchainshape(L, 1);
 	ChainShape *c = luax_checkchainshape(L, 1);
 	int index = luaL_checkint(L, 2) - 1; // Convert from 1-based index
 	int index = luaL_checkint(L, 2) - 1; // Convert from 1-based index
 	b2Vec2 v;
 	b2Vec2 v;
-	EXCEPT_GUARD(v = c->getPoint(index);)
+	luax_catchexcept(L, [&](){ v = c->getPoint(index); });
 	lua_pushnumber(L, v.x);
 	lua_pushnumber(L, v.x);
 	lua_pushnumber(L, v.y);
 	lua_pushnumber(L, v.y);
 	return 2;
 	return 2;

+ 3 - 3
src/modules/physics/box2d/wrap_Fixture.cpp

@@ -65,7 +65,7 @@ int w_Fixture_setDensity(lua_State *L)
 {
 {
 	Fixture *t = luax_checkfixture(L, 1);
 	Fixture *t = luax_checkfixture(L, 1);
 	float arg1 = (float)luaL_checknumber(L, 2);
 	float arg1 = (float)luaL_checknumber(L, 2);
-	EXCEPT_GUARD(t->setDensity(arg1);)
+	luax_catchexcept(L, [&](){ t->setDensity(arg1); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -157,7 +157,7 @@ int w_Fixture_rayCast(lua_State *L)
 	Fixture *t = luax_checkfixture(L, 1);
 	Fixture *t = luax_checkfixture(L, 1);
 	lua_remove(L, 1);
 	lua_remove(L, 1);
 	int ret = 0;
 	int ret = 0;
-	EXCEPT_GUARD(ret = t->rayCast(L);)
+	luax_catchexcept(L, [&](){ ret = t->rayCast(L); });
 	return ret;
 	return ret;
 }
 }
 
 
@@ -258,7 +258,7 @@ int w_Fixture_setGroupIndex(lua_State *L)
 int w_Fixture_destroy(lua_State *L)
 int w_Fixture_destroy(lua_State *L)
 {
 {
 	Fixture *t = luax_checkfixture(L, 1);
 	Fixture *t = luax_checkfixture(L, 1);
-	EXCEPT_GUARD(t->destroy();)
+	luax_catchexcept(L, [&](){ t->destroy(); });
 	return 0;
 	return 0;
 }
 }
 
 

+ 2 - 2
src/modules/physics/box2d/wrap_FrictionJoint.cpp

@@ -40,7 +40,7 @@ int w_FrictionJoint_setMaxForce(lua_State *L)
 {
 {
 	FrictionJoint *t = luax_checkfrictionjoint(L, 1);
 	FrictionJoint *t = luax_checkfrictionjoint(L, 1);
 	float arg1 = (float)luaL_checknumber(L, 2);
 	float arg1 = (float)luaL_checknumber(L, 2);
-	EXCEPT_GUARD(t->setMaxForce(arg1);)
+	luax_catchexcept(L, [&](){ t->setMaxForce(arg1); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -55,7 +55,7 @@ int w_FrictionJoint_setMaxTorque(lua_State *L)
 {
 {
 	FrictionJoint *t = luax_checkfrictionjoint(L, 1);
 	FrictionJoint *t = luax_checkfrictionjoint(L, 1);
 	float arg1 = (float)luaL_checknumber(L, 2);
 	float arg1 = (float)luaL_checknumber(L, 2);
-	EXCEPT_GUARD(t->setMaxTorque(arg1);)
+	luax_catchexcept(L, [&](){ t->setMaxTorque(arg1); });
 	return 0;
 	return 0;
 }
 }
 
 

+ 1 - 1
src/modules/physics/box2d/wrap_GearJoint.cpp

@@ -40,7 +40,7 @@ int w_GearJoint_setRatio(lua_State *L)
 {
 {
 	GearJoint *t = luax_checkgearjoint(L, 1);
 	GearJoint *t = luax_checkgearjoint(L, 1);
 	float arg1 = (float)luaL_checknumber(L, 2);
 	float arg1 = (float)luaL_checknumber(L, 2);
-	EXCEPT_GUARD(t->setRatio(arg1);)
+	luax_catchexcept(L, [&](){ t->setRatio(arg1); });
 	return 0;
 	return 0;
 }
 }
 
 

+ 1 - 1
src/modules/physics/box2d/wrap_Joint.cpp

@@ -78,7 +78,7 @@ int w_Joint_getCollideConnected(lua_State *L)
 int w_Joint_destroy(lua_State *L)
 int w_Joint_destroy(lua_State *L)
 {
 {
 	Joint *t = luax_checkjoint(L, 1);
 	Joint *t = luax_checkjoint(L, 1);
-	EXCEPT_GUARD(t->destroyJoint();)
+	luax_catchexcept(L, [&](){ t->destroyJoint(); });
 	return 0;
 	return 0;
 }
 }
 
 

+ 3 - 3
src/modules/physics/box2d/wrap_MotorJoint.cpp

@@ -69,7 +69,7 @@ int w_MotorJoint_setMaxForce(lua_State *L)
 {
 {
 	MotorJoint *t = luax_checkmotorjoint(L, 1);
 	MotorJoint *t = luax_checkmotorjoint(L, 1);
 	float arg1 = (float) luaL_checknumber(L, 2);
 	float arg1 = (float) luaL_checknumber(L, 2);
-	EXCEPT_GUARD(t->setMaxForce(arg1);)
+	luax_catchexcept(L, [&](){ t->setMaxForce(arg1); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -84,7 +84,7 @@ int w_MotorJoint_setMaxTorque(lua_State *L)
 {
 {
 	MotorJoint *t = luax_checkmotorjoint(L, 1);
 	MotorJoint *t = luax_checkmotorjoint(L, 1);
 	float arg1 = (float) luaL_checknumber(L, 2);
 	float arg1 = (float) luaL_checknumber(L, 2);
-	EXCEPT_GUARD(t->setMaxTorque(arg1);)
+	luax_catchexcept(L, [&](){ t->setMaxTorque(arg1); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -99,7 +99,7 @@ int w_MotorJoint_setCorrectionFactor(lua_State *L)
 {
 {
 	MotorJoint *t = luax_checkmotorjoint(L, 1);
 	MotorJoint *t = luax_checkmotorjoint(L, 1);
 	float arg1 = (float) luaL_checknumber(L, 2);
 	float arg1 = (float) luaL_checknumber(L, 2);
-	EXCEPT_GUARD(t->setCorrectionFactor(arg1);)
+	luax_catchexcept(L, [&](){ t->setCorrectionFactor(arg1); });
 	return 0;
 	return 0;
 }
 }
 
 

+ 44 - 24
src/modules/physics/box2d/wrap_Physics.cpp

@@ -58,7 +58,7 @@ int w_newWorld(lua_State *L)
 	bool sleep = luax_optboolean(L, 3, true);
 	bool sleep = luax_optboolean(L, 3, true);
 
 
 	World *w;
 	World *w;
-	EXCEPT_GUARD(w = instance->newWorld(gx, gy, sleep);)
+	luax_catchexcept(L, [&](){ w = instance->newWorld(gx, gy, sleep); });
 	luax_pushtype(L, "World", PHYSICS_WORLD_T, w);
 	luax_pushtype(L, "World", PHYSICS_WORLD_T, w);
 
 
 	return 1;
 	return 1;
@@ -76,7 +76,7 @@ int w_newBody(lua_State *L)
 		return luaL_error(L, "Invalid Body type: %s", typestr);
 		return luaL_error(L, "Invalid Body type: %s", typestr);
 
 
 	Body *body;
 	Body *body;
-	EXCEPT_GUARD(body = instance->newBody(world, x, y, btype);)
+	luax_catchexcept(L, [&](){ body = instance->newBody(world, x, y, btype); });
 	luax_pushtype(L, "Body", PHYSICS_BODY_T, body);
 	luax_pushtype(L, "Body", PHYSICS_BODY_T, body);
 	return 1;
 	return 1;
 }
 }
@@ -87,7 +87,7 @@ int w_newFixture(lua_State *L)
 	Shape *shape = luax_checkshape(L, 2);
 	Shape *shape = luax_checkshape(L, 2);
 	float density = (float)luaL_optnumber(L, 3, 1.0f);
 	float density = (float)luaL_optnumber(L, 3, 1.0f);
 	Fixture *fixture;
 	Fixture *fixture;
-	EXCEPT_GUARD(fixture = instance->newFixture(body, shape, density);)
+	luax_catchexcept(L, [&](){ fixture = instance->newFixture(body, shape, density); });
 	luax_pushtype(L, "Fixture", PHYSICS_FIXTURE_T, fixture);
 	luax_pushtype(L, "Fixture", PHYSICS_FIXTURE_T, fixture);
 	return 1;
 	return 1;
 }
 }
@@ -100,7 +100,7 @@ int w_newCircleShape(lua_State *L)
 	{
 	{
 		float radius = (float)luaL_checknumber(L, 1);
 		float radius = (float)luaL_checknumber(L, 1);
 		CircleShape *shape;
 		CircleShape *shape;
-		EXCEPT_GUARD(shape = instance->newCircleShape(radius);)
+		luax_catchexcept(L, [&](){ shape = instance->newCircleShape(radius); });
 		luax_pushtype(L, "CircleShape", PHYSICS_CIRCLE_SHAPE_T, shape);
 		luax_pushtype(L, "CircleShape", PHYSICS_CIRCLE_SHAPE_T, shape);
 		return 1;
 		return 1;
 	}
 	}
@@ -110,7 +110,7 @@ int w_newCircleShape(lua_State *L)
 		float y = (float)luaL_checknumber(L, 2);
 		float y = (float)luaL_checknumber(L, 2);
 		float radius = (float)luaL_checknumber(L, 3);
 		float radius = (float)luaL_checknumber(L, 3);
 		CircleShape *shape;
 		CircleShape *shape;
-		EXCEPT_GUARD(shape = instance->newCircleShape(x, y, radius);)
+		luax_catchexcept(L, [&](){ shape = instance->newCircleShape(x, y, radius); });
 		luax_pushtype(L, "CircleShape", PHYSICS_CIRCLE_SHAPE_T, shape);
 		luax_pushtype(L, "CircleShape", PHYSICS_CIRCLE_SHAPE_T, shape);
 		return 1;
 		return 1;
 	}
 	}
@@ -127,7 +127,7 @@ int w_newRectangleShape(lua_State *L)
 		float w = (float)luaL_checknumber(L, 1);
 		float w = (float)luaL_checknumber(L, 1);
 		float h = (float)luaL_checknumber(L, 2);
 		float h = (float)luaL_checknumber(L, 2);
 		PolygonShape *shape;
 		PolygonShape *shape;
-		EXCEPT_GUARD(shape = instance->newRectangleShape(w, h);)
+		luax_catchexcept(L, [&](){ shape = instance->newRectangleShape(w, h); });
 		luax_pushtype(L, "PolygonShape", PHYSICS_POLYGON_SHAPE_T, shape);
 		luax_pushtype(L, "PolygonShape", PHYSICS_POLYGON_SHAPE_T, shape);
 		return 1;
 		return 1;
 	}
 	}
@@ -139,7 +139,7 @@ int w_newRectangleShape(lua_State *L)
 		float h = (float)luaL_checknumber(L, 4);
 		float h = (float)luaL_checknumber(L, 4);
 		float angle = (float)luaL_optnumber(L, 5, 0);
 		float angle = (float)luaL_optnumber(L, 5, 0);
 		PolygonShape *shape;
 		PolygonShape *shape;
-		EXCEPT_GUARD(shape = instance->newRectangleShape(x, y, w, h, angle);)
+		luax_catchexcept(L, [&](){ shape = instance->newRectangleShape(x, y, w, h, angle); });
 		luax_pushtype(L, "PolygonShape", PHYSICS_POLYGON_SHAPE_T, shape);
 		luax_pushtype(L, "PolygonShape", PHYSICS_POLYGON_SHAPE_T, shape);
 		return 1;
 		return 1;
 	}
 	}
@@ -154,7 +154,7 @@ int w_newEdgeShape(lua_State *L)
 	float x2 = (float)luaL_checknumber(L, 3);
 	float x2 = (float)luaL_checknumber(L, 3);
 	float y2 = (float)luaL_checknumber(L, 4);
 	float y2 = (float)luaL_checknumber(L, 4);
 	EdgeShape *shape;
 	EdgeShape *shape;
-	EXCEPT_GUARD(shape = instance->newEdgeShape(x1, y1, x2, y2);)
+	luax_catchexcept(L, [&](){ shape = instance->newEdgeShape(x1, y1, x2, y2); });
 	luax_pushtype(L, "EdgeShape", PHYSICS_EDGE_SHAPE_T, shape);
 	luax_pushtype(L, "EdgeShape", PHYSICS_EDGE_SHAPE_T, shape);
 	return 1;
 	return 1;
 }
 }
@@ -162,14 +162,14 @@ int w_newEdgeShape(lua_State *L)
 int w_newPolygonShape(lua_State *L)
 int w_newPolygonShape(lua_State *L)
 {
 {
 	int ret = 0;
 	int ret = 0;
-	EXCEPT_GUARD(ret = instance->newPolygonShape(L);)
+	luax_catchexcept(L, [&](){ ret = instance->newPolygonShape(L); });
 	return ret;
 	return ret;
 }
 }
 
 
 int w_newChainShape(lua_State *L)
 int w_newChainShape(lua_State *L)
 {
 {
 	int ret = 0;
 	int ret = 0;
-	EXCEPT_GUARD(ret = instance->newChainShape(L);)
+	luax_catchexcept(L, [&](){ ret = instance->newChainShape(L); });
 	return ret;
 	return ret;
 }
 }
 
 
@@ -183,7 +183,9 @@ int w_newDistanceJoint(lua_State *L)
 	float y2 = (float)luaL_checknumber(L, 6);
 	float y2 = (float)luaL_checknumber(L, 6);
 	bool collideConnected = luax_optboolean(L, 7, false);
 	bool collideConnected = luax_optboolean(L, 7, false);
 	DistanceJoint *j;
 	DistanceJoint *j;
-	EXCEPT_GUARD(j = instance->newDistanceJoint(body1, body2, x1, y1, x2, y2, collideConnected);)
+	luax_catchexcept(L, [&]() {
+		j = instance->newDistanceJoint(body1, body2, x1, y1, x2, y2, collideConnected);
+	});
 	luax_pushtype(L, "DistanceJoint", PHYSICS_DISTANCE_JOINT_T, j);
 	luax_pushtype(L, "DistanceJoint", PHYSICS_DISTANCE_JOINT_T, j);
 	return 1;
 	return 1;
 }
 }
@@ -194,7 +196,7 @@ int w_newMouseJoint(lua_State *L)
 	float x = (float)luaL_checknumber(L, 2);
 	float x = (float)luaL_checknumber(L, 2);
 	float y = (float)luaL_checknumber(L, 3);
 	float y = (float)luaL_checknumber(L, 3);
 	MouseJoint *j;
 	MouseJoint *j;
-	EXCEPT_GUARD(j = instance->newMouseJoint(body, x, y);)
+	luax_catchexcept(L, [&](){ j = instance->newMouseJoint(body, x, y); });
 	luax_pushtype(L, "MouseJoint", PHYSICS_MOUSE_JOINT_T, j);
 	luax_pushtype(L, "MouseJoint", PHYSICS_MOUSE_JOINT_T, j);
 	return 1;
 	return 1;
 }
 }
@@ -207,7 +209,9 @@ int w_newRevoluteJoint(lua_State *L)
 	float y = (float)luaL_checknumber(L, 4);
 	float y = (float)luaL_checknumber(L, 4);
 	bool collideConnected = luax_optboolean(L, 5, false);
 	bool collideConnected = luax_optboolean(L, 5, false);
 	RevoluteJoint *j;
 	RevoluteJoint *j;
-	EXCEPT_GUARD(j = instance->newRevoluteJoint(body1, body2, x, y, collideConnected);)
+	luax_catchexcept(L, [&]() {
+		j = instance->newRevoluteJoint(body1, body2, x, y, collideConnected);
+	});
 	luax_pushtype(L, "RevoluteJoint", PHYSICS_REVOLUTE_JOINT_T, j);
 	luax_pushtype(L, "RevoluteJoint", PHYSICS_REVOLUTE_JOINT_T, j);
 	return 1;
 	return 1;
 }
 }
@@ -237,7 +241,9 @@ int w_newPrismaticJoint(lua_State *L)
 		collideConnected = luax_optboolean(L, 7, false);
 		collideConnected = luax_optboolean(L, 7, false);
 	}
 	}
 	PrismaticJoint *j;
 	PrismaticJoint *j;
-	EXCEPT_GUARD(j = instance->newPrismaticJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected);)
+	luax_catchexcept(L, [&]() {
+		j = instance->newPrismaticJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected);
+	});
 	luax_pushtype(L, "PrismaticJoint", PHYSICS_PRISMATIC_JOINT_T, j);
 	luax_pushtype(L, "PrismaticJoint", PHYSICS_PRISMATIC_JOINT_T, j);
 	return 1;
 	return 1;
 }
 }
@@ -258,7 +264,9 @@ int w_newPulleyJoint(lua_State *L)
 	bool collideConnected = luax_optboolean(L, 12, true); // PulleyJoints default to colliding connected bodies, see b2PulleyJoint.h
 	bool collideConnected = luax_optboolean(L, 12, true); // PulleyJoints default to colliding connected bodies, see b2PulleyJoint.h
 
 
 	PulleyJoint *j;
 	PulleyJoint *j;
-	EXCEPT_GUARD(j = instance->newPulleyJoint(body1, body2, b2Vec2(gx1,gy1), b2Vec2(gx2,gy2), b2Vec2(x1,y1), b2Vec2(x2,y2), ratio, collideConnected);)
+	luax_catchexcept(L, [&]() {
+		j = instance->newPulleyJoint(body1, body2, b2Vec2(gx1,gy1), b2Vec2(gx2,gy2), b2Vec2(x1,y1), b2Vec2(x2,y2), ratio, collideConnected);
+	});
 	luax_pushtype(L, "PulleyJoint", PHYSICS_PULLEY_JOINT_T, j);
 	luax_pushtype(L, "PulleyJoint", PHYSICS_PULLEY_JOINT_T, j);
 	return 1;
 	return 1;
 }
 }
@@ -271,7 +279,9 @@ int w_newGearJoint(lua_State *L)
 	bool collideConnected = luax_optboolean(L, 4, false);
 	bool collideConnected = luax_optboolean(L, 4, false);
 
 
 	GearJoint *j;
 	GearJoint *j;
-	EXCEPT_GUARD(j = instance->newGearJoint(joint1, joint2, ratio, collideConnected);)
+	luax_catchexcept(L, [&]() {
+		j = instance->newGearJoint(joint1, joint2, ratio, collideConnected);
+	});
 	luax_pushtype(L, "GearJoint", PHYSICS_GEAR_JOINT_T, j);
 	luax_pushtype(L, "GearJoint", PHYSICS_GEAR_JOINT_T, j);
 	return 1;
 	return 1;
 }
 }
@@ -297,7 +307,9 @@ int w_newFrictionJoint(lua_State *L)
 		collideConnected = luax_optboolean(L, 5, false);
 		collideConnected = luax_optboolean(L, 5, false);
 	}
 	}
 	FrictionJoint *j;
 	FrictionJoint *j;
-	EXCEPT_GUARD(j = instance->newFrictionJoint(body1, body2, xA, yA, xB, yB, collideConnected);)
+	luax_catchexcept(L, [&]() {
+		j = instance->newFrictionJoint(body1, body2, xA, yA, xB, yB, collideConnected);
+	});
 	luax_pushtype(L, "FrictionJoint", PHYSICS_FRICTION_JOINT_T, j);
 	luax_pushtype(L, "FrictionJoint", PHYSICS_FRICTION_JOINT_T, j);
 	return 1;
 	return 1;
 }
 }
@@ -323,7 +335,9 @@ int w_newWeldJoint(lua_State *L)
 		collideConnected = luax_optboolean(L, 5, false);
 		collideConnected = luax_optboolean(L, 5, false);
 	}
 	}
 	WeldJoint *j;
 	WeldJoint *j;
-	EXCEPT_GUARD(j = instance->newWeldJoint(body1, body2, xA, yA, xB, yB, collideConnected);)
+	luax_catchexcept(L, [&]() {
+		j = instance->newWeldJoint(body1, body2, xA, yA, xB, yB, collideConnected);
+	});
 	luax_pushtype(L, "WeldJoint", PHYSICS_WELD_JOINT_T, j);
 	luax_pushtype(L, "WeldJoint", PHYSICS_WELD_JOINT_T, j);
 	return 1;
 	return 1;
 }
 }
@@ -354,7 +368,9 @@ int w_newWheelJoint(lua_State *L)
 	}
 	}
 
 
 	WheelJoint *j;
 	WheelJoint *j;
-	EXCEPT_GUARD(j = instance->newWheelJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected);)
+	luax_catchexcept(L, [&]() {
+		j = instance->newWheelJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected);
+	});
 	luax_pushtype(L, "WheelJoint", PHYSICS_WHEEL_JOINT_T, j);
 	luax_pushtype(L, "WheelJoint", PHYSICS_WHEEL_JOINT_T, j);
 	return 1;
 	return 1;
 }
 }
@@ -370,7 +386,9 @@ int w_newRopeJoint(lua_State *L)
 	float maxLength = (float)luaL_checknumber(L, 7);
 	float maxLength = (float)luaL_checknumber(L, 7);
 	bool collideConnected = luax_optboolean(L, 8, false);
 	bool collideConnected = luax_optboolean(L, 8, false);
 	RopeJoint *j;
 	RopeJoint *j;
-	EXCEPT_GUARD(j = instance->newRopeJoint(body1, body2, x1, y1, x2, y2, maxLength, collideConnected);)
+	luax_catchexcept(L, [&]() {
+		j = instance->newRopeJoint(body1, body2, x1, y1, x2, y2, maxLength, collideConnected);
+	});
 	luax_pushtype(L, "RopeJoint", PHYSICS_ROPE_JOINT_T, j);
 	luax_pushtype(L, "RopeJoint", PHYSICS_ROPE_JOINT_T, j);
 	return 1;
 	return 1;
 }
 }
@@ -383,11 +401,13 @@ int w_newMotorJoint(lua_State *L)
 	if (!lua_isnoneornil(L, 3))
 	if (!lua_isnoneornil(L, 3))
 	{
 	{
 		float correctionFactor = (float)luaL_checknumber(L, 3);
 		float correctionFactor = (float)luaL_checknumber(L, 3);
-		EXCEPT_GUARD(j = instance->newMotorJoint(body1, body2, correctionFactor);)
+		luax_catchexcept(L, [&]() {
+			j = instance->newMotorJoint(body1, body2, correctionFactor);
+		});
 	}
 	}
 	else
 	else
 	{
 	{
-		EXCEPT_GUARD(j = instance->newMotorJoint(body1, body2);)
+		luax_catchexcept(L, [&](){ j = instance->newMotorJoint(body1, body2); });
 	}
 	}
 	luax_pushtype(L, "MotorJoint", PHYSICS_MOTOR_JOINT_T, j);
 	luax_pushtype(L, "MotorJoint", PHYSICS_MOTOR_JOINT_T, j);
 	return 1;
 	return 1;
@@ -401,7 +421,7 @@ int w_getDistance(lua_State *L)
 int w_setMeter(lua_State *L)
 int w_setMeter(lua_State *L)
 {
 {
 	int arg1 = luaL_checkint(L, 1);
 	int arg1 = luaL_checkint(L, 1);
-	EXCEPT_GUARD(Physics::setMeter(arg1);)
+	luax_catchexcept(L, [&](){ Physics::setMeter(arg1); });
 	return 0;
 	return 0;
 
 
 }
 }
@@ -469,7 +489,7 @@ extern "C" int luaopen_love_physics(lua_State *L)
 {
 {
 	if (instance == 0)
 	if (instance == 0)
 	{
 	{
-		EXCEPT_GUARD(instance = new Physics();)
+		luax_catchexcept(L, [&](){ instance = new Physics(); });
 	}
 	}
 	else
 	else
 		instance->retain();
 		instance->retain();

+ 3 - 3
src/modules/physics/box2d/wrap_PrismaticJoint.cpp

@@ -122,7 +122,7 @@ int w_PrismaticJoint_setUpperLimit(lua_State *L)
 {
 {
 	PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
 	PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
 	float arg1 = (float)luaL_checknumber(L, 2);
 	float arg1 = (float)luaL_checknumber(L, 2);
-	EXCEPT_GUARD(t->setUpperLimit(arg1);)
+	luax_catchexcept(L, [&](){ t->setUpperLimit(arg1); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -130,7 +130,7 @@ int w_PrismaticJoint_setLowerLimit(lua_State *L)
 {
 {
 	PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
 	PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
 	float arg1 = (float)luaL_checknumber(L, 2);
 	float arg1 = (float)luaL_checknumber(L, 2);
-	EXCEPT_GUARD(t->setLowerLimit(arg1);)
+	luax_catchexcept(L, [&](){ t->setLowerLimit(arg1); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -139,7 +139,7 @@ int w_PrismaticJoint_setLimits(lua_State *L)
 	PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
 	PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
 	float arg1 = (float)luaL_checknumber(L, 2);
 	float arg1 = (float)luaL_checknumber(L, 2);
 	float arg2 = (float)luaL_checknumber(L, 3);
 	float arg2 = (float)luaL_checknumber(L, 3);
-	EXCEPT_GUARD(t->setLimits(arg1, arg2);)
+	luax_catchexcept(L, [&](){ t->setLimits(arg1, arg2); });
 	return 0;
 	return 0;
 }
 }
 
 

+ 3 - 3
src/modules/physics/box2d/wrap_RevoluteJoint.cpp

@@ -122,7 +122,7 @@ int w_RevoluteJoint_setUpperLimit(lua_State *L)
 {
 {
 	RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
 	RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
 	float arg1 = (float)luaL_checknumber(L, 2);
 	float arg1 = (float)luaL_checknumber(L, 2);
-	EXCEPT_GUARD(t->setUpperLimit(arg1);)
+	luax_catchexcept(L, [&](){ t->setUpperLimit(arg1); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -130,7 +130,7 @@ int w_RevoluteJoint_setLowerLimit(lua_State *L)
 {
 {
 	RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
 	RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
 	float arg1 = (float)luaL_checknumber(L, 2);
 	float arg1 = (float)luaL_checknumber(L, 2);
-	EXCEPT_GUARD(t->setLowerLimit(arg1);)
+	luax_catchexcept(L, [&](){ t->setLowerLimit(arg1); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -139,7 +139,7 @@ int w_RevoluteJoint_setLimits(lua_State *L)
 	RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
 	RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
 	float arg1 = (float)luaL_checknumber(L, 2);
 	float arg1 = (float)luaL_checknumber(L, 2);
 	float arg2 = (float)luaL_checknumber(L, 3);
 	float arg2 = (float)luaL_checknumber(L, 3);
-	EXCEPT_GUARD(t->setLimits(arg1, arg2);)
+	luax_catchexcept(L, [&](){ t->setLimits(arg1, arg2); });
 	return 0;
 	return 0;
 }
 }
 
 

+ 1 - 1
src/modules/physics/box2d/wrap_Shape.cpp

@@ -76,7 +76,7 @@ int w_Shape_rayCast(lua_State *L)
 	Shape *t = luax_checkshape(L, 1);
 	Shape *t = luax_checkshape(L, 1);
 	lua_remove(L, 1);
 	lua_remove(L, 1);
 	int ret = 0;
 	int ret = 0;
-	EXCEPT_GUARD(ret = t->rayCast(L);)
+	luax_catchexcept(L, [&](){ ret = t->rayCast(L); });
 	return ret;
 	return ret;
 }
 }
 
 

+ 7 - 7
src/modules/physics/box2d/wrap_World.cpp

@@ -39,7 +39,7 @@ int w_World_update(lua_State *L)
 {
 {
 	World *t = luax_checkworld(L, 1);
 	World *t = luax_checkworld(L, 1);
 	float dt = (float)luaL_checknumber(L, 2);
 	float dt = (float)luaL_checknumber(L, 2);
-	EXCEPT_GUARD(t->update(dt);)
+	luax_catchexcept(L, [&](){ t->update(dt); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -92,7 +92,7 @@ int w_World_translateOrigin(lua_State *L)
 	World *t = luax_checkworld(L, 1);
 	World *t = luax_checkworld(L, 1);
 	float arg1 = (float)luaL_checknumber(L, 2);
 	float arg1 = (float)luaL_checknumber(L, 2);
 	float arg2 = (float)luaL_checknumber(L, 3);
 	float arg2 = (float)luaL_checknumber(L, 3);
-	EXCEPT_GUARD(t->translateOrigin(arg1, arg2);)
+	luax_catchexcept(L, [&](){ t->translateOrigin(arg1, arg2); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -144,7 +144,7 @@ int w_World_getBodyList(lua_State *L)
 	World *t = luax_checkworld(L, 1);
 	World *t = luax_checkworld(L, 1);
 	lua_remove(L, 1);
 	lua_remove(L, 1);
 	int ret = 0;
 	int ret = 0;
-	EXCEPT_GUARD(ret = t->getBodyList(L);)
+	luax_catchexcept(L, [&](){ ret = t->getBodyList(L); });
 	return ret;
 	return ret;
 }
 }
 
 
@@ -153,7 +153,7 @@ int w_World_getJointList(lua_State *L)
 	World *t = luax_checkworld(L, 1);
 	World *t = luax_checkworld(L, 1);
 	lua_remove(L, 1);
 	lua_remove(L, 1);
 	int ret = 0;
 	int ret = 0;
-	EXCEPT_GUARD(ret = t->getJointList(L);)
+	luax_catchexcept(L, [&](){ ret = t->getJointList(L); });
 	return ret;
 	return ret;
 }
 }
 
 
@@ -162,7 +162,7 @@ int w_World_getContactList(lua_State *L)
 	World *t = luax_checkworld(L, 1);
 	World *t = luax_checkworld(L, 1);
 	lua_remove(L, 1);
 	lua_remove(L, 1);
 	int ret = 0;
 	int ret = 0;
-	EXCEPT_GUARD(ret = t->getContactList(L);)
+	luax_catchexcept(L, [&](){ ret = t->getContactList(L); });
 	return ret;
 	return ret;
 }
 }
 
 
@@ -178,14 +178,14 @@ int w_World_rayCast(lua_State *L)
 	World *t = luax_checkworld(L, 1);
 	World *t = luax_checkworld(L, 1);
 	lua_remove(L, 1);
 	lua_remove(L, 1);
 	int ret = 0;
 	int ret = 0;
-	EXCEPT_GUARD(ret = t->rayCast(L);)
+	luax_catchexcept(L, [&](){ ret = t->rayCast(L); });
 	return ret;
 	return ret;
 }
 }
 
 
 int w_World_destroy(lua_State *L)
 int w_World_destroy(lua_State *L)
 {
 {
 	World *t = luax_checkworld(L, 1);
 	World *t = luax_checkworld(L, 1);
-	EXCEPT_GUARD(t->destroy();)
+	luax_catchexcept(L, [&](){ t->destroy(); });
 	return 0;
 	return 0;
 }
 }
 
 

+ 7 - 4
src/modules/sound/wrap_Sound.cpp

@@ -43,7 +43,7 @@ int w_newSoundData(lua_State *L)
 		int bitDepth = luaL_optint(L, 3, Decoder::DEFAULT_BIT_DEPTH);
 		int bitDepth = luaL_optint(L, 3, Decoder::DEFAULT_BIT_DEPTH);
 		int channels = luaL_optint(L, 4, Decoder::DEFAULT_CHANNELS);
 		int channels = luaL_optint(L, 4, Decoder::DEFAULT_CHANNELS);
 
 
-		EXCEPT_GUARD(t = instance->newSoundData(samples, sampleRate, bitDepth, channels);)
+		luax_catchexcept(L, [&](){ t = instance->newSoundData(samples, sampleRate, bitDepth, channels); });
 	}
 	}
 	// Must be string or decoder.
 	// Must be string or decoder.
 	else
 	else
@@ -55,7 +55,7 @@ int w_newSoundData(lua_State *L)
 			lua_replace(L, 1);
 			lua_replace(L, 1);
 		}
 		}
 
 
-		EXCEPT_GUARD(t = instance->newSoundData(luax_checkdecoder(L, 1));)
+		luax_catchexcept(L, [&](){ t = instance->newSoundData(luax_checkdecoder(L, 1)); });
 	}
 	}
 
 
 	luax_pushtype(L, "SoundData", SOUND_SOUND_DATA_T, t);
 	luax_pushtype(L, "SoundData", SOUND_SOUND_DATA_T, t);
@@ -68,7 +68,10 @@ int w_newDecoder(lua_State *L)
 	int bufferSize = luaL_optint(L, 2, Decoder::DEFAULT_BUFFER_SIZE);
 	int bufferSize = luaL_optint(L, 2, Decoder::DEFAULT_BUFFER_SIZE);
 
 
 	Decoder *t = nullptr;
 	Decoder *t = nullptr;
-	EXCEPT_GUARD_FINALLY(t = instance->newDecoder(data, bufferSize);, data->release();)
+	luax_catchexcept(L,
+		[&]() { t = instance->newDecoder(data, bufferSize); },
+		[&]() { data->release(); }
+	);
 
 
 	if (t == nullptr)
 	if (t == nullptr)
 		return luaL_error(L, "Extension \"%s\" not supported.", data->getExtension().c_str());
 		return luaL_error(L, "Extension \"%s\" not supported.", data->getExtension().c_str());
@@ -96,7 +99,7 @@ extern "C" int luaopen_love_sound(lua_State *L)
 {
 {
 	if (instance == 0)
 	if (instance == 0)
 	{
 	{
-		EXCEPT_GUARD(instance = new lullaby::Sound();)
+		luax_catchexcept(L, [&](){ instance = new lullaby::Sound(); });
 	}
 	}
 	else
 	else
 		instance->retain();
 		instance->retain();

+ 2 - 2
src/modules/sound/wrap_SoundData.cpp

@@ -73,7 +73,7 @@ int w_SoundData_setSample(lua_State *L)
 	int i = (int) luaL_checkinteger(L, 2);
 	int i = (int) luaL_checkinteger(L, 2);
 	float sample = (float) luaL_checknumber(L, 3);
 	float sample = (float) luaL_checknumber(L, 3);
 
 
-	EXCEPT_GUARD(sd->setSample(i, sample);)
+	luax_catchexcept(L, [&](){ sd->setSample(i, sample); });
 	return 0;
 	return 0;
 }
 }
 
 
@@ -82,7 +82,7 @@ int w_SoundData_getSample(lua_State *L)
 	SoundData *sd = luax_checksounddata(L, 1);
 	SoundData *sd = luax_checksounddata(L, 1);
 	int i = (int) luaL_checkinteger(L, 2);
 	int i = (int) luaL_checkinteger(L, 2);
 
 
-	EXCEPT_GUARD(lua_pushnumber(L, sd->getSample(i));)
+	luax_catchexcept(L, [&](){ lua_pushnumber(L, sd->getSample(i)); });
 	return 1;
 	return 1;
 }
 }
 
 

+ 1 - 1
src/modules/thread/wrap_ThreadModule.cpp

@@ -91,7 +91,7 @@ extern "C" int luaopen_love_thread(lua_State *L)
 {
 {
 	if (instance == 0)
 	if (instance == 0)
 	{
 	{
-		EXCEPT_GUARD(instance = new love::thread::ThreadModule();)
+		luax_catchexcept(L, [&](){ instance = new love::thread::ThreadModule(); });
 	}
 	}
 	else
 	else
 		instance->retain();
 		instance->retain();

+ 1 - 1
src/modules/timer/wrap_Timer.cpp

@@ -85,7 +85,7 @@ extern "C" int luaopen_love_timer(lua_State *L)
 {
 {
 	if (instance == 0)
 	if (instance == 0)
 	{
 	{
-		EXCEPT_GUARD(instance = new love::timer::sdl::Timer();)
+		luax_catchexcept(L, [&](){ instance = new love::timer::sdl::Timer(); });
 	}
 	}
 	else
 	else
 		instance->retain();
 		instance->retain();

+ 5 - 2
src/modules/window/wrap_Window.cpp

@@ -101,7 +101,10 @@ int w_setMode(lua_State *L)
 	// Display index is 1-based in Lua and 0-based internally.
 	// Display index is 1-based in Lua and 0-based internally.
 	settings.display--;
 	settings.display--;
 
 
-	EXCEPT_GUARD(luax_pushboolean(L, instance->setWindow(w, h, &settings));)
+	luax_catchexcept(L,
+		[&](){ luax_pushboolean(L, instance->setWindow(w, h, &settings)); }
+	);
+
 	return 1;
 	return 1;
 }
 }
 
 
@@ -339,7 +342,7 @@ static const luaL_Reg functions[] =
 
 
 extern "C" int luaopen_love_window(lua_State *L)
 extern "C" int luaopen_love_window(lua_State *L)
 {
 {
-	EXCEPT_GUARD(instance = sdl::Window::createSingleton();)
+	luax_catchexcept(L, [&](){ instance = sdl::Window::createSingleton(); });
 
 
 	WrappedModule w;
 	WrappedModule w;
 	w.module = instance;
 	w.module = instance;