gsub x lua 3.1

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

gsub x lua 3.1

Roberto Ierusalimschy
  The function gsub, for pattern substitution, has got a new optional
argument in Lua 3.0:

> gsub (s, pat, repl [, table] [, n])
> [...]
> If repl is a function, then this function is called every time a match occurs,
> with the following arguments: If table is present, then the first argument
> is this table and the second one is a match counter (1 for the first call).

(from the reference manual)

  The purpose of that table was to allow the code calling gsub to pass
some context to function "repl". However, that was an ad-hoc solution, and
quite peculiar to gsub. Since Lua 3.1 will have nested functions with
proper static visibility, it will be possible to put this kind of context
in function "repl" itself, in a cleaner way. Therefore, we are considering
removing this parameter from gsub, going back to its form in Lua 2.5:

> gsub (s, pat, repl [, n])

We hope this will be the only incompatibility between Lua 3.0 and 3.1.
We strongly encourage people not to use this parameter, or at least to
have its uses well documented.

-- Roberto