Files
aux-addon-ClassicAPI/module.lua
T
Manuel Simon Hirsig 956fabc85e bugfix
2016-08-08 12:03:59 +02:00

62 lines
1.6 KiB
Lua

local __ = {}
local public_interface_mt = {
__newindex = function()
error('Unsupported operation.', 2)
end,
__index = function(self, key)
if __[self].public[key] then
return __[self].attributes[key]
else
error('Read of undeclared "'..key..'".', 2)
end
end,
}
local private_interface_mt = {
__newindex = function(self, key, value)
if not __[self].declared[key] then
error('Write of undeclared "'..key..'".', 2)
end
__[self].attributes[key] = value
end,
__index = function(self, key)
if not __[self].declared[key] then
error('Read of undeclared "'..key..'".', 2)
end
return __[self].attributes[key]
end,
}
local public_declarator_mt = {
__newindex = function(self, key, value)
if __[self].declared[key] then
error('Multiple declarations of "'..key..'".', 2)
end
__[self].attributes[key] = value
__[self].public[key] = true
__[self].declared[key] = true
end,
__index = function()
error('Unsupported operation.', 2)
end,
}
local private_declarator_mt = {
__newindex = function(self, key, value)
if __[self].declared[key] then
error('Multiple declarations of "'..key..'".', 2)
end
__[self].attributes[key] = value
__[self].declared[key] = true
end,
__index = function()
error('Unsupported operation.', 2)
end,
}
function aux_module()
local data = {attributes={}, 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
__[component] = data
end
return module
end