From d7d879959b5402a8cae836b8c8285f38d9414f6e Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Thu, 20 Mar 2014 16:21:16 +1000 Subject: First hack at Thing. --- ClientHamr/GuiLua/GuiLua.c | 105 ++++++++++++++------------------------------ ClientHamr/GuiLua/skang.lua | 85 ++++++++++++++++++++++++++++++++--- ClientHamr/GuiLua/test.lua | 1 + 3 files changed, 112 insertions(+), 79 deletions(-) (limited to 'ClientHamr/GuiLua') diff --git a/ClientHamr/GuiLua/GuiLua.c b/ClientHamr/GuiLua/GuiLua.c index befc582..94a29eb 100644 --- a/ClientHamr/GuiLua/GuiLua.c +++ b/ClientHamr/GuiLua/GuiLua.c @@ -34,7 +34,11 @@ scripts can have a poper GUI for a change. NOTES and TODOs - -Making these packages all a sub package of skang seems like a great idea. +Making these packages all a sub package of skang seems like a great +idea. On the other hand, looks like most things are just getting folded +into skang anyway. See +http://www.inf.puc-rio.br/~roberto/pil2/chapter15.pdf part 15.5 for +package details. See if I can use LuaJIT FFI here. Since this will be a library, and skang apps could be written in C or Lua, perhaps writing this library to @@ -76,76 +80,16 @@ we will be using Lua tables anyway. B-) */ -/* coordinates and sizes - -Originally skang differentiated between pixels and character cells, -using plain integers to represent pixels, and _123 to represent -character cells. The skang TODO wanted to expand that to percentages -and relative numbers. We can't use _123 in Lua, so some other method -needs to be used. Should include those TODO items in this new design. - -Specifying character cells should be done as strings - "123" - -Percentages can be done as small floating point numbers between 0 and 1, -which is similar to Edje. Since Lua only has a floating point number -type, both 0 and 1 should still represent pixels / character cells - - -0.1, 0.5, "0.2", "0.9" - -Relative numbers could be done as strings, with the widget to be -relative to, a + or -, then the number. This still leaves the problem -of telling if the number is pixels or character cells. Also, relative -to what part of the other widget? Some more thought needs to be put -into this. - -*/ - - /* thing package -matrix-RAD had Thing as the base class of everything. Lua doesn't have -inheritance as such, but an inheritance structure can be built using -Lua's meta language capabilities. I think we still need this sort of -thing. Java inheritance and interfaces where used. There's quite a few -variations of OO support has been written for Lua, maybe some of that -could be used? http://lua-users.org/wiki/ObjectOrientedProgramming - -Other useful links - - -http://lua-users.org/wiki/ClassesViaModules (not in the above for some reason. -http://lua-users.org/wiki/MetamethodsTutorial -http://lua-users.org/wiki/MetatableEvents - -http://lua-users.org/wiki/MechanismNotPolicy -http://www.inf.puc-rio.br/~roberto/pil2/chapter15.pdf -http://lua-users.org/lists/lua-l/2011-10/msg00485.html -http://lua-users.org/wiki/LuaModuleFunctionCritiqued - -On the other hand, Thing as such might just vanish and merge into -various Lua and metatable things. Seems that's what is going on. We -didn't really need much OO beyond this anyway. - -Each "users session" (matrix-RAD term that came from Java -applets/servlets) has a ThingSpace, which is a tree that holds -everything else. It holds the class cache, commands, loaded modules, -variables and their values, widgets and their states. In matrix-RAD I -built BonsiaTree and LeafLike, for the old FDO system I built dumbtrees. -Perhaps some combination of the two will work here? On the other hand, -with Lua tables, who needs trees? lol +Currently this is in skang.lua, but should bring this in here later. -Get/set variables would be done here, though the widget package, for -instance, would override this to deal with the UI side, and call the -parents function to deal with the variable side - +*/ -foo:set('stuff') -bar = foo:get() -Also, since skang Lua scripts should be defined as modules, we can use -module semantics - +/* skang package -local other = require('otherPackageName') -other.foo = 'stuff' -bar = other.foo +Currently this is in skang.lua, but should bring this in here later. */ @@ -162,13 +106,6 @@ database stuff for now, but should keep it in mind. */ -/* skang package - -Currently this is in skang.lua, but should bring this in here later. - -*/ - - /* widget package Should include functions for actually dealing with widgets, plus a way @@ -199,6 +136,30 @@ this.bar = 'new first choice' .. this.bar */ +/* coordinates and sizes + +Originally skang differentiated between pixels and character cells, +using plain integers to represent pixels, and _123 to represent +character cells. The skang TODO wanted to expand that to percentages +and relative numbers. We can't use _123 in Lua, so some other method +needs to be used. Should include those TODO items in this new design. + +Specifying character cells should be done as strings - "123" + +Percentages can be done as small floating point numbers between 0 and 1, +which is similar to Edje. Since Lua only has a floating point number +type, both 0 and 1 should still represent pixels / character cells - + +0.1, 0.5, "0.2", "0.9" + +Relative numbers could be done as strings, with the widget to be +relative to, a + or -, then the number. This still leaves the problem +of telling if the number is pixels or character cells. Also, relative +to what part of the other widget? Some more thought needs to be put +into this. + +*/ + /* introspection diff --git a/ClientHamr/GuiLua/skang.lua b/ClientHamr/GuiLua/skang.lua index 0c10389..dbbe19c 100644 --- a/ClientHamr/GuiLua/skang.lua +++ b/ClientHamr/GuiLua/skang.lua @@ -1,5 +1,8 @@ -- TODO - This should be in C, but so far development has been quite rapid doing it in Lua. --[[ + +--[[ Skang package + In here should live all the internals of matrix-RAD that don't specifically relate to widgets. This would include the "window" though. @@ -116,19 +119,92 @@ end -- Call this now, via the above wrapper, so that from now on, this is like any other module. local _M = smb('skang', 'David Seikel', '2014', '0.0', '2014-03-19 19:01:00') +--[[ Thing package + +matrix-RAD had Thing as the base class of everything. Lua doesn't have +inheritance as such, but an inheritance structure can be built using +Lua's meta language capabilities. I think we still need this sort of +thing. Java inheritance and interfaces where used. There's quite a few +variations of OO support has been written for Lua, maybe some of that +could be used? http://lua-users.org/wiki/ObjectOrientedProgramming + +Other useful links - + +http://lua-users.org/wiki/ClassesViaModules (not in the above for some reason. +http://lua-users.org/wiki/MetamethodsTutorial +http://lua-users.org/wiki/MetatableEvents + +http://lua-users.org/wiki/MechanismNotPolicy +http://www.inf.puc-rio.br/~roberto/pil2/chapter15.pdf +http://lua-users.org/lists/lua-l/2011-10/msg00485.html +http://lua-users.org/wiki/LuaModuleFunctionCritiqued + +On the other hand, Thing as such might just vanish and merge into +various Lua and metatable things. Seems that's what is going on. We +didn't really need much OO beyond this anyway. + +Each "users session" (matrix-RAD term that came from Java +applets/servlets) has a ThingSpace, which is a tree that holds +everything else. It holds the class cache, commands, loaded modules, +variables and their values, widgets and their states. In matrix-RAD I +built BonsiaTree and LeafLike, for the old FDO system I built dumbtrees. +Perhaps some combination of the two will work here? On the other hand, +with Lua tables, who needs trees? lol + +Get/set variables would be done here, though the widget package, for +instance, would override this to deal with the UI side, and call the +parents function to deal with the variable side - + +foo:set('stuff') +bar = foo:get() + +Also, since skang Lua scripts should be defined as modules, we can use +module semantics - + +local other = require('otherPackageName') +other.foo = 'stuff' +bar = other.foo +]] + ThingSpace = {} ThingSpace.cache = {} ThingSpace.commands = {} ThingSpace.modules = {} ThingSpace.parameters = {} ThingSpace.widgets = {} + +Thing = +{ + __index = function (table, key) + -- This only works for keys that don't exist. By definition a value of nil means it doesn't exist. + return ThingSpace.parameters[key].default + end, + + __newindex = function (table, key, value) + -- TODO - maybe if this is trying to set a command to a non function value, bitch and don't do it? + rawset(table, key, value) + local command = ThingSpace.commands[key] + -- TODO - If found, and value is a function, then command.func = value + local param = ThingSpace.parameters[key] + -- TODO - If found, go through it's linked things and set them to. + local widget = ThingSpace.widgets[key] + -- TODO - If found, go through it's linked things and set them to. + end, + + __call = function (func, ...) + return func.func(...) + end, +} + -- Actually stuff ourself into ThingSpace. ThingSpace.modules[_NAME] = {module = _M, name = _NAME, } +setmetatable(_M, {__index=Thing}) -- This is the final version that we export. Finally we can include the ThingSpace stuff. moduleBegin = function (name, author, copyright, version, timestamp, skin) local result = skangModuleBegin(name, author, copyright, version, timestamp, skin) ThingSpace.modules[name] = {module = result, name = name, } + setmetatable(result, {__index=Thing}) return result end @@ -138,13 +214,6 @@ moduleEnd = function (module) end --[[ -Thing = {} -Thing.__index = Thing -- So this can be used as the metatable for Things. -So in newParam and newCommand - - setmetatable(module, Thing) -]] - - -- skang.newParam stashes the default value into _M['bar'], and the details into ThingSpace.parameters['bar']. -- TODO - If it's not required, and there's no default, then skip setting _M['bar']. @@ -160,6 +229,7 @@ So in newParam and newCommand - newParam = function (module, name, required, shortcut, default, help, acl, boss) module[name] = default ThingSpace.parameters[name] = {module = module, name = name, required = required, shortcut = shortcut, default = default, help = help, acl = acl, boss = boss, } + setmetatable(ThingSpace.parameters[name], Thing) print(name .. ' -> ' .. shortcut .. ' -> ' .. help) end @@ -168,6 +238,7 @@ end newCommand = function (module, name, types, help, func, acl, boss) module[name] = func ThingSpace.commands[name] = {module = module, name = name, help = help, func = func, acl = acl, boss = boss, } + setmetatable(ThingSpace.commands[name], Thing) print(name .. '(' .. types .. ') -> ' .. help) end diff --git a/ClientHamr/GuiLua/test.lua b/ClientHamr/GuiLua/test.lua index e1e2de8..6518de8 100644 --- a/ClientHamr/GuiLua/test.lua +++ b/ClientHamr/GuiLua/test.lua @@ -51,3 +51,4 @@ local test = require 'test' print('End ' .. test.bar .. ' ' .. test.VERSION .. ' ' .. skang.ThingSpace.commands.func.help) test.func('one', 2) skang.ThingSpace.commands.func.func(3, 'four') +skang.ThingSpace.commands.func('five', 'six') -- cgit v1.1