filter bugfix

This commit is contained in:
Manuel Simon Hirsig
2016-08-11 19:14:17 +02:00
parent 4ee99e43e8
commit dba5dcdf8d
8 changed files with 55 additions and 68 deletions
+19 -41
View File
@@ -1,62 +1,40 @@
local PUBLIC, PRIVATE = 1, 2
local state = {}
local public_interface_mt = {
__newindex = function()
error('Unsupported operation.', 2)
end,
local interface_mt = {
__index = function(self, key)
if state[self].public[key] then
return state[self].data[key]
else
error('Read of undeclared "'..key..'".', 2)
end
end,
}
local private_interface_mt = {
__newindex = function(self, key, value)
if not state[self].declared[key] then
error('Write of undeclared "'..key..'".', 2)
end
state[self].data[key] = value
end,
__index = function(self, key)
if not state[self].declared[key] then
if not state[self].access[state[self].type][key] then
error('Read of undeclared "'..key..'".', 2)
end
return state[self].data[key]
end,
}
local public_declarator_mt = {
__newindex = function(self, key, value)
if state[self].declared[key] then
error('Multiple declarations of "'..key..'".', 2)
if state[self].type == PUBLIC then
error('Unsupported operation.', 2)
elseif not state[self].access[PRIVATE][key] then
error('Write of undeclared "'..key..'".', 2)
end
state[self].data[key] = value
state[self].public[key] = true
state[self].declared[key] = true
end,
}
local declarator_mt = {
__index = function()
error('Unsupported operation.', 2)
end,
}
local private_declarator_mt = {
__newindex = function(self, key, value)
if state[self].declared[key] then
if state[self].access[PRIVATE][key] then
error('Multiple declarations of "'..key..'".', 2)
end
state[self].data[key] = value
state[self].declared[key] = true
end,
__index = function()
error('Unsupported operation.', 2)
state[self].access[PRIVATE][key] = true
state[self].access[state[self].type][key] = true
end,
}
function aux_module()
local new_state = {data={}, public={}, declared={}}
local module = {setmetatable({}, public_interface_mt), setmetatable({}, private_interface_mt), setmetatable({}, public_declarator_mt), setmetatable({}, private_declarator_mt)}
for _, component in module do
state[component] = new_state
end
return module
local data, access = {}, {{}, {}}
local public_state, private_state = {type=PUBLIC, data=data, access=access}, {type=PRIVATE, data=data, access=access}
local public_interface, private_interface = setmetatable({}, interface_mt), setmetatable({}, interface_mt)
local public_declarator, private_declarator = setmetatable({}, declarator_mt), setmetatable({}, declarator_mt)
state[public_interface], state[private_interface] = public_state, private_state
state[public_declarator], state[private_declarator] = public_state, private_state
return public_interface, private_interface, public_declarator, private_declarator
end