From 299bd08ac0774b0b70225b76dcd990e82944cae5 Mon Sep 17 00:00:00 2001 From: "p.kosyh" Date: Wed, 23 Jun 2010 12:09:33 +0000 Subject: [PATCH] stead.hook and stead.inherit --- stead/click.lua | 4 ++-- stead/dbg.lua | 4 ++-- stead/goto.lua | 6 +++--- stead/input.lua | 4 ++-- stead/object.lua | 16 ++++++++-------- stead/para.lua | 2 +- stead/stead.lua | 2 ++ stead/vars.lua | 4 ++-- 8 files changed, 22 insertions(+), 20 deletions(-) diff --git a/stead/click.lua b/stead/click.lua index 3a03854..c56d671 100644 --- a/stead/click.lua +++ b/stead/click.lua @@ -1,4 +1,4 @@ -input.click = hook(input.click, +input.click = stead.hook(input.click, function(f, s, press, mb, x, y, px, py, ...) if press and px then return "click "..px..','..py; @@ -6,7 +6,7 @@ function(f, s, press, mb, x, y, px, py, ...) return f(s, press, mb, x, y, px, py, unpack(arg)) end) -game.action = hook(game.action, +game.action = stead.hook(game.action, function(f, s, cmd, x, y, ...) if cmd == 'click' then if here().click then diff --git a/stead/dbg.lua b/stead/dbg.lua index 6d54cd4..ec90cdb 100644 --- a/stead/dbg.lua +++ b/stead/dbg.lua @@ -211,7 +211,7 @@ debug_tool = menu { end, }; -game.action = hook(game.action, +game.action = stead.hook(game.action, function (f, s, cmd, ...) if cmd == 'use_debug' then return debug_tool:inv() @@ -219,7 +219,7 @@ function (f, s, cmd, ...) return f(s, cmd, unpack(arg)) end) -input.key = hook(input.key, +input.key = stead.hook(input.key, function(f, s, down, key, ...) if not here().debug and down and key == 'f7' then return 'use_debug' end return f(s, down, key, unpack(arg)) diff --git a/stead/goto.lua b/stead/goto.lua index 8dd3dda..92b2f2b 100644 --- a/stead/goto.lua +++ b/stead/goto.lua @@ -108,7 +108,7 @@ iface.fmt = function(self, cmd, st, moved, r, av, objs, pv) -- st -- changed sta return vv end -go = hook(go, function(f, ...) +go = stead.hook(go, function(f, ...) local r,v = f(unpack(arg)) if type(r) == 'string' and cctx() then pr (r) @@ -119,12 +119,12 @@ go = hook(go, function(f, ...) return r,v end) -iface.cmd = hook(iface.cmd, function(f, ...) +iface.cmd = stead.hook(iface.cmd, function(f, ...) NEED_SCENE = nil return f(unpack(arg)) end) -player = inherit(player, function(v) +player = stead.inherit(player, function(v) v.look = function(s) NEED_SCENE = true end diff --git a/stead/input.lua b/stead/input.lua index 0ad7eb2..0bc3e9a 100644 --- a/stead/input.lua +++ b/stead/input.lua @@ -191,7 +191,7 @@ function kbdxlat(s) return kbd[s] end -game.action = hook(game.action, function (f, s, cmd, ...) +game.action = stead.hook(game.action, function (f, s, cmd, ...) if cmd == 'kbd_enter' then if here().inp_enter then return call(here(), 'inp_enter'); @@ -251,7 +251,7 @@ input_kbd = function(s, down, key) end end -input.key = hook(input.key, +input.key = stead.hook(input.key, function(f, ...) local r = input_kbd(unpack(arg)) if r then return r end diff --git a/stead/object.lua b/stead/object.lua index 2f56ede..95c8796 100644 --- a/stead/object.lua +++ b/stead/object.lua @@ -1,35 +1,35 @@ -obj = inherit(obj, function(v) +obj = stead.inherit(obj, function(v) if v.use then - v.use = hook(v.use, function(f, s, on, ...) + v.use = stead.hook(v.use, function(f, s, on, ...) return f(s, ref(on), unpack(arg)) end) end if v.used then - v.used = hook(v.used, function(f, s, by, ...) + v.used = stead.hook(v.used, function(f, s, by, ...) return f(s, ref(by), unpack(arg)) end) end return v end) -room = inherit(room, function(v) +room = stead.inherit(room, function(v) if v.enter then - v.enter = hook(v.enter, function(f, s, from, ...) + v.enter = stead.hook(v.enter, function(f, s, from, ...) return f(s, ref(from), unpack(arg)) end) end if v.entered then - v.entered = hook(v.entered, function(f, s, from, ...) + v.entered = stead.hook(v.entered, function(f, s, from, ...) return f(s, ref(from), unpack(arg)) end) end if v.exit then - v.exit = hook(v.exit, function(f, s, to, ...) + v.exit = stead.hook(v.exit, function(f, s, to, ...) return f(s, ref(to), unpack(arg)) end) end if v.left then - v.left = hook(v.left, function(f, s, to, ...) + v.left = stead.hook(v.left, function(f, s, to, ...) return f(s, ref(to), unpack(arg)) end) end diff --git a/stead/para.lua b/stead/para.lua index 1327184..d40698d 100644 --- a/stead/para.lua +++ b/stead/para.lua @@ -1,4 +1,4 @@ -stead.fmt = hook(stead.fmt, function(f, ...) +stead.fmt = stead.hook(stead.fmt, function(f, ...) local r = f(unpack(arg)) if type(r) == 'string' then r = r:gsub('~[ \t]*([^ \t]+)', txtnb(' %1')); diff --git a/stead/stead.lua b/stead/stead.lua index 25191b3..48ca72f 100644 --- a/stead/stead.lua +++ b/stead/stead.lua @@ -2382,6 +2382,7 @@ function inherit(o, f) return f(o(unpack(arg))) end end +stead.inherit = inherit function hook(o, f) return function(...) @@ -2396,6 +2397,7 @@ function hook(o, f) return f(ff, unpack(arg)) end end +stead.hook = hook function check_version(v) if not tostring(v) then diff --git a/stead/vars.lua b/stead/vars.lua index f787cd7..46e4086 100644 --- a/stead/vars.lua +++ b/stead/vars.lua @@ -1,4 +1,4 @@ -isForSave = hook(isForSave, +isForSave = stead.hook(isForSave, function (f, k, v, s, ...) -- k - key, v - value, s -- parent table local i,o if type(s.var) == 'table' then @@ -43,7 +43,7 @@ vars_object = obj { end } -obj = hook(obj, +obj = stead.hook(obj, function(f, v, ...) __vars_fill(v) return f(v, unpack(arg))