aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--ClientHamr/GuiLua/skang.lua77
1 files changed, 50 insertions, 27 deletions
diff --git a/ClientHamr/GuiLua/skang.lua b/ClientHamr/GuiLua/skang.lua
index 80abdfb..3825f47 100644
--- a/ClientHamr/GuiLua/skang.lua
+++ b/ClientHamr/GuiLua/skang.lua
@@ -190,42 +190,65 @@ ThingSpace.parameters = {}
190ThingSpace.things = {} 190ThingSpace.things = {}
191ThingSpace.widgets = {} 191ThingSpace.widgets = {}
192 192
193Thing = 193Thing =
194{ 194{
195 __index = function (table, key) 195 __index = function (table, key)
196 -- This only works for keys that don't exist. By definition a value of nil means it doesn't exist. 196 -- This only works for keys that don't exist. By definition a value of nil means it doesn't exist.
197 -- TODO - Should allow looking up via alias as well somehow. 197 local thing = ThingSpace.things[key]
198 -- Very slow, but uses less memory. Would only need to be done if an alias is used, and they are mostly for shortcuts. 198
199 return ThingSpace.things[key].default 199 -- First see if this is a Thing.
200 if thing then return thing.default end
201
202 -- Look up aliases. Very slow, but uses less memory. Would only need to be done if an alias is used, and they are mostly for shortcuts.
203 for k, thing in pairs(ThingSpace.things) do
204 for i, v in ipairs(thing.names) do
205 if v == key then return table[ thing.names[1] ] end
206 end
207 end
208
209 -- If all else fails, return nil.
210 return nil
200 end, 211 end,
201 212
202 __newindex = function (table, key, value) 213 __newindex = function (table, key, value)
203 local thing = ThingSpace.things[key] 214 local thing = ThingSpace.things[key]
204 215
205 if 'function' == type(value) then 216 -- NOTE - This is really slow when setting stuff that is in the module that is NOT a Thing. Wont scale well.
206 thing.default = nil 217 if not thing then
207 thing.func = value 218 -- Look up aliases. Very slow, but uses less memory. Would only need to be done if an alias is used, and they are mostly for shortcuts.
208 ThingSpace.commands[key] = thing 219 for k, thng in pairs(ThingSpace.things) do
209 ThingSpace.parameters[key] = nil 220 for i, v in ipairs(thng.names) do
210 setmetatable(thing, {__call = Thing._call}) 221 if v == key then thing = thng; break end
211 local types = '' 222 end
212 for i, v in ipairs(thing.types) do
213 if 1 ~= i then types = types .. v .. ', ' end
214 end 223 end
215 print(thing.module._NAME .. '.' .. key .. '(' .. types .. ') -> ' .. thing.help) 224 end
216 else 225
217 if ThingSpace.parameters[key] ~= thing then 226 -- NOTE - A Thing is either a command or a parameter, not both.
218 ThingSpace.commands[key] = nil 227 if thing then
219 ThingSpace.parameters[key] = thing 228 if 'function' == type(value) then
220 setmetatable(thing, nil) 229 thing.default = nil
230 thing.func = value
231 ThingSpace.commands[key] = thing
232 ThingSpace.parameters[key] = nil
233 setmetatable(thing, {__call = Thing._call})
234 local types = ''
235 for i, v in ipairs(thing.types) do
236 if 1 ~= i then types = types .. v .. ', ' end
237 end
238 print(thing.module._NAME .. '.' .. key .. '(' .. types .. ') -> ' .. thing.help)
239 else
240 if ThingSpace.parameters[key] ~= thing then
241 ThingSpace.commands[key] = nil
242 ThingSpace.parameters[key] = thing
243 setmetatable(thing, nil)
244 end
245 print(thing.types[1] .. ' ' .. thing.module._NAME .. '.' .. thing.names[1] .. ' = ' .. value .. ' -> ' .. thing.help)
246 -- TODO - Go through it's linked things and set them to.
221 end 247 end
222 print(thing.types[1] .. ' ' .. thing.module._NAME .. '.' .. thing.names[1] .. ' = ' .. value .. ' -> ' .. thing.help) 248 rawset(table, thing.names[1], value)
223 -- TODO - Go through it's linked things and set them to. 249 else
250 rawset(table, key, value)
224 end 251 end
225 -- TODO - Should set all aliases here, then __index doesn't have to do a linear search through all of ThingSpace.
226 -- Uses more memory, and allows bypassing the Thing by setting the alias.
227 -- Which is a problem anyway, so have to deal with twiddling aliases.
228 rawset(table, thing.names[1], value)
229 end, 252 end,
230 253
231 -- Not an actual metatable event until it gets set as the metatable above. 254 -- Not an actual metatable event until it gets set as the metatable above.