diff --git a/aux-addon.lua b/aux-addon.lua index 964eb9a..3b18120 100644 --- a/aux-addon.lua +++ b/aux-addon.lua @@ -17,50 +17,6 @@ do local modules = {} end end ---do --- local call_method, call_self --- local function generic_call(...) --- return call_method(call_self, unpack(arg)) --- end --- --- local state = setmetatable({}, {__mode='k'}) --- local mt = {__metatable=false} --- function mt:__index(self, key) self=state[self] --- local getter = self.class.getters[key] --- if getter then return getter(self.self) end --- local method = self.class.methods[key] --- if method then --- call_method, call_self = method, self.self --- return generic_call --- end --- end --- function mt:__newindex(self, key, value) self=state[self] --- local setter = self.class.setters[key] --- if setter then return setter(self.self, value) end --- end --- -- function mt:__unm(self) self=state[self] --- -- reclaim() --- -- end --- local function instantiate(methods, getters, setters, init, arg) --- local interface = setmetatable({}, mt) --- local self = {I=interface}; init(self, unpack(arg)) --- state[interface] = {class={methods=methods, getters=getters, setters=setters}, self=self} --- return interface --- end --- function public.class(methods, getters, setters, init) --- return function(arg) instantiate(methods, getters, setters, init, arg) end --- end ---end --- ---do --- local state = {} --- local mt = {__metatable=false, __newindex=error} --- function mt:__index(key) return state[self][key] end --- function public.immutable(t) --- return class({}, t, {}, function() end, {}) --- end ---end - aux 'core' public.version = '5.0.0' @@ -75,11 +31,6 @@ function public.bids_loaded.get() return bids_loaded end local current_owner_page function public.current_owner_page.get() return current_owner_page end ---do --- local mt = {__call=function(self,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20) return self.f(unpack(self)) end} -- TODO --- function public.F.get(arg) arg.f = tremove(arg, 1) return setmetatable(arg, mt) end ---end - local event_frame = CreateFrame('Frame') for event in temp-S('ADDON_LOADED', 'VARIABLES_LOADED', 'PLAYER_LOGIN', 'AUCTION_HOUSE_SHOW', 'AUCTION_HOUSE_CLOSED', 'AUCTION_BIDDER_LIST_UPDATE', 'AUCTION_OWNED_LIST_UPDATE') do event_frame:RegisterEvent(event) diff --git a/core/scan.lua b/core/scan.lua index dc488ed..29c106c 100644 --- a/core/scan.lua +++ b/core/scan.lua @@ -1,6 +1,6 @@ aux 'scan' local info, history = aux.info, aux.history -PAGE_SIZE = 50 +local PAGE_SIZE = 50 do local scan_states = t @@ -38,8 +38,7 @@ do end function private.state.get() - local _, state = next(filter(copy(scan_states), function(state) return state.id == thread_id end)) - return state + for _, state in scan_states do if state.id == thread_id then return state end end end end @@ -47,8 +46,7 @@ function private.query.get() return state.params.queries[state.query_index] end function wait_for_callback(...) temp=arg local send_signal, signal_received = signal() - local suspended - local ret + local suspended, ret local f = tremove(arg, 1) local k = tremove(arg) @@ -60,9 +58,7 @@ function wait_for_callback(...) temp=arg }) f(unpack(arg)) end - if not suspended then - send_signal() - end + if not suspended then send_signal() end return when(signal_received, function() return k(unpack(signal_received())) end) end @@ -92,11 +88,7 @@ function scan() end function process_query() - if query.blizzard_query then - return submit_query() - else - return scan_page() - end + return (query.blizzard_query and submit_query or scan_page)() end function submit_query() @@ -226,9 +218,7 @@ end function owner_data_complete(type) for i = 1, PAGE_SIZE do local auction_info = info.auction(i, type) - if auction_info and not auction_info.owner then - return false - end + if auction_info and not auction_info.owner then return false end end return true end diff --git a/libs/green_t.lua b/libs/green_t.lua index 298505a..1fe2358 100644 --- a/libs/green_t.lua +++ b/libs/green_t.lua @@ -1,8 +1,10 @@ -green_t = module +--green_t = module +setglobal('green_t', green_t and error(nil) or module) local next, setn, type, setmetatable = next, table.setn, type, setmetatable -local wipe, release, acquire, acquire_temp +local wipe, release, acquire, acquire_temp, empty +-- TODO mandatory operation table mandate + comply/fulfill functions local pool, pool_size, overflow_pool, auto_release = {}, 0, setmetatable({}, {__mode='k'}), {} CreateFrame('Frame'):SetScript('OnUpdate', function() @@ -18,7 +20,8 @@ end public.wipe = wipe function release(t) - wipe(t); auto_release[t] = nil + wipe(t) + auto_release[t] = nil if pool_size < 50 then pool_size = pool_size + 1 pool[pool_size] = t @@ -48,17 +51,16 @@ function acquire_temp() local t = acquire(); auto_release[t] = true; return t en public.tt.get = acquire_temp do local mt = {__newindex=nop} - function public.empty.get() return setmetatable(acquire_temp(), mt) end + function empty() return setmetatable(acquire_temp(), mt) end + public.empty.get = empty end -do local f, mt - f = function(_, v) if type(v) == 'table' then auto_release[v] = true end return v end - mt = {__call=f, __sub=f} +do local f = function(_, v) if type(v) == 'table' then auto_release[v] = true end return v end + local mt = {__call=f, __sub=f} public.temp {get=function() return setmetatable(acquire_temp(), mt) end, set=function(t) auto_release[t] = true end} end -do local f, mt - f = function(_, v) if type(v) == 'table' then auto_release[v] = nil end return v end - mt = {__call=f, __sub=f} +do local f = function(_, v) if type(v) == 'table' then auto_release[v] = nil end return v end + local mt = {__call=f, __sub=f} public.perm {get=function() return setmetatable(acquire_temp(), mt) end, set=function(t) auto_release[t] = nil end} end @@ -69,35 +71,67 @@ do local mt, key = {}, nil function public.__(t) mt.__newindex = wipe(t); return setmetatable(acquire_temp(), mt) end end -do local function constructor(type) - local chunk = 'local setn, error = table.setn, error; return function(' - for i = 1, 99 do chunk = chunk .. 'a' .. i..',' end - chunk = chunk .. 'overflow) local t = t' - if type == 'set' then - for i = 1, 99 do chunk = format('%s; if a%d == nil then return t end; t[a%d] = true', chunk, i, i) end - elseif type == 'array' then - chunk = chunk .. '; setn(t, 99); if a1 == nil then return t end; t[1] = a1' - for i = 2, 99 do chunk = format('%s; if a%d == nil then setn(t, %d); return t end; t[%d] = a%d', chunk, i, i - 1, i, i) end - elseif type == 'array0' then - chunk = chunk .. '; setn(t, 99)' - for i = 1, 99 do chunk = format('%s; t[%d] = a%d', chunk, i, i) end - elseif type == 'table' then - for i = 1, 97, 2 do chunk = format('%s; if a%d == nil then return t end; t[a%d] = a%d', chunk, i, i, i + 1) end - end - chunk = chunk .. '; return (overflow == nil or error "Overflow.") and t end' - local f = loadstring(chunk); setfenv(f, M); return f() - end - public(); S, A, A0, T = constructor'set', constructor'array', constructor 'array0', constructor 'table' +local function arg_chunk(k, n) + k = k or 1 + n = n or 100 + local str = k > n and '' or 'a' .. k + for i = k + 1, n do str = str .. ',a' .. i end + return str end -do local chunk = 'return function(i' - for i = 1, 99 do chunk = chunk .. ',a' .. i end - chunk = chunk .. ')' - for i = 1, 99 do - chunk = format('%s if i == %d then return a%i', chunk, i, i) - for j = i + 1, 99 do chunk = chunk .. ',a' .. j end - chunk = chunk .. ' end' +function public.pseudo_vararg_function(body, upvals) + local upval_chunk = '' + for k in upvals or empty() do + upval_chunk = upval_chunk .. format('local %1$s = %1$s;', k) end - chunk = chunk .. ' end' - public.select = loadstring(chunk)() + local f = loadstring(format('%s return function(%s) %s end', upval_chunk, arg_chunk(), body)) or error() + setfenv(f, upvals or empty()) + return (f or error())() +end + +local function insert_chunk(mode) + local body = '' + if mode == 'k' then + for i = 2, 99 do + body = body .. format('if a%1$d == nil then return end; a1[a%1$d] = true;', i) + end + elseif mode == 'v' then + body = body .. 'if a2 == nil then return end; a1[1] = a2;' + for i = 3, 99 do + body = body .. format('if a%1$d == nil then setn(a1, %d); return end; a1[%d] = a%1$d;', i, i-2, i-1) + end + elseif mode == 'v0' then + body = body .. 'setn(a1, 98);' + for i = 2, 99 do + body = body .. format('a1[%d] = a%d;', i-1, i) + end + elseif mode == 'kv' then + for i = 2, 98, 2 do + body = body .. format('if a%1$d == nil then return end; a1[a%1$d] = a%d;', i, i+1) + end + end + return body .. 'if a100 ~= nil then error"Overflow." end;' +end + +do + local function pseudo_literal(mode) + local upvals = {setmetatable=setmetatable, setn=table.setn, error=error} + local mt = { + __newindex = nop, + __call = pseudo_vararg_function(insert_chunk(mode) .. 'setmetatable(a1, nil); return a1', upvals) + } + return function() return setmetatable(acquire_temp(), mt) end + end + public.S.get = pseudo_literal'k' + public.A.get = pseudo_literal'v' + public.A0.get = pseudo_literal'v0' + public.T.get = pseudo_literal'kv' +end + +do + local body = '' + for i = 2, 100 do + body = body .. format('if a1 == %d then return %s end;', i, arg_chunk(i, 100)) + end + public.select = pseudo_vararg_function(body) end \ No newline at end of file diff --git a/util/color.lua b/util/color.lua index 66e6f51..f36d824 100644 --- a/util/color.lua +++ b/util/color.lua @@ -33,7 +33,7 @@ do end function color_accessor(callback) return function() - return index_function({callback=callback, table=COLORS}, index_handler) + return index_function(__(tt) :callback(callback) :table(COLORS), index_handler) end end end @@ -51,7 +51,7 @@ do } public.color.get = color_accessor(function(color) local r, g, b, a = unpack(color) - return setmetatable({r/255, g/255, b/255, a}, mt) + return setmetatable(A(r/255, g/255, b/255, a), mt) end) end diff --git a/util/core.lua b/util/core.lua index 8c0add7..41bb9ec 100644 --- a/util/core.lua +++ b/util/core.lua @@ -1,5 +1,49 @@ aux 'core' +--do +-- local call_method, call_self +-- local function generic_call(...) +-- return call_method(call_self, unpack(arg)) +-- end +-- +-- local state = setmetatable({}, {__mode='k'}) +-- local mt = {__metatable=false} +-- function mt:__index(self, key) self=state[self] +-- local getter = self.class.getters[key] +-- if getter then return getter(self.self) end +-- local method = self.class.methods[key] +-- if method then +-- call_method, call_self = method, self.self +-- return generic_call +-- end +-- end +-- function mt:__newindex(self, key, value) self=state[self] +-- local setter = self.class.setters[key] +-- if setter then return setter(self.self, value) end +-- end +-- -- function mt:__unm(self) self=state[self] +-- -- reclaim() +-- -- end +-- local function instantiate(methods, getters, setters, init, arg) +-- local interface = setmetatable({}, mt) +-- local self = {I=interface}; init(self, unpack(arg)) +-- state[interface] = {class={methods=methods, getters=getters, setters=setters}, self=self} +-- return interface +-- end +-- function public.class(methods, getters, setters, init) +-- return function(arg) instantiate(methods, getters, setters, init, arg) end +-- end +--end +-- +--do +-- local state = {} +-- local mt = {__metatable=false, __newindex=error} +-- function mt:__index(key) return state[self][key] end +-- function public.immutable(t) +-- return class({}, t, {}, function() end, {}) +-- end +--end + public.join = _G.table.concat function public.range(arg1, arg2) @@ -46,7 +90,7 @@ do else -- body = gsub(body, '_([ab])', function(char) return '_' .. end) -- local lambda = loadstring('return function(_1,_2,_3,_4,_5,_6,_7,_8,_9)' .. body .. ' end') - local lambda = loadstring('return ' .. body) or loadstring(body) + local lambda = loadstring('return ' .. body) or loadstring(body) or error() setfenv(lambda, getfenv(2)) return lambda end