[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: [Proposal] Allow yields through string.gsub
- From: "Soni L." <fakedme@...>
- Date: Mon, 4 Apr 2016 16:42:06 -0300
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.