From ada0cb48d11bc54dc97574a177de68924decdc3a Mon Sep 17 00:00:00 2001 From: Pinya <800pin.ru@gmail.com> Date: Wed, 27 Dec 2017 19:41:32 +0300 Subject: [PATCH] update match function --- !Compatibility/api/luaAPI.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/!Compatibility/api/luaAPI.lua b/!Compatibility/api/luaAPI.lua index 924cbfb..f2d4dc6 100644 --- a/!Compatibility/api/luaAPI.lua +++ b/!Compatibility/api/luaAPI.lua @@ -100,11 +100,16 @@ strjoin = string.join function string.match(str, pattern, index) assert(type(str) == "string" or type(str) == "number", format("bad argument #1 to 'match' (string expected, got %s)", str and type(str) or "no value")) assert(type(pattern) == "string" or type(pattern) == "number", format("bad argument #2 to 'match' (string expected, got %s)", pattern and type(pattern) or "no value")) + assert(not index or type(index) == "number" or type(index) == "string", format("bad argument #3 to 'match' (number expected, got %s)", index and type(index) or "no value")) str = type(str) == "number" and tostring(str) or str pattern = type(pattern) == "number" and tostring(pattern) or pattern - return gfind(index and sub(str, index) or str, pattern)() + if type(index) == "string" then + index = index ~= "" and tonumber(index) or nil + end + + return gfind(index and sub(str, index) or str, gsub(pattern, "%^", ""))() or "" end strmatch = string.match