lua-users home
lua-l archive

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


With the recent changes to string.gmatch and the whole pattern matching code, it seems like it'd be much easier to allow yields through string.gsub. May I have yieldable string.gsub?

local function f(s, p) return string.gsub(s, p, coroutine.yield) end
local co = coroutine.wrap(f)
local s1 = co("test", ".")
print(v1) -- t
print(co("g"), co("o")) -- e s
local s2 = co("o")
print(s2) -- t
print(co("d")) -- good 4
co = coroutine.wrap(f)
-- in other words: pass `co` around to allow for fast dynamic substitution, something we currently can't do. -- string.gsub uses a buffer internally, while a string.gmatch-based approach would require either table allocation -- or string concatenation. for large source strings and small replacement strings, string.gsub would probably be better.

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.