fix string.match function

update assert of select function
This commit is contained in:
Pinya
2017-12-16 20:49:49 +03:00
parent aabd0134c4
commit bc9f256f77
+4 -4
View File
@@ -22,9 +22,9 @@ function difftime(time2, time1)
end end
function select(n, ...) function select(n, ...)
assert(type(n) == "number" or type(n) == "string", format("bad argument #1 to 'select' (number expected, got %s)", n and type(n) or "no value")) assert(type(n) == "number" or (type(n) == "string" and n == "#"), format("bad argument #1 to 'select' (number expected, got %s)", n and type(n) or "no value"))
if type(n) == "string" and n == "#" then if type(n) == "string" then
if type(arg) == "table" then if type(arg) == "table" then
return getn(arg) return getn(arg)
else else
@@ -71,9 +71,9 @@ function string.match(str, pattern, index)
assert(type(pattern) == "string", format("bad argument #2 to 'match' (string expected, got %s)", pattern and type(pattern) or "no value")) assert(type(pattern) == "string", format("bad argument #2 to 'match' (string expected, got %s)", pattern and type(pattern) or "no value"))
str = type(str) == "number" and tostring(str) or str str = type(str) == "number" and tostring(str) or str
local _, _, match = find(index and sub(str, index) or str, "("..pattern..")") local i, j = find(index and sub(str, index) or str, pattern)
return match return i and sub(str, i, j)
end end
strmatch = string.match strmatch = string.match