[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: string.gsub accepting a callable userdata
- From: Wesley Smith <wesley.hoke@...>
- Date: Thu, 13 Dec 2012 11:07:13 -0800
You can also do this to avoid generating closures each time:
local gsub = (function()
local ref = setmetatable({}, {__mode='v'})
local f = function(...) return ref.userdata(...) end
return function(s, pat, repl)
if type(repl) == 'userdata' then
ref.userdata = repl
repl = f
end
print(s, pat, repl)
return s:gsub(pat,repl)
end
end)()