diff options
Diffstat (limited to 'engines')
-rw-r--r-- | engines/sword25/util/lua/ldo.cpp | 25 | ||||
-rw-r--r-- | engines/sword25/util/lua/lua.h | 9 | ||||
-rw-r--r-- | engines/sword25/util/lua/luaconf.h | 2 |
3 files changed, 20 insertions, 16 deletions
diff --git a/engines/sword25/util/lua/ldo.cpp b/engines/sword25/util/lua/ldo.cpp index 5d9667f4f0..33ed3255a3 100644 --- a/engines/sword25/util/lua/ldo.cpp +++ b/engines/sword25/util/lua/ldo.cpp @@ -6,12 +6,10 @@ // FIXME: LUAI_THROW and LUAI_TRY use either throw/catch or setjmp/longjmp. -// Neither of these is supported in ScummVM. So we need to come up -// with a replacement. The most simple, direct and crude approach: -// Replace "throw" with an "error()" call. Of course we only -// would want to do that if this actually never happens... -#define FORBIDDEN_SYMBOL_EXCEPTION_setjmp -#define FORBIDDEN_SYMBOL_EXCEPTION_longjmp +// Neither of these is supported in ScummVM. Calls to LUAI_THROW have been +// replaced with error() in ScummVM, but the calls to LUAI_TRY remain +#define FORBIDDEN_SYMBOL_EXCEPTION_setjmp // for LUAI_TRY, i.e. try() +#define FORBIDDEN_SYMBOL_EXCEPTION_longjmp // for LUAI_TRY and LUAI_THROW, i.e. throw() #include "common/textconsole.h" @@ -103,12 +101,10 @@ static void resetstack (lua_State *L, int status) { void luaD_throw (lua_State *L, int errcode) { if (L->errorJmp) { L->errorJmp->status = errcode; - // FIXME: LUAI_THROW and LUAI_TRY use either throw/catch or setjmp/longjmp. - // Neither of these is supported in ScummVM. So we need to come up - // with a replacement. The most simple, direct and crude approach: - // Replace "throw" with an "error()" call. Of course we only - // would want to do that if this actually never happens... - LUAI_THROW(L, L->errorJmp); + // LUAI_THROW has been replaced with an error message in ScummVM, together + // with the LUA error code and description + //LUAI_THROW(L, L->errorJmp); + error("LUA error occured, error code is %d (%s)", errcode, luaErrorDescription[errcode]); } else { L->status = cast_byte(errcode); @@ -129,9 +125,8 @@ int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { L->errorJmp = &lj; // FIXME: LUAI_THROW and LUAI_TRY use either throw/catch or setjmp/longjmp. // Neither of these is supported in ScummVM. So we need to come up - // with a replacement. The most simple, direct and crude approach: - // Replace "throw" with an "error()" call. Of course we only - // would want to do that if this actually never happens... + // with a replacement. Calls to LUAI_THROW have been replaced with error() + // in ScummVM, but the calls to LUAI_TRY remain LUAI_TRY(L, &lj, (*f)(L, ud); ); diff --git a/engines/sword25/util/lua/lua.h b/engines/sword25/util/lua/lua.h index 08ad80d70f..768ec1ad74 100644 --- a/engines/sword25/util/lua/lua.h +++ b/engines/sword25/util/lua/lua.h @@ -48,6 +48,15 @@ #define LUA_ERRMEM 4 #define LUA_ERRERR 5 +// Added in ScummVM. Refer to http://www.lua.org/manual/5.1/manual.html +static const char* luaErrorDescription[] = { + "No error", + "Coroutine yield", // not an actual error, see lua_resume + "Runtime error", + "Syntax error during pre-compilation", // refer to lua_load + "Memory allocation error", + "Error while running the error handler function" +}; typedef struct lua_State lua_State; diff --git a/engines/sword25/util/lua/luaconf.h b/engines/sword25/util/lua/luaconf.h index 53d0f55290..fb85983998 100644 --- a/engines/sword25/util/lua/luaconf.h +++ b/engines/sword25/util/lua/luaconf.h @@ -621,7 +621,7 @@ union luai_Cast { double l_d; long l_l; }; #else /* default handling with long jumps */ -#define LUAI_THROW(L,c) longjmp((c)->b, 1) +//#define LUAI_THROW(L,c) longjmp((c)->b, 1) // replaced with error() in ScummVM #define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a } #define luai_jmpbuf jmp_buf |