big refactoring
This commit is contained in:
@@ -7,8 +7,7 @@ do
|
|||||||
local table_pool, auto_recycle = {}, {}
|
local table_pool, auto_recycle = {}, {}
|
||||||
local function wipe(t) -- like with a cloth or something
|
local function wipe(t) -- like with a cloth or something
|
||||||
for k in t do t[k] = nil end
|
for k in t do t[k] = nil end
|
||||||
setn(t, 0)
|
setn(t, 0); return t
|
||||||
return t
|
|
||||||
end
|
end
|
||||||
function public.recycle(t)
|
function public.recycle(t)
|
||||||
auto_recycle[t] = nil
|
auto_recycle[t] = nil
|
||||||
@@ -19,8 +18,7 @@ do
|
|||||||
function public.t.get() return tremove(table_pool) or {} end
|
function public.t.get() return tremove(table_pool) or {} end
|
||||||
CreateFrame('Frame'):SetScript('OnUpdate', function()
|
CreateFrame('Frame'):SetScript('OnUpdate', function()
|
||||||
for t in auto_recycle do recycle(t) end
|
for t in auto_recycle do recycle(t) end
|
||||||
recycle(auto_recycle)
|
recycle(auto_recycle); auto_recycle = t
|
||||||
auto_recycle = t
|
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -30,8 +28,7 @@ do
|
|||||||
function public.module(name)
|
function public.module(name)
|
||||||
local env = module_env(name)
|
local env = module_env(name)
|
||||||
if not modules[name] then env.import(temp-{['']='modules', ['']='core', ['']='util'}) end
|
if not modules[name] then env.import(temp-{['']='modules', ['']='core', ['']='util'}) end
|
||||||
setfenv(2, env)
|
setfenv(2, env); modules[name] = true
|
||||||
modules[name] = true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+8
-22
@@ -2,7 +2,7 @@ local type, setmetatable, setfenv, unpack, mask, _g = type, setmetatable, setfen
|
|||||||
local PRIVATE, PUBLIC, MUTABLE, PROPERTY = 0, 1, 2, 4
|
local PRIVATE, PUBLIC, MUTABLE, PROPERTY = 0, 1, 2, 4
|
||||||
local MODIFIER = {private=PRIVATE, public=PUBLIC, mutable=MUTABLE, property=PROPERTY}
|
local MODIFIER = {private=PRIVATE, public=PUBLIC, mutable=MUTABLE, property=PROPERTY}
|
||||||
local MODIFIER_MASK, PROPERTY_MASK = {private=MUTABLE+PROPERTY, public=MUTABLE+PROPERTY, mutable=PRIVATE+PUBLIC}, PRIVATE+PUBLIC
|
local MODIFIER_MASK, PROPERTY_MASK = {private=MUTABLE+PROPERTY, public=MUTABLE+PROPERTY, mutable=PRIVATE+PUBLIC}, PRIVATE+PUBLIC
|
||||||
local error, declaration_error, immutable_error, collision_error, void_error, import, define_property, lock_mt, env_mt, interface_mt, declarator_mt, property_mt
|
local error, declaration_error, immutable_error, collision_error, void_error, import, property_setter, lock_mt, env_mt, interface_mt, declarator_mt
|
||||||
lock_mt = {}
|
lock_mt = {}
|
||||||
local _state, _modules = {}, setmetatable({}, lock_mt)
|
local _state, _modules = {}, setmetatable({}, lock_mt)
|
||||||
function error(message, level, ...) _g.error(format(message, unpack(arg))..'\n'..debugstack(3, 5, 0), (level or 1) + 1) end
|
function error(message, level, ...) _g.error(format(message, unpack(arg))..'\n'..debugstack(3, 5, 0), (level or 1) + 1) end
|
||||||
@@ -11,26 +11,12 @@ function immutable_error(key, level) error('Field "%s" is immutable.', level + 1
|
|||||||
function collision_error(key, level) error('Field "%s" already exists.', level + 1, key) end
|
function collision_error(key, level) error('Field "%s" already exists.', level + 1, key) end
|
||||||
function void_error(key, level) error('No field "%s".', level + 1, key) end
|
function void_error(key, level) error('No field "%s".', level + 1, key) end
|
||||||
function import(imports, t) for k, v in t do imports[type(k) == 'number' and v or k] = v end end
|
function import(imports, t) for k, v in t do imports[type(k) == 'number' and v or k] = v end end
|
||||||
declarator_mt = {__metatable=false}
|
declarator_mt = {__metatable=false }
|
||||||
property_mt = {
|
function property_setter(data, property, value)
|
||||||
__index = function(self, key)
|
local state = _state[self]; local property = state.property
|
||||||
local state = _state[self]; local modifiers = state.metadata[key]
|
if not property or data[property] then declaration_error(2) end
|
||||||
if modifiers and mask(PROPERTY, modifiers) ~= 0 or declaration_error(2) then
|
data[property] = type(value) == 'function' and value or declaration_error(2)
|
||||||
state.property = key; return self
|
end
|
||||||
end
|
|
||||||
end,
|
|
||||||
__newindex = function(self, key, value)
|
|
||||||
local state, function_value = _state[self], type(value) == 'function'
|
|
||||||
local property, getters, setters = state.property, state.getters, state.setters
|
|
||||||
if key == 'get' then
|
|
||||||
if getters[property] then declaration_error(2) end
|
|
||||||
getters[property] = function_value and value or error('Getter must be a function.', 2)
|
|
||||||
elseif key == 'set' or declaration_error(2) then
|
|
||||||
if setters[property] then declaration_error(2) end
|
|
||||||
setters[property] = function_value and value or error('Setter must be a function.', 2)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
}
|
|
||||||
function declarator_mt.__call() end
|
function declarator_mt.__call() end
|
||||||
function declarator_mt.__index(self, key)
|
function declarator_mt.__index(self, key)
|
||||||
local state, modifier = _state[self], MODIFIER[key]
|
local state, modifier = _state[self], MODIFIER[key]
|
||||||
@@ -38,7 +24,7 @@ function declarator_mt.__index(self, key)
|
|||||||
state.modifiers = modifier + mask(MODIFIER_MASK[key], state.modifiers)
|
state.modifiers = modifier + mask(MODIFIER_MASK[key], state.modifiers)
|
||||||
return self
|
return self
|
||||||
elseif not state.metadata[key] or collision_error(key, 2) then
|
elseif not state.metadata[key] or collision_error(key, 2) then
|
||||||
state.property, state.metadata[key] = key, PROPERTY + mask(PROPERTY_MASK, state.modifiers)
|
state.property, state.metadata[key], state.modifiers = key, PROPERTY + mask(PROPERTY_MASK, state.modifiers), PRIVATE
|
||||||
return state.property_initializer
|
return state.property_initializer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user