aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ClientHamr
diff options
context:
space:
mode:
authorDavid Walter Seikel2014-03-29 16:40:29 +1000
committerDavid Walter Seikel2014-03-29 16:40:29 +1000
commitdf2e44ac370555bc7b91b89ccba86701b94ab43a (patch)
tree1c322bda98950983914cd4a0d02fb2f609b58cbe /ClientHamr
parentChange table to module, coz table is one of the Lua supplied modules. (diff)
downloadSledjHamr-df2e44ac370555bc7b91b89ccba86701b94ab43a.zip
SledjHamr-df2e44ac370555bc7b91b89ccba86701b94ab43a.tar.gz
SledjHamr-df2e44ac370555bc7b91b89ccba86701b94ab43a.tar.bz2
SledjHamr-df2e44ac370555bc7b91b89ccba86701b94ab43a.tar.xz
Update isValid() to deal with multiple Thing copies.
Diffstat (limited to 'ClientHamr')
-rw-r--r--ClientHamr/GuiLua/skang.lua14
1 files changed, 8 insertions, 6 deletions
diff --git a/ClientHamr/GuiLua/skang.lua b/ClientHamr/GuiLua/skang.lua
index dfca188..7ec7a64 100644
--- a/ClientHamr/GuiLua/skang.lua
+++ b/ClientHamr/GuiLua/skang.lua
@@ -335,20 +335,22 @@ end
335Thing.things = {} -- The sub things this Thing has, for modules and Stuff. 335Thing.things = {} -- The sub things this Thing has, for modules and Stuff.
336Thing.errors = {} -- A list of errors returned by isValid(). 336Thing.errors = {} -- A list of errors returned by isValid().
337 337
338Thing.isValid = function (self) -- Check if this Thing is valid, return resulting error messages in errors. 338Thing.isValid = function (self, module) -- Check if this Thing is valid, return resulting error messages in errors.
339 -- Anything that overrides this method, should call this super method first. 339 -- Anything that overrides this method, should call this super method first.
340 local value = self.value 340 local pre = rawget(module, 'pre')
341 if pre then pre = pre .. '_value' else pre = 'value' end
342 local value = self[pre]
341 local t = type(value) 343 local t = type(value)
342 self.errors = {} 344 self.errors = {}
343 -- TODO - Naturally there should be formatting functions for stuffing Thing stuff into strings, and overridable output functions. 345 -- TODO - Naturally there should be formatting functions for stuffing Thing stuff into strings, and overridable output functions.
344 if 'nil' == t then 346 if 'nil' == t then
345 if self.required then table.insert(self.errors, self.names[1] .. ' is required!') end 347 if self.required then table.insert(self.errors, module._NAME .. '.' .. self.names[1] .. ' is required!') end
346 else 348 else
347 if self.types[1] ~= t then table.insert(self.errors, self.names[1] .. ' should be a ' .. self.types[1] .. ', but it is a ' .. type(value) .. '!') 349 if self.types[1] ~= t then table.insert(self.errors, module._NAME .. '.' .. self.names[1] .. ' should be a ' .. self.types[1] .. ', but it is a ' .. type(value) .. '!')
348 else 350 else
349 if 'number' == t then value = '' .. value end 351 if 'number' == t then value = '' .. value end
350 if ('number' == t) or ('string' == t) then 352 if ('number' == t) or ('string' == t) then
351 if 1 ~= string.find(value, '^' .. self.pattern .. '$') then table.insert(self.errors, self.names[1] .. ' does not match pattern "' .. self.pattern .. '"!') end 353 if 1 ~= string.find(value, '^' .. self.pattern .. '$') then table.insert(self.errors, module._NAME .. '.' .. self.names[1] .. ' does not match pattern "' .. self.pattern .. '"!') end
352 end 354 end
353 end 355 end
354 end 356 end
@@ -396,7 +398,7 @@ Thing.__newindex = function (module, key, value)
396-- print(thing.module._NAME .. '.' .. name .. '(' .. types .. ') -> ' .. thing.help) 398-- print(thing.module._NAME .. '.' .. name .. '(' .. types .. ') -> ' .. thing.help)
397 else 399 else
398 -- NOTE - invalid values are still stored, this is by design. 400 -- NOTE - invalid values are still stored, this is by design.
399 if not thing:isValid() then 401 if not thing:isValid(module) then
400 for i, v in ipairs(thing.errors) do 402 for i, v in ipairs(thing.errors) do
401 print('ERROR - ' .. v) 403 print('ERROR - ' .. v)
402 end 404 end