string.gsub
’s third parameter allows you to pass a function which should return the final replacement string. The params of this function are dependant on how many captures there are from the input string + the pattern. However, the typing on this function seems to be incorrect as it seems to only ever expect one param regardless of number of captures.
local someString = "Hello world!"
local result = string.gsub(someString, "([%w]+) ([%w]+)", function(a, b)
-- this is valid, but the lint yells at you
return b .. " " .. a
end)
print(result) -- world Hello!