This commit is contained in:
Manuel Simon Hirsig
2016-09-10 13:35:30 +02:00
parent 9bf8574bed
commit cb3b336625
6 changed files with 40 additions and 41 deletions
-1
View File
@@ -13,7 +13,6 @@ do local modules = {}
end)()
end
modules[name].import (modules.core._I)
modules[name].private()
setfenv(2, modules[name])
end
end
+20 -24
View File
@@ -1,9 +1,12 @@
if getmetatable(getfenv(0)) == false then return end
local tinsert, tremove, getn, setn, strfind, type, setmetatable, setfenv, _G = tinsert, tremove, getn, table.setn, strfind, type, setmetatable, setfenv, getfenv(0)
local PUBLIC, FIELD, ACCESSOR, MUTATOR = 1, 2, 4, 6
local PRIVATE, PUBLIC, FIELD, ACCESSOR, MUTATOR = 0, 1, 2, 4, 6
local TYPES = { FIELD, ACCESSOR, MUTATOR }
local READ, WRITE = '', '='
local OPERATION = { [FIELD]=READ, [ACCESSOR]=READ, [MUTATOR]=WRITE }
local ACCESS = { private=PRIVATE, public=PUBLIC }
local META = { get=ACCESSOR, set=MUTATOR }
local function error(msg, ...) return _G.error(format(msg or '', unpack(arg)) .. '\n' .. debugstack(), 0) end
@@ -23,30 +26,23 @@ function definition_helper_mt:__index(k)
tinsert(_modifiers[self], k)
return self
end
do
local PUBLIC, META = { public=PUBLIC, private=0 }, { get=ACCESSOR, set=MUTATOR }
function definition_helper_mt:__newindex(k, v) local module, modifiers = _module[self], _modifiers[self]
local public = PUBLIC[tremove(modifiers, 1)] or error('Invalid definition.')
local name = META[k] and (tremove(modifiers) or error('Invalid definition.')) or k
if type(name) ~= 'string' or not strfind(name, '^[_%a][_%w]*') then error('Invalid definition.') end
local type = META[k] or FIELD
module.defined[name..OPERATION[type]] = module.defined[name..OPERATION[type]] and error('"%s" already exists.', name) or true
for i = getn(modifiers), 1, -1 do v = module[FIELD][modifiers[i]](v) end
module[type][name], module[public+type][name] = v, v
setn(modifiers, 0)
end
function definition_helper_mt:__newindex(k, v) local module, modifiers = _module[self], _modifiers[self]
local access = ACCESS[tremove(modifiers, 1)] or error('Invalid definition.')
local name = META[k] and (tremove(modifiers) or error('Invalid definition.')) or k
if type(name) ~= 'string' or not strfind(name, '^[_%a][_%w]*') then error('Invalid definition.') end
local type = META[k] or FIELD
module.defined[name..OPERATION[type]] = module.defined[name..OPERATION[type]] and error('"%s" already exists.', name) or true
for i = getn(modifiers), 1, -1 do v = module[FIELD][modifiers[i]](v) end
module[type][name], module[access+type][name] = v, v
setn(modifiers, 0)
end
local import
do
local TYPES = { FIELD, ACCESSOR, MUTATOR }
function import(self, 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
self.defined[k..OPERATION[type]], self[type][k] = true, v
end
local function import(self, 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
self.defined[k..OPERATION[type]], self[type][k] = true, v
end
end
end
@@ -60,7 +56,7 @@ function global_mt:__index(key)
local module, environment, interface, definition_helper, accessors, mutators, fields, public_accessors, public_mutators, public_fields
environment, interface, definition_helper = {}, {}, setmetatable({}, definition_helper_mt)
accessors = { private=function() return definition_helper.private end, public=function() return definition_helper.public end }
mutators = setmetatable({}, { __index=function(_, k) return function(v) if v == interface and (_G[k] == nil or error(nil)) then _G[k] = v end end end})
mutators = setmetatable({}, { __index=function(_, k) return function(v) if v == interface and (_G[k] == nil or _G.error(nil)) then _G[k] = v else definition_helper.private[k] = v end end end})
fields = setmetatable(
{ _E=environment, _I=interface, _G=_G, import=function(interface) import(module, interface) end, error=error, nop=nop, id=id },
{ __index=function(_, key) local accessor = accessors[key]; if accessor then return accessor() else return _G[key] end end }
+8 -4
View File
@@ -38,12 +38,16 @@ function refresh_button_click()
refresh = true
end
do local item
selected_item {get=function() return item end, set=function(v) item = v end}
do
local item
function private.selected_item.get() return item end
function private.selected_item.set(v) item = v end
end
do local c = 0
refresh {get=function() return c end, set=function(v) c = v end}
do
local c = 0
function private.refresh.get() return c end
function private.refresh.set(v) c = v end
end
function LOAD()
+4 -2
View File
@@ -4,11 +4,13 @@ _G.aux_auto_buy_filter = ''
do
local id = 0
search_scan_id { get=function() return id end, set=function(v) id = v end }
function private.search_scan_id.get() return id end
function private.search_scan_id.set(v) id = v end
end
do
local validator
auto_buy_validator { get=function() return validator end, set=function(v) validator = v end }
function private.auto_buy_validator.get() return validator end
function private.auto_buy_validator.set(v) validator = v end
end
do
+3 -5
View File
@@ -1,10 +1,8 @@
aux 'money'
public()
GOLD_TEXT = '|cffffd70ag|r'
SILVER_TEXT = '|cffc7c7cfs|r'
COPPER_TEXT = '|cffeda55fc|r'
private()
public.GOLD_TEXT = '|cffffd70ag|r'
public.SILVER_TEXT = '|cffc7c7cfs|r'
public.COPPER_TEXT = '|cffeda55fc|r'
COPPER_PER_GOLD = 10000
COPPER_PER_SILVER = 100
+5 -5
View File
@@ -1,10 +1,10 @@
aux 'sorting'
public()
public.EQ = 0
public.LT = 1
public.GT = 2
LT, EQ, GT = t, t, t
function compare(a, b, desc)
function public.compare(a, b, desc)
if a < b then
return desc and GT or LT
elseif a > b then
@@ -14,7 +14,7 @@ function compare(a, b, desc)
end
end
function multi_lt(xs, ys)
function public.multi_lt(xs, ys)
local i = 1
while true do
if xs[i] and ys[i] and xs[i] ~= ys[i] then