self(), pclr, pget replaces pstart pend

This commit is contained in:
p.kosyh 2009-10-27 14:53:39 +00:00
parent 294a447a9e
commit f54434f4d8

View file

@ -4,40 +4,49 @@ stead = {
string = string, string = string,
math = math, math = math,
io = io, io = io,
txt_top = 0, call_top = 0,
txt = {}, cctx = { txt = nil, self = nil },
} }
function ppush() function callpush()
stead.txt_top = stead.txt_top + 1; stead.call_top = stead.call_top + 1;
stead.cctx[stead.call_top] = { txt = nil, self = nil };
end end
function ppop() function callpop()
stead.txt_top = stead.txt_top - 1; stead.cctx[stead.call_top] = nil;
if stead.txt_top < 0 then stead.call_top = stead.call_top - 1;
error "pstart/pend mismatch" if stead.call_top < 0 then
error "callpush/callpop mismatch"
end end
end end
function pstart() function self(v)
stead.txt[stead.txt_top] = nil if v ~= nil then
stead.cctx[stead.call_top].self = v;
end
return stead.cctx[stead.call_top].self;
end end
function pend() function pclr()
return stead.txt[stead.txt_top] stead.cctx[stead.call_top].txt = nil
end
function pget()
return stead.cctx[stead.call_top].txt;
end end
function p(...) function p(...)
local i local i
for i = 1, stead.table.maxn(arg) do for i = 1, stead.table.maxn(arg) do
stead.txt[stead.txt_top] = par('',stead.txt[stead.txt_top], arg[i]); stead.cctx[stead.call_top].txt = par('',stead.cctx[stead.call_top].txt, arg[i]);
end end
stead.txt[stead.txt_top] = cat(stead.txt[stead.txt_top], ' '); stead.cctx[stead.call_top].txt = cat(stead.cctx[stead.call_top].txt, ' ');
end end
function pn(...) function pn(...)
p(unpack(arg)); p(unpack(arg));
stead.txt[stead.txt_top] = par('',stead.txt[stead.txt_top],'^'); stead.cctx[stead.call_top].txt = par('',stead.cctx[stead.call_top].txt,'^');
end end
-- merge strings with "space" as separator -- merge strings with "space" as separator
@ -573,14 +582,15 @@ function call(v, n, ...)
return v[n]; return v[n];
end end
if type(v[n]) == 'function' then if type(v[n]) == 'function' then
ppush() callpush()
pstart() pclr()
self(v)
local a,b = v[n](v, unpack(arg)); local a,b = v[n](v, unpack(arg));
if a == nil and b == nil then if a == nil and b == nil then
a = pend(); a = pget()
b = nil; b = nil
end end
ppop() callpop()
return a,b return a,b
end end
error ("Method not string nor function:"..tostring(n)); error ("Method not string nor function:"..tostring(n));