module refactoring

This commit is contained in:
Simon Hirsig
2017-10-31 06:51:16 +01:00
parent 9989ceb42f
commit 8823b34904
36 changed files with 669 additions and 646 deletions
+14 -12
View File
@@ -1,14 +1,16 @@
module 'aux'
M.immutable = setmetatable(T, {
local T = require 'T'
M.immutable = setmetatable(T.acquire(), {
__metatable = false,
__newindex = nop,
__sub = function(_, t)
return setmetatable(T, O('__metatable', false, '__newindex', nop, '__index', t))
return setmetatable(T.acquire(), T.map('__metatable', false, '__newindex', nop, '__index', t))
end
})
M.select = vararg-function(arg)
M.select = T.vararg-function(arg)
for _ = 1, arg[1] do
tremove(arg, 1)
end
@@ -30,7 +32,7 @@ function M.replicate(count, value)
if count > 0 then return value, replicate(count - 1, value) end
end
M.index = vararg-function(arg)
M.index = T.vararg-function(arg)
local t = tremove(arg, 1)
for _, v in ipairs(arg) do
t = t and t[v]
@@ -40,12 +42,12 @@ end
M.huge = 1.8 * 10 ^ 308
function M.get.modified()
function M.modified()
return IsShiftKeyDown() or IsControlKeyDown() or IsAltKeyDown()
end
function M.copy(t)
local copy = T
local copy = T.acquire()
for k, v in pairs(t) do
copy[k] = v
end
@@ -70,7 +72,7 @@ function M.key(t, value)
end
function M.keys(t)
local keys = T
local keys = T.acquire()
for k in pairs(t) do
tinsert(keys, k)
end
@@ -78,7 +80,7 @@ function M.keys(t)
end
function M.values(t)
local values = T
local values = T.acquire()
for _, v in pairs(t) do
tinsert(values, v)
end
@@ -137,7 +139,7 @@ function M.trim(str)
end
function M.split(str, separator)
local parts = T
local parts = T.acquire()
while true do
local start_index = strfind(str, separator, 1, true)
if start_index then
@@ -153,7 +155,7 @@ function M.split(str, separator)
end
function M.tokenize(str)
local tokens = T
local tokens = T.acquire()
for token in string.gfind(str, '%S+') do tinsert(tokens, token) end
return tokens
end
@@ -173,8 +175,8 @@ end
function M.signal()
local params
return vararg-function(arg)
static(arg)
return T.vararg-function(arg)
T.static(arg)
params = arg
end, function()
return params