diff options
author | David Walter Seikel | 2014-03-29 00:09:09 +1000 |
---|---|---|
committer | David Walter Seikel | 2014-03-29 00:09:09 +1000 |
commit | 4cea493aa33e8a3f4f6336ceff44d0b9602e97ec (patch) | |
tree | a383f45428c27bf18bf0afa5b0df89458c906f06 /ClientHamr | |
parent | Typo-- (diff) | |
download | SledjHamr-4cea493aa33e8a3f4f6336ceff44d0b9602e97ec.zip SledjHamr-4cea493aa33e8a3f4f6336ceff44d0b9602e97ec.tar.gz SledjHamr-4cea493aa33e8a3f4f6336ceff44d0b9602e97ec.tar.bz2 SledjHamr-4cea493aa33e8a3f4f6336ceff44d0b9602e97ec.tar.xz |
Notes about multiple module copies, and Stuff.
Diffstat (limited to 'ClientHamr')
-rw-r--r-- | ClientHamr/GuiLua/skang.lua | 78 |
1 files changed, 54 insertions, 24 deletions
diff --git a/ClientHamr/GuiLua/skang.lua b/ClientHamr/GuiLua/skang.lua index cd95f6a..7829055 100644 --- a/ClientHamr/GuiLua/skang.lua +++ b/ClientHamr/GuiLua/skang.lua | |||
@@ -254,31 +254,60 @@ Other Thing things are - | |||
254 | ]] | 254 | ]] |
255 | 255 | ||
256 | 256 | ||
257 | --[[ TODO - Users might want to use two or more copies of this module. Keep that in mind. local a = require 'test', b = require 'test' might handle that though? | 257 | --[[ TODO |
258 | Not unless skang.thing() knows about a and b, which it wont. | 258 | NOTE that skang.thing{} doesn't care what other names you pass in, they all get assigned to the thing. |
259 | Both a and b get the same table, not different copies of it. | 259 | |
260 | Perhaps clone the table if it exists? Only clone the parameters, the rest can be linked back to the original. | 260 | Multiple copies of modules - |
261 | Then we have to deal with widgets linking to specific clones. | 261 | skang.new(test, 'pre') |
262 | Actually, not sure matrix-RAD solved that either. lol | 262 | local result = {} |
263 | ]] | 263 | setmetatable(result, test) |
264 | result.pre = 'pre' | ||
265 | -- loop through the Things in test | ||
266 | -- Will have to be a deeper copy if it's a Stuff. | ||
267 | skang.things['pre' .. '_' .. 'foo'] = skang.things.foo | ||
268 | skang.things['pre' .. '_' .. 'foo'].module = result | ||
269 | return result | ||
270 | end | ||
264 | 271 | ||
265 | --[[ ideas | 272 | __index |
266 | __newindex could catch a table being assigned - test.foo = {widget = '...', acl='...'} | 273 | local aKey = key |
267 | though that interferes with using tables for Stuff | 274 | if table.pre then aKey = table.pre .. '_' .. key end |
268 | test.someStuff = {key='blah', field0='something', field1=1, ...} | 275 | local thing = things[aKey] |
269 | test.someStuff.key | 276 | ... |
270 | happily Lua function call syntax supports test.foo{ ... } as a function call with a table argument. B-) | 277 | -- Then see if we can inherit it from Thing. |
271 | so maybe a use for __call after all, if the argument is that table | 278 | thing = Thing[key] |
272 | the table itself is passed to __call as the first argument, the rest of the arguments follow. | 279 | |
273 | test.foo(1, 'two') -> __call(foo, 1, 'two') | 280 | |
274 | foo has to be a table value though, with a metatable | 281 | __newindex |
275 | and the rest of skang is treating test.foo as a nil value so that __index and __newindex work. B-( | 282 | local aKey = key |
276 | test itself is a table, so all is not lost - | 283 | if table.pre then aKey = table.pre .. '_' .. key end |
277 | test{'foo', widget='...', acl='..'} -> __call(test, {'foo', ...}) -> skang.thing{'foo', ...} | 284 | local thing = things[aKey] |
278 | which would assign stuff to skang.things.foo.widget and skang.things.foo.acl | 285 | ... |
279 | as opposed to - | 286 | |
280 | skang.things.foo = {widget='...', acl='...'} | 287 | skang.things.foo.value |
281 | which blanks out the other stuff. | 288 | skang.things.pre_foo.value |
289 | |||
290 | Stuff - | ||
291 | test{'foo', key='blah', field0='something', field1=1, ...} -> skang.things.foo.key='blah' skang.things.foo.field='something' ... | ||
292 | test{'foo', bar='...', baz='..'} -> __call(test, {'foo', ...}) -> skang.stuff{'foo', ...} | ||
293 | What we really want though is something like (if foo is defined as a table) - | ||
294 | -> skang.things.foo.value = {key='blah', field0='something', field1=1, ...} | ||
295 | or even (if foo is defined as a Stuff) - | ||
296 | -> skang.things.foo.value[blah] = {key = 'blah', field0='something', field1=1, ...} | ||
297 | Stuff is kinda rigid though, it's fields are fixed, not an everything goes Lua table. So it needs to be defined. | ||
298 | Reusing Thing semantics, with aliases. | ||
299 | Also, let's NOT mix skang.thing{} semantics with test{} semantics, make it a different function. | ||
300 | Then we can avoid conflicts with Thing.* names, and having to sort out where to put things. | ||
301 | skang.thing{'foo', stuff={{'key', 'The Stuff key', types='string', required=true}, | ||
302 | {'field0,b' ... other Thing like stuff ... acl=''}, | ||
303 | {'field1', 'field1 is a stufflet', 42, 'number'}} } | ||
304 | skang.thing('foo', stuff=someOtherThing) | ||
305 | skang.thing('foo', stuff=skang.new(someOtherThing, 'pre')) | ||
306 | skang.things.foo.things.field0 | ||
307 | skang.things.foo.things.field1 | ||
308 | test.foo[blah].field1 | ||
309 | |||
310 | Widgets - | ||
282 | Use generic positional / named arguments for widget to, then we can do - | 311 | Use generic positional / named arguments for widget to, then we can do - |
283 | widget.button{'Cancel', 0.5, 0.5, 1, 0, look='cancel.edj', colour={1, 2, 3, 4}, action='...'} | 312 | widget.button{'Cancel', 0.5, 0.5, 1, 0, look='cancel.edj', colour={1, 2, 3, 4}, action='...'} |
284 | Using the Thing alias stuff, maybe we can do the "first stage tokenise" step after all - | 313 | Using the Thing alias stuff, maybe we can do the "first stage tokenise" step after all - |
@@ -314,6 +343,7 @@ Thing.hasCrashed = 0 -- How many times this Thing has crashed. | |||
314 | Thing.append = function (self,data) -- Append to the value of this Thing. | 343 | Thing.append = function (self,data) -- Append to the value of this Thing. |
315 | end | 344 | end |
316 | 345 | ||
346 | Thing.things = {} -- The sub things this Thing has, for modules and Stuff. | ||
317 | Thing.errors = {} -- A list of errors returned by isValid(). | 347 | Thing.errors = {} -- A list of errors returned by isValid(). |
318 | 348 | ||
319 | Thing.isValid = function (self) -- Check if this Thing is valid, return resulting error messages in errors. | 349 | Thing.isValid = function (self) -- Check if this Thing is valid, return resulting error messages in errors. |