aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorMax Horn2011-05-23 18:59:37 +0200
committerMax Horn2011-05-23 19:12:25 +0200
commite6c78b4f469729726561af44aa1df8259f0fdf27 (patch)
treeb8444895c21f551c1373e1ea1aefb7b075a10018 /engines
parent8e3aafd30d14bcd586cc06a525e2dc2a8298c7b2 (diff)
downloadscummvm-rg350-e6c78b4f469729726561af44aa1df8259f0fdf27.tar.gz
scummvm-rg350-e6c78b4f469729726561af44aa1df8259f0fdf27.tar.bz2
scummvm-rg350-e6c78b4f469729726561af44aa1df8259f0fdf27.zip
SWORD25: Include scummsys.h from lua.h, partially deal with the consequences
This should help mark the spots that are still non-portable, just follow the FIXMEs.
Diffstat (limited to 'engines')
-rw-r--r--engines/sword25/util/lua/ldo.cpp18
-rw-r--r--engines/sword25/util/lua/lmathlib.cpp4
-rw-r--r--engines/sword25/util/lua/loadlib.cpp65
-rw-r--r--engines/sword25/util/lua/loslib.cpp6
-rw-r--r--engines/sword25/util/lua/lua.h2
-rw-r--r--engines/sword25/util/lua/print.cpp3
6 files changed, 46 insertions, 52 deletions
diff --git a/engines/sword25/util/lua/ldo.cpp b/engines/sword25/util/lua/ldo.cpp
index 07508fbb14..b03992385a 100644
--- a/engines/sword25/util/lua/ldo.cpp
+++ b/engines/sword25/util/lua/ldo.cpp
@@ -5,6 +5,14 @@
*/
+// 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
+
#include <setjmp.h>
#include <stdlib.h>
#include <string.h>
@@ -94,6 +102,11 @@ 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);
}
else {
@@ -113,6 +126,11 @@ int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) {
lj.status = 0;
lj.previous = L->errorJmp; /* chain new error handler */
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...
LUAI_TRY(L, &lj,
(*f)(L, ud);
);
diff --git a/engines/sword25/util/lua/lmathlib.cpp b/engines/sword25/util/lua/lmathlib.cpp
index 7e64d75789..6c36bbcf4e 100644
--- a/engines/sword25/util/lua/lmathlib.cpp
+++ b/engines/sword25/util/lua/lmathlib.cpp
@@ -5,6 +5,10 @@
*/
+// FIXME: rand and srand should be replaced by a RandomSource
+#define FORBIDDEN_SYMBOL_EXCEPTION_rand
+#define FORBIDDEN_SYMBOL_EXCEPTION_srand
+
#include <stdlib.h>
// MSVC does not define M_PI, M_SQRT2 and other math defines by default.
// _USE_MATH_DEFINES must be defined in order to have these defined, thus
diff --git a/engines/sword25/util/lua/loadlib.cpp b/engines/sword25/util/lua/loadlib.cpp
index 2549e2bdb1..2fa831ac2a 100644
--- a/engines/sword25/util/lua/loadlib.cpp
+++ b/engines/sword25/util/lua/loadlib.cpp
@@ -8,6 +8,15 @@
** implementation for Windows, and a stub for other systems.
*/
+// FIXME: Avoid using these APIs.
+// Actually, this could be achieved by removing 80% of the remaining
+// code in this file. Most of it is an elaborate way of expressing
+// something like "return ERROR;" anyway, as we don't support loading
+// dynamic libs
+#define FORBIDDEN_SYMBOL_EXCEPTION_FILE
+#define FORBIDDEN_SYMBOL_EXCEPTION_fopen
+#define FORBIDDEN_SYMBOL_EXCEPTION_fclose
+
#include <stdlib.h>
#include <string.h>
@@ -39,13 +48,6 @@
#define ERRLIB 1
#define ERRFUNC 2
-#define setprogdir(L) ((void)0)
-
-
-static void ll_unloadlib (void *lib);
-static void *ll_load (lua_State *L, const char *path);
-static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym);
-
/*
** {======================================================
@@ -60,24 +62,6 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym);
#define DLMSG "dynamic libraries not enabled; check your Lua installation"
-static void ll_unloadlib (void *lib) {
- (void)lib; /* to avoid warnings */
-}
-
-
-static void *ll_load (lua_State *L, const char *path) {
- (void)path; /* to avoid warnings */
- lua_pushliteral(L, DLMSG);
- return NULL;
-}
-
-
-static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {
- (void)lib; (void)sym; /* to avoid warnings */
- lua_pushliteral(L, DLMSG);
- return NULL;
-}
-
/* }====================================================== */
@@ -108,7 +92,6 @@ static void **ll_register (lua_State *L, const char *path) {
*/
static int gctm (lua_State *L) {
void **lib = (void **)luaL_checkudata(L, 1, "_LOADLIB");
- if (*lib) ll_unloadlib(*lib);
*lib = NULL; /* mark library as closed */
return 0;
}
@@ -116,15 +99,11 @@ static int gctm (lua_State *L) {
static int ll_loadfunc (lua_State *L, const char *path, const char *sym) {
void **reg = ll_register(L, path);
- if (*reg == NULL) *reg = ll_load(L, path);
- if (*reg == NULL)
+ if (*reg == NULL) {
+ lua_pushliteral(L, DLMSG); // loading not supported, just push an error msg
return ERRLIB; /* unable to load library */
- else {
- lua_CFunction f = ll_sym(L, *reg, sym);
- if (f == NULL)
- return ERRFUNC; /* unable to find function */
- lua_pushcfunction(L, f);
- return 0; /* return function */
+ } else {
+ return ERRFUNC; /* unable to find function */
}
}
@@ -407,23 +386,11 @@ static int ll_seeall (lua_State *L) {
-/* auxiliary mark (for internal use) */
-#define AUXMARK "\1"
-
static void setpath (lua_State *L, const char *fieldname, const char *envname,
const char *def) {
- const char *path = getenv(envname);
- if (path == NULL) /* no environment variable? */
- lua_pushstring(L, def); /* use default */
- else {
- /* replace ";;" by ";AUXMARK;" and then AUXMARK by default path */
- path = luaL_gsub(L, path, LUA_PATHSEP LUA_PATHSEP,
- LUA_PATHSEP AUXMARK LUA_PATHSEP);
- luaL_gsub(L, path, AUXMARK, def);
- lua_remove(L, -2);
- }
- setprogdir(L);
- lua_setfield(L, -2, fieldname);
+ // no environment variable -> use default
+ lua_pushstring(L, def);
+ lua_setfield(L, -2, fieldname);
}
diff --git a/engines/sword25/util/lua/loslib.cpp b/engines/sword25/util/lua/loslib.cpp
index ac634db558..c46aea59bd 100644
--- a/engines/sword25/util/lua/loslib.cpp
+++ b/engines/sword25/util/lua/loslib.cpp
@@ -4,6 +4,9 @@
** See Copyright Notice in lua.h
*/
+// FIXME: Get rid of all time.h stuff
+#define FORBIDDEN_SYMBOL_EXCEPTION_time_h
+
#include <time.h>
#define loslib_c
@@ -14,9 +17,6 @@
#include "lauxlib.h"
#include "lualib.h"
-// FIXME: Get rid of all time.h stuff
-#define FORBIDDEN_SYMBOL_EXCEPTION_time_h
-
#include "common/system.h"
diff --git a/engines/sword25/util/lua/lua.h b/engines/sword25/util/lua/lua.h
index 088a511cf9..417cdadf8b 100644
--- a/engines/sword25/util/lua/lua.h
+++ b/engines/sword25/util/lua/lua.h
@@ -9,6 +9,8 @@
#ifndef lua_h
#define lua_h
+#include "common/scummsys.h"
+
#include <stdarg.h>
#include <stddef.h>
diff --git a/engines/sword25/util/lua/print.cpp b/engines/sword25/util/lua/print.cpp
index 22039c9861..70c6081b81 100644
--- a/engines/sword25/util/lua/print.cpp
+++ b/engines/sword25/util/lua/print.cpp
@@ -4,6 +4,9 @@
** See Copyright Notice in lua.h
*/
+// FIXME
+#define FORBIDDEN_SYMBOL_EXCEPTION_printf
+
#include <ctype.h>
#include <stdio.h>