refactoring
This commit is contained in:
+12
-13
@@ -11,11 +11,11 @@ function importer_mt.__index(self, key)
|
|||||||
if type(key) ~= 'string' then import_error() end
|
if type(key) ~= 'string' then import_error() end
|
||||||
_state[self][self] = key; return self
|
_state[self][self] = key; return self
|
||||||
end
|
end
|
||||||
function importer_mt.__call(self, arg1, arg2)
|
function importer_mt.__call(self, arg1, arg2, state) state=_state[self]
|
||||||
local name, state, module, alias
|
local name, module, alias
|
||||||
name = arg2 or arg1
|
name = arg2 or arg1
|
||||||
if type(name) ~= 'string' then import_error() end
|
if type(name) ~= 'string' then import_error() end
|
||||||
state, module = _state[self], _modules[name]
|
module = _modules[name]
|
||||||
alias, state[self] = state[self] or name, nil
|
alias, state[self] = state[self] or name, nil
|
||||||
if module then
|
if module then
|
||||||
if alias == '' then
|
if alias == '' then
|
||||||
@@ -34,13 +34,12 @@ declarator_mt = {__metatable=false}
|
|||||||
do
|
do
|
||||||
local MODIFIER = {private=PRIVATE, public=PUBLIC, mutable=MUTABLE}
|
local MODIFIER = {private=PRIVATE, public=PUBLIC, mutable=MUTABLE}
|
||||||
local COMPATIBLE = {private=MUTABLE+PROPERTY, public=PROPERTY, mutable=PRIVATE}
|
local COMPATIBLE = {private=MUTABLE+PROPERTY, public=PROPERTY, mutable=PRIVATE}
|
||||||
function declarator_mt.__index(self, key)
|
function declarator_mt.__index(self, key, state) state=_state[self]
|
||||||
local state, modifiers, modifier, compatible; state = _state[self]
|
|
||||||
if state.property then declaration_error() end
|
if state.property then declaration_error() end
|
||||||
modifiers, modifier, compatible = state.modifiers, MODIFIER[key], COMPATIBLE[key]
|
local modifiers, modifier, compatible = state[self], MODIFIER[key], COMPATIBLE[key]
|
||||||
if not modifier then modifier, compatible, state.property = PROPERTY, PRIVATE+PUBLIC, key end
|
if not modifier then modifier, compatible, state.property = PROPERTY, PRIVATE+PUBLIC, key end
|
||||||
if mask(compatible, modifiers) ~= modifiers then declaration_error() end
|
if mask(compatible, modifiers) ~= modifiers then declaration_error() end
|
||||||
state.modifiers = modifiers + modifier
|
state[self] = modifiers + modifier
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -61,13 +60,13 @@ do
|
|||||||
self.data[key] = value
|
self.data[key] = value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
declarator_mt.__newindex = function(self, key, value) self=_state[self]
|
declarator_mt.__newindex = function(self, key, value, state) state=_state[self]
|
||||||
local property, modifiers; property, modifiers, self[self] = self.property, self[self], PRIVATE
|
local property, modifiers; property, modifiers, state[self] = state.property, state[self], PRIVATE
|
||||||
if property then self.property = nil; declare(self, modifiers, property, {key=value}) end
|
if property then state.property = nil; declare(state, modifiers, property, {[key]=value}) end
|
||||||
end
|
end
|
||||||
function declarator_mt.__call(self, value) self=_state[self]
|
function declarator_mt.__call(self, value, state) state=_state[self]
|
||||||
local property, modifiers; property, modifiers, self[self] = self.property, self[self], PRIVATE
|
local property, modifiers; property, modifiers, state[self] = state.property, state[self], PRIVATE
|
||||||
if property then self.property = nil; declare(self, modifiers, property, value) else self.modifiers = modifiers end
|
if property then state.property = nil; declare(state, modifiers, property, value) else state.modifiers = modifiers end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
do
|
do
|
||||||
|
|||||||
Reference in New Issue
Block a user