bugfix in module library and new class encapsulation

This commit is contained in:
Manuel Simon Hirsig
2016-09-29 23:38:45 +02:00
parent d49ea15c13
commit ae1cf6dc14
2 changed files with 37 additions and 55 deletions
+6 -6
View File
@@ -12,11 +12,11 @@ local function error(msg, ...) return _G.error(format(msg or '', unpack(arg)) ..
local nop, id = function() end, function(v) return v end
local interface_eq = function() return true end
local INTERFACE = setmetatable({}, { __eq=interface_eq })
local interface_lt = function() return true end
local INTERFACE = setmetatable({}, { __lt=interface_lt })
local function proxy_mt(fields, mutators, eq)
return { __metatable=false, __index=fields, __newindex=function(_, k, v) return mutators[k](v) end, __eq=eq }
local function proxy_mt(fields, mutators, lt)
return { __metatable=false, __index=fields, __newindex=function(_, k, v) return mutators[k](v) end, __lt=lt }
end
local _module, _modifiers = {}, {}
@@ -38,7 +38,7 @@ function definition_helper_mt:__newindex(k, v) local module, modifiers = _module
end
local function import(self, interface)
local module = (interface == INTERFACE or error'Import error.') and _module[interface]
local module = (interface < INTERFACE or error'Import error.') and _module[interface]
for _, type in TYPES do
for k, v in module[PUBLIC+type] do
if not self.defined[k .. OPERATION[type]] then
@@ -65,7 +65,7 @@ function global_mt:__index(key)
public_mutators = setmetatable({}, nop_default_mt)
public_fields = setmetatable({}, { __index=function(_, key) return public_accessors[key]() end })
setmetatable(environment, proxy_mt(fields, mutators))
setmetatable(interface, proxy_mt(public_fields, public_mutators, interface_eq))
setmetatable(interface, proxy_mt(public_fields, public_mutators, interface_lt))
module = {
defined = { _E=true, _I=true, _G=true, import=true, error=true, nop=true, id=true, public=true, private=true, ['_=']=true },
[ACCESSOR] = accessors,