much better xact
This commit is contained in:
parent
d404b623c9
commit
12e522b6e6
|
@ -1,43 +1,3 @@
|
|||
function isXobject(s)
|
||||
return type(s) == 'table' and s.xobject_type;
|
||||
end
|
||||
|
||||
__hook_act = function(v, n)
|
||||
local k,o
|
||||
if type(v.var) == 'table' then
|
||||
for k,o in ipairs(v.var) do -- var add
|
||||
if o == n then
|
||||
stead.table.insert(v.var, 'x'..n);
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
return function(s, ...)
|
||||
local r, v = call(s, 'x'..n, unpack(arg));
|
||||
if type(r) == 'string' then
|
||||
r = do_xact(s, r);
|
||||
end
|
||||
return r,v
|
||||
end
|
||||
end
|
||||
|
||||
xobj = stead.inherit(obj, function(v) -- object without name and dsc, but with xact attribute
|
||||
v.xdsc = v.dsc
|
||||
v.dsc = __hook_act(v, 'dsc');
|
||||
v.xact = v.act
|
||||
v.act = __hook_act(v, 'act');
|
||||
v.xinv = v.inv
|
||||
v.inv = __hook_act(v, 'inv');
|
||||
v.xtak = v.tak
|
||||
v.tak = __hook_act(v, 'tak');
|
||||
v.xuse = v.use
|
||||
v.use = __hook_act(v, 'use');
|
||||
v.xused = v.used
|
||||
v.used = __hook_act(v, 'used');
|
||||
v.xobject_type = true
|
||||
return v
|
||||
end)
|
||||
|
||||
xact = function(n, f) -- just simple action!
|
||||
local v = {};
|
||||
if type(n) ~= 'string' or (type(f) ~= 'string' and not isCode(f)) then
|
||||
|
@ -45,7 +5,7 @@ xact = function(n, f) -- just simple action!
|
|||
end
|
||||
v.nam = n
|
||||
v.act = f;
|
||||
v = xobj(v);
|
||||
v = obj(v);
|
||||
v.save = function(self, name, h, need)
|
||||
if need then
|
||||
local f = self.xact;
|
||||
|
@ -61,7 +21,7 @@ xact = function(n, f) -- just simple action!
|
|||
return v
|
||||
end
|
||||
|
||||
do_xact = function(self, str)
|
||||
__do_xact = function(str)
|
||||
local aarg = {}
|
||||
local function parg(v)
|
||||
stead.table.insert(aarg, v);
|
||||
|
@ -81,10 +41,11 @@ do_xact = function(self, str)
|
|||
o = o:sub(1, i - 1);
|
||||
a:gsub('[^,()]+', parg);
|
||||
end
|
||||
if o == '' then o = self end
|
||||
if o == '' then
|
||||
error("Empty link: "..s, 2);
|
||||
end
|
||||
else
|
||||
o = self
|
||||
d = s;
|
||||
error("Wrong link: "..s, 2);
|
||||
end
|
||||
local oo = objs():srch(o)
|
||||
if not oo then
|
||||
|
@ -93,13 +54,14 @@ do_xact = function(self, str)
|
|||
return xref(d, ref(oo), unpack(aarg));
|
||||
end
|
||||
if type(str) ~= 'string' then return end
|
||||
me():tag()
|
||||
local s = stead.string.gsub(str,'{[^}]+}', xrefrep);
|
||||
return s;
|
||||
end
|
||||
|
||||
xroom = stead.inherit(room, function(v)
|
||||
v.xdsc = v.dsc
|
||||
v.dsc = __hook_act(v, 'dsc');
|
||||
return v;
|
||||
stead.fmt = stead.hook(stead.fmt, function(f, ...)
|
||||
local r = f(unpack(arg))
|
||||
if type(r) == 'string' and stead.state then
|
||||
r = __do_xact(r);
|
||||
end
|
||||
return r;
|
||||
end)
|
Loading…
Reference in a new issue