Skip to content

Commit

Permalink
SWORD25: Replace some non-portable calls, add FIXMEs
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed May 23, 2011
1 parent 944e0be commit fa2c268
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions engines/sword25/util/lua/loslib.cpp
Expand Up @@ -4,9 +4,6 @@
** See Copyright Notice in lua.h
*/


#include <stdlib.h>
#include <string.h>
#include <time.h>

#define loslib_c
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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? */
Expand Down Expand Up @@ -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 */
Expand All @@ -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;
Expand All @@ -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));
}

Expand Down

0 comments on commit fa2c268

Please sign in to comment.