module refactoring

This commit is contained in:
Simon Hirsig
2017-11-01 15:01:41 +01:00
parent 9989ceb42f
commit 8823b34904
36 changed files with 669 additions and 646 deletions
+7 -10
View File
@@ -1,5 +1,4 @@
if defined 'T' then return end
module 'T'
if module 'T' then return end
local next, getn, setn, tremove, setmetatable = next, getn, table.setn, tremove, setmetatable
@@ -56,17 +55,15 @@ do
M.static = setmetatable({}, {__metatable=false, __newindex=nop, __call=f, __sub=f})
end
M.get.T = acquire
do
local function ret(t)
local function unpack(t)
if getn(t) > 0 then
return tremove(t, 1), ret(t)
return tremove(t, 1), unpack(t)
else
release(t)
end
end
M.ret = ret
M.unpack = unpack
end
M.empty = setmetatable({}, {__metatable=false, __newindex=nop})
@@ -118,18 +115,18 @@ do
})
end
M.A = vararg(function(arg)
M.list = vararg(function(arg)
auto_release[arg] = nil
return arg
end)
M.S = vararg(function(arg)
M.set = vararg(function(arg)
local t = acquire()
for _, v in pairs(arg) do
t[v] = true
end
return t
end)
M.O = vararg(function(arg)
M.map = vararg(function(arg)
local t = acquire()
for i = 1, getn(arg), 2 do
t[arg[i]] = arg[i + 1]