aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorMax Horn2011-05-23 14:21:00 +0200
committerMax Horn2011-05-23 19:12:24 +0200
commitfa2c268d6a813a2fdfc4475607b1ebb5d878a624 (patch)
tree40571aeb94bea441d42613f85c0531b7a5a0ad5d /engines
parent944e0be209f5ab47c3b903f258d2d41b990d80cb (diff)
downloadscummvm-rg350-fa2c268d6a813a2fdfc4475607b1ebb5d878a624.tar.gz
scummvm-rg350-fa2c268d6a813a2fdfc4475607b1ebb5d878a624.tar.bz2
scummvm-rg350-fa2c268d6a813a2fdfc4475607b1ebb5d878a624.zip
SWORD25: Replace some non-portable calls, add FIXMEs
Diffstat (limited to 'engines')
-rw-r--r--engines/sword25/util/lua/loslib.cpp42
1 files changed, 35 insertions, 7 deletions
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 <stdlib.h>
-#include <string.h>
#include <time.h>
#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));
}