diff options
author | David Walter Seikel | 2014-03-20 16:21:16 +1000 |
---|---|---|
committer | David Walter Seikel | 2014-03-20 16:21:16 +1000 |
commit | d7d879959b5402a8cae836b8c8285f38d9414f6e (patch) | |
tree | a276bc1c63ecbdb823051ffb1e5c874a18249d28 | |
parent | Rejig stubs a little. (diff) | |
download | SledjHamr-d7d879959b5402a8cae836b8c8285f38d9414f6e.zip SledjHamr-d7d879959b5402a8cae836b8c8285f38d9414f6e.tar.gz SledjHamr-d7d879959b5402a8cae836b8c8285f38d9414f6e.tar.bz2 SledjHamr-d7d879959b5402a8cae836b8c8285f38d9414f6e.tar.xz |
First hack at Thing.
-rw-r--r-- | ClientHamr/GuiLua/GuiLua.c | 105 | ||||
-rw-r--r-- | ClientHamr/GuiLua/skang.lua | 85 | ||||
-rw-r--r-- | ClientHamr/GuiLua/test.lua | 1 |
3 files changed, 112 insertions, 79 deletions
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. | |||
34 | 34 | ||
35 | NOTES and TODOs - | 35 | NOTES and TODOs - |
36 | 36 | ||
37 | Making these packages all a sub package of skang seems like a great idea. | 37 | Making these packages all a sub package of skang seems like a great |
38 | idea. On the other hand, looks like most things are just getting folded | ||
39 | into skang anyway. See | ||
40 | http://www.inf.puc-rio.br/~roberto/pil2/chapter15.pdf part 15.5 for | ||
41 | package details. | ||
38 | 42 | ||
39 | See if I can use LuaJIT FFI here. Since this will be a library, and | 43 | See if I can use LuaJIT FFI here. Since this will be a library, and |
40 | skang apps could be written in C or Lua, perhaps writing this library to | 44 | 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-) | |||
76 | */ | 80 | */ |
77 | 81 | ||
78 | 82 | ||
79 | /* coordinates and sizes | ||
80 | |||
81 | Originally skang differentiated between pixels and character cells, | ||
82 | using plain integers to represent pixels, and _123 to represent | ||
83 | character cells. The skang TODO wanted to expand that to percentages | ||
84 | and relative numbers. We can't use _123 in Lua, so some other method | ||
85 | needs to be used. Should include those TODO items in this new design. | ||
86 | |||
87 | Specifying character cells should be done as strings - "123" | ||
88 | |||
89 | Percentages can be done as small floating point numbers between 0 and 1, | ||
90 | which is similar to Edje. Since Lua only has a floating point number | ||
91 | type, both 0 and 1 should still represent pixels / character cells - | ||
92 | |||
93 | 0.1, 0.5, "0.2", "0.9" | ||
94 | |||
95 | Relative numbers could be done as strings, with the widget to be | ||
96 | relative to, a + or -, then the number. This still leaves the problem | ||
97 | of telling if the number is pixels or character cells. Also, relative | ||
98 | to what part of the other widget? Some more thought needs to be put | ||
99 | into this. | ||
100 | |||
101 | */ | ||
102 | |||
103 | |||
104 | /* thing package | 83 | /* thing package |
105 | 84 | ||
106 | matrix-RAD had Thing as the base class of everything. Lua doesn't have | 85 | Currently this is in skang.lua, but should bring this in here later. |
107 | inheritance as such, but an inheritance structure can be built using | ||
108 | Lua's meta language capabilities. I think we still need this sort of | ||
109 | thing. Java inheritance and interfaces where used. There's quite a few | ||
110 | variations of OO support has been written for Lua, maybe some of that | ||
111 | could be used? http://lua-users.org/wiki/ObjectOrientedProgramming | ||
112 | |||
113 | Other useful links - | ||
114 | |||
115 | http://lua-users.org/wiki/ClassesViaModules (not in the above for some reason. | ||
116 | http://lua-users.org/wiki/MetamethodsTutorial | ||
117 | http://lua-users.org/wiki/MetatableEvents | ||
118 | |||
119 | http://lua-users.org/wiki/MechanismNotPolicy | ||
120 | http://www.inf.puc-rio.br/~roberto/pil2/chapter15.pdf | ||
121 | http://lua-users.org/lists/lua-l/2011-10/msg00485.html | ||
122 | http://lua-users.org/wiki/LuaModuleFunctionCritiqued | ||
123 | |||
124 | On the other hand, Thing as such might just vanish and merge into | ||
125 | various Lua and metatable things. Seems that's what is going on. We | ||
126 | didn't really need much OO beyond this anyway. | ||
127 | |||
128 | Each "users session" (matrix-RAD term that came from Java | ||
129 | applets/servlets) has a ThingSpace, which is a tree that holds | ||
130 | everything else. It holds the class cache, commands, loaded modules, | ||
131 | variables and their values, widgets and their states. In matrix-RAD I | ||
132 | built BonsiaTree and LeafLike, for the old FDO system I built dumbtrees. | ||
133 | Perhaps some combination of the two will work here? On the other hand, | ||
134 | with Lua tables, who needs trees? lol | ||
135 | 86 | ||
136 | Get/set variables would be done here, though the widget package, for | 87 | */ |
137 | instance, would override this to deal with the UI side, and call the | ||
138 | parents function to deal with the variable side - | ||
139 | 88 | ||
140 | foo:set('stuff') | ||
141 | bar = foo:get() | ||
142 | 89 | ||
143 | Also, since skang Lua scripts should be defined as modules, we can use | 90 | /* skang package |
144 | module semantics - | ||
145 | 91 | ||
146 | local other = require('otherPackageName') | 92 | Currently this is in skang.lua, but should bring this in here later. |
147 | other.foo = 'stuff' | ||
148 | bar = other.foo | ||
149 | 93 | ||
150 | */ | 94 | */ |
151 | 95 | ||
@@ -162,13 +106,6 @@ database stuff for now, but should keep it in mind. | |||
162 | */ | 106 | */ |
163 | 107 | ||
164 | 108 | ||
165 | /* skang package | ||
166 | |||
167 | Currently this is in skang.lua, but should bring this in here later. | ||
168 | |||
169 | */ | ||
170 | |||
171 | |||
172 | /* widget package | 109 | /* widget package |
173 | 110 | ||
174 | Should include functions for actually dealing with widgets, plus a way | 111 | Should include functions for actually dealing with widgets, plus a way |
@@ -199,6 +136,30 @@ this.bar = 'new first choice' .. this.bar | |||
199 | */ | 136 | */ |
200 | 137 | ||
201 | 138 | ||
139 | /* coordinates and sizes | ||
140 | |||
141 | Originally skang differentiated between pixels and character cells, | ||
142 | using plain integers to represent pixels, and _123 to represent | ||
143 | character cells. The skang TODO wanted to expand that to percentages | ||
144 | and relative numbers. We can't use _123 in Lua, so some other method | ||
145 | needs to be used. Should include those TODO items in this new design. | ||
146 | |||
147 | Specifying character cells should be done as strings - "123" | ||
148 | |||
149 | Percentages can be done as small floating point numbers between 0 and 1, | ||
150 | which is similar to Edje. Since Lua only has a floating point number | ||
151 | type, both 0 and 1 should still represent pixels / character cells - | ||
152 | |||
153 | 0.1, 0.5, "0.2", "0.9" | ||
154 | |||
155 | Relative numbers could be done as strings, with the widget to be | ||
156 | relative to, a + or -, then the number. This still leaves the problem | ||
157 | of telling if the number is pixels or character cells. Also, relative | ||
158 | to what part of the other widget? Some more thought needs to be put | ||
159 | into this. | ||
160 | |||
161 | */ | ||
162 | |||
202 | 163 | ||
203 | /* introspection | 164 | /* introspection |
204 | 165 | ||
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 @@ | |||
1 | -- TODO - This should be in C, but so far development has been quite rapid doing it in Lua. | 1 | -- TODO - This should be in C, but so far development has been quite rapid doing it in Lua. |
2 | --[[ | 2 | --[[ |
3 | |||
4 | --[[ Skang package | ||
5 | |||
3 | In here should live all the internals of matrix-RAD that don't | 6 | In here should live all the internals of matrix-RAD that don't |
4 | specifically relate to widgets. This would include the "window" though. | 7 | specifically relate to widgets. This would include the "window" though. |
5 | 8 | ||
@@ -116,19 +119,92 @@ end | |||
116 | -- Call this now, via the above wrapper, so that from now on, this is like any other module. | 119 | -- Call this now, via the above wrapper, so that from now on, this is like any other module. |
117 | local _M = smb('skang', 'David Seikel', '2014', '0.0', '2014-03-19 19:01:00') | 120 | local _M = smb('skang', 'David Seikel', '2014', '0.0', '2014-03-19 19:01:00') |
118 | 121 | ||
122 | --[[ Thing package | ||
123 | |||
124 | matrix-RAD had Thing as the base class of everything. Lua doesn't have | ||
125 | inheritance as such, but an inheritance structure can be built using | ||
126 | Lua's meta language capabilities. I think we still need this sort of | ||
127 | thing. Java inheritance and interfaces where used. There's quite a few | ||
128 | variations of OO support has been written for Lua, maybe some of that | ||
129 | could be used? http://lua-users.org/wiki/ObjectOrientedProgramming | ||
130 | |||
131 | Other useful links - | ||
132 | |||
133 | http://lua-users.org/wiki/ClassesViaModules (not in the above for some reason. | ||
134 | http://lua-users.org/wiki/MetamethodsTutorial | ||
135 | http://lua-users.org/wiki/MetatableEvents | ||
136 | |||
137 | http://lua-users.org/wiki/MechanismNotPolicy | ||
138 | http://www.inf.puc-rio.br/~roberto/pil2/chapter15.pdf | ||
139 | http://lua-users.org/lists/lua-l/2011-10/msg00485.html | ||
140 | http://lua-users.org/wiki/LuaModuleFunctionCritiqued | ||
141 | |||
142 | On the other hand, Thing as such might just vanish and merge into | ||
143 | various Lua and metatable things. Seems that's what is going on. We | ||
144 | didn't really need much OO beyond this anyway. | ||
145 | |||
146 | Each "users session" (matrix-RAD term that came from Java | ||
147 | applets/servlets) has a ThingSpace, which is a tree that holds | ||
148 | everything else. It holds the class cache, commands, loaded modules, | ||
149 | variables and their values, widgets and their states. In matrix-RAD I | ||
150 | built BonsiaTree and LeafLike, for the old FDO system I built dumbtrees. | ||
151 | Perhaps some combination of the two will work here? On the other hand, | ||
152 | with Lua tables, who needs trees? lol | ||
153 | |||
154 | Get/set variables would be done here, though the widget package, for | ||
155 | instance, would override this to deal with the UI side, and call the | ||
156 | parents function to deal with the variable side - | ||
157 | |||
158 | foo:set('stuff') | ||
159 | bar = foo:get() | ||
160 | |||
161 | Also, since skang Lua scripts should be defined as modules, we can use | ||
162 | module semantics - | ||
163 | |||
164 | local other = require('otherPackageName') | ||
165 | other.foo = 'stuff' | ||
166 | bar = other.foo | ||
167 | ]] | ||
168 | |||
119 | ThingSpace = {} | 169 | ThingSpace = {} |
120 | ThingSpace.cache = {} | 170 | ThingSpace.cache = {} |
121 | ThingSpace.commands = {} | 171 | ThingSpace.commands = {} |
122 | ThingSpace.modules = {} | 172 | ThingSpace.modules = {} |
123 | ThingSpace.parameters = {} | 173 | ThingSpace.parameters = {} |
124 | ThingSpace.widgets = {} | 174 | ThingSpace.widgets = {} |
175 | |||
176 | Thing = | ||
177 | { | ||
178 | __index = function (table, key) | ||
179 | -- This only works for keys that don't exist. By definition a value of nil means it doesn't exist. | ||
180 | return ThingSpace.parameters[key].default | ||
181 | end, | ||
182 | |||
183 | __newindex = function (table, key, value) | ||
184 | -- TODO - maybe if this is trying to set a command to a non function value, bitch and don't do it? | ||
185 | rawset(table, key, value) | ||
186 | local command = ThingSpace.commands[key] | ||
187 | -- TODO - If found, and value is a function, then command.func = value | ||
188 | local param = ThingSpace.parameters[key] | ||
189 | -- TODO - If found, go through it's linked things and set them to. | ||
190 | local widget = ThingSpace.widgets[key] | ||
191 | -- TODO - If found, go through it's linked things and set them to. | ||
192 | end, | ||
193 | |||
194 | __call = function (func, ...) | ||
195 | return func.func(...) | ||
196 | end, | ||
197 | } | ||
198 | |||
125 | -- Actually stuff ourself into ThingSpace. | 199 | -- Actually stuff ourself into ThingSpace. |
126 | ThingSpace.modules[_NAME] = {module = _M, name = _NAME, } | 200 | ThingSpace.modules[_NAME] = {module = _M, name = _NAME, } |
201 | setmetatable(_M, {__index=Thing}) | ||
127 | 202 | ||
128 | -- This is the final version that we export. Finally we can include the ThingSpace stuff. | 203 | -- This is the final version that we export. Finally we can include the ThingSpace stuff. |
129 | moduleBegin = function (name, author, copyright, version, timestamp, skin) | 204 | moduleBegin = function (name, author, copyright, version, timestamp, skin) |
130 | local result = skangModuleBegin(name, author, copyright, version, timestamp, skin) | 205 | local result = skangModuleBegin(name, author, copyright, version, timestamp, skin) |
131 | ThingSpace.modules[name] = {module = result, name = name, } | 206 | ThingSpace.modules[name] = {module = result, name = name, } |
207 | setmetatable(result, {__index=Thing}) | ||
132 | return result | 208 | return result |
133 | end | 209 | end |
134 | 210 | ||
@@ -138,13 +214,6 @@ moduleEnd = function (module) | |||
138 | end | 214 | end |
139 | 215 | ||
140 | --[[ | 216 | --[[ |
141 | Thing = {} | ||
142 | Thing.__index = Thing -- So this can be used as the metatable for Things. | ||
143 | So in newParam and newCommand - | ||
144 | setmetatable(module, Thing) | ||
145 | ]] | ||
146 | |||
147 | |||
148 | 217 | ||
149 | -- skang.newParam stashes the default value into _M['bar'], and the details into ThingSpace.parameters['bar']. | 218 | -- skang.newParam stashes the default value into _M['bar'], and the details into ThingSpace.parameters['bar']. |
150 | -- TODO - If it's not required, and there's no default, then skip setting _M['bar']. | 219 | -- 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 - | |||
160 | newParam = function (module, name, required, shortcut, default, help, acl, boss) | 229 | newParam = function (module, name, required, shortcut, default, help, acl, boss) |
161 | module[name] = default | 230 | module[name] = default |
162 | ThingSpace.parameters[name] = {module = module, name = name, required = required, shortcut = shortcut, default = default, help = help, acl = acl, boss = boss, } | 231 | ThingSpace.parameters[name] = {module = module, name = name, required = required, shortcut = shortcut, default = default, help = help, acl = acl, boss = boss, } |
232 | setmetatable(ThingSpace.parameters[name], Thing) | ||
163 | print(name .. ' -> ' .. shortcut .. ' -> ' .. help) | 233 | print(name .. ' -> ' .. shortcut .. ' -> ' .. help) |
164 | end | 234 | end |
165 | 235 | ||
@@ -168,6 +238,7 @@ end | |||
168 | newCommand = function (module, name, types, help, func, acl, boss) | 238 | newCommand = function (module, name, types, help, func, acl, boss) |
169 | module[name] = func | 239 | module[name] = func |
170 | ThingSpace.commands[name] = {module = module, name = name, help = help, func = func, acl = acl, boss = boss, } | 240 | ThingSpace.commands[name] = {module = module, name = name, help = help, func = func, acl = acl, boss = boss, } |
241 | setmetatable(ThingSpace.commands[name], Thing) | ||
171 | print(name .. '(' .. types .. ') -> ' .. help) | 242 | print(name .. '(' .. types .. ') -> ' .. help) |
172 | end | 243 | end |
173 | 244 | ||
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' | |||
51 | print('End ' .. test.bar .. ' ' .. test.VERSION .. ' ' .. skang.ThingSpace.commands.func.help) | 51 | print('End ' .. test.bar .. ' ' .. test.VERSION .. ' ' .. skang.ThingSpace.commands.func.help) |
52 | test.func('one', 2) | 52 | test.func('one', 2) |
53 | skang.ThingSpace.commands.func.func(3, 'four') | 53 | skang.ThingSpace.commands.func.func(3, 'four') |
54 | skang.ThingSpace.commands.func('five', 'six') | ||