[outdated] Bug in string.gsub
lua5.1 / lua5.2 console (from ubuntu packages):
Lua Code:
Code:
"<une>rune de puissance" 1 lua5.1* in ESO: Lua Code:
Code:
"<une>rune <de>puissance" 3 Edit: minor correction. The second value returned from gsub is the number of matches, not the number of replacements (words that match but are not in the table are not replaced). Of course 3 is still wrong, as there should be only 1 match. |
It's just not recognizing the beginning anchor (^).
Lua Code:
As far as the number of matches, it's correct (without the beginning anchor). It matches 3 words with spaces after, even though it can only replace two. I suppose as a hack way, you could use a function and only replace the first time it's called: Lua Code:
|
string.gsub has an optional max_replacements parameter, so atm I'm passing 1 to prevent multiple replacements.
Some more tests: Lua Code:
Warning: Spoiler
It appears the anchor actually works at first. The 3rd example string starts with a space, and there's no match, which is correct. But in the 2nd example, after the first replacement (1:une ), the anchor incorrectly matches at "rune", as if the matcher was reset and thought it was at the start of the string. |
I wonder if it's consuming the input pattern as it matches. Something like:
First match of "une rune de puissance" is "une ". It then tries to match against "rune de puissance", then "de puissance", etc. If that's the case, you could get the space in a separate step. Lua Code:
|
Quote:
Lua Code:
EDIT: Quote:
But yes that was my conclusion to when I tested it. |
All times are GMT -6. The time now is 01:15 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI