diff options
-rw-r--r-- | ClientHamr/GuiLua/skang.lua | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/ClientHamr/GuiLua/skang.lua b/ClientHamr/GuiLua/skang.lua index 29b62a9..17773e9 100644 --- a/ClientHamr/GuiLua/skang.lua +++ b/ClientHamr/GuiLua/skang.lua | |||
@@ -213,7 +213,6 @@ Other Thing things are - | |||
213 | ]] | 213 | ]] |
214 | 214 | ||
215 | --[[ ideas | 215 | --[[ ideas |
216 | use a Lua pattern instead of a mask, with ^ and $ automatically added at the ends. | ||
217 | __newindex could catch a table being assigned - test.foo = {widget = '...', acl='...'} | 216 | __newindex could catch a table being assigned - test.foo = {widget = '...', acl='...'} |
218 | though that interferes with using tables for Stuff | 217 | though that interferes with using tables for Stuff |
219 | test.someStuff = {key='blah', field0='something', field1=1, ...} | 218 | test.someStuff = {key='blah', field0='something', field1=1, ...} |
@@ -259,14 +258,20 @@ Thing.errors = {} -- A list of errors returned by isValid(). | |||
259 | Thing.isValid = function (self) -- Check if this Thing is valid, return resulting error messages in errors. | 258 | Thing.isValid = function (self) -- Check if this Thing is valid, return resulting error messages in errors. |
260 | -- Anything that overrides this method, should call this super method first. | 259 | -- Anything that overrides this method, should call this super method first. |
261 | local value = self.value | 260 | local value = self.value |
261 | local t = type(value) | ||
262 | self.errors = {} | 262 | self.errors = {} |
263 | -- TODO - Naturally there should be formatting functions for stuffing Thing stuff into strings, and overridable output functions. | 263 | -- TODO - Naturally there should be formatting functions for stuffing Thing stuff into strings, and overridable output functions. |
264 | if 'nil' == type(value) then | 264 | if 'nil' == t then |
265 | if self.required then table.insert(self.errors, self.names[1] .. ' is required!') end | 265 | if self.required then table.insert(self.errors, self.names[1] .. ' is required!') end |
266 | else | 266 | else |
267 | if self.types[1] ~= type(value) then table.insert(self.errors, self.names[1] .. ' should be a ' .. self.types[1] .. ', but it is a ' .. type(value) .. '!') end | 267 | 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) .. '!') |
268 | else | ||
269 | if 'number' == t then value = '' .. value end | ||
270 | if ('number' == t) or ('string' == t) then | ||
271 | if 1 ~= string.find(value, '^' .. self.pattern .. '$') then table.insert(self.errors, self.names[1] .. ' does not match pattern "' .. self.pattern .. '"!') end | ||
272 | end | ||
273 | end | ||
268 | end | 274 | end |
269 | -- TODO - Should check for matching mask, and anything else. | ||
270 | return #(self.errors) == 0 | 275 | return #(self.errors) == 0 |
271 | end | 276 | end |
272 | 277 | ||