From 60d0ba5ac661d8c0601955ac335ee79473e15185 Mon Sep 17 00:00:00 2001
From: "p.kosyh"
Date: Mon, 7 Jun 2010 10:18:44 +0000
Subject: [PATCH] requre feature, goto module added
---
src/sdl-instead/game.h | 2 +
src/sdl-instead/instead.c | 23 +++++++++-
src/sdl-instead/unix.c | 10 +++++
src/sdl-instead/windows.c | 8 ++++
stead/goto.lua | 90 ++++++++++++++++++++++++++++++++++++++
stead/stead.lua | 92 ---------------------------------------
6 files changed, 131 insertions(+), 94 deletions(-)
create mode 100644 stead/goto.lua
diff --git a/src/sdl-instead/game.h b/src/sdl-instead/game.h
index 4be8f16..c1498d5 100644
--- a/src/sdl-instead/game.h
+++ b/src/sdl-instead/game.h
@@ -21,6 +21,8 @@ extern char *err_msg; /* last error message */
extern char game_cwd[PATH_MAX]; /* current game cwd */
extern char *curgame_dir;
+extern char *game_local_stead_path(void);
+
extern char *game_local_games_path(int cr);
extern char *game_tmp_path(void);
extern int game_theme_select(const char *name);
diff --git a/src/sdl-instead/instead.c b/src/sdl-instead/instead.c
index 4e123ff..f36032d 100644
--- a/src/sdl-instead/instead.c
+++ b/src/sdl-instead/instead.c
@@ -413,8 +413,27 @@ static const luaL_Reg base_funcs[] = {
int instead_init(void)
{
+ char *p;
+ static char stead_path[PATH_MAX];
setlocale(LC_ALL,"");
- setlocale(LC_NUMERIC,"C"); /* to avoid . -> , in numbers */
+ setlocale(LC_NUMERIC,"C"); /* to avoid . -> , in numbers */
+
+ if (STEAD_PATH[0] == '.') {
+ strcpy(stead_path, game_cwd);
+ strcat(stead_path, "/");
+ strcat(stead_path, STEAD_PATH);
+ } else {
+ strcpy(stead_path, STEAD_PATH);
+ }
+ strcat(stead_path, "/?.lua");
+ p = game_local_stead_path();
+ if (p) {
+ strcat(stead_path, ";");
+ strcat(stead_path, p);
+ strcat(stead_path, "/?.lua");
+ }
+
+ setenv("LUA_PATH", stead_path, 1);
// strcpy(curcp, "UTF-8");
/* initialize Lua */
L = lua_open();
@@ -426,7 +445,7 @@ int instead_init(void)
return -1;
}
- if (dofile(L,STEAD_PATH"/gui.lua")) {
+ if (dofile(L,STEAD_PATH"/gui.lua")) {
instead_clear();
return -1;
}
diff --git a/src/sdl-instead/unix.c b/src/sdl-instead/unix.c
index f64496f..a7c2be1 100644
--- a/src/sdl-instead/unix.c
+++ b/src/sdl-instead/unix.c
@@ -27,6 +27,7 @@ static char save_path[PATH_MAX];
static char cfg_path[PATH_MAX];
static char local_games_path[PATH_MAX];
static char local_themes_path[PATH_MAX];
+static char local_stead_path[PATH_MAX];
void nsleep(int u)
@@ -190,6 +191,15 @@ char *game_local_themes_path(void)
return local_themes_path;
}
+char *game_local_stead_path(void)
+{
+ char *app = appdir();
+ if (!app)
+ return NULL;
+ snprintf(local_stead_path, sizeof(local_stead_path) - 1 , "%s/stead", app);
+ return local_stead_path;
+}
+
char *game_cfg_path(void)
{
char *app = appdir();
diff --git a/src/sdl-instead/windows.c b/src/sdl-instead/windows.c
index 688bd6a..cb65d95 100644
--- a/src/sdl-instead/windows.c
+++ b/src/sdl-instead/windows.c
@@ -16,6 +16,7 @@ extern char *curgame_dir;
static char local_games_path[PATH_MAX];
static char local_themes_path[PATH_MAX];
+static char local_stead_path[PATH_MAX];
static char save_path[PATH_MAX];
static char cfg_path[PATH_MAX];
@@ -132,6 +133,13 @@ char *game_local_themes_path(void)
snprintf(local_themes_path, sizeof(local_themes_path) - 1 , "%s/themes", app_dir());
return local_themes_path;
}
+
+char *game_local_stead_path(void)
+{
+ snprintf(local_stead_path, sizeof(local_stead_path) - 1 , "%s/stead", app_dir());
+ return local_stead_path;
+}
+
#if 0
char *home_dir( void )
{
diff --git a/stead/goto.lua b/stead/goto.lua
new file mode 100644
index 0000000..6db491b
--- /dev/null
+++ b/stead/goto.lua
@@ -0,0 +1,90 @@
+go = function (self, where, back)
+ local was = self.where;
+ local need_scene = false;
+ local ret
+
+ if not stead.in_goto_call then
+ ret = function(rc) stead.in_goto_call = false return nil end
+ else
+ ret = function(rc) return rc end
+ end
+
+ stead.in_goto_call = true
+
+ if where == nil then
+ return nil, ret(false)
+ end
+
+ if not isRoom(ref(where)) then
+ error ("Trying to go nowhere: "..where);
+ end
+
+ if not isRoom(ref(self.where)) then
+ error ("Trying to go from nowhere: "..self.where);
+ end
+
+ if stead.in_entered_call or stead.in_onexit_call then
+ error ("Do not use goto from left/entered action! Use exit/enter action instead:" .. self.where);
+ end
+
+ local v, r;
+
+ if not isVroom(ref(where)) and not stead.in_exit_call then
+ stead.in_exit_call = true -- to break recurse
+ v,r = call(ref(self.where), 'exit', where);
+ stead.in_exit_call = nil
+ if r == false then
+ return v, ret(r)
+ end
+ end
+
+ local res = v;
+ v = nil;
+
+ if not isVroom(ref(where)) then
+ self.where = deref(where);
+ end
+
+ if not back or not isDialog(ref(self.where)) or isDialog(ref(where)) then
+ v, r = call(ref(where), 'enter', deref(was));
+ if r == false then
+ self.where = was;
+ return par('^^', res, v), ret(r)
+ end
+ need_scene = true;
+ if ref(where) ~= ref(self.where) then -- jump !!!
+ need_scene = false;
+ end
+ end
+ res = par('^^',res,v);
+
+ if not back then
+ ref(where).__from__ = deref(was);
+ end
+
+
+ ret()
+
+ if not stead.in_goto_call then
+ local to = self.where
+ self.where = was
+
+ stead.in_onexit_call = true
+ v = call(ref(was), 'left', deref(to));
+ stead.in_onexit_call = false
+ res = par('^^',res,v);
+
+ self.where = deref(to)
+
+ stead.in_entered_call = true
+ v = call(ref(to), 'entered', deref(was));
+ stead.in_entered_call = false
+ res = par('^^',res,v);
+ end
+
+
+ if need_scene then -- or isForcedsc(ref(where)) then -- i'am not sure...
+ return par('^^',res,ref(where):scene());
+ end
+ return res;
+end
diff --git a/stead/stead.lua b/stead/stead.lua
index 563d315..0152e41 100644
--- a/stead/stead.lua
+++ b/stead/stead.lua
@@ -1163,98 +1163,6 @@ function go(self, where, back)
return res;
end
-function newgo(self, where, back)
- local was = self.where;
- local need_scene = false;
- local ret
-
- if not stead.in_goto_call then
- ret = function(rc) stead.in_goto_call = false return nil end
- else
- ret = function(rc) return rc end
- end
-
- stead.in_goto_call = true
-
- if where == nil then
- return nil, ret(false)
- end
-
- if not isRoom(ref(where)) then
- error ("Trying to go nowhere: "..where);
- end
-
- if not isRoom(ref(self.where)) then
- error ("Trying to go from nowhere: "..self.where);
- end
-
- if stead.in_entered_call or stead.in_onexit_call then
- error ("Do not use goto from left/entered action! Use exit/enter action instead:" .. self.where);
- end
-
- local v, r;
-
- if not isVroom(ref(where)) and not stead.in_exit_call then
- stead.in_exit_call = true -- to break recurse
- v,r = call(ref(self.where), 'exit', where);
- stead.in_exit_call = nil
- if r == false then
- return v, ret(r)
- end
- end
-
- local res = v;
- v = nil;
-
- if not isVroom(ref(where)) then
- self.where = deref(where);
- end
-
- if not back or not isDialog(ref(self.where)) or isDialog(ref(where)) then
- v, r = call(ref(where), 'enter', deref(was));
- if r == false then
- self.where = was;
- return par('^^', res, v), ret(r)
- end
- need_scene = true;
- if ref(where) ~= ref(self.where) then -- jump !!!
- need_scene = false;
- end
- end
- res = par('^^',res,v);
-
- if not back then
- ref(where).__from__ = deref(was);
- end
-
-
- ret()
-
- if not stead.in_goto_call then
- local to = self.where
- self.where = was
-
- stead.in_onexit_call = true
- v = call(ref(was), 'left', deref(to));
- stead.in_onexit_call = false
- res = par('^^',res,v);
-
- self.where = deref(to)
-
- stead.in_entered_call = true
- v = call(ref(to), 'entered', deref(was));
- stead.in_entered_call = false
- res = par('^^',res,v);
- end
-
-
- if need_scene then -- or isForcedsc(ref(where)) then -- i'am not sure...
- return par('^^',res,ref(where):scene());
- end
- return res;
-end
-
-
function player_goto(self, where)
local v, r = go(self, where, false);
return v, r;