From aaa4287118ea2de5e1c81b0011798f1817c612ef Mon Sep 17 00:00:00 2001
From: "p.kosyh"
Date: Sun, 20 Sep 2009 10:21:11 +0000
Subject: [PATCH] goodbye gui.h, hello gui.lua
---
src/sdl-instead/Makefile | 2 +-
src/sdl-instead/gui.h | 65 ----------------------
src/sdl-instead/instead.c | 4 +-
stead/Makefile | 1 +
stead/Makefile.windows | 1 +
stead/gui.lua | 113 ++++++++++++++++++++++++++++++++++++++
stead/stead.lua | 42 --------------
7 files changed, 118 insertions(+), 110 deletions(-)
delete mode 100644 src/sdl-instead/gui.h
create mode 100644 stead/gui.lua
diff --git a/src/sdl-instead/Makefile b/src/sdl-instead/Makefile
index f6fc72b..39d6069 100644
--- a/src/sdl-instead/Makefile
+++ b/src/sdl-instead/Makefile
@@ -10,7 +10,7 @@ OBJ := $(patsubst %.c, %.o, $(SRC))
all: sdl-instead$(EXE)
-$(OBJ): %.o : %.c gui.h menu.h config.h game.h themes.h externals.h internals.h util.h
+$(OBJ): %.o : %.c menu.h config.h game.h themes.h externals.h internals.h util.h
$(CC) -c $(<) $(I) $(CFLAGS)
sdl-instead$(EXE): $(OBJ) $(RESOURCES)
diff --git a/src/sdl-instead/gui.h b/src/sdl-instead/gui.h
deleted file mode 100644
index a93c7c0..0000000
--- a/src/sdl-instead/gui.h
+++ /dev/null
@@ -1,65 +0,0 @@
-char *instead_gui_lua = "game.hinting = true;\n\
-game.showlast = true;\n\
-iface.xref = function(self, str, obj)\n\
--- return '@'..str..'{'..obj..'}';\n\
- local o = ref(here():srch(obj));\n\
- local cmd=''\n\
- if not o then \n\
- o = ref(ways():srch(obj));\n\
- if o then\n\
- cmd = 'go ';\n\
- end\n\
- end\n\
- if not o then\n\
- o = ref(me():srch(obj));\n\
- end\n\
- if not isObject(o) or isStatus(o) or not o.id then\n\
- return str;\n\
- end\n\
- if isMenu(o) then\n\
- cmd = 'act ';\n\
- end\n\
- return cat('',str,'');\n\
-end;\n\
-iface.title = function(self, str)\n\
- return nil\n\
-end;\n\
-iface.under = function(self, str)\n\
- if str == nil then return nil; end; \n\
- return cat('',str,'');\n\
-end;\n\
-iface.em = function(self, str)\n\
- if str == nil then return nil; end; \n\
- return cat('',str,'');\n\
-end;\n\
-iface.right = function(self, str)\n\
- if str == nil then return nil; end; \n\
- return cat('',str,'');\n\
-end;\n\
-iface.left = function(self, str)\n\
- if str == nil then return nil; end; \n\
- return cat('',str,'');\n\
-end;\n\
-iface.center = function(self, str)\n\
- if str == nil then return nil; end; \n\
- return cat('',str,'');\n\
-end;\n\
-iface.bold = function(self, str)\n\
- if str == nil then return nil; end; \n\
- return cat('',str,'');\n\
-end;\n\
-\n\
-iface.inv = function(self, str)\n\
- if str then\n\
- return string.gsub(str,',','^');\n\
- end\n\
- return str\n\
-end;\n\
-\n\
-iface.ways = function(self, str)\n\
- if str then\n\
- return ''..string.gsub(str,',',' | ')..'';\n\
- end\n\
- return str\n\
-end;";
-
diff --git a/src/sdl-instead/instead.c b/src/sdl-instead/instead.c
index 9e61ae7..cc870c1 100644
--- a/src/sdl-instead/instead.c
+++ b/src/sdl-instead/instead.c
@@ -2,7 +2,6 @@
#define STEAD_PATH "./stead"
#endif
-#include "gui.h"
#include "externals.h"
#include "internals.h"
/* the Lua interpreter */
@@ -235,7 +234,8 @@ int instead_init(void)
if (dofile(L,STEAD_PATH"/stead.lua")) {
return -1;
}
- if (luacall(instead_gui_lua)) {
+
+ if (dofile(L,STEAD_PATH"/gui.lua")) {
return -1;
}
/* cleanup Lua */
diff --git a/stead/Makefile b/stead/Makefile
index 300234d..e05d59a 100644
--- a/stead/Makefile
+++ b/stead/Makefile
@@ -5,4 +5,5 @@ all: stead.lua
install:
install -m 0755 -d $(STEADPATH)
install -m 0644 stead.lua $(STEADPATH)/stead.lua
+ install -m 0644 gui.lua $(STEADPATH)/gui.lua
diff --git a/stead/Makefile.windows b/stead/Makefile.windows
index 48fd5ee..ab53a6e 100644
--- a/stead/Makefile.windows
+++ b/stead/Makefile.windows
@@ -4,3 +4,4 @@ all: stead.lua
install:
if not exist ..\bin\stead mkdir ..\bin\stead
copy stead.lua ..\bin\stead
+ copy gui.lua ..\bin\stead
diff --git a/stead/gui.lua b/stead/gui.lua
new file mode 100644
index 0000000..ad76656
--- /dev/null
+++ b/stead/gui.lua
@@ -0,0 +1,113 @@
+game.hinting = true;
+game.showlast = true;
+
+iface.xref = function(self, str, obj)
+ local o = ref(here():srch(obj));
+ local cmd=''
+ if not o then
+ o = ref(ways():srch(obj));
+ if o then
+ cmd = 'go ';
+ end
+ end
+ if not o then
+ o = ref(me():srch(obj));
+ end
+ if not isObject(o) or isStatus(o) or not o.id then
+ return str;
+ end
+ if isMenu(o) then
+ cmd = 'act ';
+ end
+ return cat('',str,'');
+end;
+
+iface.title = function(self, str)
+ return nil
+end;
+
+iface.under = function(self, str)
+ if str == nil then return nil; end;
+ return cat('',str,'');
+end;
+
+iface.em = function(self, str)
+ if str == nil then return nil; end;
+ return cat('',str,'');
+end;
+
+iface.right = function(self, str)
+ if str == nil then return nil; end;
+ return cat('',str,'');
+end;
+
+iface.left = function(self, str)
+ if str == nil then return nil; end;
+ return cat('',str,'');
+end;
+
+iface.center = function(self, str)
+ if str == nil then return nil; end;
+ return cat('',str,'');
+end;
+
+iface.bold = function(self, str)
+ if str == nil then return nil; end;
+ return cat('',str,'');
+end;
+
+iface.inv = function(self, str)
+ if str then
+ return string.gsub(str,',','^');
+ end
+ return str
+end;
+
+iface.ways = function(self, str)
+ if str then
+ return ''..string.gsub(str,',',' | ')..'';
+ end
+ return str
+end;
+
+-- here is gui staff only
+function stat(v)
+ v.status_type = true
+ return obj(v);
+end
+
+function isStatus(v)
+ if type(v) ~= 'table' then
+ return false
+ end
+ if v.status_type then
+ return true
+ end
+ return false
+end
+
+function menu_save(self, name, h, need)
+ local dsc;
+ if need then
+ h:write(name.." = menu {nam = '"..tostring(self.nam).."'}\n");
+ end
+ savemembers(h, self, name, need);
+end
+
+function menu(v)
+ v.menu_type = true
+ if v.save == nil then
+ v.save = menu_save;
+ end
+ return obj(v);
+end
+
+function isMenu(v)
+ if type(v) ~= 'table' then
+ return false
+ end
+ if v.menu_type then
+ return true
+ end
+ return false
+end
diff --git a/stead/stead.lua b/stead/stead.lua
index d2d1760..9ca8c0d 100644
--- a/stead/stead.lua
+++ b/stead/stead.lua
@@ -1847,46 +1847,4 @@ function isForSave(k)
return string.find(k, '_') == 1 or string.match(k,'^%u')
end
--- here is gui staff only
-function stat(v)
- v.status_type = true
- return obj(v);
-end
-
-function isStatus(v)
- if type(v) ~= 'table' then
- return false
- end
- if v.status_type then
- return true
- end
- return false
-end
-
-function menu_save(self, name, h, need)
- local dsc;
- if need then
- h:write(name.." = menu {nam = '"..tostring(self.nam).."'}\n");
- end
- savemembers(h, self, name, need);
-end
-
-function menu(v)
- v.menu_type = true
- if v.save == nil then
- v.save = menu_save;
- end
- return obj(v);
-end
-
-function isMenu(v)
- if type(v) ~= 'table' then
- return false
- end
- if v.menu_type then
- return true
- end
- return false
-end
-
-- here the game begins