diff options
author | David Walter Seikel | 2014-03-19 12:39:35 +1000 |
---|---|---|
committer | David Walter Seikel | 2014-03-19 12:39:35 +1000 |
commit | 524473f881d6b89bf85f7d5e2bd7b19a5a8ab18a (patch) | |
tree | 659efe693807166b7ed774f3b7a7e476b6617efd | |
parent | More design notes. (diff) | |
download | SledjHamr-524473f881d6b89bf85f7d5e2bd7b19a5a8ab18a.zip SledjHamr-524473f881d6b89bf85f7d5e2bd7b19a5a8ab18a.tar.gz SledjHamr-524473f881d6b89bf85f7d5e2bd7b19a5a8ab18a.tar.bz2 SledjHamr-524473f881d6b89bf85f7d5e2bd7b19a5a8ab18a.tar.xz |
Added some GuiLua test source files, and lots of comments in GuiLua.c.
-rw-r--r-- | ClientHamr/GuiLua/GuiLua.c | 272 | ||||
-rw-r--r-- | ClientHamr/GuiLua/test.c | 19 | ||||
-rw-r--r-- | ClientHamr/GuiLua/test.lua | 15 | ||||
-rw-r--r-- | ClientHamr/GuiLua/test.skang | 12 |
4 files changed, 318 insertions, 0 deletions
diff --git a/ClientHamr/GuiLua/GuiLua.c b/ClientHamr/GuiLua/GuiLua.c new file mode 100644 index 0000000..3086889 --- /dev/null +++ b/ClientHamr/GuiLua/GuiLua.c | |||
@@ -0,0 +1,272 @@ | |||
1 | /* GuiLua - a GUI library that implements matrix-RAD style stuff. | ||
2 | |||
3 | Provides the skang and widget Lua packages. | ||
4 | |||
5 | This should be a library in the end, but for now it's just an | ||
6 | application that is a test bed for what goes into the library. In the | ||
7 | initial intended use case, several applications will be using this all at | ||
8 | once, with one central app hosting all the GUIs. | ||
9 | |||
10 | Basically this should deal with "windows" and their contents. A | ||
11 | "window" in this case is hosted in the central app as some sort of | ||
12 | internal window, but the user can "tear off" those windows, then they | ||
13 | get their own OS hosted window. This could be done by the hosting app | ||
14 | sending the current window contents to the original app as a skang file. | ||
15 | |||
16 | Between the actual GUI and the app might be a socket, or a stdin/out | ||
17 | pipe. Just like matrix-RAD, this should be transparent to the app. | ||
18 | Also just like matrix-RAD, widgets can be connected to variable / | ||
19 | functions (C or Lua), and any twiddlings with those widgets runs the | ||
20 | function / changes the variable, again transparent to the app, except | ||
21 | for any registered get/set methods. | ||
22 | |||
23 | This interface between the GUI and the app is "skang" files, which are | ||
24 | basically Lua scripts. The GUI and the app can send skang files back | ||
25 | and forth, usually the app sends actual GUI stuff, and usually the GUI | ||
26 | sends variable twiddles or action calls. Usually. | ||
27 | |||
28 | To start with, this will be used to support multiple apps hosting their | ||
29 | windows in extantz, allowing the big viewer blob to be split up into | ||
30 | modules. At some point converting LL XML based UI shit into skang could | ||
31 | be done. Also, this should be an exntension to LuaSL, so in-world | ||
32 | scripts can have a poper GUI for a change. | ||
33 | |||
34 | |||
35 | NOTES and TODOs - | ||
36 | |||
37 | See if I can use LuaJIT FFI here. Since this will be a library, and | ||
38 | skang apps could be writte nin C or Lua, perhaps writing this library to | ||
39 | be FFI friendly instead of the usual Lua C binding might be the way to | ||
40 | go? | ||
41 | |||
42 | For the "GUI hosted in another app" case, we will need some sort of | ||
43 | internal window manager running in that other app. | ||
44 | |||
45 | This might end up running dozens of Lua scripts, and could use the LuaSL | ||
46 | Lua script running system. Moving that into this library might be a | ||
47 | sane idea I think? Or prehaps a separate library that both LuaSL and | ||
48 | GuiLua use? | ||
49 | |||
50 | Raster wants a method of sending Lua tables around as edje messages. | ||
51 | Between C, Edje, Edje Lua, and Lua. Sending between threads, and across | ||
52 | sockets. Using a new edje message type, or eet for sockets, was | ||
53 | suggested, but perhaps Lua skang is a better choice? | ||
54 | |||
55 | Somehow access to the edje_lua2.c bindings should be provided. And | ||
56 | bindings to the rest of EFL when they are done. Assuming the other EFL | ||
57 | developers do proper introspection stuff, or let me do it. | ||
58 | |||
59 | The generic Lua binding helper functions I wrote for edje?lua2.c could | ||
60 | be used here as well, and expanded as discussed on the E devs mailing | ||
61 | list. This would include the thread safe Lua function stuff copied | ||
62 | into the README. | ||
63 | |||
64 | There will eventually be a built in editor, like the zen editor from | ||
65 | matrix-RAD. It might be a separate app. | ||
66 | |||
67 | NAWS should probably live in here to. If I ever get around to writing | ||
68 | it. lol | ||
69 | |||
70 | The pre tokenized widget structure thingy I had planned in the | ||
71 | matrix-RAD TODO just wont work, as it uses symbols. On the other hand, | ||
72 | we will be using Lua tables anyway. B-) | ||
73 | |||
74 | */ | ||
75 | |||
76 | |||
77 | /* coordinates and sizes | ||
78 | |||
79 | Originally skang differentiated between pixels and character cells, | ||
80 | using plain integers to represent pixels, and _123 to represent | ||
81 | character cells. The skang TODO wanted to expand that to percentages | ||
82 | and relative numbers. We can't use _123 in Lua, so some other method | ||
83 | needs to be used. Should include those TODO items in this new design. | ||
84 | |||
85 | Specifying character cells should be done as strings - "123" | ||
86 | |||
87 | Percentages can be done as small floating point numbers between 0 and 1, | ||
88 | which is similar to Edje. Since Lua only has a floating point number | ||
89 | type, both 0 and 1 should still represent pixels / character cells - | ||
90 | |||
91 | 0.1, 0.5, "0.2", "0.9" | ||
92 | |||
93 | Relative numbers could be done as strings, with the widget to be | ||
94 | relative to, a + or -, then the number. This still leaves the problem | ||
95 | of telling if the number is pixels or character cells. Also, relative | ||
96 | to what part of the other widget? Some more thought needs to be put | ||
97 | into this. | ||
98 | |||
99 | */ | ||
100 | |||
101 | |||
102 | /* thing package | ||
103 | |||
104 | matrix-RAD had Thing as the base class of everything. Lua doesn't have | ||
105 | inheritance as such, but an inheritance structure can be built using | ||
106 | Lua's meta language capabilities. I think we still need this sort of | ||
107 | thing. Java inheritance and interfaces where used. There's quite a few | ||
108 | variations of OO support has been written for Lua, maybe some of that | ||
109 | could be used? http://lua-users.org/wiki/ObjectOrientedProgramming | ||
110 | |||
111 | Each "users session" (matrix-RAD term that came from Java | ||
112 | applets/servlets) has a ThingSpace, which is a tree that holds | ||
113 | everything else. It holds the class cache, commands, loaded modules, | ||
114 | variables and their values, widgets and their states. In matrix-RAD I | ||
115 | built BonsiaTree and LeafLike, for the old FDO system I built dumbtrees. | ||
116 | Perhaps some combination of the two will work here? | ||
117 | |||
118 | Get/set variables would be done here, though the widget package, for | ||
119 | instance, would override this to deal with the UI side, and call the | ||
120 | parents function to deal with the variable side - | ||
121 | |||
122 | foo:set('stuff') | ||
123 | bar = foo:get() | ||
124 | |||
125 | Also, since skang Lua scripts should be defined as modules, we can use | ||
126 | module semantics - | ||
127 | |||
128 | local other = require('otherPackageName') | ||
129 | other.foo = 'stuff' | ||
130 | bar = other.foo | ||
131 | |||
132 | */ | ||
133 | |||
134 | |||
135 | /* stuff & squeal packages | ||
136 | |||
137 | In matrix-RAD Stuff took care of multi value Things, like database rows. | ||
138 | I'm not sure this is needed here, since Lua has nice tables. B-) | ||
139 | |||
140 | Squeal was the database driver interface for SquealStuff, the database | ||
141 | version of Stuff. Maybe we could wrap esskyuehl? Not really in need of | ||
142 | database stuff for now, but should keep it in mind. | ||
143 | |||
144 | */ | ||
145 | |||
146 | |||
147 | /* skang package | ||
148 | |||
149 | In here should live all the internals of matrix-RAD that don't | ||
150 | specifically relate to widgets. This would include the "window" though. | ||
151 | |||
152 | skang.module(Evas) | ||
153 | skang.module(Elementary) | ||
154 | skang.load('some/skang/file.skang') | ||
155 | |||
156 | This package is also what "apps" that use the system should "inherit" | ||
157 | from, in the same way matrix-RAD apps did. Skang "apps" could be Lua | ||
158 | modules. They could also be C code, like the extantz modules are likely | ||
159 | to be. Skang "apps" would automatically be associated with skang files | ||
160 | of the same name. So a Lua skang "app" could look like this - | ||
161 | |||
162 | local skang = require('skang') | ||
163 | local result = {}; | ||
164 | result.author = 'onefang' | ||
165 | result.version = '0.72 alpha 2004-11-19 16:28:00' | ||
166 | local bar | ||
167 | -- The first argument would be the name of a local variable / method. Which could be accessed via _G? | ||
168 | -- Not sure if we could use a global bar, AND use it directly. | ||
169 | result.bar = skang.newParam('bar', "Required", "Shortcut", "Default", "Help text") | ||
170 | result.func = skang.newCommand('arg1_type,arg2_type', 'Help Text', function (arg1, arg2) | ||
171 | ... do something here ... | ||
172 | end) | ||
173 | |||
174 | ... do something here ... | ||
175 | |||
176 | return result; | ||
177 | |||
178 | |||
179 | A basic skang file could look like this - | ||
180 | |||
181 | #!skang myApp.skang | ||
182 | -- There's an implied local this = require('myApp') | ||
183 | -- There's an implied local skang = require('skang') | ||
184 | local widget = require('EvasWidgets') | ||
185 | local other = require('otherPackageName') | ||
186 | skang.clear | ||
187 | skang.window(200, 200, "G'day planet.") | ||
188 | quitter = widget.button('Quit', 0.5, 0.5, 0.5, 0.5) | ||
189 | quitter:action('quit') -- 'quit' is looked up in ThingSpcae.commands, and translated into the Lua 'skang.quit()'. | ||
190 | other.foo = 'stuff' | ||
191 | this.bar = other.foo | ||
192 | this.func(1, 'two') | ||
193 | |||
194 | The skang command (written in C) would strip off the first line, add the | ||
195 | two implied lines, then run it as Lua. The skang.load() command would | ||
196 | do the same. So that skang C comand would just pass the file name to | ||
197 | skang.load() in this library. B-) | ||
198 | |||
199 | |||
200 | The old skang argument types are - | ||
201 | |||
202 | {"name", "java.lang.String"}, | ||
203 | {"action", "java.lang.String"}, | ||
204 | {"type", "java.lang.String"}, | ||
205 | {"data", "java.lang.String"}, | ||
206 | {"URL", "java.lang.String"}, | ||
207 | {"file", "java.lang.String"}, | ||
208 | {"method", "java.lang.String"}, | ||
209 | {"lx", "java.lang.String"}, | ||
210 | {"ly", "java.lang.String"}, | ||
211 | {"lw", "java.lang.String"}, | ||
212 | {"lh", "java.lang.String"}, | ||
213 | {"normal", "java.lang.String"}, | ||
214 | {"ghost", "java.lang.String"}, | ||
215 | {"active", "java.lang.String"}, | ||
216 | {"toggle", "java.lang.String"}, | ||
217 | {"boolean","java.lang.Boolean"}, | ||
218 | {"number", "java.lang.Integer"}, | ||
219 | {"int", "java.lang.Integer"}, | ||
220 | {"x", "java.lang.Integer"}, | ||
221 | {"y", "java.lang.Integer"}, | ||
222 | {"w", "java.lang.Integer"}, | ||
223 | {"h", "java.lang.Integer"}, | ||
224 | {"r", "java.lang.Integer"}, | ||
225 | {"g", "java.lang.Integer"}, | ||
226 | {"b", "java.lang.Integer"}, | ||
227 | {"alpha", "java.lang.Integer"}, | ||
228 | {"acl", "net.matrix_rad.security.ACL"}, | ||
229 | |||
230 | */ | ||
231 | |||
232 | |||
233 | /* widget package | ||
234 | |||
235 | Should include functions for actually dealing with widgets, plus a way | ||
236 | of creating widgets via introspection. Should also allow access to | ||
237 | widget internals via table access. Lua code could look like this - | ||
238 | |||
239 | foo = widget.label(0, "0.1", 0.5, 0, 'Text goes here :") | ||
240 | -- Method style. | ||
241 | foo:colour(255, 255, 255, 0, 0, 100, 255, 0) | ||
242 | foo:hide() | ||
243 | foo:action("skang.load(some/skang/file.skang)") | ||
244 | -- Table style. | ||
245 | foo.action = "skang.load('some/skang/file.skang')" | ||
246 | foo.colour.r = 123 | ||
247 | foo.look('some/edje/file/somewhere.edj') | ||
248 | foo.help = 'This is a widget for labelling some foo.' | ||
249 | |||
250 | For widgets with "rows", which was handled by Stuff in skang, we could | ||
251 | maybe use the Lua concat operator via metatable. I think that works by | ||
252 | having the widget (a table) on one side of the concat or the other, and | ||
253 | the metatable function gets passed left and right sides, then must | ||
254 | return the result. Needs some experimentation, but this might look like | ||
255 | this - | ||
256 | |||
257 | this.bar = this.bar .. 'new choice' | ||
258 | this.bar = 'new first choice' .. this.bar | ||
259 | |||
260 | */ | ||
261 | |||
262 | |||
263 | |||
264 | /* introspection | ||
265 | |||
266 | As detailed in README, EFL introspection doesn't seem to really be on | ||
267 | the radar, but I might get lucky, or I might have to write it myself. | ||
268 | For quick and dirty early testing, I'll probably write a widget package | ||
269 | that has hard coded mappings between some basic "label", "button", etc. | ||
270 | and ordinary elementary widgets. Proper introspection can come later. | ||
271 | |||
272 | */ | ||
diff --git a/ClientHamr/GuiLua/test.c b/ClientHamr/GuiLua/test.c new file mode 100644 index 0000000..12b5901 --- /dev/null +++ b/ClientHamr/GuiLua/test.c | |||
@@ -0,0 +1,19 @@ | |||
1 | /* Should be a Lua module, roughly the same as - | ||
2 | |||
3 | local skang = require('skang') | ||
4 | local result = {}; | ||
5 | result.author = 'onefang' | ||
6 | result.version = '0.72 alpha 2004-11-19 16:28:00' | ||
7 | local bar | ||
8 | -- The first argument would be the name of a local variable / method. Which could be accessed via _G? | ||
9 | -- Not sure if we could use a global bar, AND use it directly. | ||
10 | result.bar = skang.newParam('bar', "Required", "Shortcut", "Default", "Help text") | ||
11 | result.func = skang.newCommand('number,data', 'Help Text', function (arg1, arg2) | ||
12 | -- do something here | ||
13 | end) | ||
14 | |||
15 | -- do something here | ||
16 | |||
17 | return result; | ||
18 | |||
19 | */ | ||
diff --git a/ClientHamr/GuiLua/test.lua b/ClientHamr/GuiLua/test.lua new file mode 100644 index 0000000..7e668d2 --- /dev/null +++ b/ClientHamr/GuiLua/test.lua | |||
@@ -0,0 +1,15 @@ | |||
1 | local skang = require('skang') | ||
2 | local result = {}; | ||
3 | result.author = 'onefang' | ||
4 | result.version = '0.72 alpha 2004-11-19 16:28:00' | ||
5 | local bar | ||
6 | -- The first argument would be the name of a local variable / method. Which could be accessed via _G? | ||
7 | -- Not sure if we could use a global bar, AND use it directly. | ||
8 | result.bar = skang.newParam('bar', "Required", "Shortcut", "Default", "Help text") | ||
9 | result.func = skang.newCommand('number,data', 'Help Text', function (arg1, arg2) | ||
10 | -- do something here | ||
11 | end) | ||
12 | |||
13 | -- do something here | ||
14 | |||
15 | return result; | ||
diff --git a/ClientHamr/GuiLua/test.skang b/ClientHamr/GuiLua/test.skang new file mode 100644 index 0000000..ba40f1f --- /dev/null +++ b/ClientHamr/GuiLua/test.skang | |||
@@ -0,0 +1,12 @@ | |||
1 | #!skang test.skang -- This is Lua, so this might not work. | ||
2 | -- There's an implied local this = require('test') | ||
3 | -- There's an implied local skang = require('skang') | ||
4 | local widget = require('widget') | ||
5 | -- local other = require('otherPackageName') | ||
6 | skang.clear | ||
7 | skang.window(200, 200, "G'day planet.") | ||
8 | quitter = widget.button('Quit', 0.5, 0.5, 0.5, 0.5) | ||
9 | quitter:action('quit') -- 'quit' is looked up in ThingSpcae.commands, and translated into the Lua 'skang.quit()'. | ||
10 | --other.foo = 'stuff' | ||
11 | this.bar = 'things' | ||
12 | this.func(1, 'two') | ||