goodbye gui.h, hello gui.lua

This commit is contained in:
p.kosyh 2009-09-20 10:21:11 +00:00
parent cac3077c3d
commit aaa4287118
7 changed files with 118 additions and 110 deletions

View file

@ -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)

View file

@ -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('<a:'..cmd..'0'..tostring(o.id)..'>',str,'</a>');\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('<u>',str,'</u>');\n\
end;\n\
iface.em = function(self, str)\n\
if str == nil then return nil; end; \n\
return cat('<i>',str,'</i>');\n\
end;\n\
iface.right = function(self, str)\n\
if str == nil then return nil; end; \n\
return cat('<r>',str,'</r>');\n\
end;\n\
iface.left = function(self, str)\n\
if str == nil then return nil; end; \n\
return cat('<l>',str,'</l>');\n\
end;\n\
iface.center = function(self, str)\n\
if str == nil then return nil; end; \n\
return cat('<c>',str,'</c>');\n\
end;\n\
iface.bold = function(self, str)\n\
if str == nil then return nil; end; \n\
return cat('<b>',str,'</b>');\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 '<c>'..string.gsub(str,',',' | ')..'</c>';\n\
end\n\
return str\n\
end;";

View file

@ -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 */

View file

@ -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

View file

@ -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

113
stead/gui.lua Normal file
View file

@ -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('<a:'..cmd..'0'..tostring(o.id)..'>',str,'</a>');
end;
iface.title = function(self, str)
return nil
end;
iface.under = function(self, str)
if str == nil then return nil; end;
return cat('<u>',str,'</u>');
end;
iface.em = function(self, str)
if str == nil then return nil; end;
return cat('<i>',str,'</i>');
end;
iface.right = function(self, str)
if str == nil then return nil; end;
return cat('<r>',str,'</r>');
end;
iface.left = function(self, str)
if str == nil then return nil; end;
return cat('<l>',str,'</l>');
end;
iface.center = function(self, str)
if str == nil then return nil; end;
return cat('<c>',str,'</c>');
end;
iface.bold = function(self, str)
if str == nil then return nil; end;
return cat('<b>',str,'</b>');
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 '<c>'..string.gsub(str,',',' | ')..'</c>';
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

View file

@ -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