[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: gsub X Lua 3.1
- From: tomas@... (Tomas Guisasola Gorham)
- Date: Thu, 24 Sep 1998 16:47:25 -0300 (EST)
Hi,
anticipating problems with the incompatibility of gsub between
Lua 3.1 and Lua 3.0, I made a Gsub function (below) which intends to do
the same job as the obsolete one. Maybe it will be useful to some of
you (and maybe you can test it too :-) ).
Tomas
======================================================================
function Gsub (str, pat, repl, table, n)
if not table then
return gsub (str, pat, repl)
elseif type (table) ~= "table" then
return gsub (str, pat, repl, table)
else
local t = { n=0 }
local f = function (...)
%t.n = %t.n + 1
local i = 1
local newargs = { %table, %t.n }
while i <= arg.n do
newargs[i+2] = arg[i]
i = i+1
end
newargs.n = i + 2 - 1
return call (%repl, newargs)
end
if n then
return gsub (str, pat, f, n)
else
return gsub (str, pat, f)
end
end
end