refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-07-31 12:25:57 +02:00
parent af15a2defa
commit be200921ef
2 changed files with 14 additions and 14 deletions
+12 -12
View File
@@ -1,12 +1,12 @@
function Aux_module(name)
function Aux_module()
local data, is_public, is_declared, public_interface, private_interface, public, private = {}, {}, {}, {}, {}, {}, {}
setmetatable(public_interface, {
__newindex = function(_, key)
error('Illegal write of attribute "'..key..'" on public interface of "'..name..'"!', 2)
__newindex = function()
error('Unsupported operation.', 2)
end,
__index = function(_, key)
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
if is_public[key] then
return data[key]
@@ -19,13 +19,13 @@ function Aux_module(name)
setmetatable(private_interface, {
__newindex = function(_, key, value)
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
data[key] = value
end,
__index = function(_, key)
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
return data[key]
end,
@@ -36,26 +36,26 @@ function Aux_module(name)
setmetatable(public, {
__newindex = function(_, key, value)
if is_declared[key] then
error('Multiple declarations of "'..key..'" in "'..name..'"!', 2)
error('Multiple declarations of "'..key..'".', 2)
end
data[key] = value
is_public[key] = true
is_declared[key] = true
end,
__index = function(_, key)
error('Illegal read of attribute "'..key..'" on public keyword in "'..name..'"!', 2)
__index = function()
error('Unsupported operation.', 2)
end,
})
setmetatable(private, {
__newindex = function(_, key, value)
if is_declared[key] then
error('Multiple declarations of "'..key..'" in "'..name..'"!', 2)
error('Multiple declarations of "'..key..'".', 2)
end
data[key] = value
is_declared[key] = true
end,
__index = function(_, key)
error('Illegal read of attribute "'..key..'" on private keyword in "'..name..'"!', 2)
__index = function()
error('Unsupported operation.', 2)
end,
})
return { public_interface, private_interface, public, private }