From 1c679a282bf1255cddfbb6b3e8c5c72d9ebe57e8 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 29 Aug 2024 17:14:46 -0300 Subject: [PATCH] fix: math.tointeger accepts strings convertible to integers (#66) --- 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))