diff options
author | David Walter Seikel | 2014-03-22 15:28:09 +1000 |
---|---|---|
committer | David Walter Seikel | 2014-03-22 15:28:09 +1000 |
commit | b41cec51bb90a9e96b44a19a7b62d55c095b3a9d (patch) | |
tree | d0e8324a4787e3d43e511229e1b10f314950fd8a /ClientHamr | |
parent | Add Thing inheritance, and some stubs to inherit. (diff) | |
download | SledjHamr-b41cec51bb90a9e96b44a19a7b62d55c095b3a9d.zip SledjHamr-b41cec51bb90a9e96b44a19a7b62d55c095b3a9d.tar.gz SledjHamr-b41cec51bb90a9e96b44a19a7b62d55c095b3a9d.tar.bz2 SledjHamr-b41cec51bb90a9e96b44a19a7b62d55c095b3a9d.tar.xz |
Dissolve ThingSpace, and commands & parameters.
Diffstat (limited to 'ClientHamr')
-rw-r--r-- | ClientHamr/GuiLua/skang.lua | 37 | ||||
-rw-r--r-- | ClientHamr/GuiLua/test.lua | 6 |
2 files changed, 16 insertions, 27 deletions
diff --git a/ClientHamr/GuiLua/skang.lua b/ClientHamr/GuiLua/skang.lua index aa0f3c8..a4d5e91 100644 --- a/ClientHamr/GuiLua/skang.lua +++ b/ClientHamr/GuiLua/skang.lua | |||
@@ -176,19 +176,17 @@ Other Thing things are - | |||
176 | Also various functions to wrap checking the security, like canDo, canRead, etc. | 176 | Also various functions to wrap checking the security, like canDo, canRead, etc. |
177 | ]] | 177 | ]] |
178 | 178 | ||
179 | ThingSpace = {} | 179 | |
180 | ThingSpace.cache = {} | 180 | -- There is no ThingSpace, now it's just in these tables - |
181 | ThingSpace.commands = {} | 181 | things = {} |
182 | ThingSpace.modules = {} | 182 | modules = {} |
183 | ThingSpace.parameters = {} | 183 | |
184 | ThingSpace.things = {} | ||
185 | ThingSpace.widgets = {} | ||
186 | 184 | ||
187 | Thing = | 185 | Thing = |
188 | { | 186 | { |
189 | __index = function (table, key) | 187 | __index = function (table, key) |
190 | -- This only works for keys that don't exist. By definition a value of nil means it doesn't exist. | 188 | -- This only works for keys that don't exist. By definition a value of nil means it doesn't exist. |
191 | local thing = ThingSpace.things[key] | 189 | local thing = things[key] |
192 | 190 | ||
193 | -- First see if this is a Thing. | 191 | -- First see if this is a Thing. |
194 | if thing then return thing.default end | 192 | if thing then return thing.default end |
@@ -202,28 +200,18 @@ Thing = | |||
202 | end, | 200 | end, |
203 | 201 | ||
204 | __newindex = function (table, key, value) | 202 | __newindex = function (table, key, value) |
205 | local thing = ThingSpace.things[key] | 203 | local thing = things[key] |
206 | 204 | ||
207 | -- NOTE - A Thing is either a command or a parameter, not both. | ||
208 | if thing then | 205 | if thing then |
209 | local name = thing.names[1] | 206 | local name = thing.names[1] |
210 | if 'function' == type(value) then | 207 | if 'function' == type(value) then |
211 | thing.default = nil | ||
212 | thing.func = value | 208 | thing.func = value |
213 | ThingSpace.commands[name] = thing | ||
214 | ThingSpace.parameters[name] = nil | ||
215 | setmetatable(thing, {__call = Thing._call, __index=Thing.__index}) | ||
216 | local types = '' | 209 | local types = '' |
217 | for i, v in ipairs(thing.types) do | 210 | for i, v in ipairs(thing.types) do |
218 | if 1 ~= i then types = types .. v .. ', ' end | 211 | if 1 ~= i then types = types .. v .. ', ' end |
219 | end | 212 | end |
220 | print(thing.module._NAME .. '.' .. name .. '(' .. types .. ') -> ' .. thing.help) | 213 | print(thing.module._NAME .. '.' .. name .. '(' .. types .. ') -> ' .. thing.help) |
221 | else | 214 | else |
222 | if ThingSpace.parameters[name] ~= thing then | ||
223 | ThingSpace.commands[name] = nil | ||
224 | ThingSpace.parameters[name] = thing | ||
225 | setmetatable(thing, {__index=Thing.__index}) | ||
226 | end | ||
227 | thing:isValid() | 215 | thing:isValid() |
228 | print(thing.types[1] .. ' ' .. thing.module._NAME .. '.' .. name .. ' = ' .. value .. ' -> ' .. thing.help) | 216 | print(thing.types[1] .. ' ' .. thing.module._NAME .. '.' .. name .. ' = ' .. value .. ' -> ' .. thing.help) |
229 | -- TODO - Go through it's linked things and set them to. | 217 | -- TODO - Go through it's linked things and set them to. |
@@ -249,6 +237,8 @@ Thing = | |||
249 | append = function (self,data) -- Append to the value of this Thing. | 237 | append = function (self,data) -- Append to the value of this Thing. |
250 | end, | 238 | end, |
251 | isValid = function (self) -- Check if this Thing is valid, return resulting error messages in errors. | 239 | isValid = function (self) -- Check if this Thing is valid, return resulting error messages in errors. |
240 | self.errors = {} | ||
241 | return true | ||
252 | end, | 242 | end, |
253 | remove = function (self) -- Delete this Thing. | 243 | remove = function (self) -- Delete this Thing. |
254 | end, | 244 | end, |
@@ -264,13 +254,13 @@ Thing = | |||
264 | } | 254 | } |
265 | 255 | ||
266 | -- Actually stuff ourself into ThingSpace. | 256 | -- Actually stuff ourself into ThingSpace. |
267 | ThingSpace.modules[_NAME] = {module = _M, name = _NAME, } | 257 | modules[_NAME] = {module = _M, name = _NAME, } |
268 | setmetatable(_M, {Thing}) | 258 | setmetatable(_M, {Thing}) |
269 | 259 | ||
270 | -- This is the final version that we export. Finally we can include the ThingSpace stuff. | 260 | -- This is the final version that we export. Finally we can include the ThingSpace stuff. |
271 | moduleBegin = function (name, author, copyright, version, timestamp, skin) | 261 | moduleBegin = function (name, author, copyright, version, timestamp, skin) |
272 | local result = skangModuleBegin(name, author, copyright, version, timestamp, skin) | 262 | local result = skangModuleBegin(name, author, copyright, version, timestamp, skin) |
273 | ThingSpace.modules[name] = {module = result, name = name, } | 263 | modules[name] = {module = result, name = name, } |
274 | setmetatable(result, Thing) | 264 | setmetatable(result, Thing) |
275 | return result | 265 | return result |
276 | end | 266 | end |
@@ -316,7 +306,7 @@ end | |||
316 | quitter:action('quit') | 306 | quitter:action('quit') |
317 | ]] | 307 | ]] |
318 | 308 | ||
319 | -- skang.thing() stashes the default value into _M['bar'], and the details into ThingSpace.things['bar']. | 309 | -- skang.thing() stashes the default value into _M['bar'], and the details into things['bar']. |
320 | -- names - a comma seperated list of names, aliasas, and shortcuts. The first one is the official name. | 310 | -- names - a comma seperated list of names, aliasas, and shortcuts. The first one is the official name. |
321 | -- help - help text describing this Thing. | 311 | -- help - help text describing this Thing. |
322 | -- default - the default value. This could be a funcion, making this a command. | 312 | -- default - the default value. This could be a funcion, making this a command. |
@@ -351,9 +341,10 @@ thing = function (module, names, help, default, types, widget, required, acl, bo | |||
351 | -- Set it all up. | 341 | -- Set it all up. |
352 | -- TODO - might want to merge into pre existing Thing instead of over writing like this. | 342 | -- TODO - might want to merge into pre existing Thing instead of over writing like this. |
353 | local thing = {module = module, names = n, help = help, default = default, types = t, widget = widget, required = required, acl = acl, boss = boss, } | 343 | local thing = {module = module, names = n, help = help, default = default, types = t, widget = widget, required = required, acl = acl, boss = boss, } |
344 | setmetatable(thing, {__call = Thing._call, __index=Thing.__index}) | ||
354 | -- Stash the Thing under all of it's names. | 345 | -- Stash the Thing under all of it's names. |
355 | for i, v in ipairs(thing.names) do | 346 | for i, v in ipairs(thing.names) do |
356 | ThingSpace.things[v] = thing | 347 | things[v] = thing |
357 | end | 348 | end |
358 | -- This triggers the Thing.__newindex metamethod above. | 349 | -- This triggers the Thing.__newindex metamethod above. |
359 | module[name] = default | 350 | module[name] = default |
diff --git a/ClientHamr/GuiLua/test.lua b/ClientHamr/GuiLua/test.lua index f17238c..0c4968d 100644 --- a/ClientHamr/GuiLua/test.lua +++ b/ClientHamr/GuiLua/test.lua | |||
@@ -47,8 +47,6 @@ end | |||
47 | -- Test it. | 47 | -- Test it. |
48 | local skang = require 'skang' | 48 | local skang = require 'skang' |
49 | local test = require 'test' | 49 | local test = require 'test' |
50 | print('End ' .. test.bar .. ' ' .. test.VERSION .. ' ' .. skang.ThingSpace.commands.func.help .. ' ->> ' .. test.action .. ' ' .. skang.ThingSpace.things.f.action) | 50 | print('End ' .. test.bar .. ' ' .. test.VERSION .. ' ' .. skang.things.func.help .. ' ->> ' .. test.action .. ' ' .. skang.things.f.action) |
51 | test.func('one', 2) | 51 | test.func('one', 2) |
52 | skang.ThingSpace.things.func('seven', 'aight') | 52 | skang.things.func('seven', 'aight') |
53 | skang.ThingSpace.commands.func.func(3, 'four') | ||
54 | skang.ThingSpace.commands.func('five', 'six') | ||