refactoring
This commit is contained in:
+3
-3
@@ -302,10 +302,10 @@ function public.editbox(parent)
|
|||||||
editbox:SetTextInsets(1.5, 1.5, 3, 3)
|
editbox:SetTextInsets(1.5, 1.5, 3, 3)
|
||||||
editbox:SetMaxLetters(nil)
|
editbox:SetMaxLetters(nil)
|
||||||
editbox:SetHeight(24)
|
editbox:SetHeight(24)
|
||||||
-- editbox:SetTextColor(0, 0, 0, 0)
|
editbox:SetTextColor(0, 0, 0, 0)
|
||||||
set_content_style(editbox)
|
set_content_style(editbox)
|
||||||
local function colorize() end -- this.display:SetText((this.colorizer or id)(this:GetText())) end
|
local function colorize() this.display:SetText((this.colorizer or id)(this:GetText())) end
|
||||||
local function format() end-- this.display:SetText((this.formatter or this.colorizer or id)(this:GetText())) end
|
local function format() this.display:SetText((this.formatter or this.colorizer or id)(this:GetText())) end
|
||||||
editbox:SetScript('OnEscapePressed', function()
|
editbox:SetScript('OnEscapePressed', function()
|
||||||
this:ClearFocus()
|
this:ClearFocus()
|
||||||
;(this.escape or nop)()
|
;(this.escape or nop)()
|
||||||
|
|||||||
+57
-27
@@ -2,7 +2,7 @@ green_t = module
|
|||||||
--setglobal('green_t', green_t and error(nil) or module)
|
--setglobal('green_t', green_t and error(nil) or module)
|
||||||
|
|
||||||
local next, setn, type, setmetatable = next, table.setn, type, setmetatable
|
local next, setn, type, setmetatable = next, table.setn, type, setmetatable
|
||||||
local wipe, release, acquire, acquire_temp, empty
|
local wipe, release, acquire, acquire_auto, empty
|
||||||
|
|
||||||
-- TODO mandatory operation table mandate + comply/fulfill functions
|
-- TODO mandatory operation table mandate + comply/fulfill functions
|
||||||
local pool, pool_size, overflow_pool, auto_release = {}, 0, setmetatable({}, { __mode='k' }), {}
|
local pool, pool_size, overflow_pool, auto_release = {}, 0, setmetatable({}, { __mode='k' }), {}
|
||||||
@@ -33,14 +33,6 @@ function release(t)
|
|||||||
end
|
end
|
||||||
public.release = release
|
public.release = release
|
||||||
|
|
||||||
function public.ret(t)
|
|
||||||
if getn(t) > 0 then
|
|
||||||
return tremove(t, 1), ret(t)
|
|
||||||
else
|
|
||||||
release(t)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function acquire()
|
function acquire()
|
||||||
if pool_size > 0 then
|
if pool_size > 0 then
|
||||||
pool_size = pool_size - 1
|
pool_size = pool_size - 1
|
||||||
@@ -55,36 +47,47 @@ function acquire()
|
|||||||
end
|
end
|
||||||
public.t.get = acquire
|
public.t.get = acquire
|
||||||
|
|
||||||
function acquire_temp()
|
function acquire_auto()
|
||||||
local t = acquire()
|
local t = acquire()
|
||||||
auto_release[t] = true
|
auto_release[t] = true
|
||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
public.tt.get = acquire_temp
|
public.tt.get = acquire_auto
|
||||||
|
|
||||||
|
function public.ret(t)
|
||||||
|
if getn(t) > 0 then
|
||||||
|
return tremove(t, 1), ret(t)
|
||||||
|
else
|
||||||
|
release(t)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
do
|
do
|
||||||
local mt = { __newindex=nop }
|
local mt = { __newindex=nop }
|
||||||
function empty() return setmetatable(acquire_temp(), mt) end
|
function empty() return setmetatable(acquire_auto(), mt) end
|
||||||
public.empty.get = empty
|
public.empty.get = empty
|
||||||
end
|
end
|
||||||
|
|
||||||
do
|
do
|
||||||
local f = function(_, v) if type(v) == 'table' then auto_release[v] = true end return v end
|
local function apply(v, enable)
|
||||||
local mt = { __call=f, __sub=f }
|
if type(v) ~= 'table' then return end
|
||||||
public.temp {get=function() return setmetatable(acquire_temp(), mt) end, set=function(t) auto_release[t] = true end}
|
auto_release[v] = enable and true or nil
|
||||||
end
|
end
|
||||||
do
|
local function define_modifier(name, enable)
|
||||||
local f = function(_, v) if type(v) == 'table' then auto_release[v] = nil end return v end
|
local f = function(_, v) apply(v, enable); return v end
|
||||||
local mt = { __call=f, __sub=f }
|
local mt = { __call=f, __sub=f }
|
||||||
public.perm { get=function() return setmetatable(acquire_temp(), mt) end, set=function(t) auto_release[t] = nil end }
|
public[name] { get=function() return setmetatable(acquire_auto(), mt) end, set=function(v) apply(v, enable) end }
|
||||||
|
end
|
||||||
|
define_modifier('temp', true)
|
||||||
|
define_modifier('perm', false)
|
||||||
end
|
end
|
||||||
|
|
||||||
do
|
do
|
||||||
local mt, key = {}, nil
|
local mt, key = {}, nil
|
||||||
function mt:__unm() local temp = mt.__index; mt.__index = nil; return temp end
|
function mt:__unm() local temp = mt.__index; mt.__index = nil; return temp end
|
||||||
function mt:__index(k) key = k; return self end
|
function mt:__index(k) key = k; return self end
|
||||||
function mt:__call(v) self[key] = v; key = nil return self end
|
function mt:__call(v) self[key] = v; key = nil; return self end
|
||||||
function public.__(t) mt.__newindex = wipe(t); return setmetatable(acquire_temp(), mt) end
|
function public.__(t) mt.__newindex = wipe(t); return setmetatable(acquire_auto(), mt) end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function arg_chunk(k, n)
|
local function arg_chunk(k, n)
|
||||||
@@ -105,6 +108,33 @@ function public.pseudo_vararg_function(body, upvals)
|
|||||||
return f()
|
return f()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
do
|
||||||
|
local body = [[
|
||||||
|
if arg100 ~= nil then error("Vararg overflow.") end
|
||||||
|
local n
|
||||||
|
repeat
|
||||||
|
]]
|
||||||
|
for i = 99, 1, -1 do
|
||||||
|
body = body .. format('if a%1$d ~= nil then n = %1$d; break end;', i)
|
||||||
|
end
|
||||||
|
body = body .. [[
|
||||||
|
until true
|
||||||
|
local t = acquire_auto()
|
||||||
|
setn(t, n)
|
||||||
|
repeat
|
||||||
|
]]
|
||||||
|
for i = 1, 99 do
|
||||||
|
body = body .. format('if %1$d > n then break end; t[%1$d] = a%1$d;', i)
|
||||||
|
end
|
||||||
|
body = body .. [[
|
||||||
|
until true
|
||||||
|
return f(t)
|
||||||
|
]]
|
||||||
|
function public.vararg(f)
|
||||||
|
return pseudo_vararg_function(body, {f=f, error=error, setn=setn, acquire=acquire_auto, release=release})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function insert_chunk(mode)
|
local function insert_chunk(mode)
|
||||||
local body = 'repeat '
|
local body = 'repeat '
|
||||||
if mode == 'k' then
|
if mode == 'k' then
|
||||||
@@ -126,7 +156,7 @@ local function insert_chunk(mode)
|
|||||||
body = body .. format('if a%1$d == nil then break end; a1[a%1$d] = a%d;', i, i+1)
|
body = body .. format('if a%1$d == nil then break end; a1[a%1$d] = a%d;', i, i+1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return body .. 'if a100 ~= nil then error"Overflow." end until true;'
|
return body .. 'if a100 ~= nil then error("Vararg overflow.") end until true;'
|
||||||
end
|
end
|
||||||
|
|
||||||
do
|
do
|
||||||
@@ -135,10 +165,10 @@ do
|
|||||||
local mt = {__call = pseudo_vararg_function(insert_chunk(mode) .. 'setmetatable(a1, nil); return a1', upvals)}
|
local mt = {__call = pseudo_vararg_function(insert_chunk(mode) .. 'setmetatable(a1, nil); return a1', upvals)}
|
||||||
return function() return setmetatable(acquire(), mt) end
|
return function() return setmetatable(acquire(), mt) end
|
||||||
end
|
end
|
||||||
public.S.get = pseudo_literal'k'
|
public.S.get = pseudo_literal('k')
|
||||||
public.A.get = pseudo_literal'v'
|
public.A.get = pseudo_literal('v')
|
||||||
public.A0.get = pseudo_literal'v0'
|
public.A0.get = pseudo_literal('v0')
|
||||||
public.T.get = pseudo_literal'kv'
|
public.T.get = pseudo_literal('kv')
|
||||||
end
|
end
|
||||||
|
|
||||||
do
|
do
|
||||||
|
|||||||
Reference in New Issue
Block a user