From cee03dfde1a843d79558d5ad07d052ca9ca2489d Mon Sep 17 00:00:00 2001 From: Pinya <800pin.ru@gmail.com> Date: Thu, 15 Feb 2018 21:16:05 +0300 Subject: [PATCH] added math.modulo function as replacement for the '%' operator --- !Compatibility/api/luaAPI.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/!Compatibility/api/luaAPI.lua b/!Compatibility/api/luaAPI.lua index 548e3a9..c3f467c 100644 --- a/!Compatibility/api/luaAPI.lua +++ b/!Compatibility/api/luaAPI.lua @@ -56,6 +56,19 @@ function math.modf(i) return int, i - int end +function math.modulo(x, y) + x = type(x) ~= "number" and tonumber(i) or x + y = type(y) ~= "number" and tonumber(i) or y + + if type(x) ~= "number" then + error(format("bad argument #1 to 'modulo' (number expected, got %s)", x and type(x) or "no value"), 2) + elseif type(y) ~= "number" then + error(format("bad argument #2 to 'modulo' (number expected, got %s)", y and type(y) or "no value"), 2) + end + + return x - floor(x / y) * y +end + function math.cosh(i) i = type(i) ~= "number" and tonumber(i) or i