stead.hook and stead.inherit
This commit is contained in:
parent
d5ed3f9748
commit
299bd08ac0
|
@ -1,4 +1,4 @@
|
||||||
input.click = hook(input.click,
|
input.click = stead.hook(input.click,
|
||||||
function(f, s, press, mb, x, y, px, py, ...)
|
function(f, s, press, mb, x, y, px, py, ...)
|
||||||
if press and px then
|
if press and px then
|
||||||
return "click "..px..','..py;
|
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))
|
return f(s, press, mb, x, y, px, py, unpack(arg))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
game.action = hook(game.action,
|
game.action = stead.hook(game.action,
|
||||||
function(f, s, cmd, x, y, ...)
|
function(f, s, cmd, x, y, ...)
|
||||||
if cmd == 'click' then
|
if cmd == 'click' then
|
||||||
if here().click then
|
if here().click then
|
||||||
|
|
|
@ -211,7 +211,7 @@ debug_tool = menu {
|
||||||
end,
|
end,
|
||||||
};
|
};
|
||||||
|
|
||||||
game.action = hook(game.action,
|
game.action = stead.hook(game.action,
|
||||||
function (f, s, cmd, ...)
|
function (f, s, cmd, ...)
|
||||||
if cmd == 'use_debug' then
|
if cmd == 'use_debug' then
|
||||||
return debug_tool:inv()
|
return debug_tool:inv()
|
||||||
|
@ -219,7 +219,7 @@ function (f, s, cmd, ...)
|
||||||
return f(s, cmd, unpack(arg))
|
return f(s, cmd, unpack(arg))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
input.key = hook(input.key,
|
input.key = stead.hook(input.key,
|
||||||
function(f, s, down, key, ...)
|
function(f, s, down, key, ...)
|
||||||
if not here().debug and down and key == 'f7' then return 'use_debug' end
|
if not here().debug and down and key == 'f7' then return 'use_debug' end
|
||||||
return f(s, down, key, unpack(arg))
|
return f(s, down, key, unpack(arg))
|
||||||
|
|
|
@ -108,7 +108,7 @@ iface.fmt = function(self, cmd, st, moved, r, av, objs, pv) -- st -- changed sta
|
||||||
return vv
|
return vv
|
||||||
end
|
end
|
||||||
|
|
||||||
go = hook(go, function(f, ...)
|
go = stead.hook(go, function(f, ...)
|
||||||
local r,v = f(unpack(arg))
|
local r,v = f(unpack(arg))
|
||||||
if type(r) == 'string' and cctx() then
|
if type(r) == 'string' and cctx() then
|
||||||
pr (r)
|
pr (r)
|
||||||
|
@ -119,12 +119,12 @@ go = hook(go, function(f, ...)
|
||||||
return r,v
|
return r,v
|
||||||
end)
|
end)
|
||||||
|
|
||||||
iface.cmd = hook(iface.cmd, function(f, ...)
|
iface.cmd = stead.hook(iface.cmd, function(f, ...)
|
||||||
NEED_SCENE = nil
|
NEED_SCENE = nil
|
||||||
return f(unpack(arg))
|
return f(unpack(arg))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
player = inherit(player, function(v)
|
player = stead.inherit(player, function(v)
|
||||||
v.look = function(s)
|
v.look = function(s)
|
||||||
NEED_SCENE = true
|
NEED_SCENE = true
|
||||||
end
|
end
|
||||||
|
|
|
@ -191,7 +191,7 @@ function kbdxlat(s)
|
||||||
return kbd[s]
|
return kbd[s]
|
||||||
end
|
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 cmd == 'kbd_enter' then
|
||||||
if here().inp_enter then
|
if here().inp_enter then
|
||||||
return call(here(), 'inp_enter');
|
return call(here(), 'inp_enter');
|
||||||
|
@ -251,7 +251,7 @@ input_kbd = function(s, down, key)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
input.key = hook(input.key,
|
input.key = stead.hook(input.key,
|
||||||
function(f, ...)
|
function(f, ...)
|
||||||
local r = input_kbd(unpack(arg))
|
local r = input_kbd(unpack(arg))
|
||||||
if r then return r end
|
if r then return r end
|
||||||
|
|
|
@ -1,35 +1,35 @@
|
||||||
obj = inherit(obj, function(v)
|
obj = stead.inherit(obj, function(v)
|
||||||
if v.use then
|
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))
|
return f(s, ref(on), unpack(arg))
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
if v.used then
|
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))
|
return f(s, ref(by), unpack(arg))
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
return v
|
return v
|
||||||
end)
|
end)
|
||||||
|
|
||||||
room = inherit(room, function(v)
|
room = stead.inherit(room, function(v)
|
||||||
if v.enter then
|
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))
|
return f(s, ref(from), unpack(arg))
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
if v.entered then
|
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))
|
return f(s, ref(from), unpack(arg))
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
if v.exit then
|
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))
|
return f(s, ref(to), unpack(arg))
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
if v.left then
|
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))
|
return f(s, ref(to), unpack(arg))
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
stead.fmt = hook(stead.fmt, function(f, ...)
|
stead.fmt = stead.hook(stead.fmt, function(f, ...)
|
||||||
local r = f(unpack(arg))
|
local r = f(unpack(arg))
|
||||||
if type(r) == 'string' then
|
if type(r) == 'string' then
|
||||||
r = r:gsub('~[ \t]*([^ \t]+)', txtnb(' %1'));
|
r = r:gsub('~[ \t]*([^ \t]+)', txtnb(' %1'));
|
||||||
|
|
|
@ -2382,6 +2382,7 @@ function inherit(o, f)
|
||||||
return f(o(unpack(arg)))
|
return f(o(unpack(arg)))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
stead.inherit = inherit
|
||||||
|
|
||||||
function hook(o, f)
|
function hook(o, f)
|
||||||
return function(...)
|
return function(...)
|
||||||
|
@ -2396,6 +2397,7 @@ function hook(o, f)
|
||||||
return f(ff, unpack(arg))
|
return f(ff, unpack(arg))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
stead.hook = hook
|
||||||
|
|
||||||
function check_version(v)
|
function check_version(v)
|
||||||
if not tostring(v) then
|
if not tostring(v) then
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
isForSave = hook(isForSave,
|
isForSave = stead.hook(isForSave,
|
||||||
function (f, k, v, s, ...) -- k - key, v - value, s -- parent table
|
function (f, k, v, s, ...) -- k - key, v - value, s -- parent table
|
||||||
local i,o
|
local i,o
|
||||||
if type(s.var) == 'table' then
|
if type(s.var) == 'table' then
|
||||||
|
@ -43,7 +43,7 @@ vars_object = obj {
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
obj = hook(obj,
|
obj = stead.hook(obj,
|
||||||
function(f, v, ...)
|
function(f, v, ...)
|
||||||
__vars_fill(v)
|
__vars_fill(v)
|
||||||
return f(v, unpack(arg))
|
return f(v, unpack(arg))
|
||||||
|
|
Loading…
Reference in a new issue