diff --git a/compat53/module.lua b/compat53/module.lua index 225d8ca..67b2a4a 100644 --- a/compat53/module.lua +++ b/compat53/module.lua @@ -115,6 +115,7 @@ if lua_version < "5.3" then M.math.mininteger = minint function M.math.tointeger(n) + n = tonumber(n) if type(n) == "number" and n <= maxint and n >= minint and n % 1 == 0 then return n end diff --git a/tests/test.lua b/tests/test.lua index 443f6f7..ddc00fe 100755 --- a/tests/test.lua +++ b/tests/test.lua @@ -228,6 +228,7 @@ print("math.mininteger", math.mininteger-1 < math.mininteger) ___'' print("math.tointeger", math.tointeger(0)) print("math.tointeger", math.tointeger(math.pi)) +print("math.tointeger", math.tointeger("123")) print("math.tointeger", math.tointeger("hello")) print("math.tointeger", math.tointeger(math.maxinteger+2.0)) print("math.tointeger", math.tointeger(math.mininteger*2.0))