2010-06-27 13:02:56 +03:00
|
|
|
function isXaction(v)
|
|
|
|
return type(v) == 'table' and v.xaction_type
|
|
|
|
end
|
|
|
|
|
2010-06-25 12:31:54 +03:00
|
|
|
xact = function(n, f) -- just simple action!
|
2010-06-07 16:06:00 +03:00
|
|
|
local v = {};
|
2010-07-02 15:11:21 +03:00
|
|
|
|
|
|
|
if f == nil and type(n) == 'table' then
|
|
|
|
f = n[2];
|
|
|
|
n = n[1];
|
|
|
|
end
|
|
|
|
|
2010-07-11 16:26:47 +03:00
|
|
|
if type(n) ~= 'string' then
|
2010-06-25 12:31:54 +03:00
|
|
|
error ("Wrong parameter to xact.", 2)
|
|
|
|
end
|
2010-06-27 13:02:56 +03:00
|
|
|
v.xaction_type = true
|
2010-06-25 12:31:54 +03:00
|
|
|
v.nam = n
|
|
|
|
v.act = f;
|
2010-06-27 08:37:32 +03:00
|
|
|
v = obj(v);
|
2010-06-25 12:31:54 +03:00
|
|
|
v.save = function(self, name, h, need)
|
|
|
|
if need then
|
2010-06-28 07:48:57 +03:00
|
|
|
local f = self.act;
|
2010-07-11 16:26:47 +03:00
|
|
|
f = stead.tostring(f);
|
|
|
|
if f == nil then
|
|
|
|
error("Can not save xact: "..name);
|
2010-06-25 12:31:54 +03:00
|
|
|
end
|
|
|
|
h:write(stead.string.format("%s = xact(%q, %s);\n", name, self.nam, f))
|
|
|
|
end
|
|
|
|
savemembers(h, self, name, false);
|
|
|
|
end
|
2010-06-07 16:06:00 +03:00
|
|
|
return v
|
|
|
|
end
|
|
|
|
|
2010-06-27 12:43:18 +03:00
|
|
|
__do_xact = function(str, self)
|
2010-06-25 12:31:54 +03:00
|
|
|
local aarg = {}
|
|
|
|
local function parg(v)
|
|
|
|
stead.table.insert(aarg, v);
|
|
|
|
return ''
|
|
|
|
end
|
2010-06-07 16:06:00 +03:00
|
|
|
local xrefrep = function(str)
|
|
|
|
local s = stead.string.gsub(str,'[{}]','');
|
2010-06-27 12:43:18 +03:00
|
|
|
local o,d,a, oo;
|
2010-07-12 16:11:32 +03:00
|
|
|
s = s:gsub("\\:","<:>");
|
2010-06-25 12:31:54 +03:00
|
|
|
local i = s:find(":", 1, true);
|
|
|
|
aarg = {}
|
|
|
|
if i then
|
|
|
|
o = s:sub(1, i - 1);
|
|
|
|
d = s:sub(i + 1);
|
|
|
|
i = o:find("(", 1, true);
|
|
|
|
if i then
|
|
|
|
a = o:sub(i);
|
|
|
|
o = o:sub(1, i - 1);
|
|
|
|
a:gsub('[^,()]+', parg);
|
|
|
|
end
|
2010-06-27 08:37:32 +03:00
|
|
|
if o == '' then
|
2010-06-27 12:43:18 +03:00
|
|
|
if isObject(self) then
|
|
|
|
oo = self
|
|
|
|
else
|
|
|
|
error("Empty link: "..s, 3);
|
|
|
|
end
|
|
|
|
else
|
|
|
|
oo = objs():srch(o)
|
|
|
|
if not oo then
|
2010-07-27 10:17:11 +03:00
|
|
|
oo = ref(o, true)
|
2010-06-27 12:43:18 +03:00
|
|
|
end
|
2010-06-27 08:37:32 +03:00
|
|
|
end
|
2010-06-27 12:43:18 +03:00
|
|
|
elseif isObject(self) then
|
|
|
|
oo = self
|
|
|
|
d = s;
|
2010-06-25 12:31:54 +03:00
|
|
|
else
|
2010-06-27 08:51:14 +03:00
|
|
|
error("Wrong link: "..s, 3);
|
2010-06-25 12:31:54 +03:00
|
|
|
end
|
2010-07-12 16:11:32 +03:00
|
|
|
d = d:gsub("<:>", ":");
|
2010-07-27 10:17:11 +03:00
|
|
|
return xref(d, ref(oo, true), unpack(aarg));
|
2010-06-07 16:06:00 +03:00
|
|
|
end
|
|
|
|
if type(str) ~= 'string' then return end
|
|
|
|
local s = stead.string.gsub(str,'{[^}]+}', xrefrep);
|
|
|
|
return s;
|
|
|
|
end
|
|
|
|
|
2010-06-27 08:37:32 +03:00
|
|
|
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;
|
2010-06-25 12:31:54 +03:00
|
|
|
end)
|
2010-06-27 09:01:36 +03:00
|
|
|
|
2010-06-27 12:43:18 +03:00
|
|
|
obj = stead.inherit(obj, function(v)
|
2010-06-27 09:01:36 +03:00
|
|
|
v.xref = function(s, str)
|
2010-06-27 12:43:18 +03:00
|
|
|
return __do_xact(str, s);
|
2010-06-27 09:01:36 +03:00
|
|
|
end
|
|
|
|
return v
|
|
|
|
end)
|
2010-06-28 07:48:57 +03:00
|
|
|
|
|
|
|
function xdsc(n)
|
|
|
|
local v = {}
|
|
|
|
v.nam = true
|
|
|
|
if n == nil then
|
|
|
|
v.disp = 'xdsc'
|
|
|
|
elseif type(n) == 'string' then
|
|
|
|
v.disp = n;
|
|
|
|
else
|
|
|
|
error("Wrong parameter to xdsc.", 2);
|
|
|
|
end
|
|
|
|
v.dsc = function(s)
|
|
|
|
return call(here(), s.disp);
|
|
|
|
end
|
|
|
|
v.save = function(self, name, h, need)
|
|
|
|
if need then
|
|
|
|
h:write(stead.string.format("%s = xdsc(%q);\n", name, self.disp))
|
|
|
|
end
|
|
|
|
savemembers(h, self, name, false);
|
|
|
|
end
|
|
|
|
return obj(v)
|
|
|
|
end
|
2010-06-29 16:18:03 +03:00
|
|
|
|
2010-06-29 19:23:52 +03:00
|
|
|
xroom = stead.inherit(room, function(v)
|
|
|
|
v.look = stead.hook(v.look, function(f, s,...)
|
|
|
|
local xdsc = call(s, 'xdsc');
|
|
|
|
return par(' ', xdsc, f(s, unpack(arg)));
|
|
|
|
end)
|
|
|
|
return v
|
2010-06-29 16:18:03 +03:00
|
|
|
end)
|
2010-07-06 13:15:27 +03:00
|
|
|
-- vim:ts=4
|