mirror of
https://github.com/TangentFoxy/lua-date.git
synced 2025-07-28 11:02:17 +00:00
fixed vararg usage for lua 5.1/5.2. Fixes #1
This commit is contained in:
8
date.lua
8
date.lua
@@ -32,6 +32,7 @@
|
|||||||
local math = math
|
local math = math
|
||||||
local os = os
|
local os = os
|
||||||
local unpack = unpack or table.unpack
|
local unpack = unpack or table.unpack
|
||||||
|
local pack = table.pack or function(...) return { n = select('#', ...), ... } end
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
local getmetatable = getmetatable
|
local getmetatable = getmetatable
|
||||||
--[[ EXTRA FUNCTIONS ]]--
|
--[[ EXTRA FUNCTIONS ]]--
|
||||||
@@ -403,6 +404,7 @@
|
|||||||
end
|
end
|
||||||
--#end -- not DATE_OBJECT_AFX
|
--#end -- not DATE_OBJECT_AFX
|
||||||
local function date_from(...)
|
local function date_from(...)
|
||||||
|
local arg = pack(...)
|
||||||
local y, m, d = fix(arg[1]), getmontharg(arg[2]), fix(arg[3])
|
local y, m, d = fix(arg[1]), getmontharg(arg[2]), fix(arg[3])
|
||||||
local h, r, s, t = tonumber(arg[4] or 0), tonumber(arg[5] or 0), tonumber(arg[6] or 0), tonumber(arg[7] or 0)
|
local h, r, s, t = tonumber(arg[4] or 0), tonumber(arg[5] or 0), tonumber(arg[6] or 0), tonumber(arg[7] or 0)
|
||||||
if y and m and d and h and r and s and t then
|
if y and m and d and h and r and s and t then
|
||||||
@@ -700,9 +702,9 @@
|
|||||||
end
|
end
|
||||||
|
|
||||||
function date:__call(...)
|
function date:__call(...)
|
||||||
local n = arg.n
|
local arg = pack(...)
|
||||||
if n > 1 then return (date_from(unpack(arg)))
|
if arg.n > 1 then return (date_from(...))
|
||||||
elseif n == 0 then return (date_getdobj(false))
|
elseif arg.n == 0 then return (date_getdobj(false))
|
||||||
else local o, r = date_getdobj(arg[1]); return r and o:copy() or o end
|
else local o, r = date_getdobj(arg[1]); return r and o:copy() or o end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user