stead.hook and stead.inherit

This commit is contained in:
p.kosyh 2010-06-23 12:09:33 +00:00
parent d5ed3f9748
commit 299bd08ac0
8 changed files with 22 additions and 20 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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