From ba679a83c1bce49d0a9684160def77ae0a8e7ba7 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Wed, 28 Aug 2024 00:46:56 -0300 Subject: [PATCH] fix: math.tointeger accepts strings convertible to integers --- compat53/module.lua | 1 + tests/test.lua | 1 + 2 files changed, 2 insertions(+) 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))