1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
fonts {
font: "Vera.ttf" "default";
}
images {
image: "bubble.png" COMP;
}
collections {
group {
name: "lua_base";
lua_script_only: 1;
lua_script {
--// stick object private/local vars here
local D;
local text_geom;
--// Functions to print tables.
local print_table, print_table_start;
function print_table_start(table, space, name)
print(space .. name .. ": ");
print(space .. "{");
print_table(table, space .. " ");
print(space .. "}");
end
function print_table(table, space)
for k, v in pairs(table) do
if type(v) == "table" then
print_table_start(v, space, k);
elseif type(v) == "string" then
print(space .. k .. ': "' .. v .. '";')
else
print(space .. k .. ": " .. v .. ";")
end
end
end
--// init object here
D = {}; --// data is empty table to start
edje_geom = edje.geom();
D.edje = edje.edje();
D.edje:file("plain/edje/group");
D.edje:move(0, 0);
D.edje:resize(edje_geom.w, edje_geom.h);
D.edje:show();
edje.text_class("test_text_class", "Sans:style=Bold", 10);
--// send some random edje message
edje.messagesend(7, "none" );
edje.messagesend(7, "sig", "lua message signal", "luaSource");
edje.messagesend(7, "str", "hello world");
edje.messagesend(7, "int", 987);
edje.messagesend(7, "float", 987.321);
edje.messagesend(7, "strset", {"hello", "there", "world"});
edje.messagesend(7, "intset", {1, 2, 3});
edje.messagesend(7, "floatset", {1.1, 2.2, 3.3});
edje.messagesend(7, "strint", "hello world", 7);
edje.messagesend(7, "strfloat", "hello world", 7.654);
edje.messagesend(7, "strintset","hello world", {1, 2, 3});
--// and a signal
edje.emit("lua signal", "luaSource");
function move (x, y)
print("lua::move x=" .. x .. " x=" .. y);
D.edje:move(0, 0);
end
function resize (w, h)
print("lua::resize w=" .. w .. " h=" .. h);
D.edje:resize(w, h);
end
function message (id, type, ...)
print("lua::message id=" .. id .. " type=" .. type);
--// handle your message type here. check id + type then use the
--// vararg appropriately. they are the same as the params passed
--// to edje:messagesend() (if any are passed at all). Any array
--// arguments are passed as a single table.
if ("none" == type) then
print("lua::message no args");
elseif ("strset" == type) then
strs = ... ;
print_table_start(strs, "", "lua::message strings");
elseif ("intset" == type) then
ints = ... ;
print_table_start(ints, "", "lua::message ints");
elseif ("floatset" == type) then
floats = ... ;
print_table_start(floats, "", "lua::message floats");
elseif ("strintset" == type) then
str, ints = ... ;
print("lua::message " .. str);
print_table_start(ints, "", "lua::message ints");
elseif ("strfloatset" == type) then
str, floats = ... ;
print("lua::message " .. str);
print_table_start(floats, "", "lua::message floats");
else
print("lua::message " .. ... );
end
end
function signal (sig, src)
print("lua::signal sig=|" .. sig .. "| src=" .. src .. "|");
end
}
}
// The group name NEEDS a / in it,
// or the part below that tries to swallow it won't work.
// Leaving just the lua part visible.
group {
name: "bubbles/lua";
lua_script_only: 1;
lua_script {
local bubbles = { };
local bubbleCols = 8;
local bubbleRows = 6;
--// Functions to print tables.
local print_table, print_table_start;
function print_table_start(table, space, name)
print(space .. name .. ": ");
print(space .. "{");
print_table(table, space .. " ");
print(space .. "}");
end
function print_table(table, space)
for k, v in pairs(table) do
if type(v) == "table" then
print_table_start(v, space, k);
elseif type(v) == "string" then
print(space .. k .. ': "' .. v .. '";')
else
print(space .. k .. ": " .. v .. ";")
end
end
end
for i = 1, bubbleRows do
row = { };
for j = 1, bubbleCols do
image = edje.image();
image:image("bubble.png");
image:show();
table.insert(row, image);
end
table.insert(bubbles, row);
end
function resize (w, h)
for i = 1, bubbleRows do
for j = 1, bubbleCols do
w1 = w / bubbleCols;
h1 = h / bubbleRows;
bubbles[i][j]:geom((j - 1) * w1, (i - 1) * h1, w1, h1);
if ((1 == i) or (1 == j) or (bubbleRows == i) or (bubbleCols == j)) then
bubbles[i][j]:color(0, 255, 0, 200);
else
bubbles[i][j]:color(math.random(200) + 55, 0, math.random(255) + 55, 200);
end
end
end
end
function message (id, type, ...)
print("bubbles::message id=" .. id .. " type=" .. type);
--// handle your message type here. check id + type then use the
--// vararg appropriately. they are the same as the params passed
--// to edje:messagesend() (if any are passed at all). Any array
--// arguments are passed as a single table.
if ("none" == type) then
print("bubbles::message no args");
elseif ("strset" == type) then
strs = ... ;
print_table_start(strs, "", "bubbles::message strings");
elseif ("intset" == type) then
ints = ... ;
print_table_start(ints, "", "bubbles::message ints");
elseif ("floatset" == type) then
floats = ... ;
print_table_start(floats, "", "bubbles::message floats");
elseif ("strintset" == type) then
str, ints = ... ;
print("bubbles::message " .. str);
print_table_start(ints, "", "bubbles::message ints");
elseif ("strfloatset" == type) then
str, floats = ... ;
print("bubbles::message " .. str);
print_table_start(floats, "", "bubbles::message floats");
else
print("bubbles::message " .. ... );
end
end
function signal (sig, src)
print("bubbles::signal sig=|" .. sig .. "| src=|" .. src .. "|");
end
}
}
group {
name: "plain/edje/group";
parts {
part {
name: "background";
type: RECT;
mouse_events: 0;
description {
state: "default" 0.0;
color: 0 0 0 255;
}
}
// A lua group embedded in an edje group.
part {
name: "bubbles_lua";
type: GROUP;
source: "bubbles/lua";
mouse_events: 0;
description { state: "default" 0.0; visible: 1; }
}
part {
name: "some_text";
type: TEXT;
mouse_events: 0;
description {
state: "default" 0;
visible: 1;
text
{
text: "This is test text.";
text_class: "test_text_class";
}
}
}
program { name: "show_signals";
signal: "*";
source: "*";
script
{
new buf[128];
snprintf(buf, 128, "edje::signal sig=%s sig=%s", sig, src);
set_text(PART:"some_text", buf);
}
}
script {
public global_str0;
public global_str1;
public global_str2;
public str_idx;
public set_text_string() {
new tmp[1024];
new idx;
idx = get_int(str_idx);
if (idx == 0)
get_str(global_str0, tmp, 1024);
else if (idx == 1)
get_str(global_str1, tmp, 1024);
else if (idx == 2)
get_str(global_str2, tmp, 1024);
else return;
set_text(PART:"some_text", tmp);
send_message(MSG_STRING, 1, tmp);
}
public message(Msg_Type:type, id, ...) {
if (type == MSG_STRING) {
new text[64];
new buf[128];
getsarg(3, text, 64);
snprintf(buf, 128, "embryo::message |%s|", text);
set_text(PART:"some_text", buf);
}
}
}
}
}
}
|