[Scummvm-cvs-logs] scummvm master -> afdb28b4e96d0a7ebfba15821b3e7071f4a02e6a
bluegr
bluegr at gmail.com
Sun Feb 3 17:17:59 CET 2013
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
afdb28b4e9 SWORD25: Replace calls to LUAI_THROW() with error() in LUA
Commit: afdb28b4e96d0a7ebfba15821b3e7071f4a02e6a
https://github.com/scummvm/scummvm/commit/afdb28b4e96d0a7ebfba15821b3e7071f4a02e6a
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2013-02-03T08:17:02-08:00
Commit Message:
SWORD25: Replace calls to LUAI_THROW() with error() in LUA
This removes one of the uses of setjmp(), but its use in LUAI_TRY still
remains
Changed paths:
engines/sword25/util/lua/ldo.cpp
engines/sword25/util/lua/lua.h
engines/sword25/util/lua/luaconf.h
diff --git a/engines/sword25/util/lua/ldo.cpp b/engines/sword25/util/lua/ldo.cpp
index 5d9667f..33ed325 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 08ad80d..768ec1a 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 53d0f55..fb85983 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
More information about the Scummvm-git-logs
mailing list