diff --git a/control.lua b/control.lua index 90e5355..dc51f42 100644 --- a/control.lua +++ b/control.lua @@ -1,4 +1,4 @@ -module 'core' +aux 'core' event_frame = CreateFrame 'Frame' mutable.listeners = t diff --git a/core/cache.lua b/core/cache.lua index 138b116..dd516fc 100644 --- a/core/cache.lua +++ b/core/cache.lua @@ -1,4 +1,4 @@ -module 'cache' import 'info' +aux 'cache' import 'info' MIN_ITEM_ID = 1 MAX_ITEM_ID = 30000 diff --git a/core/disenchant.lua b/core/disenchant.lua index 6d9e2cd..fd8de2c 100644 --- a/core/disenchant.lua +++ b/core/disenchant.lua @@ -1,4 +1,4 @@ -module 'disenchant' +aux 'disenchant' UNCOMMON, RARE, EPIC = 2, 3, 4 diff --git a/core/history.lua b/core/history.lua index 751c666..a78bf88 100644 --- a/core/history.lua +++ b/core/history.lua @@ -1,4 +1,4 @@ -module 'history' import 'persistence' +aux 'history' import 'persistence' --local history_schema = tuple('#') -- :next_push 'number' diff --git a/core/post.lua b/core/post.lua index 423d905..ab2d6b6 100644 --- a/core/post.lua +++ b/core/post.lua @@ -1,4 +1,4 @@ -module 'post' +aux 'post' state = nil diff --git a/core/scan.lua b/core/scan.lua index 26ad141..472f8c2 100644 --- a/core/scan.lua +++ b/core/scan.lua @@ -1,4 +1,4 @@ -module 'scan' import 'info' +aux 'scan' import 'info' function LOAD() import 'history' diff --git a/core/slash.lua b/core/slash.lua index c004485..a403d13 100644 --- a/core/slash.lua +++ b/core/slash.lua @@ -1,4 +1,4 @@ -module 'slash' import 'persistence' +aux 'slash' import 'persistence' _G.SLASH_AUX1 = '/aux' function _G.SlashCmdList.AUX(command) diff --git a/core/stack.lua b/core/stack.lua index eca08d4..63a4103 100644 --- a/core/stack.lua +++ b/core/stack.lua @@ -1,4 +1,4 @@ -module 'stack' import 'info' +aux 'stack' import 'info' state = nil diff --git a/core/tooltip.lua b/core/tooltip.lua index a1b886d..01d81b6 100644 --- a/core/tooltip.lua +++ b/core/tooltip.lua @@ -1,4 +1,4 @@ -module 'tooltip' import 'info' 'disenchant' 'cache' 'money' 'history' +aux 'tooltip' import 'info' 'disenchant' 'cache' 'money' 'history' _G.aux_tooltip_value = true diff --git a/frame.lua b/frame.lua index 0c4ec6d..e100008 100644 --- a/frame.lua +++ b/frame.lua @@ -1,4 +1,4 @@ -module 'core' import 'gui' +aux 'core' import 'gui' function LOAD() for _, info in tab_info do tabs:create_tab(info.name) end diff --git a/gui/auction_listing.lua b/gui/auction_listing.lua index 5a26474..8866e91 100644 --- a/gui/auction_listing.lua +++ b/gui/auction_listing.lua @@ -1,4 +1,4 @@ -module 'auction_listing' import 'gui' 'sorting' 'history' 'money' 'info' +aux 'auction_listing' import 'gui' 'sorting' 'history' 'money' 'info' _G.aux_price_per_unit = false diff --git a/gui/core.lua b/gui/core.lua index 63d34d5..efa4175 100644 --- a/gui/core.lua +++ b/gui/core.lua @@ -1,4 +1,4 @@ -module 'gui' +aux 'gui' function LOAD() do diff --git a/gui/item_listing.lua b/gui/item_listing.lua index 61e2f64..9dbf06f 100644 --- a/gui/item_listing.lua +++ b/gui/item_listing.lua @@ -1,4 +1,4 @@ -module 'item_listing' import 'gui' 'info' +aux 'item_listing' import 'gui' 'info' local ROW_HEIGHT = 39 diff --git a/gui/listing.lua b/gui/listing.lua index f501d50..b51ad86 100644 --- a/gui/listing.lua +++ b/gui/listing.lua @@ -1,4 +1,4 @@ -module 'listing' import 'gui' +aux 'listing' import 'gui' local ST_COUNT = 0 diff --git a/module.lua b/module.lua index 4f9b70c..370cc30 100644 --- a/module.lua +++ b/module.lua @@ -2,41 +2,45 @@ local type, setmetatable, setfenv, unpack, next, mask, combine, pcall, _G = type local error, import_error, declaration_error, collision_error, mutability_error local pass, env_mt, interface_mt, declarator_mt, importer_mt -aux:module 'kek' - -aux.module 'kek' - local NULL, PRIVATE, PUBLIC, MUTABLE, DYNAMIC, PROPERTY = 0, 1, 2, 4, 8, 16 -local state, env_state = {}, {}, {} +local INDEX, NEWINDEX, CALL = 1, 2, 4 +local _state, _env_state = {}, {} function error(message, ...) return _G.error(format(message or '', unpack(arg))..'\n'..debugstack(), 0) end -import_error = function() error 'Invalid import statement.' end +import_error = function() error 'Invalid imports.' end declaration_error = function() error 'Invalid declaration.' end collision_error = function(key) error('Field "%s" already exists.', key) end mutability_error = function(key) error('Field "%s" is immutable.', key) end pass = function() end ---function intercept_index(env, callback, state) --- ---end --- ---function intercept_newindex(env, callback, state) --- ---end --- ---function intercept_call(env, callback, state) --- ---end --- ---generic_function_mt = {__metatable=false} ---function generic_function_mt:__call(...) --- self. ---end - - +do + local mt = {__metatable=false} + do + local MODIFIER = {private=PRIVATE, public=PUBLIC, mutable=MUTABLE, dynamic=DYNAMIC, property=PROPERTY} + local COMPATIBLE = {private=MUTABLE+PROPERTY, public=DYNAMIC+PROPERTY, mutable=PRIVATE, dynamic=PUBLIC+PROPERTY, property=PUBLIC} + function mt:__call(state, type, key, value) + if type == INDEX then + if state.property then declaration_error() end + local modifiers, modifier, compatible = state.modifiers, MODIFIER[key], COMPATIBLE[key] + if not modifier then modifier, compatible, state.property = PROPERTY, PUBLIC, key end + if mask(compatible, modifiers) ~= modifiers then declaration_error() end + state.properties = modifiers + modifier + return true + elseif type == NEWINDEX then + local property, modifiers; property, modifiers, state.modifiers = state.property, state.modifiers, PRIVATE + if property then key, value, state.property = property, {[key]=value}, nil end + declare(state.module, modifiers, key, value) + elseif type == CALL then + local property, modifiers; property, modifiers, state.modifiers = state.property, state.modifiers, PRIVATE + if property then state.property = nil; declare(state, modifiers, property, value) else state.modifiers = modifiers end + end + end + end + local declarator = setmetatable({}, declarator_mt) +end do local function dynamize(f) @@ -62,34 +66,9 @@ do end end - declarator_mt = {__metatable=false} - do - local MODIFIER = {private=PRIVATE, public=PUBLIC, mutable=MUTABLE, dynamic=DYNAMIC, property=PROPERTY} - local COMPATIBLE = {private=MUTABLE+PROPERTY, public=DYNAMIC+PROPERTY, mutable=PRIVATE, dynamic=PUBLIC+PROPERTY, property=PUBLIC} - function declarator_mt:__index(key, state) state=_state[self] - if state.property then declaration_error() end - local modifiers, modifier, compatible = state[self], MODIFIER[key], COMPATIBLE[key] - if not modifier then modifier, compatible, state.property = PROPERTY, PUBLIC, key end - if mask(compatible, modifiers) ~= modifiers then declaration_error() end - state[self] = modifiers + modifier - return self - end - end - do - function declarator_mt:__newindex(key, value, state) state=_state[self] - local property, modifiers; property, modifiers, state[self] = state.property, state[self], PRIVATE - if property then key, value, state.property = property, {[key]=value}, nil end - declare(state, modifiers, key, value) - end - function declarator_mt:__call(value, state) state=_state[self] - local property, modifiers; property, modifiers, state[self] = state.property, state[self], PRIVATE - if property then state.property = nil; declare(state, modifiers, property, value) else state.modifiers = modifiers end - end - end - env_mt = {__metatable=false} function env_mt:__index(key, state) state=_state[self] - if state.intercept_index(key) then return self end + if state.intercept(INDEX, key) then return self end if mask(PROPERTY, state.metadata[key] or 0) ~= 0 then return state.getters[key]() else @@ -98,7 +77,7 @@ do end end function env_mt:__newindex(key, value, state) state=_state[self] - if state.intercept_newindex(key, value) then return end + if state.intercept(NEWINDEX, key, value) then return end local modifiers = state.metadata[key] if modifiers then if mask(PROPERTY, modifiers) ~= 0 then @@ -111,7 +90,7 @@ do end end function env_mt:__call(key, ...) - _state[self].intercept_call(key, arg); return self + _state[self].intercept(CALL, key, arg); return self end end @@ -134,69 +113,33 @@ function interface_mt:__newindex(key, value, state) state=_state[self] end end end -local metadata_mt = { - __index = function() return 0 end -} -local function import(state, interface) - local module = _state[interface] or import_error() -end +metadata_mt = {__index=function() return 0 end} +property_mt = {__index=function() return pass end} local function create_module(...) local env_state, env, interface = setmetatable({}, env_mt), setmetatable({}, interface_mt) local state = { - env = env, - interface = interface, - modifiers = PRIVATE, - metadata = {_=PROPERTY, _G=PRIVATE, M=PRIVATE, error=PRIVATE, import=PRIVATE, private=PROPERTY, public=PROPERTY, mutable=PROPERTY, dynamic=PROPERTY, property=PROPERTY}, + metadata = {_=PROPERTY, _G=PRIVATE, M=PRIVATE, error=PRIVATE, private=PROPERTY, public=PROPERTY, mutable=PROPERTY, dynamic=PROPERTY, property=PROPERTY}, fields = {_G=_G, M=env, error=error}, - getters = { - _ = pass, + getters = setmetatable({ private = function() state[declarator] = PRIVATE; return declarator end, public = function() state[declarator] = PUBLIC; return declarator end, mutable = function() state[declarator] = MUTABLE; return declarator end, dynamic = function() state[declarator] = DYNAMIC; return declarator end, property = function() state[declarator] = PROPERTY; return declarator end, - }, - setters = {_=pass, private=pass, public=pass, mutable=pass, dynamic=pass, property=pass}, + }, property_mt), + setters = setmetatable({}, property_mt), } - state[env], state[interface] = state, state - for i=1,arg.n do local module = state[arg[i] or import_error()] or import_error() for k, v in module.metadata do - if mask(PUBLIC, v) ~= 0 then - + if mask(PUBLIC, v) ~= 0 and (not state.metadata[k] or import_error()) then + state.metadata[k], state.data[k], state.getters[k], state.setters[k] = v, module.data[k], module.getters[k], module.setters[k] end end end - + state[env], state[interface] = state, state return env, interface - -- -- TODO create_env (per module call) --- setfenv(2, _modules[name].env) -end - -do - local modules = {} - function _G.module(name) - local module = modules[name] - if not module then - local submodules = {} - module = create_module() --- local submodules = create_module() - module.metadata[name] = submodules.interface - module.metadata.module = PUBLIC - function module.fields.module(name) - local submodule = submodules[name] - if not submodule then - submodule = create_module() - submodules[name] = submodule - end - setfenv(2, submodule.env) - end - modules[name], _G[name] = module, module - end - setfenv(2, module.env) - end end \ No newline at end of file diff --git a/tabs/auctions/core.lua b/tabs/auctions/core.lua index f2a43f9..b0cbbc5 100644 --- a/tabs/auctions/core.lua +++ b/tabs/auctions/core.lua @@ -1,4 +1,4 @@ -module 'auctions_tab' import 'scan' +aux 'auctions_tab' import 'scan' auction_records = {} diff --git a/tabs/auctions/frame.lua b/tabs/auctions/frame.lua index 3e77910..7d37b7e 100644 --- a/tabs/auctions/frame.lua +++ b/tabs/auctions/frame.lua @@ -1,4 +1,4 @@ -module 'auctions_tab' import 'gui' 'auction_listing' +aux 'auctions_tab' import 'gui' 'auction_listing' function create_frames() frame = CreateFrame('Frame', nil, aux_frame) diff --git a/tabs/bids/core.lua b/tabs/bids/core.lua index baadd20..19e6ae5 100644 --- a/tabs/bids/core.lua +++ b/tabs/bids/core.lua @@ -1,4 +1,4 @@ -module 'bids_tab' import 'scan' +aux 'bids_tab' import 'scan' auction_records = {} diff --git a/tabs/bids/frame.lua b/tabs/bids/frame.lua index 53d4266..50eb7b8 100644 --- a/tabs/bids/frame.lua +++ b/tabs/bids/frame.lua @@ -1,4 +1,4 @@ -module 'bids_tab' import 'gui' 'auction_listing' +aux 'bids_tab' import 'gui' 'auction_listing' function create_frames() frame = CreateFrame('Frame', nil, aux_frame) diff --git a/tabs/post/core.lua b/tabs/post/core.lua index cf9cca2..18fd145 100644 --- a/tabs/post/core.lua +++ b/tabs/post/core.lua @@ -1,4 +1,4 @@ -module 'post_tab' import 'scan' 'scan_util' 'post' 'history' 'info' 'persistence' 'item_listing' :al 'auction_listing' 'sorting' +aux 'post_tab' import 'scan' 'scan_util' 'post' 'history' 'info' 'persistence' 'item_listing' :al 'auction_listing' 'sorting' local DURATION_4, DURATION_8, DURATION_24 = 120, 480, 1440 local settings_schema = {'record', '#', {stack_size='number'}, {duration='number'}, {start_price='number'}, {buyout_price='number'}, {hidden='boolean'}} diff --git a/tabs/post/frame.lua b/tabs/post/frame.lua index 25b98ac..840c85f 100644 --- a/tabs/post/frame.lua +++ b/tabs/post/frame.lua @@ -1,4 +1,4 @@ -module 'post_tab' import [''] 'core' 'gui' 'listing' 'item_listing' 'money' 'search_tab' +aux 'post_tab' import [''] 'core' 'gui' 'listing' 'item_listing' 'money' 'search_tab' function create_frames() frame = CreateFrame('Frame', nil, aux_frame) diff --git a/tabs/search/core.lua b/tabs/search/core.lua index 86eeda2..839f46f 100644 --- a/tabs/search/core.lua +++ b/tabs/search/core.lua @@ -1,4 +1,4 @@ -module 'search_tab' import 'scan' 'scan_util' +aux 'search_tab' import 'scan' 'scan_util' StaticPopupDialogs['AUX_SEARCH_TABLE_FULL'] = { text = 'Table full!\nFurther results from this search will still be processed but no longer displayed in the table.', diff --git a/tabs/search/filter.lua b/tabs/search/filter.lua index 619ec87..b429896 100644 --- a/tabs/search/filter.lua +++ b/tabs/search/filter.lua @@ -1,4 +1,4 @@ -module 'search_tab' import 'filter_util' +aux 'search_tab' import 'filter_util' function valid_level(str) local level = tonumber(str) diff --git a/tabs/search/frame.lua b/tabs/search/frame.lua index 52d752e..b5790e0 100644 --- a/tabs/search/frame.lua +++ b/tabs/search/frame.lua @@ -1,4 +1,4 @@ -module 'search_tab' import 'gui' [''] 'core' 'completion' 'listing' 'auction_listing' 'filter_util' +aux 'search_tab' import 'gui' [''] 'core' 'completion' 'listing' 'auction_listing' 'filter_util' FILTER_SPACING = 28.5 diff --git a/tabs/search/results.lua b/tabs/search/results.lua index f89530f..04e657e 100644 --- a/tabs/search/results.lua +++ b/tabs/search/results.lua @@ -1,4 +1,4 @@ -module 'search_tab' import 'info' +aux 'search_tab' import 'info' _G.aux_auto_buy_filter = '' diff --git a/tabs/search/saved.lua b/tabs/search/saved.lua index e2704c8..b5dd2bf 100644 --- a/tabs/search/saved.lua +++ b/tabs/search/saved.lua @@ -1,4 +1,4 @@ -module 'search_tab' +aux 'search_tab' _G.aux_favorite_searches = {} _G.aux_recent_searches = {} diff --git a/util/color.lua b/util/color.lua index ae68ea0..c8c8a55 100644 --- a/util/color.lua +++ b/util/color.lua @@ -1,4 +1,4 @@ -module 'core' +aux 'core' COLORS = { text = {enabled = {255, 254, 250, 1}, disabled = {147, 151, 139, 1}}, diff --git a/util/completion.lua b/util/completion.lua index e80687b..37f9eda 100644 --- a/util/completion.lua +++ b/util/completion.lua @@ -1,4 +1,4 @@ -module 'completion' import 'filter_util' +aux 'completion' import 'filter_util' function public:complete_filter() if IsControlKeyDown() then -- TODO problem is ctrl-v, maybe find a better solution diff --git a/util/core.lua b/util/core.lua index 4fd55bc..7300e4b 100644 --- a/util/core.lua +++ b/util/core.lua @@ -1,4 +1,4 @@ -module 'core' +aux 'core' public.join = _G.table.concat diff --git a/util/filter.lua b/util/filter.lua index 7432391..d131e49 100644 --- a/util/filter.lua +++ b/util/filter.lua @@ -1,4 +1,4 @@ -module 'filter_util' import 'info' +aux 'filter_util' import 'info' function LOAD() import 'cache' diff --git a/util/info.lua b/util/info.lua index 6741d80..dc2e016 100644 --- a/util/info.lua +++ b/util/info.lua @@ -1,4 +1,4 @@ -module 'info' +aux 'info' CreateFrame('GameTooltip', 'AuxTooltip', nil, 'GameTooltipTemplate') AuxTooltip:SetScript('OnTooltipAddMoney', function() diff --git a/util/money.lua b/util/money.lua index 4b027bc..0ebb5f9 100644 --- a/util/money.lua +++ b/util/money.lua @@ -1,4 +1,4 @@ -module 'money' +aux 'money' GOLD_TEXT = '|cffffd70ag|r' SILVER_TEXT = '|cffc7c7cfs|r' diff --git a/util/persistence.lua b/util/persistence.lua index d611e15..dda4f31 100644 --- a/util/persistence.lua +++ b/util/persistence.lua @@ -1,4 +1,4 @@ -module 'persistence' +aux 'persistence' _G.aux_datasets = t diff --git a/util/scan.lua b/util/scan.lua index d26a3e4..dd6ec96 100644 --- a/util/scan.lua +++ b/util/scan.lua @@ -1,4 +1,4 @@ -module 'scan_util' import 'info' +aux 'scan_util' import 'info' function LOAD() import 'filter_util' 'scan' diff --git a/util/sort.lua b/util/sort.lua index 01d7867..ce72404 100644 --- a/util/sort.lua +++ b/util/sort.lua @@ -1,4 +1,4 @@ -module 'sorting' +aux 'sorting' public()