diff options
-rw-r--r-- | compat53/module.lua | 1 | ||||
-rwxr-xr-x | tests/test.lua | 1 |
2 files changed, 2 insertions, 0 deletions
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 | |||
115 | M.math.mininteger = minint | 115 | M.math.mininteger = minint |
116 | 116 | ||
117 | function M.math.tointeger(n) | 117 | function M.math.tointeger(n) |
118 | n = tonumber(n) | ||
118 | if type(n) == "number" and n <= maxint and n >= minint and n % 1 == 0 then | 119 | if type(n) == "number" and n <= maxint and n >= minint and n % 1 == 0 then |
119 | return n | 120 | return n |
120 | end | 121 | 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) | |||
228 | ___'' | 228 | ___'' |
229 | print("math.tointeger", math.tointeger(0)) | 229 | print("math.tointeger", math.tointeger(0)) |
230 | print("math.tointeger", math.tointeger(math.pi)) | 230 | print("math.tointeger", math.tointeger(math.pi)) |
231 | print("math.tointeger", math.tointeger("123")) | ||
231 | print("math.tointeger", math.tointeger("hello")) | 232 | print("math.tointeger", math.tointeger("hello")) |
232 | print("math.tointeger", math.tointeger(math.maxinteger+2.0)) | 233 | print("math.tointeger", math.tointeger(math.maxinteger+2.0)) |
233 | print("math.tointeger", math.tointeger(math.mininteger*2.0)) | 234 | print("math.tointeger", math.tointeger(math.mininteger*2.0)) |