refactoring
This commit is contained in:
@@ -1,24 +1,22 @@
|
|||||||
do
|
local wrap, unwrap = (function()
|
||||||
local null = {}
|
local null = {}
|
||||||
|
return function(value)
|
||||||
function Aux_wrap(value)
|
|
||||||
if value == nil then
|
if value == nil then
|
||||||
return null
|
return null
|
||||||
else
|
else
|
||||||
return value
|
return value
|
||||||
end
|
end
|
||||||
end
|
end,
|
||||||
|
function(value)
|
||||||
function Aux_unwrap(value)
|
|
||||||
if value == null then
|
if value == null then
|
||||||
return nil
|
return nil
|
||||||
else
|
else
|
||||||
return value
|
return value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end)()
|
||||||
|
|
||||||
function Aux_module(name)
|
local function Aux_module(name)
|
||||||
local data, is_public, public_interface, private_interface, public, private = {}, {}, {}, {}, {}, {}
|
local data, is_public, public_interface, private_interface, public, private = {}, {}, {}, {}, {}, {}
|
||||||
setmetatable(public_interface, {
|
setmetatable(public_interface, {
|
||||||
__newindex = function(_, key)
|
__newindex = function(_, key)
|
||||||
@@ -29,7 +27,7 @@ function Aux_module(name)
|
|||||||
error('Access of undeclared attribute "'..key..'" on public interface of "'..name..'"!')
|
error('Access of undeclared attribute "'..key..'" on public interface of "'..name..'"!')
|
||||||
end
|
end
|
||||||
if is_public[key] then
|
if is_public[key] then
|
||||||
return Aux_unwrap(data[key])
|
return unwrap(data[key])
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
__call = function(_, key)
|
__call = function(_, key)
|
||||||
@@ -41,13 +39,13 @@ function Aux_module(name)
|
|||||||
if data[key] == nil then
|
if data[key] == nil then
|
||||||
error('Assignment of undeclared attribute "'..key..'" on private interface of "'..name..'"!')
|
error('Assignment of undeclared attribute "'..key..'" on private interface of "'..name..'"!')
|
||||||
end
|
end
|
||||||
data[key] = Aux_wrap(value)
|
data[key] = wrap(value)
|
||||||
end,
|
end,
|
||||||
__index = function(_, key)
|
__index = function(_, key)
|
||||||
if data[key] == nil then
|
if data[key] == nil then
|
||||||
error('Access of undeclared attribute "'..key..'" on private interface of "'..name..'"!')
|
error('Access of undeclared attribute "'..key..'" on private interface of "'..name..'"!')
|
||||||
end
|
end
|
||||||
return Aux_unwrap(data[key])
|
return unwrap(data[key])
|
||||||
end,
|
end,
|
||||||
__call = function(_, key)
|
__call = function(_, key)
|
||||||
return data[key] ~= nil
|
return data[key] ~= nil
|
||||||
@@ -58,7 +56,7 @@ function Aux_module(name)
|
|||||||
if data[key] ~= nil then
|
if data[key] ~= nil then
|
||||||
error('Multiple declarations of "'..key..'" in "'..name..'"!')
|
error('Multiple declarations of "'..key..'" in "'..name..'"!')
|
||||||
end
|
end
|
||||||
data[key] = Aux_wrap(value)
|
data[key] = wrap(value)
|
||||||
is_public[key] = true
|
is_public[key] = true
|
||||||
end,
|
end,
|
||||||
__index = function(_, key)
|
__index = function(_, key)
|
||||||
@@ -70,7 +68,7 @@ function Aux_module(name)
|
|||||||
if data[key] ~= nil then
|
if data[key] ~= nil then
|
||||||
error('Multiple declarations of "'..key..'" in "'..name..'"!')
|
error('Multiple declarations of "'..key..'" in "'..name..'"!')
|
||||||
end
|
end
|
||||||
data[key] = Aux_wrap(value)
|
data[key] = wrap(value)
|
||||||
is_public[key] = nil
|
is_public[key] = nil
|
||||||
end,
|
end,
|
||||||
__index = function(_, key)
|
__index = function(_, key)
|
||||||
@@ -80,33 +78,28 @@ function Aux_module(name)
|
|||||||
return { public_interface, private_interface, public, private }
|
return { public_interface, private_interface, public, private }
|
||||||
end
|
end
|
||||||
|
|
||||||
function Aux_addon(name)
|
-----------------------------------------------------------------------------------------------------
|
||||||
local public_interface, private_interface, public, private = unpack(Aux_module(name))
|
-----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
private.modules = { public_interface }
|
local addon = Aux_module('Aux')
|
||||||
|
|
||||||
function public.module(name)
|
|
||||||
local module = Aux_module(name)
|
|
||||||
local public_interface = tremove(module, 1)
|
|
||||||
tinsert(private_interface.modules, public_interface)
|
|
||||||
public[name] = public_interface
|
|
||||||
return unpack(module)
|
|
||||||
end
|
|
||||||
|
|
||||||
return { public_interface, private_interface, public, private }
|
|
||||||
end
|
|
||||||
|
|
||||||
local addon = Aux_addon('Aux')
|
|
||||||
Aux = tremove(addon, 1)
|
Aux = tremove(addon, 1)
|
||||||
local m, public, private = unpack(addon)
|
local m, public, private = unpack(addon)
|
||||||
|
|
||||||
|
private.modules = { Aux }
|
||||||
|
function public.module(name)
|
||||||
|
local module = Aux_module(name)
|
||||||
|
local public_interface = tremove(module, 1)
|
||||||
|
tinsert(m.modules, public_interface)
|
||||||
|
public[name] = public_interface
|
||||||
|
return unpack(module)
|
||||||
|
end
|
||||||
|
|
||||||
private.tabs = {}
|
private.tabs = {}
|
||||||
function public.tab(index, name)
|
function public.tab(index, name)
|
||||||
local ret = { m.module(name) }
|
local ret = { m.module(name) }
|
||||||
m.tabs[index] = m[name]
|
m.tabs[index] = m[name]
|
||||||
return unpack(ret)
|
return unpack(ret)
|
||||||
end
|
end
|
||||||
|
|
||||||
private.active_tab = nil
|
private.active_tab = nil
|
||||||
|
|
||||||
function public.on_load()
|
function public.on_load()
|
||||||
|
|||||||
Reference in New Issue
Block a user