Skip to content

Commit

Permalink
fix: math.tointeger accepts strings convertible to integers
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamhm committed Aug 28, 2024
1 parent 11062dd commit ba679a8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions compat53/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit ba679a8

Please sign in to comment.