aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ClientHamr/GuiLua/skang.lua
diff options
context:
space:
mode:
authorDavid Walter Seikel2014-03-29 16:29:11 +1000
committerDavid Walter Seikel2014-03-29 16:29:11 +1000
commit860de89154bd170936818a77392058352a00d83c (patch)
tree755cc88753f8b3242debd3362c9b0daaba8d4c69 /ClientHamr/GuiLua/skang.lua
parentCombine and improve the widget TODOs. (diff)
downloadSledjHamr-860de89154bd170936818a77392058352a00d83c.zip
SledjHamr-860de89154bd170936818a77392058352a00d83c.tar.gz
SledjHamr-860de89154bd170936818a77392058352a00d83c.tar.bz2
SledjHamr-860de89154bd170936818a77392058352a00d83c.tar.xz
Implement multiple Thing copies.
Diffstat (limited to 'ClientHamr/GuiLua/skang.lua')
-rw-r--r--ClientHamr/GuiLua/skang.lua74
1 files changed, 39 insertions, 35 deletions
diff --git a/ClientHamr/GuiLua/skang.lua b/ClientHamr/GuiLua/skang.lua
index b6af22d..ce4fb9f 100644
--- a/ClientHamr/GuiLua/skang.lua
+++ b/ClientHamr/GuiLua/skang.lua
@@ -258,37 +258,6 @@ Other Thing things are -
258 NOTE that skang.thing{} doesn't care what other names you pass in, they all get assigned to the thing. 258 NOTE that skang.thing{} doesn't care what other names you pass in, they all get assigned to the thing.
259 259
260 260
261 Multiple copies of modules -
262 skang.new(test, 'pre')
263 local result = {}
264 setmetatable(result, test)
265 result.pre = 'pre'
266 -- loop through the Things in test
267 -- Will have to be a deeper copy if it's a Stuff.
268 skang.things['pre' .. '_' .. 'foo'] = skang.things.foo
269 skang.things['pre' .. '_' .. 'foo'].module = result
270 return result
271 end
272
273 __index
274 local aKey = key
275 if table.pre then aKey = table.pre .. '_' .. key end
276 local thing = things[aKey]
277 ...
278 -- Then see if we can inherit it from Thing.
279 thing = Thing[key]
280
281
282 __newindex
283 local aKey = key
284 if table.pre then aKey = table.pre .. '_' .. key end
285 local thing = things[aKey]
286 ...
287
288 skang.things.foo.value
289 skang.things.pre_foo.value
290
291
292 Stuff - 261 Stuff -
293 test{'foo', key='blah', field0='something', field1=1, ...} -> skang.things.foo.key='blah' skang.things.foo.field='something' ... 262 test{'foo', key='blah', field0='something', field1=1, ...} -> skang.things.foo.key='blah' skang.things.foo.field='something' ...
294 test{'foo', bar='...', baz='..'} -> __call(test, {'foo', ...}) -> skang.stuff{'foo', ...} 263 test{'foo', bar='...', baz='..'} -> __call(test, {'foo', ...}) -> skang.stuff{'foo', ...}
@@ -391,12 +360,14 @@ end
391 360
392Thing.__index = function (table, key) 361Thing.__index = function (table, key)
393 -- This only works for keys that don't exist. By definition a value of nil means it doesn't exist. 362 -- This only works for keys that don't exist. By definition a value of nil means it doesn't exist.
363 local pre = rawget(table, 'pre')
364 if pre then pre = pre .. '_value' else pre = 'value' end
394 local thing = things[key] 365 local thing = things[key]
395 -- First see if this is a Thing. 366 -- First see if this is a Thing.
396 -- TODO - Java skang called isValid() on get(). On the other hand, doesn't seem to call it on set(), but calls it on append(). 367 -- TODO - Java skang called isValid() on get(). On the other hand, doesn't seem to call it on set(), but calls it on append().
397 -- Ah, it was doing isValid() on setStufflet(). 368 -- Ah, it was doing isValid() on setStufflet().
398 -- TODO - Call thing.func() if it exists. 369 -- TODO - Call thing.func() if it exists.
399 if thing then return thing.value or thing.default end 370 if thing then return thing[pre] or thing.default end
400 371
401 -- Then see if we can inherit it from Thing. 372 -- Then see if we can inherit it from Thing.
402 thing = Thing[key] 373 thing = Thing[key]
@@ -408,12 +379,14 @@ end
408 379
409Thing.__newindex = function (table, key, value) 380Thing.__newindex = function (table, key, value)
410 -- This only works for keys that don't exist. By definition a value of nil means it doesn't exist. 381 -- This only works for keys that don't exist. By definition a value of nil means it doesn't exist.
382 local pre = rawget(table, 'pre')
383 if pre then pre = pre .. '_value' else pre = 'value' end
411 local thing = things[key] 384 local thing = things[key]
412 385
413 if thing then 386 if thing then
414-- local name = thing.names[1] 387-- local name = thing.names[1]
415 -- This is a proxy table, the values never exist in the real table. 388 -- This is a proxy table, the values never exist in the real table.
416 thing.value = value 389 thing[pre] = value
417 if 'function' == type(value) then 390 if 'function' == type(value) then
418 thing.func = value 391 thing.func = value
419 local types = '' 392 local types = ''
@@ -509,11 +482,11 @@ thing = function (names, ...)
509 482
510 -- Remove old names, then stash the Thing under all of it's new names. 483 -- Remove old names, then stash the Thing under all of it's new names.
511 for i, v in ipairs(oldNames) do 484 for i, v in ipairs(oldNames) do
512 thing.things[v] = nil 485 thing.module.things[v] = nil
513 things[v] = nil 486 things[v] = nil
514 end 487 end
515 for i, v in ipairs(thing.names) do 488 for i, v in ipairs(thing.names) do
516 thing.things[v] = thing 489 thing.module.things[v] = thing
517 things[v] = thing 490 things[v] = thing
518 end 491 end
519 492
@@ -522,6 +495,37 @@ thing = function (names, ...)
522end 495end
523 496
524 497
498-- skang.new() Creats a new copy of a module.
499--[[
500 A module isn't exactly a thing, it has Thing as it's metatable though.
501
502 local test = require 'test'
503 skang.moduleBegin('test', ...)
504 setmetatable(test, Thing)
505 skang.thing('foo', ...)
506 setmetatable(test.module.things.foo, Thing)
507 test.module.things.foo = skang.things.foo
508 local tester = skang.new(test, 'pre')
509
510 skang.things.foo.value
511 skang.things.foo.pre_value
512 ]]
513new = function (module, pre)
514 local result = {}
515
516 setmetatable(result, Thing)
517 result.pre = pre
518 -- Loop through the Things in thing
519 -- TODO - Will have to be a deeper copy if it's a Stuff?
520 for k, v in pairs(module.things) do
521 v[pre .. '_value'] = v.value
522-- things[pre .. '_' .. k].module = result
523 end
524
525 return result
526 end
527
528
525-- TODO - Some function stubs, for now. Fill them up later. 529-- TODO - Some function stubs, for now. Fill them up later.
526nada = function () end 530nada = function () end
527 531