big refactoring
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
module 'tooltip'
|
||||
import 'gui' 'lol' 'kek'
|
||||
--import 'gui' 'lol' 'kek'
|
||||
|
||||
_g.aux_tooltip_value = true
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ public.bids_loaded = false
|
||||
public.current_owner_page = nil
|
||||
|
||||
function LOAD()
|
||||
import :_ 'util' 'gui'
|
||||
do
|
||||
local frame = CreateFrame('Frame', gui.name, UIParent)
|
||||
tinsert(UISpecialFrames, 'aux_frame1')
|
||||
|
||||
@@ -31,46 +31,6 @@ public.config = {
|
||||
huge_font_size = 23,
|
||||
}
|
||||
|
||||
do
|
||||
local function index_handler(self, key)
|
||||
self.private.table = self.private.table[key]
|
||||
if getn(self.private.table) == 0 then
|
||||
return self.public
|
||||
else
|
||||
local color = copy(self.private.table)
|
||||
self.private.table = config.colors
|
||||
return self.private.callback(color)
|
||||
end
|
||||
end
|
||||
function color_accessor(callback)
|
||||
return function()
|
||||
return index_function({callback=callback, table=config.colors}, index_handler)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local mt = {
|
||||
__call = function(self, text)
|
||||
local r, g, b, a = unpack(self)
|
||||
if text then
|
||||
return format('|c%02X%02X%02X%02X', a, r*255, g*255, b*255)..text..FONT_COLOR_CODE_CLOSE
|
||||
else
|
||||
return r, g, b, a
|
||||
end
|
||||
end
|
||||
}
|
||||
public.getter.color = color_accessor(function(color)
|
||||
local r, g, b, a = unpack(color)
|
||||
return setmetatable({r/255, g/255, b/255, a}, mt)
|
||||
end)
|
||||
end
|
||||
|
||||
public.getter.inline_color = color_accessor(function(color)
|
||||
local r, g, b, a = unpack(color)
|
||||
return format('|c%02X%02X%02X%02X', a, r, g, b)
|
||||
end)
|
||||
|
||||
do
|
||||
local id = 0
|
||||
function public.getter.name() id = id + 1; return 'aux_frame'..id end
|
||||
@@ -78,13 +38,11 @@ end
|
||||
|
||||
do
|
||||
local menu, structure
|
||||
|
||||
function public.menu(menu_structure)
|
||||
structure = menu_structure
|
||||
menu:SetPoint('BOTTOMLEFT', GetCursorPosition())
|
||||
menu:Show()
|
||||
end
|
||||
|
||||
function initialize_menu()
|
||||
menu = CreateFrame('Frame', name, UIParent, 'UIMenuTemplate')
|
||||
local orig = menu:GetScript 'OnShow'
|
||||
@@ -103,6 +61,48 @@ do
|
||||
end
|
||||
|
||||
function LOAD()
|
||||
import :_ 'util'
|
||||
|
||||
do
|
||||
local function index_handler(self, key)
|
||||
self.private.table = self.private.table[key]
|
||||
if getn(self.private.table) == 0 then
|
||||
return self.public
|
||||
else
|
||||
local color = copy(self.private.table)
|
||||
self.private.table = config.colors
|
||||
return self.private.callback(color)
|
||||
end
|
||||
end
|
||||
function color_accessor(callback)
|
||||
return function()
|
||||
return index_function({callback=callback, table=config.colors}, index_handler)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local mt = {
|
||||
__call = function(self, text)
|
||||
local r, g, b, a = unpack(self)
|
||||
if text then
|
||||
return format('|c%02X%02X%02X%02X', a, r*255, g*255, b*255)..text..FONT_COLOR_CODE_CLOSE
|
||||
else
|
||||
return r, g, b, a
|
||||
end
|
||||
end
|
||||
}
|
||||
public.getter.color = color_accessor(function(color)
|
||||
local r, g, b, a = unpack(color)
|
||||
return setmetatable({r/255, g/255, b/255, a}, mt)
|
||||
end)
|
||||
end
|
||||
|
||||
public.getter.inline_color = color_accessor(function(color)
|
||||
local r, g, b, a = unpack(color)
|
||||
return format('|c%02X%02X%02X%02X', a, r, g, b)
|
||||
end)
|
||||
|
||||
initialize_menu()
|
||||
initialize_dropdown()
|
||||
end
|
||||
|
||||
@@ -1,31 +1,14 @@
|
||||
function INIT()
|
||||
import{['']='core', ['']='util'} -- 'xxx' .foo .bar {x = 'core'} {y='core'} 'kek'
|
||||
import :_ 'core' :_ 'util'
|
||||
end
|
||||
|
||||
-- import 'foo' 'bar' 'baz'
|
||||
import .kek .kuck 'foo' .kick .kock 'bar'
|
||||
|
||||
-- x = record '#'. string 'kek'. number 'lol' . record '~'[]].
|
||||
--mt = {
|
||||
-- __index = function(self, key)
|
||||
--
|
||||
-- tinsert(self, getn(self), key)
|
||||
-- return self
|
||||
-- end,
|
||||
-- __call = function(self, value)
|
||||
-- tinsert(self, getn(self), value);
|
||||
-- tinsert(self, {});
|
||||
-- return self
|
||||
-- end,
|
||||
--}
|
||||
|
||||
module 'core'
|
||||
public.version = '5.0.0'
|
||||
|
||||
do
|
||||
local table_pool, auto_recycle = {}, {}
|
||||
function public.wipe(t) -- like with a cloth or something
|
||||
for k in t do t[k] = nil end; setn(t, 0)
|
||||
for k in t do t[k] = nil end; table.setn(t, 0)
|
||||
end
|
||||
function public.recycle(t)
|
||||
auto_recycle[t] = nil; wipe(t); tinsert(table_pool, t)
|
||||
|
||||
+17
-13
@@ -11,18 +11,23 @@ function immutable_error(key, level) error('Field "%s" is immutable.', level + 1
|
||||
function collision_error(key, level) error('Field "%s" already exists.', level + 1, key) end
|
||||
function void_error(key, level) error('No field "%s".', level + 1, key) end
|
||||
importer_mt = {__metatable=false}
|
||||
function importer_mt.__index(self, key) self._alias = key end
|
||||
function importer_mt.__call(self, name)
|
||||
local state, module, alias = _state[self], _modules[name], self._alias or name; self._alias = nil
|
||||
if not module then error('Import failed. No module "%s".', 2, name) end
|
||||
function importer_mt.__index(self, key) _state[self][self] = key; return self end
|
||||
function importer_mt.__call(self, arg1, arg2)
|
||||
local name, state, module, alias
|
||||
name = arg2 or arg1
|
||||
state, module = _state[self], _modules[name]
|
||||
alias, state[self] = state[self] or name, nil
|
||||
if not module then return end
|
||||
if alias == '_' then
|
||||
for key, modifiers in module.metadata do
|
||||
if state.metadata[key] then error('Import of "%s" failed. Name collision for "%s"', 1, name, key) end
|
||||
state.metadata[key], state.data[key], state.getters[key], state.setters[key] = modifiers, module.data[key], module.getters[key], module.setters[key]
|
||||
if not state.metadata[key] and mask(PUBLIC, modifiers) ~= 0 then
|
||||
state.metadata[key], state.data[key], state.getters[key], state.setters[key] = modifiers, module.data[key], module.getters[key], module.setters[key]
|
||||
end
|
||||
end
|
||||
elseif not state.metadata[alias] or error('Import of "%s" failed. Name collision for "%s"', 1, name, alias) then
|
||||
elseif not state.metadata[alias] then
|
||||
state.metadata[alias], state.data[alias] = PRIVATE, module.interface
|
||||
end
|
||||
return self
|
||||
end
|
||||
function set_property(data, property, value)
|
||||
if property and not data[property] and type(value) == 'function' or declaration_error(2) then
|
||||
@@ -90,20 +95,19 @@ end
|
||||
function INIT() end
|
||||
function module(name)
|
||||
if not _modules[name] then
|
||||
local state, getters, setters, imports, env, interface, declarator, importer
|
||||
imports, env, interface, declarator, importer = {}, setmetatable({}, env_mt), setmetatable({}, interface_mt), setmetatable({}, declarator_mt), setmetatable({}, importer_mt)
|
||||
local state, getters, setters, env, interface, declarator, importer
|
||||
env, interface, declarator, importer = setmetatable({}, env_mt), setmetatable({}, interface_mt), setmetatable({}, declarator_mt), setmetatable({}, importer_mt)
|
||||
getters = {
|
||||
private=function() state.modifiers = PRIVATE return declarator end, public=function() state.modifiers = PUBLIC return declarator end,
|
||||
mutable=function() state.modifiers = MUTABLE return declarator end,
|
||||
getter=function() state.modifiers = PROPERTY+GETTER return declarator end, setter=function() state.modifiers = PROPERTY+SETTER return declarator end}
|
||||
setters = {getter=function(value) set_property(getters, state.property, value) end, setter=function(value) set_property(setters, state.property, value) end}
|
||||
state = {
|
||||
name=name, env=env, interface=interface, imports={}, modifiers=PRIVATE,
|
||||
env=env, interface=interface, modifiers=PRIVATE,
|
||||
metadata = setmetatable({_g=PRIVATE, _m=PRIVATE, _i=PRIVATE, import=PRIVATE, private=PROPERTY+GETTER, public=PROPERTY+GETTER, mutable=PROPERTY+GETTER, getter=PROPERTY+GETTER+SETTER, setter=PROPERTY+GETTER+SETTER}, lock_mt),
|
||||
data = {_g=_g, _m=env, _i=interface, import=importer},
|
||||
getters=getters, setters=setters,
|
||||
data = {_g=_g, _m=env, _i=interface, import=importer}, getters=getters, setters=setters,
|
||||
}
|
||||
_modules[name], _state[env], _state[interface], _state[declarator] = state, state, state, state
|
||||
_modules[name], _state[env], _state[interface], _state[declarator], _state[importer] = state, state, state, state, state
|
||||
setfenv(INIT, env); INIT()
|
||||
end
|
||||
setfenv(2, _modules[name].env)
|
||||
|
||||
@@ -19,7 +19,7 @@ function public.load_dataset()
|
||||
return _g.aux_datasets[dataset_key]
|
||||
end
|
||||
|
||||
--do TODO syntactic sugar
|
||||
--do TODO syntactic sugar record '#' {key='string'} {foo='number'}
|
||||
-- local mt = {
|
||||
-- __unm = function(self, separator)
|
||||
-- self.separator = separator
|
||||
|
||||
Reference in New Issue
Block a user