mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-02 22:21:22 +00:00
Refactor lua_jailbreak_exception
Revert the changes to the stock Lua source code and move them into the Wesnoth-specific header.
This commit is contained in:
parent
160a4611d6
commit
f88c3b22b8
@ -3,7 +3,7 @@
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include <setjmp.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -11,12 +11,6 @@
|
||||
#define ldo_c
|
||||
#define LUA_CORE
|
||||
|
||||
#include "../lua_jailbreak_exception.hpp"
|
||||
#include <exception>
|
||||
#if !defined(__cplusplus)
|
||||
#error "Exception support requires a C++ compiler."
|
||||
#endif
|
||||
|
||||
#include "lua.h"
|
||||
|
||||
#include "lapi.h"
|
||||
@ -51,33 +45,14 @@
|
||||
** C++ code, with _longjmp/_setjmp when asked to use them, and with
|
||||
** longjmp/setjmp otherwise.
|
||||
*/
|
||||
#if defined(__cplusplus)
|
||||
/* C++ exceptions */
|
||||
#define LUAI_THROW(L,c) throw(c)
|
||||
#define LUAI_TRY(L,c,a) \
|
||||
try { \
|
||||
try { \
|
||||
a \
|
||||
} catch(const tlua_jailbreak_exception &e) { \
|
||||
e.store(); \
|
||||
throw; \
|
||||
} catch(const std::exception &e) { \
|
||||
lua_pushstring(L, e.what()); \
|
||||
luaG_errormsg(L); \
|
||||
throw; \
|
||||
} catch (const lua_longjmp *) { \
|
||||
/*this exception is used internaly by lua exceptions*/ \
|
||||
throw; \
|
||||
} catch(...) { \
|
||||
assert(false && "Lua is swallowing an un-named exception... this indicates a programmer error, please derive all exceptions from either std::exception, or tlua_jailbreak_exception (and not with multiple inheritance pathways to either or this exception handler will not work!)"); \
|
||||
throw; \
|
||||
} \
|
||||
} catch(...) { \
|
||||
if((c)->status == 0) \
|
||||
(c)->status = -1;\
|
||||
}
|
||||
#define luai_jmpbuf int /* dummy variable */
|
||||
#if !defined(LUAI_THROW)
|
||||
|
||||
#if defined(__cplusplus) && !defined(LUA_USE_LONGJMP)
|
||||
/* C++ exceptions */
|
||||
#define LUAI_THROW(L,c) throw(c)
|
||||
#define LUAI_TRY(L,c,a) \
|
||||
try { a } catch(...) { if ((c)->status == 0) (c)->status = -1; }
|
||||
#define luai_jmpbuf int /* dummy variable */
|
||||
|
||||
#elif defined(LUA_USE_ULONGJMP)
|
||||
/* in Unix, try _longjmp/_setjmp (more efficient) */
|
||||
@ -93,6 +68,8 @@
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* chain list of long jump buffers */
|
||||
|
@ -57,4 +57,44 @@
|
||||
#include <string.h>
|
||||
#define strcoll(a,b) strcmp(a,b)
|
||||
|
||||
/* We need to rethrow exceptions.
|
||||
*
|
||||
* The stock Lua catch(...) consumes the exception. We need to re-throw
|
||||
* it so. This allows the inner function (in C++ -> Lua -> C++) to pass
|
||||
* back information about the exception, instead of reclassifying all
|
||||
* exceptions to a single Lua status code.
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include <exception>
|
||||
|
||||
#include "lua_jailbreak_exception.hpp"
|
||||
|
||||
#define LUAI_THROW(L,c) throw(c)
|
||||
|
||||
#define LUAI_TRY(L,c,a) \
|
||||
try { \
|
||||
try { \
|
||||
a \
|
||||
} catch(const tlua_jailbreak_exception &e) { \
|
||||
e.store(); \
|
||||
throw; \
|
||||
} catch(const std::exception &e) { \
|
||||
lua_pushstring(L, e.what()); \
|
||||
luaG_errormsg(L); \
|
||||
throw; \
|
||||
} catch (const lua_longjmp *) { \
|
||||
/*this exception is used internaly by lua exceptions*/ \
|
||||
throw; \
|
||||
} catch(...) { \
|
||||
assert(false && "Lua is swallowing an un-named exception... this indicates a programmer error, please derive all exceptions from either std::exception, or tlua_jailbreak_exception (and not with multiple inheritance pathways to either or this exception handler will not work!)"); \
|
||||
throw; \
|
||||
} \
|
||||
} catch(...) { \
|
||||
if((c)->status == 0) \
|
||||
(c)->status = -1;\
|
||||
}
|
||||
|
||||
#define luai_jmpbuf int /* dummy variable */
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user