aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ClientHamr/GuiLua
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--ClientHamr/GuiLua/skang.lua122
1 files changed, 58 insertions, 64 deletions
diff --git a/ClientHamr/GuiLua/skang.lua b/ClientHamr/GuiLua/skang.lua
index 674f8f9..b1ed581 100644
--- a/ClientHamr/GuiLua/skang.lua
+++ b/ClientHamr/GuiLua/skang.lua
@@ -348,79 +348,73 @@ TODO -
348 Weak references might help in here somewhere. 348 Weak references might help in here somewhere.
349]] 349]]
350 350
351
352-- There is no ThingSpace, or Stuff, now it's all just in this meta table. 351-- There is no ThingSpace, or Stuff, now it's all just in this meta table.
353local Thing = {} 352local Thing =
354 353{
355-- Default things values. 354-- Default Thing values.
356-- help - help text describing this Thing. 355 names = {'unknown'},
357-- default - the default value. This could be a funcion, making this a command. 356 help = 'No description supplied.', -- help text describing this Thing.
358-- types - a comma separated list of types. The first is the type of the Thing itself, the rest are for multi value Things. Or argument types for commands. 357 default = '', -- The default value. This could be a funcion, making this a command.
359-- widget - default widget command arguments for creating this Thing as a widget. 358 types = {}, -- A list of types. The first is the type of the Thing itself, the rest are for multi value Things. Or argument types for commands.
360-- required - "boolean" to say if this thing is required. TODO - Maybe fold this into types somehow, or acl? 359 required = false, -- Is this thing is required. TODO - Maybe fold this into types somehow, or acl?
361-- acl - Access Control List defining security restrains. 360 widget = '', -- Default widget command arguments for creating this Thing as a widget.
362-- boss - the Thing or person that owns this Thing, otherwise it is self owned. 361-- acl = '', -- Access Control List defining security restrains.
363Thing.names = {'unknown'} 362-- boss = '', -- The Thing or person that owns this Thing, otherwise it is self owned.
364Thing.help = 'No description supplied.' 363
365Thing.default = '' 364 action = 'nada', -- An optional action to perform.
366Thing.types = {} 365 tell = '', -- The skang command that created this Thing.
367Thing.required = false 366 pattern = '.*', -- A pattern to restrict values.
368--Thing.acl = '' 367
369--Thing.boss = '' 368 isKeyed = false, -- Is this thing an arbitrarily Keyed table?
370 369 isReadOnly = false, -- Is this Thing read only?
371Thing.action = 'nada' -- An optional action to perform. 370 isServer = false, -- Is this Thing server side?
372Thing.tell = '' -- The skang command that created this Thing. 371 isStub = false, -- Is this Thing a stub?
373Thing.pattern = '.*' -- A pattern to restrict values. 372 isStubbed = false, -- Is this Thing stubbed elsewhere?
374 373
375Thing.isKeyed = false -- Is this thing an arbitrarily Keyed table? 374 hasCrashed = 0, -- How many times this Thing has crashed.
376Thing.isReadOnly = false -- Is this Thing read only? 375
377Thing.isServer = false -- Is this Thing server side? 376 append = function (self,data) -- Append to the value of this Thing.
378Thing.isStub = false -- Is this Thing a stub? 377 end,
379Thing.isStubbed = false -- Is this Thing stubbed elsewhere? 378
380 379 stuff = {}, -- The sub things this Thing has, for modules, tables, and Keyed tables.
381Thing.hasCrashed = 0 -- How many times this Thing has crashed. 380 errors = {}, -- A list of errors returned by isValid().
382 381
383Thing.append = function (self,data) -- Append to the value of this Thing. 382 isValid = function (self, parent) -- Check if this Thing is valid, return resulting error messages in errors.
384end 383 -- Anything that overrides this method, should call this super method first.
385 384 local name = self.names[1]
386Thing.stuff = {} -- The sub things this Thing has, for modules, tables, and Keyed tables. 385 local metaMum = getmetatable(parent)
387Thing.errors = {} -- A list of errors returned by isValid(). 386 local value = metaMum.__values[name]
388 387 local mum = metaMum.__self.names[1]
389Thing.isValid = function (self, parent) -- Check if this Thing is valid, return resulting error messages in errors. 388
390 -- Anything that overrides this method, should call this super method first. 389 local t = type(value) or 'nil'
391 local name = self.names[1] 390 self.errors = {}
392 local metaMum = getmetatable(parent) 391 -- TODO - Naturally there should be formatting functions for stuffing Thing stuff into strings, and overridable output functions.
393 local value = metaMum.__values[name] 392 if 'nil' == t then
394 local mum = metaMum.__self.names[1] 393 if self.required then table.insert(self.errors, mum .. '.' .. name .. ' is required!') end
395
396 local t = type(value) or 'nil'
397 self.errors = {}
398 -- TODO - Naturally there should be formatting functions for stuffing Thing stuff into strings, and overridable output functions.
399 if 'nil' == t then
400 if self.required then table.insert(self.errors, mum .. '.' .. name .. ' is required!') end
401 else
402 if self.types[1] ~= t then table.insert(self.errors, mum .. '.' .. name .. ' should be a ' .. self.types[1] .. ', but it is a ' .. t .. '!')
403 else 394 else
404 if 'number' == t then value = '' .. value end 395 if self.types[1] ~= t then table.insert(self.errors, mum .. '.' .. name .. ' should be a ' .. self.types[1] .. ', but it is a ' .. t .. '!')
405 if ('number' == t) or ('string' == t) then 396 else
406 if 1 ~= string.find(value, '^' .. self.pattern .. '$') then table.insert(self.errors, mum .. '.' .. name .. ' does not match pattern "' .. self.pattern .. '"!') end 397 if 'number' == t then value = '' .. value end
398 if ('number' == t) or ('string' == t) then
399 if 1 ~= string.find(value, '^' .. self.pattern .. '$') then table.insert(self.errors, mum .. '.' .. name .. ' does not match pattern "' .. self.pattern .. '"!') end
400 end
407 end 401 end
408 end 402 end
409 end
410 403
411 for k, v in pairs(self.stuff) do 404 for k, v in pairs(self.stuff) do
412 if not v:isValid(value) then 405 if not v:isValid(value) then
413 for i, w in ipairs(v.errors) do 406 for i, w in ipairs(v.errors) do
414 table.insert(self.errors, w) 407 table.insert(self.errors, w)
408 end
415 end 409 end
416 end 410 end
417 end
418 411
419 return #(self.errors) == 0 412 return #(self.errors) == 0
420end 413 end,
421 414
422Thing.remove = function (self) -- Delete this Thing. 415 remove = function (self) -- Delete this Thing.
423end 416 end,
417}
424 418
425 419
426getStuffed = function (parent, key) 420getStuffed = function (parent, key)