lua-users home
lua-l archive

gsub X Lua 3.1

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


	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 

AltStyle によって変換されたページ (->オリジナル) /