mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-28 13:46:22 +01:00
fix(scripting): gsub with a metatable'd table, the trim idiom, the memory doc
- replacement_length() popped nothing after lua_getmetatable() pushed a metatable, so gsub got it
as its 4th argument ("bad argument #4 to 'gsub'"); it is popped now.
- lua_pattern_cost(): a repetition followed by what always matches (as the first %s* of
"^%s*(.-)%s*$") is tried once and doesn't multiply; a repetition of a character or a %class
right before the final '$' counts the longest run of it in the subject, not the subject. The
trim of a 10 KB line of words is allowed, a long run of spaces is still refused (it takes the
square of the run). The doc names a trim that is linear on any string.
- the doc says every concatenation within one hook interval is made whole before the memory check.
This commit is contained in:
@@ -88,9 +88,15 @@ constexpr double max_pattern_cost{1e8};
|
||||
// - a plain search (string.find with plain set, or a pattern without special characters): Subject x m;
|
||||
// - a pattern: tried from every position of the subject (Subject + 1), or from the first only when Anchored (it starts
|
||||
// with '^', and the function anchors: find, match, gsub, not gmatch), times (Subject + 1) for each repetition ('*',
|
||||
// '+', '-', %b, a back reference %1-%9) but a last one (followed by nothing but ')', which ends the match where it
|
||||
// stops), times 2 for each '?', times m for the work of each step (a set is gone through item by item)
|
||||
// '+', '-', %b, a back reference %1-%9) but one followed by what always matches (nothing, ')', a repetition with '*'
|
||||
// or '-' or a '?' of what always matches, '.*' / '.-' before '$'), where the match is over: so neither the last
|
||||
// repetition nor the first %s* of "^%s*(.-)%s*$" multiplies. times 2 for each '?', times m for the work of each step
|
||||
// (a set is gone through item by item)
|
||||
// a malformed pattern costs nothing here: the function raises its error itself
|
||||
double lua_pattern_cost(std::string_view Pattern, std::size_t Subject, bool Plain, bool Anchorable);
|
||||
// as above, on the subject itself: a repetition of a character or a %class right before the final '$' ("%s*$") counts
|
||||
// as many times as the longest run of it in the subject (plus one), not the whole subject: past that run it fails or
|
||||
// gets to the end, so the trim "^%s*(.-)%s*$" costs about the subject times its longest run of spaces
|
||||
double lua_pattern_cost(std::string_view Pattern, std::string_view Subject, bool Plain, bool Anchorable);
|
||||
|
||||
} // namespace script_screens
|
||||
|
||||
Reference in New Issue
Block a user