diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2024-08-29 17:14:46 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-29 17:14:46 -0300 |
| commit | 1c679a282bf1255cddfbb6b3e8c5c72d9ebe57e8 (patch) | |
| tree | a5fd29118c23b3438087fb1490b12cc4dedc015a | |
| parent | 11062dd41e77c9b03daf79f5838bedba6421753c (diff) | |
| download | lua-compat-5.3-1c679a282bf1255cddfbb6b3e8c5c72d9ebe57e8.tar.gz lua-compat-5.3-1c679a282bf1255cddfbb6b3e8c5c72d9ebe57e8.tar.bz2 lua-compat-5.3-1c679a282bf1255cddfbb6b3e8c5c72d9ebe57e8.zip | |
fix: math.tointeger accepts strings convertible to integers (#66)
| -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)) |
