diff options
author | David Walter Seikel | 2014-03-22 14:38:11 +1000 |
---|---|---|
committer | David Walter Seikel | 2014-03-22 14:38:11 +1000 |
commit | 2ef7fcac2db901dbb6c9def0f7eeb4a6ae9aa496 (patch) | |
tree | 7311d54cf62e91a98c13054372e4f2220c7bf4f9 | |
parent | Much saner way to deal with aliases. B-) (diff) | |
download | SledjHamr-2ef7fcac2db901dbb6c9def0f7eeb4a6ae9aa496.zip SledjHamr-2ef7fcac2db901dbb6c9def0f7eeb4a6ae9aa496.tar.gz SledjHamr-2ef7fcac2db901dbb6c9def0f7eeb4a6ae9aa496.tar.bz2 SledjHamr-2ef7fcac2db901dbb6c9def0f7eeb4a6ae9aa496.tar.xz |
Add Thing inheritance, and some stubs to inherit.
-rw-r--r-- | ClientHamr/GuiLua/skang.lua | 63 | ||||
-rw-r--r-- | ClientHamr/GuiLua/test.lua | 2 |
2 files changed, 45 insertions, 20 deletions
diff --git a/ClientHamr/GuiLua/skang.lua b/ClientHamr/GuiLua/skang.lua index d79deff..aa0f3c8 100644 --- a/ClientHamr/GuiLua/skang.lua +++ b/ClientHamr/GuiLua/skang.lua | |||
@@ -164,19 +164,13 @@ local other = require('otherPackageName') | |||
164 | other.foo = 'stuff' | 164 | other.foo = 'stuff' |
165 | bar = other.foo | 165 | bar = other.foo |
166 | 166 | ||
167 | Other Thing things are (should add defaults for some of these to Thing) - | 167 | Other Thing things are - |
168 | number No idea how this was useful. | 168 | number No idea how this was useful. |
169 | skang The owning object, a Skang (actually got this, called module for now). | 169 | skang The owning object, a Skang (actually got this, called module for now). |
170 | owner The owning object, a String (module._NAME). | 170 | owner The owning object, a String (module._NAME). |
171 | clas Class of the Thing, a Class. (pointless) | 171 | clas Class of the Thing, a Class. (pointless) |
172 | type Class of the Thing, a String. (pointless) | 172 | type Class of the Thing, a String. (pointless) |
173 | realType Real Class of the Thing, a String. (pointless) | 173 | realType Real Class of the Thing, a String. (pointless) |
174 | action An optional action to perform, a String. | ||
175 | tell The skang command that created this Thing, a String. | ||
176 | get/set/append/isValid/remove Various Methods. | ||
177 | errors A list of errors returned by isValid(). | ||
178 | isReadOnly/isServer/isStub/isStubbed Various booleans. | ||
179 | hasCrashed How many times this Thing has crashed, an Integer. | ||
180 | myRoot ThingSpace we are in, a ThingSpace. | 174 | myRoot ThingSpace we are in, a ThingSpace. |
181 | 175 | ||
182 | 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. |
@@ -199,6 +193,10 @@ Thing = | |||
199 | -- First see if this is a Thing. | 193 | -- First see if this is a Thing. |
200 | if thing then return thing.default end | 194 | if thing then return thing.default end |
201 | 195 | ||
196 | -- Then see if we can inherit it from Thing. | ||
197 | thing = Thing[key] | ||
198 | if thing then return thing end | ||
199 | |||
202 | -- If all else fails, return nil. | 200 | -- If all else fails, return nil. |
203 | return nil | 201 | return nil |
204 | end, | 202 | end, |
@@ -208,27 +206,29 @@ Thing = | |||
208 | 206 | ||
209 | -- NOTE - A Thing is either a command or a parameter, not both. | 207 | -- NOTE - A Thing is either a command or a parameter, not both. |
210 | if thing then | 208 | if thing then |
209 | local name = thing.names[1] | ||
211 | if 'function' == type(value) then | 210 | if 'function' == type(value) then |
212 | thing.default = nil | 211 | thing.default = nil |
213 | thing.func = value | 212 | thing.func = value |
214 | ThingSpace.commands[key] = thing | 213 | ThingSpace.commands[name] = thing |
215 | ThingSpace.parameters[key] = nil | 214 | ThingSpace.parameters[name] = nil |
216 | setmetatable(thing, {__call = Thing._call}) | 215 | setmetatable(thing, {__call = Thing._call, __index=Thing.__index}) |
217 | local types = '' | 216 | local types = '' |
218 | for i, v in ipairs(thing.types) do | 217 | for i, v in ipairs(thing.types) do |
219 | if 1 ~= i then types = types .. v .. ', ' end | 218 | if 1 ~= i then types = types .. v .. ', ' end |
220 | end | 219 | end |
221 | print(thing.module._NAME .. '.' .. key .. '(' .. types .. ') -> ' .. thing.help) | 220 | print(thing.module._NAME .. '.' .. name .. '(' .. types .. ') -> ' .. thing.help) |
222 | else | 221 | else |
223 | if ThingSpace.parameters[key] ~= thing then | 222 | if ThingSpace.parameters[name] ~= thing then |
224 | ThingSpace.commands[key] = nil | 223 | ThingSpace.commands[name] = nil |
225 | ThingSpace.parameters[key] = thing | 224 | ThingSpace.parameters[name] = thing |
226 | setmetatable(thing, nil) | 225 | setmetatable(thing, {__index=Thing.__index}) |
227 | end | 226 | end |
228 | print(thing.types[1] .. ' ' .. thing.module._NAME .. '.' .. thing.names[1] .. ' = ' .. value .. ' -> ' .. thing.help) | 227 | thing:isValid() |
228 | print(thing.types[1] .. ' ' .. thing.module._NAME .. '.' .. name .. ' = ' .. value .. ' -> ' .. thing.help) | ||
229 | -- TODO - Go through it's linked things and set them to. | 229 | -- TODO - Go through it's linked things and set them to. |
230 | end | 230 | end |
231 | rawset(table, thing.names[1], value) | 231 | rawset(table, name, value) |
232 | else | 232 | else |
233 | rawset(table, key, value) | 233 | rawset(table, key, value) |
234 | end | 234 | end |
@@ -238,6 +238,29 @@ Thing = | |||
238 | _call = function (func, ...) | 238 | _call = function (func, ...) |
239 | return func.func(...) | 239 | return func.func(...) |
240 | end, | 240 | end, |
241 | |||
242 | action = 'nada', -- An optional action to perform. | ||
243 | tell = '', -- The skang command that created this Thing. | ||
244 | |||
245 | get = function (self) -- Get the value of this Thing. | ||
246 | end, | ||
247 | set = function (self) -- Set the value of this Thing. | ||
248 | end, | ||
249 | append = function (self,data) -- Append to the value of this Thing. | ||
250 | end, | ||
251 | isValid = function (self) -- Check if this Thing is valid, return resulting error messages in errors. | ||
252 | end, | ||
253 | remove = function (self) -- Delete this Thing. | ||
254 | end, | ||
255 | |||
256 | errors = {}, -- A list of errors returned by isValid(). | ||
257 | |||
258 | isReadOnly = false, -- Is this Thing read only? | ||
259 | isServer = false, -- Is this Thing server side? | ||
260 | isStub = false, -- Is this Thing a stub? | ||
261 | isStubbed = false, -- Is this Thing stubbed elsewhere? | ||
262 | |||
263 | hasCrashed = 0, -- How many times this Thing has crashed. | ||
241 | } | 264 | } |
242 | 265 | ||
243 | -- Actually stuff ourself into ThingSpace. | 266 | -- Actually stuff ourself into ThingSpace. |
@@ -337,6 +360,7 @@ thing = function (module, names, help, default, types, widget, required, acl, bo | |||
337 | end | 360 | end |
338 | 361 | ||
339 | -- TODO - Some function stubs, for now. Fill them up later. | 362 | -- TODO - Some function stubs, for now. Fill them up later. |
363 | nada = function () end | ||
340 | get = function (name) | 364 | get = function (name) |
341 | end | 365 | end |
342 | set = function (name, value) | 366 | set = function (name, value) |
@@ -354,8 +378,9 @@ end | |||
354 | quit = function () | 378 | quit = function () |
355 | end | 379 | end |
356 | 380 | ||
357 | thing(_M, 'get', 'Get the current value of an existing thing.', get, 'name') -- This should be in Thing, not actually here? | 381 | thing(_M, 'nada', 'Do nothing.', nada) |
358 | thing(_M, 'set', 'Set the current value of an existing Thing.', set, 'name,data') -- This should be in Thing, not actually here? | 382 | thing(_M, 'get', 'Get the current value of an existing thing.', get, 'name') |
383 | thing(_M, 'set', 'Set the current value of an existing Thing.', set, 'name,data') | ||
359 | thing(_M, 'clear', 'The current skin is cleared of all widgets.', clear) | 384 | thing(_M, 'clear', 'The current skin is cleared of all widgets.', clear) |
360 | thing(_M, 'window', 'The size and title of the application Frame.', window, 'x,y,name', nil, nil, 'GGG') | 385 | thing(_M, 'window', 'The size and title of the application Frame.', window, 'x,y,name', nil, nil, 'GGG') |
361 | thing(_M, 'module', 'Load a module.', module, 'file,acl') | 386 | thing(_M, 'module', 'Load a module.', module, 'file,acl') |
diff --git a/ClientHamr/GuiLua/test.lua b/ClientHamr/GuiLua/test.lua index 525e66b..f17238c 100644 --- a/ClientHamr/GuiLua/test.lua +++ b/ClientHamr/GuiLua/test.lua | |||
@@ -47,7 +47,7 @@ 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) | 50 | print('End ' .. test.bar .. ' ' .. test.VERSION .. ' ' .. skang.ThingSpace.commands.func.help .. ' ->> ' .. test.action .. ' ' .. skang.ThingSpace.things.f.action) |
51 | test.func('one', 2) | 51 | test.func('one', 2) |
52 | skang.ThingSpace.things.func('seven', 'aight') | 52 | skang.ThingSpace.things.func('seven', 'aight') |
53 | skang.ThingSpace.commands.func.func(3, 'four') | 53 | skang.ThingSpace.commands.func.func(3, 'four') |