lua-users home
lua-l archive

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


On Wednesday, May 06, 2015 12:19:14 PM Gaspard Bucher wrote:
> The "matcher.func" function can take different argument count depending on
> the captures in the pattern.
> 
> Any thought on how to fix this with style ?

You could "abuse" the ability to use a function in string.gsub.

    string.gsub(line, matcher.pattern, function(...)
                matcher.func(self, line_i, ...)
            end, 1)

The 1 to stop after one match can be omitted if you anchor the pattern. And 
the return value doesn't matter since you're ignoring the substituted string.

-- 
tom <telliamed@whoopdedo.org>