lua-users home
lua-l archive

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



On 06/11/2006, at 6:33 PM, Shmuel Zeigerman wrote:

Nick Gammon wrote:
Probably the manual should be reworded as:
"gsub also returns, as its second value, the total number of matches made."

But this would be, in fact, an API alteration, and API is not allowed to change after the Lua version is officially out.

No, that is a clarification of what it currently does. It currently returns the number of times it matched, regardless of what happens when it matches.

Thus, if the API is not allowed to change, the manual rewording is what is required.

From the source:

    e = match(&ms, src, p);
    if (e) {
      n++;
      add_value(&ms, &b, src, e);
    }

The number n is what is returned as the count. It is incremented on a match, regardless of what add_value does with the match.


- Nick