refactoring
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
local addon = Aux_module('Aux')
|
local addon = Aux_module()
|
||||||
Aux = tremove(addon, 1)
|
Aux = tremove(addon, 1)
|
||||||
local m, public, private = unpack(addon)
|
local m, public, private = unpack(addon)
|
||||||
|
|
||||||
private.modules = { Aux }
|
private.modules = { Aux }
|
||||||
function public.module(name)
|
function public.module(name)
|
||||||
local module = Aux_module(name)
|
local module = Aux_module()
|
||||||
local public_interface = tremove(module, 1)
|
local public_interface = tremove(module, 1)
|
||||||
tinsert(m.modules, public_interface)
|
tinsert(m.modules, public_interface)
|
||||||
public[name] = public_interface
|
public[name] = public_interface
|
||||||
|
|||||||
+12
-12
@@ -1,12 +1,12 @@
|
|||||||
function Aux_module(name)
|
function Aux_module()
|
||||||
local data, is_public, is_declared, public_interface, private_interface, public, private = {}, {}, {}, {}, {}, {}, {}
|
local data, is_public, is_declared, public_interface, private_interface, public, private = {}, {}, {}, {}, {}, {}, {}
|
||||||
setmetatable(public_interface, {
|
setmetatable(public_interface, {
|
||||||
__newindex = function(_, key)
|
__newindex = function()
|
||||||
error('Illegal write of attribute "'..key..'" on public interface of "'..name..'"!', 2)
|
error('Unsupported operation.', 2)
|
||||||
end,
|
end,
|
||||||
__index = function(_, key)
|
__index = function(_, key)
|
||||||
if not is_public[key] then
|
if not is_public[key] then
|
||||||
error('Access of undeclared attribute "'..key..'" on public interface of "'..name..'"!', 2)
|
error('Read of undeclared "'..key..'".', 2)
|
||||||
end
|
end
|
||||||
if is_public[key] then
|
if is_public[key] then
|
||||||
return data[key]
|
return data[key]
|
||||||
@@ -19,13 +19,13 @@ function Aux_module(name)
|
|||||||
setmetatable(private_interface, {
|
setmetatable(private_interface, {
|
||||||
__newindex = function(_, key, value)
|
__newindex = function(_, key, value)
|
||||||
if not is_declared[key] then
|
if not is_declared[key] then
|
||||||
error('Assignment of undeclared attribute "'..key..'" on private interface of "'..name..'"!', 2)
|
error('Write of undeclared "'..key..'".', 2)
|
||||||
end
|
end
|
||||||
data[key] = value
|
data[key] = value
|
||||||
end,
|
end,
|
||||||
__index = function(_, key)
|
__index = function(_, key)
|
||||||
if not is_declared[key] then
|
if not is_declared[key] then
|
||||||
error('Access of undeclared attribute "'..key..'" on private interface of "'..name..'"!', 2)
|
error('Read of undeclared "'..key..'".', 2)
|
||||||
end
|
end
|
||||||
return data[key]
|
return data[key]
|
||||||
end,
|
end,
|
||||||
@@ -36,26 +36,26 @@ function Aux_module(name)
|
|||||||
setmetatable(public, {
|
setmetatable(public, {
|
||||||
__newindex = function(_, key, value)
|
__newindex = function(_, key, value)
|
||||||
if is_declared[key] then
|
if is_declared[key] then
|
||||||
error('Multiple declarations of "'..key..'" in "'..name..'"!', 2)
|
error('Multiple declarations of "'..key..'".', 2)
|
||||||
end
|
end
|
||||||
data[key] = value
|
data[key] = value
|
||||||
is_public[key] = true
|
is_public[key] = true
|
||||||
is_declared[key] = true
|
is_declared[key] = true
|
||||||
end,
|
end,
|
||||||
__index = function(_, key)
|
__index = function()
|
||||||
error('Illegal read of attribute "'..key..'" on public keyword in "'..name..'"!', 2)
|
error('Unsupported operation.', 2)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
setmetatable(private, {
|
setmetatable(private, {
|
||||||
__newindex = function(_, key, value)
|
__newindex = function(_, key, value)
|
||||||
if is_declared[key] then
|
if is_declared[key] then
|
||||||
error('Multiple declarations of "'..key..'" in "'..name..'"!', 2)
|
error('Multiple declarations of "'..key..'".', 2)
|
||||||
end
|
end
|
||||||
data[key] = value
|
data[key] = value
|
||||||
is_declared[key] = true
|
is_declared[key] = true
|
||||||
end,
|
end,
|
||||||
__index = function(_, key)
|
__index = function()
|
||||||
error('Illegal read of attribute "'..key..'" on private keyword in "'..name..'"!', 2)
|
error('Unsupported operation.', 2)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
return { public_interface, private_interface, public, private }
|
return { public_interface, private_interface, public, private }
|
||||||
|
|||||||
Reference in New Issue
Block a user