From cd54d761e10f5c8f24c5508ae22381ed71018abc Mon Sep 17 00:00:00 2001 From: md5 Date: Sat, 14 May 2011 14:57:33 +0300 Subject: SWORD25 (LUA): Disabled a lot of non-portable LUA functions sword25 doesn't use these (thankfully) --- engines/sword25/util/lua/loslib.cpp | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) (limited to 'engines/sword25/util/lua/loslib.cpp') diff --git a/engines/sword25/util/lua/loslib.cpp b/engines/sword25/util/lua/loslib.cpp index 035925ceb5..51266b522f 100644 --- a/engines/sword25/util/lua/loslib.cpp +++ b/engines/sword25/util/lua/loslib.cpp @@ -5,7 +5,6 @@ */ -#include #include #include #include @@ -20,21 +19,6 @@ #include "lualib.h" -static int os_pushresult (lua_State *L, int i, const char *filename) { - int en = errno; /* calls to Lua API may change this value */ - if (i) { - lua_pushboolean(L, 1); - return 1; - } - else { - lua_pushnil(L); - lua_pushfstring(L, "%s: %s", filename, strerror(en)); - lua_pushinteger(L, en); - return 3; - } -} - - static int os_execute (lua_State *L) { lua_pushinteger(L, system(luaL_optstring(L, 1, NULL))); return 1; @@ -42,15 +26,15 @@ static int os_execute (lua_State *L) { static int os_remove (lua_State *L) { - const char *filename = luaL_checkstring(L, 1); - return os_pushresult(L, remove(filename) == 0, filename); + // Removed in ScummVM, does nothing. It's called when loading games (perhaps + // to delete the savegame thumbnail?) + return 1; } static int os_rename (lua_State *L) { - const char *fromname = luaL_checkstring(L, 1); - const char *toname = luaL_checkstring(L, 2); - return os_pushresult(L, rename(fromname, toname) == 0, fromname); + // Removed in ScummVM, does nothing. + return 1; } -- cgit v1.2.3 From b34e776e517b893d3cc140e7282a99026c2500f8 Mon Sep 17 00:00:00 2001 From: md5 Date: Sun, 15 May 2011 11:25:46 +0300 Subject: SWORD25 (LUA): Clarified the use of os_remove() --- engines/sword25/util/lua/loslib.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'engines/sword25/util/lua/loslib.cpp') diff --git a/engines/sword25/util/lua/loslib.cpp b/engines/sword25/util/lua/loslib.cpp index 51266b522f..de96860812 100644 --- a/engines/sword25/util/lua/loslib.cpp +++ b/engines/sword25/util/lua/loslib.cpp @@ -26,8 +26,11 @@ static int os_execute (lua_State *L) { static int os_remove (lua_State *L) { - // Removed in ScummVM, does nothing. It's called when loading games (perhaps - // to delete the savegame thumbnail?) + // Non-portable call that deletes a file. Removed in ScummVM. + // This call is invoked in sword25 when loading games in order to remove the + // temporary savegame thumbnail that the original engine code created. We + // embed the thumbnail in the savegame instead, so this call is not needed at + // all. return 1; } -- cgit v1.2.3 From 5f583eda0dbd09034ae44dd726b710a18d1aaec5 Mon Sep 17 00:00:00 2001 From: md5 Date: Sun, 15 May 2011 13:46:22 +0300 Subject: SWORD25 (LUA): Removed unused non-portable locale code --- engines/sword25/util/lua/loslib.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'engines/sword25/util/lua/loslib.cpp') diff --git a/engines/sword25/util/lua/loslib.cpp b/engines/sword25/util/lua/loslib.cpp index de96860812..578a7cb09a 100644 --- a/engines/sword25/util/lua/loslib.cpp +++ b/engines/sword25/util/lua/loslib.cpp @@ -5,7 +5,6 @@ */ -#include #include #include #include @@ -183,13 +182,8 @@ static int os_difftime (lua_State *L) { static int os_setlocale (lua_State *L) { - static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, - LC_NUMERIC, LC_TIME}; - static const char *const catnames[] = {"all", "collate", "ctype", "monetary", - "numeric", "time", NULL}; - const char *l = luaL_optstring(L, 1, NULL); - int op = luaL_checkoption(L, 2, "all", catnames); - lua_pushstring(L, setlocale(cat[op], l)); + // Non-portable call to set the numeric locale. Removed in ScummVM, as it's + // not used in sword25. return 1; } -- cgit v1.2.3 From fa2c268d6a813a2fdfc4475607b1ebb5d878a624 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 23 May 2011 14:21:00 +0200 Subject: SWORD25: Replace some non-portable calls, add FIXMEs --- engines/sword25/util/lua/loslib.cpp | 42 ++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) (limited to 'engines/sword25/util/lua/loslib.cpp') diff --git a/engines/sword25/util/lua/loslib.cpp b/engines/sword25/util/lua/loslib.cpp index 578a7cb09a..ac634db558 100644 --- a/engines/sword25/util/lua/loslib.cpp +++ b/engines/sword25/util/lua/loslib.cpp @@ -4,9 +4,6 @@ ** See Copyright Notice in lua.h */ - -#include -#include #include #define loslib_c @@ -17,9 +14,16 @@ #include "lauxlib.h" #include "lualib.h" +// FIXME: Get rid of all time.h stuff +#define FORBIDDEN_SYMBOL_EXCEPTION_time_h + +#include "common/system.h" + static int os_execute (lua_State *L) { - lua_pushinteger(L, system(luaL_optstring(L, 1, NULL))); + // Non-portable call, removed in ScummVM. + // FIXME: Is this ever invoked? If so, investigate that code further. + lua_pushinteger(L, -1); // signal that an error occurred return 1; } @@ -35,24 +39,30 @@ static int os_remove (lua_State *L) { static int os_rename (lua_State *L) { - // Removed in ScummVM, does nothing. + // Non-portable call, removed in ScummVM. return 1; } static int os_tmpname (lua_State *L) { + // Non-portable call, removed in ScummVM. + // FIXME: Why do we return an error in tmpname, but for other + // removed methods we just do nothing? return luaL_error(L, "unable to generate a unique filename"); } static int os_getenv (lua_State *L) { - lua_pushstring(L, getenv(luaL_checkstring(L, 1))); /* if NULL push nil */ + // Non-portable call, removed in ScummVM. + // FIXME: Is this ever invoked? If so, investigate that code further. + lua_pushstring(L, NULL); return 1; } static int os_clock (lua_State *L) { - lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC); + // Non-portable call to clock() replaced by invocation of OSystem::getMillis. + lua_pushnumber(L, ((lua_Number)g_system->getMillis())/(lua_Number)1000); return 1; } @@ -103,6 +113,12 @@ static int getfield (lua_State *L, const char *key, int d) { static int os_date (lua_State *L) { const char *s = luaL_optstring(L, 1, "%c"); + // FIXME: Rewrite the code below to use OSystem::getTimeAndDate + // Alternatively, remove it, if sword25 does not use it. + // + // The former would mean sacrificing the ability to choose the timezone, *or* + // we would have to drive an effort to add time zone support to OSystem (is it + // worth that, though???) time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL)); struct tm *stm; if (*s == '!') { /* UTC? */ @@ -148,6 +164,8 @@ static int os_date (lua_State *L) { static int os_time (lua_State *L) { + // FIXME: Rewrite the code below to use OSystem::getTimeAndDate. + // Alternatively, remove it, if sword25 does not use it. time_t t; if (lua_isnoneornil(L, 1)) /* called without args? */ t = time(NULL); /* get current time */ @@ -173,6 +191,9 @@ static int os_time (lua_State *L) { static int os_difftime (lua_State *L) { + // FIXME: difftime is not portable, unfortunately. + // So we either have to replace this code, or just remove it, + // depending on whether sword25 actually uses it. lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)), (time_t)(luaL_optnumber(L, 2, 0)))); return 1; @@ -189,6 +210,13 @@ static int os_setlocale (lua_State *L) { static int os_exit (lua_State *L) { + // FIXME: Using exit is not portable! + // Using OSystem::quit() isn't really a great idea, either. + // We really would prefer to let the main run loop exit, so that + // our main() can perform cleanup. + g_system->quit(); + // leave the exit call in there for now, in case some of our + // OSystem::quit applications are incorrect... *sigh* exit(luaL_optint(L, 1, EXIT_SUCCESS)); } -- cgit v1.2.3 From e6c78b4f469729726561af44aa1df8259f0fdf27 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 23 May 2011 18:59:37 +0200 Subject: 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. --- engines/sword25/util/lua/loslib.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'engines/sword25/util/lua/loslib.cpp') 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 #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" -- cgit v1.2.3 From 6c5f50c246062bcb50a20efe7951be7e23449ca0 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 23 May 2011 19:20:56 +0200 Subject: COMMON: Add exit() to list of forbidden symbols --- engines/sword25/util/lua/loslib.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'engines/sword25/util/lua/loslib.cpp') diff --git a/engines/sword25/util/lua/loslib.cpp b/engines/sword25/util/lua/loslib.cpp index c46aea59bd..b61f8c65e1 100644 --- a/engines/sword25/util/lua/loslib.cpp +++ b/engines/sword25/util/lua/loslib.cpp @@ -18,6 +18,7 @@ #include "lualib.h" #include "common/system.h" +#include "common/textconsole.h" static int os_execute (lua_State *L) { @@ -214,10 +215,9 @@ static int os_exit (lua_State *L) { // Using OSystem::quit() isn't really a great idea, either. // We really would prefer to let the main run loop exit, so that // our main() can perform cleanup. - g_system->quit(); - // leave the exit call in there for now, in case some of our - // OSystem::quit applications are incorrect... *sigh* - exit(luaL_optint(L, 1, EXIT_SUCCESS)); + if (0 == luaL_optint(L, 1, EXIT_SUCCESS)) + g_system->quit(); + error("LUA os_exit invokes with non-zero exit value"); } static const luaL_Reg syslib[] = { -- cgit v1.2.3