mirror of
https://github.com/Bluewhale1337/ElvUIModernized.git
synced 2026-07-27 08:24:44 +00:00
update select & math.modf functions
This commit is contained in:
@@ -18,6 +18,18 @@ math.huge = 1/0
|
|||||||
string.gmatch = string.gfind
|
string.gmatch = string.gfind
|
||||||
gmatch = string.gfind
|
gmatch = string.gfind
|
||||||
|
|
||||||
|
local MAXN = 2147483647
|
||||||
|
local function toInt(x)
|
||||||
|
if x == floor(x) then return x end
|
||||||
|
|
||||||
|
if x > 0 then
|
||||||
|
x = floor(x + 0.5)
|
||||||
|
else
|
||||||
|
x = ceil(x - 0.5)
|
||||||
|
end
|
||||||
|
|
||||||
|
return x
|
||||||
|
end
|
||||||
function select(n, ...)
|
function select(n, ...)
|
||||||
if not (type(n) == "number" or (type(n) == "string" and n == "#")) then
|
if not (type(n) == "number" or (type(n) == "string" and n == "#")) then
|
||||||
error(format("bad argument #1 to 'select' (number expected, got %s)", n and type(n) or "no value"), 2)
|
error(format("bad argument #1 to 'select' (number expected, got %s)", n and type(n) or "no value"), 2)
|
||||||
@@ -25,18 +37,22 @@ function select(n, ...)
|
|||||||
|
|
||||||
if n == "#" then
|
if n == "#" then
|
||||||
return arg.n
|
return arg.n
|
||||||
|
elseif n == 0 or n > MAXN then
|
||||||
|
error("bad argument #1 to 'select' (index out of range)", 2)
|
||||||
elseif n == 1 then
|
elseif n == 1 then
|
||||||
return unpack(arg)
|
return unpack(arg)
|
||||||
end
|
end
|
||||||
|
|
||||||
local args = {}
|
if n < 0 then
|
||||||
args.n = arg.n - n + 1
|
n = arg.n + n + 1
|
||||||
|
end
|
||||||
|
n = toInt(n)
|
||||||
|
|
||||||
for i = n, arg.n do
|
for i = n, arg.n do
|
||||||
args[i-n+1] = arg[i]
|
tremove(arg, 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
return unpack(args)
|
return unpack(arg)
|
||||||
end
|
end
|
||||||
|
|
||||||
local huge = math.huge
|
local huge = math.huge
|
||||||
@@ -53,7 +69,7 @@ function math.modf(i)
|
|||||||
return i, i > 0 and 0 or -0
|
return i, i > 0 and 0 or -0
|
||||||
end
|
end
|
||||||
|
|
||||||
local int = i >= 0 and floor(i) or ceil(i)
|
local int = i > 0 and floor(i) or ceil(i)
|
||||||
|
|
||||||
return int, i - int
|
return int, i - int
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user