aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ClientHamr
diff options
context:
space:
mode:
authorDavid Walter Seikel2014-03-22 11:07:40 +1000
committerDavid Walter Seikel2014-03-22 11:07:40 +1000
commit395cf9375a64037891cc3567432044d8b486398a (patch)
treefcd97eb6860af096c2cf80aad5a5d9633eef5158 /ClientHamr
parentA thing about other Thing things. (diff)
downloadSledjHamr-395cf9375a64037891cc3567432044d8b486398a.zip
SledjHamr-395cf9375a64037891cc3567432044d8b486398a.tar.gz
SledjHamr-395cf9375a64037891cc3567432044d8b486398a.tar.bz2
SledjHamr-395cf9375a64037891cc3567432044d8b486398a.tar.xz
Merge newCommand and newParam into "thing".
Diffstat (limited to '')
-rw-r--r--ClientHamr/GuiLua/skang.lua121
-rw-r--r--ClientHamr/GuiLua/test.lua10
2 files changed, 80 insertions, 51 deletions
diff --git a/ClientHamr/GuiLua/skang.lua b/ClientHamr/GuiLua/skang.lua
index 383b4bd..d652d8d 100644
--- a/ClientHamr/GuiLua/skang.lua
+++ b/ClientHamr/GuiLua/skang.lua
@@ -187,6 +187,7 @@ ThingSpace.cache = {}
187ThingSpace.commands = {} 187ThingSpace.commands = {}
188ThingSpace.modules = {} 188ThingSpace.modules = {}
189ThingSpace.parameters = {} 189ThingSpace.parameters = {}
190ThingSpace.things = {}
190ThingSpace.widgets = {} 191ThingSpace.widgets = {}
191 192
192Thing = 193Thing =
@@ -230,27 +231,9 @@ moduleEnd = function (module)
230end 231end
231 232
232 233
233-- skang.newParam stashes the default value into _M['bar'], and the details into ThingSpace.parameters['bar'].
234-- TODO - If it's not required, and there's no default, then skip setting _M['bar'].
235-- TODO - Could even use __index to skip setting it if it's not required and there is a default.
236-- TODO - if default is a function, or a pre existing module[name] is a function, then set the Thing .func to that function.
237-- TODO - Users might want to use two or more copies of this module. Keep that in mind. local a = require 'test', b = require 'test' might handle that though?
238-- Not unless skang.newParam() knows about a and b, which it wont.
239-- Both a and b get the same table, not different copies of it.
240-- Perhaps clone the table if it exists? There is no Lua table cloner, would have to write one. Only clone the parameters, the rest can be linked back to the original.
241-- Then we have to deal with widgets linking to specific clones.
242-- Actually, not sure matrix-RAD solved that either. lol
243-- TODO - This could even be done with an array of these arguments, not including the _M.
244-- TODO - Maybe combine name and shortcut - 'name,s'. Make it generic, add aliases to. Any that are single characters can be shortcuts.
245newParam = function (module, name, required, shortcut, default, help, acl, boss)
246 module[name] = default
247 ThingSpace.parameters[name] = {module = module, name = name, required = required, shortcut = shortcut, default = default, help = help, acl = acl, boss = boss, }
248 setmetatable(ThingSpace.parameters[name], Thing)
249 print(name .. ' -> ' .. shortcut .. ' -> ' .. help)
250end
251
252--[[ TODO - It might be worth it to combine parameters and commands, since in Lua, functions are first class types like numbers and strings. 234--[[ TODO - It might be worth it to combine parameters and commands, since in Lua, functions are first class types like numbers and strings.
253 Merging widgets might work to. B-) 235 Merging widgets might work to. B-)
236 This does make the entire "Things with the same name link automatically" deal work easily, since they ARE the same Thing.
254 237
255 Parameter gets a type, which might help since Lua is untyped, versus Java being strongly typed. 238 Parameter gets a type, which might help since Lua is untyped, versus Java being strongly typed.
256 Widgets get a type as well, which would be label, button, edit, grid, etc. 239 Widgets get a type as well, which would be label, button, edit, grid, etc.
@@ -263,29 +246,75 @@ end
263 Default being a function makes this Thing a command. 246 Default being a function makes this Thing a command.
264 Default for a widget could be the default creation arguments - '"Press me", 1, 1, 10, 50' 247 Default for a widget could be the default creation arguments - '"Press me", 1, 1, 10, 50'
265 248
266 Or we could merge the other way - 249 skang.newThing(_M, 'foo,s,fooAlias', 'string', 'Nope', '"button", "The foo :"' 1, 1, 10, 50', 'Default', function () print(_M.foo) end, 'Foo is a bar, not the drinking type.')
267 Each Thing has names (including shortcuts and aliases), type, required, widget default arguments, default value, function, help text. 250 myButton = skang.widget('foo') -- Gets the default widget creation arguments.
268 This does make the entire "Things with the same name link automatically" deal work easily, since they ARE the same Thing. 251 myButton:colour(1, 2, 3, 4)
269 skang.newThing(_M, 'foo,s,fooAlias', 'string', 'Nope', '"button", "The foo :"' 1, 1, 10, 50', 'Default', function () print(_M.foo) end, 'Foo is a bar, not the drinking type.') 252 myEditor = skang.widget('foo', "edit", "Edit foo :", 5, 15, 10, 100)
270 myButton = skang.widget('foo') -- Gets the default widget creation arguments. 253 myEditor:colour(1, 2, 3, 4, 5, 6, 7, 8)
271 myButton:colour(1, 2, 3, 4) 254 myButton = 'Not default' -- myEditor and _M.foo change to.
272 myEditor = skang.widget('foo', "edit", "Edit foo :", 5, 15, 10, 100) 255 -- Though the 'quit' Thing could have a function that does quitting, this is just an example of NOT linking to a Thing.
273 myEditor:colour(1, 2, 3, 4, 5, 6, 7, 8) 256 -- If we had linked to this theoretical 'quit' Thing, then pushing that Quit button would invoke it's Thing function.
274 myButton = 'Not default' -- myEditor and _M.foo change to. 257 quitter = skang.widget(nil, 'button', 'Quit', 0.5, 0.5, 0.5, 0.5)
275 -- Though the 'quit' Thing could have a function that does quitting, this is just an example of NOT linking to a Thing. 258 quitter:action('quit')
276 -- If we had linked to this theoretical 'quit' Thing, then pushing that Quit button would invoke it's Thing function.
277 quitter = skang.widget(nil, 'button', 'Quit', 0.5, 0.5, 0.5, 0.5)
278 quitter:action('quit')
279]] 259]]
280 260
281-- skang.newCommand stashes the function into _M['func'], and stashes it all (including the function) into ThingSpace.commands['func'].
282newCommand = function (module, name, types, help, func, acl, boss)
283 module[name] = func
284 ThingSpace.commands[name] = {module = module, name = name, help = help, func = func, acl = acl, boss = boss, }
285 setmetatable(ThingSpace.commands[name], Thing)
286 print(name .. '(' .. types .. ') -> ' .. help)
287end
288 261
262-- skang.newThing stashes the default value into _M['bar'], and the details into ThingSpace.things['bar'].
263-- TODO - If it's not required, and there's no default, then skip setting _M['bar'].
264-- TODO - Could even use __index to skip setting it if it's not required and there is a default.
265-- TODO - if default is a function, or a pre existing module[name] is a function, then set the Thing .func to that function.
266-- TODO - Users might want to use two or more copies of this module. Keep that in mind. local a = require 'test', b = require 'test' might handle that though?
267-- Not unless skang.newParam() knows about a and b, which it wont.
268-- Both a and b get the same table, not different copies of it.
269-- Perhaps clone the table if it exists? There is no Lua table cloner, would have to write one. Only clone the parameters, the rest can be linked back to the original.
270-- Then we have to deal with widgets linking to specific clones.
271-- Actually, not sure matrix-RAD solved that either. lol
272-- TODO - This could even be done with an array of these arguments, not including the _M.
273
274-- names - a comma seperated list of names, aliasas, and shortcuts. The first one is the official name.
275-- help - help text describing this Thing.
276-- default - the default value. This could be a funcion, making this a command.
277-- 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 functions.
278-- widget - default widget command arguments for creating this Thing as a widget.
279-- required - "boolean" to say if this thing is required. TODO - Maybe fold this into types somehow, or acl?
280-- acl - Access Control List defining security restrains.
281-- boss - the Thing or person that owns this Thing, otherwise it is self owned.
282thing = function (module, names, help, default, types, widget, required, acl, boss)
283 -- Break out the names.
284 local n = {}
285 local i = 1
286 for v in string.gmatch(names, '([^,]+)') do
287 n[i] = v
288 i = i + 1
289 end
290 local name = n[1]
291
292 -- Find type, default to string, then break out the other types.
293 local t = {type(default)}
294 if 'nil' == t[1] then t[1] = 'string' end
295 i = 2
296 if types then
297 for v in string.gmatch(types, '([^,]+)') do
298 t[i] = v
299 i = i + 1
300 end
301 else
302 types = ''
303 end
304
305 -- Set it all up.
306 module[name] = default
307 ThingSpace.things[name] = {module = module, names = n, help = help, default = default, types = t, widget = widget, required = required, acl = acl, boss = boss, }
308 setmetatable(ThingSpace.things[name], Thing)
309 if 'function' == t[1] then
310 ThingSpace.things[name].func = default
311 ThingSpace.commands[name] = ThingSpace.things[name]
312 print(name .. '(' .. types .. ') -> ' .. help)
313 else
314 ThingSpace.parameters[name] = ThingSpace.things[name]
315 print(t[1] .. ' ' .. name .. ' -> ' .. help)
316 end
317end
289 318
290-- TODO - Some function stubs, for now. Fill them up later. 319-- TODO - Some function stubs, for now. Fill them up later.
291get = function (name) 320get = function (name)
@@ -305,13 +334,13 @@ end
305quit = function () 334quit = function ()
306end 335end
307 336
308newCommand(_M, 'get', 'name', 'Get the current value of an existing thing.', get) -- This should be in Thing, not actually here? 337thing(_M, 'get', 'Get the current value of an existing thing.', get, 'name') -- This should be in Thing, not actually here?
309newCommand(_M, 'set', 'name,data', 'Set the current value of an existing Thing.', set) -- This should be in Thing, not actually here? 338thing(_M, 'set', 'Set the current value of an existing Thing.', set, 'name,data') -- This should be in Thing, not actually here?
310newCommand(_M, 'clear', '', 'The current skin is cleared of all widgets.', clear) -- Was in SkangAWT in Java. 339thing(_M, 'clear', 'The current skin is cleared of all widgets.', clear)
311newCommand(_M, 'window', 'x,y,name', 'Specifies the size and title of the application Frame.', window, 'GGG') -- Was in SkangAWT in Java. 340thing(_M, 'window', 'The size and title of the application Frame.', window, 'x,y,name', nil, nil, 'GGG')
312newCommand(_M, 'module', 'file,acl', 'Load a module.', module) 341thing(_M, 'module', 'Load a module.', module, 'file,acl')
313newCommand(_M, 'skang', 'URL', 'Parse the contents of a skang file or URL.', skang) 342thing(_M, 'skang', 'Parse the contents of a skang file or URL.', skang, 'URL')
314newCommand(_M, 'quit', '', 'Quit, exit, remove thyself.', quit) 343thing(_M, 'quit', 'Quit, exit, remove thyself.', quit)
315 344
316 345
317moduleEnd(_M) 346moduleEnd(_M)
diff --git a/ClientHamr/GuiLua/test.lua b/ClientHamr/GuiLua/test.lua
index 6518de8..525e66b 100644
--- a/ClientHamr/GuiLua/test.lua
+++ b/ClientHamr/GuiLua/test.lua
@@ -30,16 +30,15 @@ print('code')
30-- A variable that is private to this module. 30-- A variable that is private to this module.
31local foo 31local foo
32 32
33skang.newParam(_M, 'bar', "Required", "Shortcut", "Default", "Help text") 33skang.thing(_M, 'fooble,f', 'Help text goes here', 1, nil, '"edit", "The fooble:", 1, 1, 10, 50')
34skang.thing(_M, 'bar', 'Help text', "Default")
34 35
35-- We can use inline functions if we don't need the function internally. 36-- We can use inline functions if we don't need the function internally.
36skang.newCommand(_M, 'func', 'number,data', 'Help Text', function (arg1, arg2) 37skang.thing(_M, 'func', 'Help Text', function (arg1, arg2)
37 print('Inside test.func ' .. arg1 .. ', ' .. arg2) 38 print('Inside test.func ' .. arg1 .. ', ' .. arg2)
38end) 39end, 'number,string')
39
40 40
41print('Ending soon') 41print('Ending soon')
42
43skang.moduleEnd(_M) 42skang.moduleEnd(_M)
44 43
45end 44end
@@ -50,5 +49,6 @@ local skang = require 'skang'
50local test = require 'test' 49local test = require 'test'
51print('End ' .. test.bar .. ' ' .. test.VERSION .. ' ' .. skang.ThingSpace.commands.func.help) 50print('End ' .. test.bar .. ' ' .. test.VERSION .. ' ' .. skang.ThingSpace.commands.func.help)
52test.func('one', 2) 51test.func('one', 2)
52skang.ThingSpace.things.func('seven', 'aight')
53skang.ThingSpace.commands.func.func(3, 'four') 53skang.ThingSpace.commands.func.func(3, 'four')
54skang.ThingSpace.commands.func('five', 'six') 54skang.ThingSpace.commands.func('five', 'six')