summaryrefslogtreecommitdiff
path: root/src/bindings/lua
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2020-05-29 17:06:22 +0200
committerDaniel Kolesa <d.kolesa@samsung.com>2020-05-29 17:06:22 +0200
commitf78d54051c26a8d3c9b3bfc61e44df09bf24e401 (patch)
treeeb757679257c00fd01fcbf9992e13b97f3dd19b9 /src/bindings/lua
parentb0203b3160f2a39c3afe549fd34a513f71532fc3 (diff)
bindings: rename luajit -> lua
Diffstat (limited to 'src/bindings/lua')
-rw-r--r--src/bindings/lua/.gitignore1
-rw-r--r--src/bindings/lua/eina/accessor.lua132
-rw-r--r--src/bindings/lua/eina/counter.lua62
-rw-r--r--src/bindings/lua/eina/file.lua399
-rw-r--r--src/bindings/lua/eina/hamster.lua31
-rw-r--r--src/bindings/lua/eina/iterator.lua133
-rw-r--r--src/bindings/lua/eina/list.lua307
-rw-r--r--src/bindings/lua/eina/log.lua211
-rw-r--r--src/bindings/lua/eina/rectangle.lua286
-rw-r--r--src/bindings/lua/eina/tiler.lua164
-rw-r--r--src/bindings/lua/eina/xattr.lua157
-rw-r--r--src/bindings/lua/eo.lua471
-rw-r--r--src/bindings/lua/eolian.lua1867
-rw-r--r--src/bindings/lua/meson.build7
14 files changed, 4228 insertions, 0 deletions
diff --git a/src/bindings/lua/.gitignore b/src/bindings/lua/.gitignore
new file mode 100644
index 0000000000..31b688b99b
--- /dev/null
+++ b/src/bindings/lua/.gitignore
@@ -0,0 +1 @@
*.luac
diff --git a/src/bindings/lua/eina/accessor.lua b/src/bindings/lua/eina/accessor.lua
new file mode 100644
index 0000000000..d2068fc8b5
--- /dev/null
+++ b/src/bindings/lua/eina/accessor.lua
@@ -0,0 +1,132 @@
1-- EFL LuaJIT bindings: Eina (accessor module)
2-- For use with Elua
3
4local ffi = require("ffi")
5local C = ffi.C
6
7ffi.cdef [[
8 typedef struct _Eina_Accessor Eina_Accessor;
9 typedef unsigned char Eina_Bool;
10
11 void eina_accessor_free (Eina_Accessor *accessor);
12 Eina_Bool eina_accessor_data_get (Eina_Accessor *accessor,
13 unsigned int position,
14 void **data);
15 Eina_Bool eina_accessor_lock (Eina_Accessor *accessor);
16 Eina_Bool eina_accessor_unlock (Eina_Accessor *accessor);
17 Eina_Accessor *eina_accessor_clone (Eina_Accessor *accessor);
18 void *eina_accessor_container_get(Eina_Accessor *accessor);
19]]
20
21local cutil = require("cutil")
22local util = require("util")
23
24local M = {}
25
26local eina
27
28local init = function()
29 eina = util.lib_load("eina")
30end
31
32local shutdown = function()
33 util.lib_unload("eina")
34end
35
36ffi.metatype("Eina_Accessor", {
37 __index = {
38 free = function(self) eina.eina_accessor_free(ffi.gc(self, nil)) end,
39 data_get = function(self, position)
40 local data = ffi.new("void*[1]")
41 local r = eina.eina_accessor_data_get(self, position - 1, data)
42 if r == 0 then return nil end
43 return data[0]
44 end,
45 lock = function(self) return eina.eina_accessor_lock (self) ~= 0 end,
46 unlock = function(self) return eina.eina_accessor_unlock(self) ~= 0 end,
47 clone = function(self)
48 local v = eina.eina_accessor_clone(self)
49 if v == ffi.nullptr then return nil end
50 return v
51 end,
52 container_get = function(self)
53 local v = eina.eina_accessor_container_get(self)
54 if v == ffi.nullptr then return nil end
55 return v
56 end
57 }
58})
59
60cutil.init_module(init, shutdown)
61
62local dgetmt = debug.getmetatable
63
64M.Accessor = util.Readonly_Object:clone {
65 __ctor = function(self, selfmt, acc)
66 -- prevent null stuff
67 if acc == ffi.nullptr then acc = nil end
68 if acc then ffi.gc(acc, acc.free) end
69 selfmt.__eq = function(self, other)
70 return selfmt.__accessor == dgetmt(other).__accessor
71 end
72 selfmt.__call = function(self)
73 return self:next()
74 end
75 local oi = selfmt.__index
76 selfmt.__index = function(self, name)
77 if type(name) == "number" then return self:data_get(name) end
78 return oi[name]
79 end
80 selfmt.__accessor = acc
81 end,
82
83 free = function(self)
84 self = dgetmt(self)
85 if not self.__accessor then return end
86 self.__accessor:free()
87 self.__accessor = nil
88 end,
89
90 lock = function(self)
91 self = dgetmt(self)
92 if not self.__accessor then return false end
93 return self.__accessor:lock()
94 end,
95
96 unlock = function(self)
97 self = dgetmt(self)
98 if not self.__accessor then return false end
99 return self.__accessor:unlock()
100 end,
101
102 clone = function(self)
103 self = dgetmt(self)
104 if not self.__accessor then return nil end
105 return self.__protos[1](self.__accessor:clone())
106 end,
107
108 data_get = function(self, pos)
109 self = dgetmt(self)
110 if not self.__accessor then return nil end
111 return self.__accessor:data_get(pos)
112 end,
113
114 container_get = function(self)
115 self = dgetmt(self)
116 if not self.__accessor then return end
117 return self.__accessor:container_get()
118 end,
119
120 each = function(self)
121 local acc = dgetmt(self).__accessor
122 if not acc then return nil end
123 local cnt = 0
124 return function()
125 cnt = cnt + 1
126 local v = self:data_get(cnt)
127 if v then return cnt, v end
128 end
129 end
130}
131
132return M
diff --git a/src/bindings/lua/eina/counter.lua b/src/bindings/lua/eina/counter.lua
new file mode 100644
index 0000000000..6a9ba33284
--- /dev/null
+++ b/src/bindings/lua/eina/counter.lua
@@ -0,0 +1,62 @@
1-- EFL LuaJIT bindings: Eina (counter module)
2-- For use with Elua
3
4local ffi = require("ffi")
5local C = ffi.C
6
7ffi.cdef [[
8 typedef struct _Eina_Counter Eina_Counter;
9 Eina_Counter *eina_counter_new (const char *name);
10 void eina_counter_free (Eina_Counter *counter);
11 void eina_counter_start(Eina_Counter *counter);
12 void eina_counter_stop (Eina_Counter *counter, int specimen);
13 char *eina_counter_dump (Eina_Counter *counter);
14
15 void free(void*);
16]]
17
18local cutil = require("cutil")
19local util = require("util")
20
21local M = {}
22
23local eina
24
25local init = function()
26 eina = util.lib_load("eina")
27end
28
29local shutdown = function()
30 util.lib_unload("eina")
31end
32
33cutil.init_module(init, shutdown)
34
35M.Counter = ffi.metatype("Eina_Counter", {
36 __new = function(self, name)
37 return ffi.gc(eina.eina_counter_new(name), self.free)
38 end,
39 __index = {
40 free = function(self)
41 return eina.eina_counter_free(ffi.gc(self, nil))
42 end,
43
44 start = function(self)
45 return eina.eina_counter_start(self)
46 end,
47
48 stop = function(self, specimen)
49 return eina.eina_counter_stop(self, specimen)
50 end,
51
52 dump = function(self)
53 local v = eina.eina_counter_dump(self)
54 if v == ffi.nullptr then return nil end
55 local r = ffi.string(v)
56 C.free(v)
57 return r
58 end
59 }
60})
61
62return M
diff --git a/src/bindings/lua/eina/file.lua b/src/bindings/lua/eina/file.lua
new file mode 100644
index 0000000000..3f59391b60
--- /dev/null
+++ b/src/bindings/lua/eina/file.lua
@@ -0,0 +1,399 @@
1-- EFL LuaJIT bindings: Eina (file module)
2-- For use with Elua
3
4local ffi = require("ffi")
5local C = ffi.C
6
7local iterator = require("eina.iterator")
8require("eina.xattr")
9
10ffi.cdef [[
11 typedef unsigned char Eina_Bool;
12 typedef long time_t;
13
14 typedef struct _Eina_File_Direct_Info Eina_File_Direct_Info;
15 typedef struct _Eina_Stat Eina_Stat;
16 typedef struct _Eina_File_Line Eina_File_Line;
17
18 typedef void (*Eina_File_Dir_List_Cb)(const char *name, const char *path,
19 void *data);
20
21 typedef Eina_Bool (*Eina_File_Copy_Progress)(void *data,
22 unsigned long long done, unsigned long long total);
23
24 typedef enum {
25 EINA_FILE_UNKNOWN,
26 EINA_FILE_FIFO,
27 EINA_FILE_CHR,
28 EINA_FILE_DIR,
29 EINA_FILE_BLK,
30 EINA_FILE_REG,
31 EINA_FILE_LNK,
32 EINA_FILE_SOCK,
33 EINA_FILE_WHT
34 } Eina_File_Type;
35
36 typedef struct _Eina_File Eina_File;
37
38 typedef enum {
39 EINA_FILE_RANDOM,
40 EINA_FILE_SEQUENTIAL,
41 EINA_FILE_WILLNEED,
42 EINA_FILE_POPULATE,
43 EINA_FILE_DONTNEED,
44 EINA_FILE_REMOVE
45 } Eina_File_Populate;
46
47 struct _Eina_File_Direct_Info {
48 size_t path_length;
49 size_t name_length;
50 size_t name_start;
51 Eina_File_Type type;
52 char path[8192];
53 };
54
55 struct _Eina_Stat {
56 unsigned long int dev;
57 unsigned long int ino;
58 unsigned int mode;
59 unsigned int nlink;
60 unsigned int uid;
61 unsigned int gid;
62 unsigned long int rdev;
63 unsigned long int size;
64 unsigned long int blksize;
65 unsigned long int blocks;
66 unsigned long int atime;
67 unsigned long int atimensec;
68 unsigned long int mtime;
69 unsigned long int mtimensec;
70 unsigned long int ctime;
71 unsigned long int ctimensec;
72 };
73
74 struct _Eina_File_Line {
75 const char *start;
76 const char *end;
77 unsigned int index;
78 unsigned long long length;
79 };
80
81 Eina_Bool eina_file_dir_list(const char *dir, Eina_Bool recursive,
82 Eina_File_Dir_List_Cb cb, void *data);
83 Eina_Iterator *eina_file_ls(const char *dir);
84 Eina_Iterator *eina_file_stat_ls(const char *dir);
85 int eina_file_statat(void *container, Eina_File_Direct_Info *info,
86 Eina_Stat *buf);
87 Eina_Iterator *eina_file_direct_ls(const char *dir);
88 char *eina_file_path_sanitize(const char *path);
89
90 typedef enum {
91 EINA_FILE_COPY_DATA = 0,
92 EINA_FILE_COPY_PERMISSION = (1 << 0),
93 EINA_FILE_COPY_XATTR = (1 << 1)
94 } Eina_File_Copy_Flags;
95
96 Eina_Bool eina_file_copy(const char *src, const char *dst,
97 Eina_File_Copy_Flags flags, Eina_File_Copy_Progress cb,
98 const void *cb_data);
99 Eina_File *eina_file_open(const char *name, Eina_Bool shared);
100 Eina_Bool eina_file_unlink(const char *pathname);
101 Eina_File *eina_file_virtualize(const char *virtual_name,
102 const void *data, unsigned long long length, Eina_Bool copy);
103 Eina_Bool eina_file_virtual(Eina_File *file);
104 Eina_Bool eina_file_refresh(Eina_File *file);
105 Eina_File *eina_file_dup(const Eina_File *file);
106 void eina_file_close(Eina_File *file);
107 size_t eina_file_size_get(const Eina_File *file);
108 time_t eina_file_mtime_get(const Eina_File *file);
109 const char *eina_file_filename_get(const Eina_File *file);
110 Eina_Iterator *eina_file_xattr_get(Eina_File *file);
111 Eina_Iterator *eina_file_xattr_value_get(Eina_File *file);
112 void *eina_file_map_all(Eina_File *file, Eina_File_Populate rule);
113 void *eina_file_map_new(Eina_File *file, Eina_File_Populate rule,
114 unsigned long int offset, unsigned long int length);
115 void eina_file_map_free(Eina_File *file, void *map);
116 void eina_file_map_populate(Eina_File *file, Eina_File_Populate rule,
117 const void *map, unsigned long int offset, unsigned long int length);
118 Eina_Iterator *eina_file_map_lines(Eina_File *file);
119 Eina_Bool eina_file_map_faulted(Eina_File *file, void *map);
120
121 void eina_stringshare_del (const char *str);
122 int eina_stringshare_strlen(const char *str);
123
124 char *strerror(int);
125 void free(void*);
126]]
127
128local cutil = require("cutil")
129local util = require("util")
130
131local Object = util.Object
132
133local M = {}
134
135local eina
136
137local init = function()
138 eina = util.lib_load("eina")
139end
140
141local shutdown = function()
142 util.lib_unload("eina")
143end
144
145cutil.init_module(init, shutdown)
146
147M.dir_list = function(dir, recursive, cb)
148 if not cb or not dir then return false end
149 local cbp = ffi.cast("Eina_File_Dir_List_Cb", function(name, path, data)
150 return cb(name, path)
151 end)
152 local v = eina.eina_file_dir_list(dir, recursive or false, cbp, nil)
153 cbp:free()
154 return v ~= 0
155end
156
157local Iterator = iterator.Iterator
158
159local Ls_Iterator = Iterator:clone {
160 __ctor = function(self, selfmt, dir)
161 return Iterator.__ctor(self, selfmt, eina.eina_file_ls(dir))
162 end,
163
164 next = function(self)
165 local v = Iterator.next(self)
166 if not v then return nil end
167 local r = ffi.string(v, eina.eina_stringshare_strlen(v))
168 eina.eina_stringshare_del(v)
169 return r
170 end
171}
172
173M.ls = function(dir) return Ls_Iterator(dir) end
174
175local file_type_map = {
176 [C.EINA_FILE_UNKNOWN] = "unknown",
177 [C.EINA_FILE_FIFO] = "fifo",
178 [C.EINA_FILE_CHR] = "chr",
179 [C.EINA_FILE_DIR] = "dir",
180 [C.EINA_FILE_BLK] = "blk",
181 [C.EINA_FILE_REG] = "reg",
182 [C.EINA_FILE_LNK] = "lnk",
183 [C.EINA_FILE_SOCK] = "sock",
184 [C.EINA_FILE_WHT] = "wht",
185}
186
187local Direct_Info = Object:clone {
188 __ctor = function(self, path, name_start, name_length, tp)
189 self.path = path
190 self.name_start = name_start
191 self.name_length = name_length
192 self.type = tp
193 end,
194
195 statat = function(self, container)
196 if not container then return false, "invalid container" end
197 local info = ffi.new("Eina_File_Direct_Info", #self.path,
198 self.name_length, self.name_start - 1,
199 C["EINA_FILE_" .. self.type:upper()], self.path)
200 local buf = ffi.new("Eina_Stat")
201 if eina.eina_file_statat(container, info, buf) ~= 0 then
202 return false, ffi.string(C.strerror(ffi.errno()))
203 end
204 return buf
205 end
206}
207
208local direct_info_iterator_next = function(self)
209 local v = Iterator.next(self)
210 if not v then return nil end
211 local s = ffi.cast("Eina_File_Direct_Info*", v)
212 local path = ffi.string(s.path, s.path_length)
213 local ns = tonumber(s.name_start)
214 local nl = tonumber(s.name_length)
215 local tp = file_type_map[s.type]
216 return Direct_Info(path, ns, nl, tp), self:container_get()
217end
218
219local Stat_Ls_Iterator = Iterator:clone {
220 __ctor = function(self, selfmt, dir)
221 return Iterator.__ctor(self, selfmt, eina.eina_file_stat_ls(dir))
222 end,
223 next = direct_info_iterator_next
224}
225
226M.stat_ls = function(dir) return Stat_Ls_Iterator(dir) end
227
228local Direct_Ls_Iterator = Iterator:clone {
229 __ctor = function(self, selfmt, dir)
230 return Iterator.__ctor(self, selfmt, eina.eina_file_direct_ls(dir))
231 end,
232 next = direct_info_iterator_next
233}
234
235M.direct_ls = function(dir) return Direct_Ls_Iterator(dir) end
236
237M.path_sanitize = function(path)
238 local v = eina.eina_file_path_sanitize(path)
239 if v == ffi.nullptr then return nil end
240 local r = ffi.string(v)
241 C.free(v)
242 return r
243end
244
245M.copy_flags = {
246 DATA = 0, PERMISION = 1, XATTR = 2
247}
248
249M.copy = function(source, destination, flags, cb)
250 if not source or not destination then return false end
251 flags = flags or 0
252 local cbp
253 if cb then
254 cbp = ffi.cast("Eina_File_Copy_Progress", function(data, done, total)
255 return not not cb(done, total)
256 end)
257 end
258 local v = eina.eina_file_copy(source, destination, flags, cbp, nil)
259 if cbp then cbp:free() end
260 return v ~= 0
261end
262
263local Xattr_Iterator = Iterator:clone {
264 __ctor = function(self, selfmt, file)
265 return Iterator.__ctor(self, selfmt, eina.eina_file_xattr_get(file))
266 end,
267 next = function(self)
268 local v = Iterator.next(self)
269 if not v then return nil end
270 return ffi.string(v)
271 end
272}
273
274local Xattr_Value_Iterator = Iterator:clone {
275 __ctor = function(self, selfmt, file)
276 return Iterator.__ctor(self, selfmt,
277 eina.eina_file_xattr_value_get(file))
278 end,
279 next = function(self)
280 local v = Iterator.next(self)
281 if not v then return nil end
282 v = ffi.cast(v, "Eina_Xattr*")
283 return ffi.string(v.name), ffi.string(v.value, v.length)
284 end
285}
286
287M.populate = {
288 RANDOM = 0,
289 SEQUENTIAL = 1,
290 WILLNEED = 2,
291 POPULATE = 3,
292 DONTNEED = 4,
293 REMOVE = 5
294}
295
296local Line_Iterator = Iterator:clone {
297 __ctor = function(self, selfmt, file)
298 return Iterator.__ctor(self, selfmt, eina.eina_file_map_lines(file))
299 end,
300 next = function(self)
301 local v = Iterator.next(self)
302 if not v then return nil end
303 v = ffi.cast(v, "Eina_File_Line*")
304 return ffi.string(v.start, v.length), tonumber(v.index)
305 end
306}
307
308M.File = ffi.metatype("Eina_File", {
309 __new = function(self, name, shared)
310 return self.open(name, shared)
311 end,
312 __len = function(self)
313 return self:size_get()
314 end,
315 __index = {
316 open = function(name, shared)
317 return eina.eina_file_open(name, shared)
318 end,
319
320 unlink = function(self)
321 return eina.eina_file_unlink(pathname)
322 end,
323
324 virtualize = function(vname, data, length, copy)
325 return eina.eina_file_virtualize(vname, data, length,
326 copy or false)
327 end,
328
329 close = function(self)
330 return eina.eina_file_close(self)
331 end,
332
333 dup = function(self)
334 return eina.eina_file_dup(self)
335 end,
336
337 is_virtual = function(self)
338 return eina.eina_file_virtual(self) ~= 0
339 end,
340 refresh = function(self)
341 return eina.eina_file_refresh(self) ~= 0
342 end,
343
344 size_get = function(self)
345 return tonumber(eina.eina_file_size_get(self))
346 end,
347
348 mtime_get = function(self)
349 return tonumber(eina.eina_file_mtime_get(self))
350 end,
351
352 filename_get = function(self)
353 return ffi.string(eina.eina_file_filename_get(self))
354 end,
355
356 xattr_get = function(self) return Xattr_Iterator(self) end,
357 xattr_value_get = function(self) Xattr_Value_Iterator(self) end,
358
359 map_all = function(self, rule, raw)
360 local v = ffi.cast("char*", eina.eina_file_map_all(self, rule or 0))
361 if v == ffi.nullptr then return nil end
362 if not raw then
363 local r = ffi.string(v)
364 self:map_free(v)
365 return r
366 end
367 return v
368 end,
369
370 map_new = function(self, rule, offset, length, raw)
371 local v = ffi.cast("char*", eina.eina_file_map_new(self, rule or 0,
372 offset or 0, length))
373 if v == ffi.nullptr then return nil end
374 if not raw then
375 local r = ffi.string(v, length)
376 self:map_free(v)
377 return r
378 end
379 return v
380 end,
381
382 map_free = function(self, map)
383 return eina.eina_file_map_free(self, map)
384 end,
385
386 map_populate = function(self, rule, map, offset, length)
387 return eina.eina_file_map_populate(self, rule or 0, offset or 0,
388 length)
389 end,
390
391 map_faulted = function(self, map)
392 return eina.eina_file_map_faulted(self, map) ~= 0
393 end,
394
395 lines = function(self) return Line_Iterator(self) end
396 }
397})
398
399return M
diff --git a/src/bindings/lua/eina/hamster.lua b/src/bindings/lua/eina/hamster.lua
new file mode 100644
index 0000000000..e8f5e7434f
--- /dev/null
+++ b/src/bindings/lua/eina/hamster.lua
@@ -0,0 +1,31 @@
1-- EFL LuaJIT bindings: Eina (hamster module)
2-- For use with Elua
3
4local ffi = require("ffi")
5
6ffi.cdef [[
7 int eina_hamster_count(void);
8]]
9
10local cutil = require("cutil")
11local util = require("util")
12
13local M = {}
14
15local eina
16
17local init = function()
18 eina = util.lib_load("eina")
19end
20
21local shutdown = function()
22 util.lib_unload("eina")
23end
24
25cutil.init_module(init, shutdown)
26
27M.count = function()
28 return tonumber(eina.eina_hamster_count())
29end
30
31return M
diff --git a/src/bindings/lua/eina/iterator.lua b/src/bindings/lua/eina/iterator.lua
new file mode 100644
index 0000000000..196a968500
--- /dev/null
+++ b/src/bindings/lua/eina/iterator.lua
@@ -0,0 +1,133 @@
1-- EFL LuaJIT bindings: Eina (iterator module)
2-- For use with Elua
3
4local ffi = require("ffi")
5local C = ffi.C
6
7ffi.cdef [[
8 typedef struct _Eina_Iterator Eina_Iterator;
9 typedef unsigned char Eina_Bool;
10
11 void eina_iterator_free (Eina_Iterator *iterator);
12 Eina_Bool eina_iterator_next (Eina_Iterator *iterator, void **data);
13 Eina_Bool eina_iterator_lock (Eina_Iterator *iterator);
14 Eina_Bool eina_iterator_unlock (Eina_Iterator *iterator);
15 void *eina_iterator_container_get(Eina_Iterator *iterator);
16]]
17
18local cutil = require("cutil")
19local util = require("util")
20
21local M = {}
22
23local eina
24
25local init = function()
26 eina = util.lib_load("eina")
27end
28
29local shutdown = function()
30 util.lib_unload("eina")
31end
32
33ffi.metatype("Eina_Iterator", {
34 __index = {
35 free = function(self) eina.eina_iterator_free(ffi.gc(self, nil)) end,
36 next = function(self)
37 local data = ffi.new("void*[1]")
38 local r = eina.eina_iterator_next(self, data)
39 if r == 0 then return nil end
40 return data[0]
41 end,
42 lock = function(self) return eina.eina_iterator_lock (self) ~= 0 end,
43 unlock = function(self) return eina.eina_iterator_unlock(self) ~= 0 end,
44 container_get = function(self)
45 local v = eina.eina_iterator_container_get(self)
46 if v == ffi.nullptr then return nil end
47 return v
48 end
49 }
50})
51
52cutil.init_module(init, shutdown)
53
54local dgetmt = debug.getmetatable
55
56M.Iterator = util.Readonly_Object:clone {
57 __ctor = function(self, selfmt, iter)
58 -- prevent null stuff
59 if iter == ffi.nullptr then iter = nil end
60 if iter then ffi.gc(iter, iter.free) end
61 selfmt.__eq = function(self, other)
62 return selfmt.__iterator == dgetmt(other).__iterator
63 end
64 selfmt.__call = function(self)
65 return self:next()
66 end
67 selfmt.__iterator = iter
68 end,
69
70 free = function(self)
71 self = dgetmt(self)
72 if not self.__iterator then return end
73 self.__iterator:free()
74 self.__iterator = nil
75 end,
76
77 next = function(self)
78 self = dgetmt(self)
79 if not self.__iterator then return nil end
80 return self.__iterator:next()
81 end,
82
83 lock = function(self)
84 self = dgetmt(self)
85 if not self.__iterator then return false end
86 return self.__iterator:lock()
87 end,
88
89 unlock = function(self)
90 self = dgetmt(self)
91 if not self.__iterator then return false end
92 return self.__iterator:unlock()
93 end,
94
95 container_get = function(self)
96 self = dgetmt(self)
97 if not self.__iterator then return nil end
98 return self.__iterator:container_get()
99 end,
100
101 to_array = function(self)
102 local ret = {}
103 for v in self do
104 ret[#ret + 1] = v
105 end
106 return ret
107 end
108}
109
110local Iterator = M.Iterator
111
112M.Ptr_Iterator = Iterator:clone {
113 __ctor = function(self, selfmt, ptrtype, iter)
114 Iterator.__ctor(self, selfmt, iter)
115 selfmt.ptrtype = ptrtype
116 end,
117
118 next = function(self)
119 local v = Iterator.next(self)
120 if not v then return nil end
121 return ffi.cast(dgetmt(self).ptrtype, v)
122 end
123}
124
125M.String_Iterator = Iterator:clone {
126 next = function(self)
127 local v = Iterator.next(self)
128 if not v then return nil end
129 return ffi.string(v)
130 end
131}
132
133return M
diff --git a/src/bindings/lua/eina/list.lua b/src/bindings/lua/eina/list.lua
new file mode 100644
index 0000000000..4c0bc6bd17
--- /dev/null
+++ b/src/bindings/lua/eina/list.lua
@@ -0,0 +1,307 @@
1-- EFL LuaJIT bindings: Eina (list module)
2-- For use with Elua
3
4local ffi = require("ffi")
5
6local iterator = require("eina.iterator")
7local accessor = require("eina.accessor")
8
9ffi.cdef [[
10 typedef unsigned char Eina_Bool;
11
12 typedef struct _Eina_List Eina_List;
13 typedef struct _Eina_List_Accounting Eina_List_Accounting;
14
15 typedef struct _Eina_List_T {
16 void *data;
17 Eina_List *next;
18 Eina_List *prev;
19 struct {
20 Eina_List *last;
21 unsigned int count;
22 } *accounting;
23 } Eina_List_T;
24
25/* Eina_List *eina_list_append(Eina_List *list, const void *data);
26 Eina_List *eina_list_prepend(Eina_List *list, const void *data);
27 Eina_List *eina_list_append_relative(Eina_List *list, const void *data, const void *relative);
28 Eina_List *eina_list_append_relative_list(Eina_List *list, const void *data, Eina_List *relative);
29 Eina_List *eina_list_prepend_relative(Eina_List *list, const void *data, const void *relative);
30 Eina_List *eina_list_prepend_relative_list(Eina_List *list, const void *data, Eina_List *relative);
31 Eina_List *eina_list_sorted_insert(Eina_List *list, Eina_Compare_Cb func, const void *data);
32 Eina_List *eina_list_remove(Eina_List *list, const void *data);
33 Eina_List *eina_list_remove_list(Eina_List *list, Eina_List *remove_list);
34 Eina_List *eina_list_promote_list(Eina_List *list, Eina_List *move_list);
35 Eina_List *eina_list_demote_list(Eina_List *list, Eina_List *move_list);
36 void *eina_list_data_find(const Eina_List *list, const void *data);
37 Eina_List *eina_list_data_find_list(const Eina_List *list, const void *data);
38 Eina_Bool eina_list_move(Eina_List **to, Eina_List **from, void *data);
39 Eina_Bool eina_list_move_list(Eina_List **to, Eina_List **from, Eina_List *data);
40 Eina_List *eina_list_free(Eina_List *list);
41*/
42 void *eina_list_nth(const Eina_List *list, unsigned int n);
43 Eina_List *eina_list_nth_list(const Eina_List *list, unsigned int n);
44/* Eina_List *eina_list_reverse(Eina_List *list);
45 Eina_List *eina_list_reverse_clone(const Eina_List *list);
46 Eina_List *eina_list_clone(const Eina_List *list);
47 Eina_List *eina_list_sort(Eina_List *list, unsigned int limit, Eina_Compare_Cb func);
48 Eina_List *eina_list_shuffle(Eina_List *list, Eina_Random_Cb func);
49 Eina_List *eina_list_merge(Eina_List *left, Eina_List *right);
50 Eina_List *eina_list_sorted_merge(Eina_List *left, Eina_List *right, Eina_Compare_Cb func);
51 Eina_List *eina_list_split_list(Eina_List *list, Eina_List *relative, Eina_List **right);
52 Eina_List *eina_list_search_sorted_near_list(const Eina_List *list, Eina_Compare_Cb func, const void *data, int *result_cmp);
53 Eina_List *eina_list_search_sorted_list(const Eina_List *list, Eina_Compare_Cb func, const void *data);
54 void *eina_list_search_sorted(const Eina_List *list, Eina_Compare_Cb func, const void *data);
55 Eina_List *eina_list_search_unsorted_list(const Eina_List *list, Eina_Compare_Cb func, const void *data);
56 void *eina_list_search_unsorted(const Eina_List *list, Eina_Compare_Cb func, const void *data);
57*/
58 Eina_Iterator *eina_list_iterator_new(const Eina_List *list);
59 Eina_Iterator *eina_list_iterator_reversed_new(const Eina_List *list);
60 Eina_Accessor *eina_list_accessor_new(const Eina_List *list);
61]]
62
63local cutil = require("cutil")
64local util = require("util")
65
66local M = {}
67
68local eina
69
70local init = function()
71 eina = util.lib_load("eina")
72end
73
74local shutdown = function()
75 util.lib_unload("eina")
76end
77
78cutil.init_module(init, shutdown)
79
80local Iterator = iterator.Iterator
81
82local dgetmt = debug.getmetatable
83
84local List_Iterator = Iterator:clone {
85 __ctor = function(self, selfmt, list)
86 if not list or list == ffi.nullptr then
87 return Iterator.__ctor(self, selfmt, nil)
88 end
89 selfmt.__list = list
90 return Iterator.__ctor(self, selfmt,
91 eina.eina_list_iterator_new(dgetmt(list).__list))
92 end,
93
94 next = function(self)
95 local v = Iterator.next(self)
96 if not v then return nil end
97 return dgetmt(self).__list:data_get(v)
98 end
99}
100
101local List_Reverse_Iterator = Iterator:clone {
102 __ctor = function(self, selfmt, list)
103 if not list or list == ffi.nullptr then
104 return Iterator.__ctor(self, selfmt, nil)
105 end
106 selfmt.__list = list
107 return Iterator.__ctor(self, selfmt,
108 eina.eina_list_iterator_reversed_new(dgetmt(list).__list))
109 end,
110
111 next = function(self)
112 local v = Iterator.next(self)
113 if not v then return nil end
114 return self.__list:data_get(v)
115 end
116}
117
118local Accessor = accessor.Accessor
119
120local List_Accessor = Accessor:clone {
121 __ctor = function(self, selfmt, list)
122 if not list or list == ffi.nullptr then
123 return Accessor.__ctor(self, selfmt, nil)
124 end
125 selfmt.__list = list
126 return Accessor.__ctor(self, selfmt,
127 eina.eina_list_accessor_new(dgetmt(list).__list))
128 end,
129
130 data_get = function(self, pos)
131 local v = Accessor.data_get(self, pos)
132 if not v then return nil end
133 return self.__list:data_get(v)
134 end
135}
136
137local get_list_t = function(list)
138 return ffi.cast("Eina_List_T*", list)
139end
140
141local List = ffi.metatype("Eina_List", {
142 __len = function(self)
143 return get_list_t(self).accounting.count
144 end,
145
146 __index = {
147 data_get = function(self, ptr)
148 if ptr ~= nil then return ptr end
149 local v = get_list_t(self).data
150 if v == ffi.nullptr then return nil end
151 return v
152 end,
153
154 nth = function(self, n)
155 local v = eina.eina_list_nth(self, n - 1)
156 if v == ffi.nullptr then return nil end
157 return self:data_get(v)
158 end,
159
160 nth_list = function(self, n)
161 local v = eina.eina_list_nth_list(self, n - 1)
162 if v == ffi.nullptr then return nil end
163 return v
164 end,
165
166 last = function(self)
167 local v = get_list_t(self).accounting.last
168 if v == ffi.nullptr then return nil end
169 return v
170 end,
171
172 next = function(self)
173 local v = get_list_t(self).next
174 if v == ffi.nullptr then return nil end
175 return v
176 end,
177
178 prev = function(self)
179 local v = get_list_t(self).prev
180 if v == ffi.nullptr then return nil end
181 return v
182 end
183 }
184})
185
186local List_Base = util.Readonly_Object:clone {
187 __ctor = function(self, selfmt, list, freefunc)
188 if list and freefunc then
189 list = ffi.gc(list, freefunc)
190 selfmt.__free = freefunc
191 end
192 if not list or list == ffi.nullptr then return end
193 selfmt.__eq = function(self, other)
194 return selfmt.__list == dgetmt(other).__list
195 end
196 selfmt.__len = self.count
197 selfmt.__list = list
198 end,
199
200 free = function(self)
201 self = dgetmt(self)
202 local ffunc, l = self.__free, self.__list
203 if not ffunc or not l or l == ffi.nullptr then return end
204 ffunc(ffi.gc(self.__list, nil))
205 end,
206
207 count = function(self)
208 self = dgetmt(self)
209 local l = self.__list
210 if not l or l == ffi.nullptr then return 0 end
211 return #l
212 end,
213
214 nth = function(self, n)
215 self = dgetmt(self)
216 local l = self.__list
217 if not l or l == ffi.nullptr then return nil end
218 return l:nth()
219 end,
220
221 nth_list = function(self, n)
222 self = dgetmt(self)
223 local l = self.__list
224 if not l or l == ffi.nullptr then return nil end
225 return self.__index(l:nth_list())
226 end,
227
228 last = function(self, n)
229 self = dgetmt(self)
230 local l = self.__list
231 if not l or l == ffi.nullptr then return nil end
232 return self.__index(l:last())
233 end,
234
235 next = function(self, n)
236 self = dgetmt(self)
237 local l = self.__list
238 if not l or l == ffi.nullptr then return nil end
239 return self.__index(l:next())
240 end,
241
242 prev = function(self, n)
243 self = dgetmt(self)
244 local l = self.__list
245 if not l or l == ffi.nullptr then return nil end
246 return self.__index(l:prev())
247 end,
248
249 data_get = function(self, ptr)
250 self = dgetmt(self)
251 local l = self.__list
252 if not l or l == ffi.nullptr then return nil end
253 return l:data_get(ptr)
254 end,
255
256 to_array = function(self)
257 local l = dgetmt(self).__list
258 if not l or l == ffi.nullptr then return {}, 0 end
259 local n = 0
260 local r = {}
261 while l ~= nil do
262 n = n + 1
263 local d = l:data_get()
264 if d ~= nil then
265 r[n] = self:data_get(d)
266 end
267 l = l:next()
268 end
269 return r, n
270 end,
271
272 iterator = function(self)
273 return List_Iterator(self)
274 end,
275
276 reverse_iterator = function(self)
277 return List_Reverse_Iterator(self)
278 end,
279
280 accessor = function(self)
281 return List_Accessor(self)
282 end
283}
284M.List_Base = List_Base
285
286M.Ptr_List = List_Base:clone {
287 __ctor = function(self, selfmt, ptrtype, list, freefunc)
288 List_Base.__ctor(self, selfmt, list, freefunc)
289 selfmt.ptrtype = ptrtype
290 end,
291
292 data_get = function(self, ptr)
293 ptr = List_Base.data_get(self, ptr)
294 if not ptr then return nil end
295 return ffi.cast(dgetmt(self).ptrtype, ptr)
296 end
297}
298
299M.String_List = List_Base:clone {
300 data_get = function(self, ptr)
301 ptr = List_Base.data_get(self, ptr)
302 if not ptr or ptr == ffi.nullptr then return nil end
303 return ffi.string(ptr)
304 end
305}
306
307return M
diff --git a/src/bindings/lua/eina/log.lua b/src/bindings/lua/eina/log.lua
new file mode 100644
index 0000000000..d2b1180b96
--- /dev/null
+++ b/src/bindings/lua/eina/log.lua
@@ -0,0 +1,211 @@
1-- EFL LuaJIT bindings: Eina (log module)
2-- For use with Elua
3
4local ffi = require("ffi")
5local C = ffi.C
6
7ffi.cdef [[
8 typedef enum _Eina_Log_Level {
9 EINA_LOG_LEVEL_CRITICAL,
10 EINA_LOG_LEVEL_ERR,
11 EINA_LOG_LEVEL_WARN,
12 EINA_LOG_LEVEL_INFO,
13 EINA_LOG_LEVEL_DBG,
14 EINA_LOG_LEVELS,
15 EINA_LOG_LEVEL_UNKNOWN = (-2147483647 - 1)
16 } Eina_Log_Level;
17
18 extern int EINA_LOG_DOMAIN_GLOBAL;
19
20 int eina_log_domain_register (const char *name, const char *color);
21 void eina_log_domain_unregister(int domain);
22
23 int eina_log_domain_registered_level_get(int domain);
24 void eina_log_domain_registered_level_set(int domain, int level);
25
26 void eina_log_print(int domain,
27 Eina_Log_Level level,
28 const char *file,
29 const char *function,
30 int line,
31 const char *fmt,
32 ...);
33
34 typedef struct _Domain_Private {
35 int domain;
36 } Domain_Private;
37
38 typedef struct _Domain Domain;
39
40 void *malloc(size_t);
41 void free(void*);
42]]
43
44local cutil = require("cutil")
45local util = require("util")
46
47local M = {}
48
49local eina
50local default_domain, global_domain
51
52local init = function()
53 eina = util.lib_load("eina")
54 global_domain = ffi.new("Domain_Private", eina.EINA_LOG_DOMAIN_GLOBAL)
55 default_domain = global_domain
56end
57
58local shutdown = function()
59 util.lib_unload("eina")
60 default_domain, global_domain = nil, nil
61end
62
63cutil.init_module(init, shutdown)
64
65M.level = {
66 CRITICAL = C.EINA_LOG_LEVEL_CRITICAL,
67 ERR = C.EINA_LOG_LEVEL_ERR,
68 WARN = C.EINA_LOG_LEVEL_WARN,
69 INFO = C.EINA_LOG_LEVEL_INFO,
70 DBG = C.EINA_LOG_LEVEL_DBG,
71 UNKNOWN = C.EINA_LOG_LEVEL_UNKNOWN,
72 levels = C.EINA_LOG_LEVELS
73}
74
75M.color = {
76 DEFAULT = "\x1B[36m",
77 LIGHTRED = "\x1B[31;1m",
78 RED = "\x1B[31m",
79 LIGHTBLUE = "\x1B[34;1m",
80 BLUE = "\x1B[34m",
81 GREEN = "\x1B[32;1m",
82 YELLOW = "\x1B[33;1m",
83 ORANGE = "\x1B[0;33m",
84 WHITE = "\x1B[37;1m",
85 LIGHTCYAN = "\x1B[36;1m",
86 CYAN = "\x1B[36m",
87 RESET = "\x1B[0m",
88 HIGH = "\x1B[1m"
89}
90
91local get_dom = function(dom)
92 dom = dom:__get_domain()
93 if not dom then return nil end
94 return ffi.cast("Domain_Private*", dom).domain
95end
96
97local unregister_dom = function(dom)
98 local dompri = ffi.cast("Domain_Private*", dom)
99 eina.eina_log_domain_unregister(dompri.domain)
100 C.free(dompri)
101end
102
103local log_full = function(dom, level, file, func, line, msg)
104 dom = get_dom(dom)
105 if not dom then return end
106 eina.eina_log_print(dom, level, file, func, line, msg)
107end
108M.log_full = log_full
109
110local getinfo = debug.getinfo
111
112local getfuncname = function(info)
113 return info.name or "<" .. tostring(info.func) .. ">"
114end
115
116local log = function(dom, level, msg, loff)
117 local info = getinfo(2 + (loff or 0), "nlSf")
118 log_full(dom, level, info.source, getfuncname(info), info.currentline, msg)
119end
120M.log = log
121
122local logfuncs = {
123 { "crit", C.EINA_LOG_LEVEL_CRITICAL },
124 { "err", C.EINA_LOG_LEVEL_ERR },
125 { "warn", C.EINA_LOG_LEVEL_WARN },
126 { "info", C.EINA_LOG_LEVEL_INFO },
127 { "dbg", C.EINA_LOG_LEVEL_DBG }
128}
129
130for i, v in ipairs(logfuncs) do
131 M[v[1]] = function(msg)
132 if not default_domain then return end
133 local info = getinfo(2, "nlSf")
134 local dom = ffi.cast("Domain_Private*", default_domain).domain
135 eina.eina_log_print(dom, v[2], info.source, getfuncname(info),
136 info.currentline, msg)
137 end
138end
139
140logfuncs = nil
141
142M.Domain_Base = util.Object:clone {
143 set_level = function(self, level)
144 local dom = get_dom(self)
145 if not dom then return end
146 eina.eina_log_domain_registered_level_set(dom, level)
147 end,
148
149 get_level = function(self)
150 local dom = get_dom(self)
151 if not dom then return -1 end
152 return eina.eina_log_domain_registered_level_get(dom)
153 end,
154
155 __get_domain = function(self)
156 return nil
157 end,
158
159 log = function(self, level, msg, loff)
160 log(self, level, msg, (loff or 0) + 1)
161 end,
162
163 is_valid = function(self)
164 return self:__get_domain() ~= nil
165 end
166}
167
168M.Domain_Global = M.Domain_Base:clone {
169 __get_domain = function(self)
170 return global_domain
171 end
172}
173
174M.global_domain = M.Domain_Global
175
176M.Domain_Default = M.Domain_Base:clone {
177 __get_domain = function(self)
178 return default_domain
179 end
180}
181
182M.default_domain = M.Domain_Default
183
184M.Domain = M.Domain_Base:clone {
185 __ctor = function(self, name, color)
186 local dom = eina.eina_log_domain_register(name, color or "\x1B[36m")
187 if dom < 0 then return end
188 local dompri = ffi.cast("Domain_Private*",
189 C.malloc(ffi.sizeof("Domain_Private")))
190 dompri.domain = dom
191 self.__domain = ffi.gc(ffi.cast("Domain*", dompri), unregister_dom)
192 end,
193
194 unregister = function(self)
195 if not self.__domain then return end
196 unregister_dom(ffi.gc(self.__domain, nil))
197 self.__domain = nil
198 end,
199
200 __get_domain = function(self)
201 return self.__domain
202 end
203}
204
205M.set_default_domain = function(dom)
206 dom = dom:__get_domain()
207 if not dom then return end
208 default_domain = dom
209end
210
211return M
diff --git a/src/bindings/lua/eina/rectangle.lua b/src/bindings/lua/eina/rectangle.lua
new file mode 100644
index 0000000000..d9988b7f2b
--- /dev/null
+++ b/src/bindings/lua/eina/rectangle.lua
@@ -0,0 +1,286 @@
1-- EFL LuaJIT bindings: Eina (rectangle module)
2-- For use with Elua
3
4local ffi = require("ffi")
5local C = ffi.C
6
7ffi.cdef [[
8 typedef struct _Eina_Rectangle {
9 int x, y, w, h;
10 } Eina_Rectangle;
11
12 typedef struct _Eina_Rectangle_Pool Eina_Rectangle_Pool;
13
14 typedef unsigned char Eina_Bool;
15
16 Eina_Rectangle_Pool *eina_rectangle_pool_new(int w, int h);
17 Eina_Rectangle_Pool *eina_rectangle_pool_get(Eina_Rectangle *rect);
18 Eina_Bool eina_rectangle_pool_geometry_get(Eina_Rectangle_Pool *pool, int *w, int *h);
19 void *eina_rectangle_pool_data_get(Eina_Rectangle_Pool *pool);
20 void eina_rectangle_pool_data_set(Eina_Rectangle_Pool *pool, const void *data);
21 void eina_rectangle_pool_free(Eina_Rectangle_Pool *pool);
22 int eina_rectangle_pool_count(Eina_Rectangle_Pool *pool);
23 Eina_Rectangle *eina_rectangle_pool_request(Eina_Rectangle_Pool *pool, int w, int h);
24 void eina_rectangle_pool_release(Eina_Rectangle *rect);
25
26 Eina_Rectangle *eina_rectangle_new (int x, int y, int w, int h);
27 void eina_rectangle_free(Eina_Rectangle *rect);
28]]
29
30local cutil = require("cutil")
31local util = require("util")
32
33local M = {}
34
35local eina
36
37local init = function()
38 eina = util.lib_load("eina")
39end
40
41local shutdown = function()
42 util.lib_unload("eina")
43end
44
45cutil.init_module(init, shutdown)
46
47local spans_intersect = function(c1, l1, c2, l2)
48 return not (((c2 + l2) <= c1) or (c2 >= (c1 + l1)))
49end
50
51M.spans_intersect = spans_intersect
52
53M.Rectangle = ffi.metatype("Eina_Rectangle", {
54 __new = function(self, x, y, w, h)
55 return ffi.gc(eina.eina_rectangle_new(x, y, w, h), self.free)
56 end,
57 __index = {
58 free = function(self) eina.eina_rectangle_free(ffi.gc(self, nil)) end,
59
60 get_pool = function(self)
61 local v = eina.eina_rectangle_pool_get(self)
62 return v ~= nil and v or nil
63 end,
64
65 is_empty = function(self)
66 return (self.w < 1) or (self.h < 1)
67 end,
68
69 coords_from = function(self, x, y, w, h)
70 self.x, self.y, self.w, self.h = x, y, w, h
71 end,
72
73 intersects = function(self, other)
74 return spans_intersect(self.x, self.w, other.x, other.w)
75 and spans_interscet(self.y, self.h, other.y, other.h)
76 end,
77
78 xcoord_inside = function(self, x)
79 return ((x >= self.x) and (x < (self.x + self.w)))
80 end,
81
82 ycoord_inside = function(self, y)
83 return ((y >= self.y) and (y < (self.y + self.h)))
84 end,
85
86 coords_inside = function(self, x, y)
87 return self:xcoord_inside(x) and self:ycoord_inside(y)
88 end,
89
90 union = function(dst, src)
91 if dst.x > src.x then
92 dst.w = dst.w + dst.x - src.x
93 dst.x = src.x
94 end
95 if (dst.x + dst.w) < (src.x + src.w) then
96 dst.w = src.x + src.w - dst.x
97 end
98 if dst.y > src.y then
99 dst.h = dst.h + dst.y - src.y
100 dst.y = src.y
101 end
102 if (dst.y + dst.h) < (src.y + src.h) then
103 dst.h = src.y + src.h - dst.y
104 end
105 end,
106
107 intersection = function(dst, src)
108 if not dst:intersects(src) then
109 return false
110 end
111
112 if dst.x < src.x then
113 dst.w = dst.w + dst.x - src.x
114 dst.x = src.x
115 if dst.w < 0 then dst.w = 0 end
116 end
117 if (dst.x + dst.w) > (src.x + src.w) then
118 dst.w = src.x + src.w - dst.x
119 end
120 if dst.y < src.y then
121 dst.h = dst.h + dst.y - src.y
122 dst.y = src.y
123 if dst.h < 0 then dst.h = 0 end
124 end
125 if (dst.y + dst.h) > (src.y + src.h) then
126 dst.h = src.y + src.h - dst.y
127 end
128
129 return true
130 end,
131
132 rescale_in = function(self, inr, outr)
133 self.x = inr.x - outr.x
134 self.y = inr.y - outr.y
135 self.w = inr.w
136 self.h = inr.h
137 end,
138
139 rescale_out = function(self, inr, outr)
140 self.x = outr.x + inr.x
141 self.y = outr.y + inr.y
142 self.w = outr.w
143 self.h = outr.h
144 end,
145
146 is_valid = function(self)
147 return self.w > 0 and self.h > 0
148 end,
149
150 max_x = function(self) return self.x + self.w end,
151 max_y = function(self) return self.y + self.h end,
152
153 x_cut = function(self, slice, leftover, amount)
154 if amount > self.w then return false end
155 if slice then
156 slice:coords_from(self.x, self.y, amount, self.h)
157 end
158 if leftover then
159 leftover:coords_from(self.x + amount, self.y,
160 self.w - amount, self.h)
161 end
162 return true
163 end,
164
165 y_cut = function(self, slice, leftover, amount)
166 if amount > self.h then return false end
167 if slice then
168 slice:coords_from(self.x, self.y, self.w, amount)
169 end
170 if leftover then
171 leftover:coords_from(self.x, self.y + amount,
172 self.w, self.h - amount)
173 end
174 return true
175 end,
176
177 width_cut = function(self, slice, leftover, amount)
178 if (self.w - amount) < 0 then return false end
179 if slice then
180 slice:coords_from(self.x + (self.w - amount), self.y,
181 amount, self.h)
182 end
183 if leftover then
184 leftover:coords_from(self.x, self.y, self.w - amount, self.h)
185 end
186 return true
187 end,
188
189 height_cut = function(self, slice, leftover, amount)
190 if (self.h - amount) < 0 then return false end
191 if slice then
192 slice:coords_from(self.x, self.y + (self.h - amount),
193 self.w, amount)
194 end
195 if leftover then
196 leftover:coords_from(self.x, self.y, self.w, self.h - amount)
197 end
198 return true
199 end,
200
201 subtract = function(self, other)
202 if not self:is_valid() then return false end
203
204 local o1, o2, o3, o4 = ffi.new("Eina_Rectangle"),
205 ffi.new("Eina_Rectangle"),
206 ffi.new("Eina_Rectangle"),
207 ffi.new("Eina_Rectangle")
208
209 local intersection = ffi.new("Eina_Rectangle", self)
210 if not intersection:intersection(other) then
211 o1:coords_from(self)
212 return true, o1, o2, o3, o4
213 end
214
215 local leftover = ffi.new("Eina_Rectangle")
216
217 local cut = self.h - (intersection.y - self.y)
218 if cut > self.h then cut = self.h end
219 self:height_cut(self, leftover, o1, cut)
220
221 local tmp = ffi.new("Eina_Rectangle", leftover)
222 if tmp:intersection(intersection) then
223 cut = leftover.h - (leftover:max_y() - tmp:max_y())
224 if cut > leftover.h then cut = leftover.h end
225 leftover:y_cut(leftover, o2, cut)
226 end
227
228 local tmp = ffi.new("Eina_Rectangle", leftover)
229 if tmp:intersection(intersection) then
230 cut = leftover.w - (tmp.x - leftover.x)
231 if cut > leftover.w then cut = leftover.w end
232 leftover:width_cut(leftover, o3, cut)
233 end
234
235 local tmp = ffi.new("Eina_Rectangle", leftover)
236 if tmp:intersection(intersection) then
237 cut = leftover.w - (leftover:max_x() - tmp:max_x())
238 if cut > leftover.w then cut = leftover.w end
239 leftover:x_cut(leftover, o4, cut)
240 end
241
242 return true, o1, o2, o3, o4
243 end
244 }
245})
246
247M.Rectangle_Pool = ffi.metatype("Eina_Rectangle_Pool", {
248 __new = function(self, w, h)
249 return ffi.gc(eina.eina_rectangle_pool_new(w, h), self.free)
250 end,
251
252 __len = function(self) return eina.eina_rectangle_pool_count(self) end,
253
254 __index = {
255 free = function(self)
256 eina.eina_rectangle_pool_free(ffi.gc(self, nil))
257 end,
258 get = function(rect) return rect:get_pool() end,
259
260 geometry_get = function(self)
261 local w, h = ffi.new("int[1]"), ffi.new("int[1]")
262 eina.eina_rectangle_pool_geometry_get(self, w, h)
263 return w[0], h[0]
264 end,
265
266 --[[
267 data_get = function(self)
268 return eina.eina_rectangle_pool_data_get(self)
269 end,
270 data_set = function(self, v)
271 eina.eina_rectangle_pool_data_set(self, v)
272 end,
273 ]]
274
275 request = function(self, w, h)
276 local v = eina.eina_rectangle_pool_request(self, w, h)
277 return v ~= nil and v or nil
278 end,
279
280 release = function(self, rect)
281 eina.eina_rectangle_pool_release(rect)
282 end
283 }
284})
285
286return M
diff --git a/src/bindings/lua/eina/tiler.lua b/src/bindings/lua/eina/tiler.lua
new file mode 100644
index 0000000000..15f4a10771
--- /dev/null
+++ b/src/bindings/lua/eina/tiler.lua
@@ -0,0 +1,164 @@
1-- EFL LuaJIT bindings: Eina (tiler module)
2-- For use with Elua
3
4local ffi = require("ffi")
5local C = ffi.C
6
7local iterator = require("eina.iterator")
8require("eina.rectangle")
9
10ffi.cdef [[
11 typedef struct _Eina_Tiler Eina_Tiler;
12
13 typedef struct _Eina_Tile_Grid_Info {
14 unsigned long col, row;
15 Eina_Rectangle rect;
16 Eina_Bool full;
17 } Eina_Tile_Grid_Info;
18
19 typedef sruct_Eina_Tile_Grid_Slicer {
20 unsigned long col1, col2, row1, row2;
21 int tile_w, tile_h;
22 int x_rel, y_rel;
23 int w1_rel, h1_rel;
24 int w2_rel, h2_rel;
25 Eina_Tile_Grid_Info info;
26 Eina_Bool first;
27 } Eina_Tile_Grid_Slicer;
28
29 typedef unsigned char Eina_Bool;
30
31 Eina_Tiler *eina_tiler_new(int w, int h);
32 void eina_tiler_free(Eina_Tiler *t);
33 void eina_tiler_tile_size_set(Eina_Tiler *t, int w, int h);
34 void eina_tiler_area_size_set(Eina_Tiler *t, int w, int h);
35 void eina_tiler_area_size_get(const Eina_Tiler *t, int *w, int *h);
36 void eina_tiler_strict_set(Eina_Tiler *t, Eina_Bool strict);
37 Eina_Bool eina_tiler_empty(Eina_Tiler *t);
38 Eina_Bool eina_tiler_rect_add(Eina_Tiler *t, const Eina_Rectangle *r);
39 void eina_tiler_rect_del(Eina_Tiler *t, const Eina_Rectangle *r);
40 void eina_tiler_clear(Eina_Tiler *t);
41 Eina_Iterator *eina_tiler_iterator_new(const Eina_Tiler *t);
42
43 Eina_Iterator *eina_tile_grid_slicer_iterator_new(int x, int y, int w, int h, int tile_w, int tile_h);
44]]
45
46local cutil = require("cutil")
47local util = require("util")
48
49local M = {}
50
51local eina
52
53local init = function()
54 eina = util.lib_load("eina")
55end
56
57local shutdown = function()
58 util.lib_unload("eina")
59end
60
61cutil.init_module(init, shutdown)
62
63local dgetmt = debug.getmetatable
64
65local Iterator = iterator.Iterator
66
67local Tiler_Iterator = Iterator:clone {
68 __ctor = function(self, selfmt, tiler)
69 return Iterator.__ctor(self, selfmt,
70 eina.eina_tiler_iterator_new(tiler))
71 end,
72
73 next = function(self)
74 local v = Iterator.next(self)
75 if not v then return nil end
76 return ffi.cast("Eina_Rectangle*", v)
77 end
78}
79
80local Tile_Grid_Slicer_Iterator = Iterator:clone {
81 __ctor = function(self, selfmt, x, y, w, h, tile_w, tile_h)
82 return Iterator.__ctor(self, selfmt,
83 eina.eina_tile_grid_slicer_iterator_new(x, y, w, h, tile_w, tile_h))
84 end,
85
86 next = function(self)
87 local v = Iterator.next(self)
88 if not v then return nil end
89 return ffi.cast("Eina_Tile_Grid_Info*", v)
90 end
91}
92
93M.Tiler = ffi.metatype("Eina_Tiler", {
94 __new = function(self, w, h)
95 return ffi.gc(eina.eina_tiler_new(w, h), self.free)
96 end,
97 __index = {
98 free = function(self) eina.eina_tiler_free(ffi.gc(self, nil)) end,
99
100 tile_size_set = function(self, w, h)
101 eina.eina_tiler_tile_size_set(self, w, h)
102 end,
103
104 area_size_set = function(self, w, h)
105 eina.eina_tiler_area_sie_set(self, w, h)
106 end,
107
108 area_size_get = function(self)
109 local w, h = ffi.new("int[1]"), ffi.new("int[2]")
110 eina.eina_tiler_area_size_get(self, w, h)
111 return w[0], h[0]
112 end,
113
114 strict_set = function(self, strict)
115 eina.eina_tiler_strict_set(self, strict)
116 end,
117
118 is_empty = function(self)
119 return eina.eina_tiler_empty(self) ~= 0
120 end,
121
122 rect_add = function(self, r)
123 return eina.eina_tiler_rect_add(self, r) ~= 0
124 end,
125 rect_del = function(self, r)
126 eina.eina_tiler_rect_del(self, r)
127 end,
128
129 clear = function(self) eina.eina_tiler_clear(self) end,
130
131 iterator = function(self)
132 return M.Tiler_Iterator(self)
133 endd
134 }
135})
136
137M.Tile_Grid_Slicer = ffi.metatype("Eina_Tile_Grid_Slicer", {
138 __index = {
139 setup = function(self, x, y, w, h, tile_w, tile_h)
140 return eina.eina_tile_grid_slicer_setup(x, y, w, h,
141 tile_w, tile_h) ~= 0
142 end,
143
144 next = function(self)
145 local info = ffi.new("Eina_Tile_Grid_Info*[1]")
146 if eina.eina_tile_grid_slicer_next(self, info) == 0 then
147 return nil
148 end
149 return info[0]
150 end,
151
152 each = function(self)
153 return function()
154 return self:next()
155 end
156 end,
157
158 Iterator = function(x, y, w, h, tw, th)
159 return Tile_Grid_Slicer_Iterator(x, y, w, h, tw, th)
160 end
161 }
162})
163
164return M
diff --git a/src/bindings/lua/eina/xattr.lua b/src/bindings/lua/eina/xattr.lua
new file mode 100644
index 0000000000..3e2417d194
--- /dev/null
+++ b/src/bindings/lua/eina/xattr.lua
@@ -0,0 +1,157 @@
1-- EFL LuaJIT bindings: Eina (xattr module)
2-- For use with Elua
3
4local ffi = require("ffi")
5local C = ffi.C
6
7local iterator = require("eina.iterator")
8
9ffi.cdef [[
10 typedef unsigned char Eina_Bool;
11 typedef ptrdiff_t ssize_t;
12
13 typedef enum {
14 EINA_XATTR_INSERT,
15 EINA_XATTR_REPLACE,
16 EINA_XATTR_CREATED
17 } Eina_Xattr_Flags;
18
19 typedef struct _Eina_Xattr Eina_Xattr;
20 struct _Eina_Xattr {
21 const char *name;
22 const char *value;
23 size_t length;
24 };
25
26 Eina_Iterator *eina_xattr_ls(const char *file);
27 Eina_Iterator *eina_xattr_value_ls(const char *file);
28 Eina_Iterator *eina_xattr_fd_ls(int fd);
29 Eina_Iterator *eina_xattr_value_fd_ls(int fd);
30 Eina_Bool eina_xattr_copy(const char *src, const char *dst);
31 Eina_Bool eina_xattr_fd_copy(int src, int dst);
32 void *eina_xattr_get(const char *file, const char *attribute, ssize_t *size);
33 void *eina_xattr_fd_get(int fd, const char *attribute, ssize_t *size);
34 Eina_Bool eina_xattr_set(const char *file, const char *attribute, const void *data, ssize_t length, Eina_Xattr_Flags flags);
35 Eina_Bool eina_xattr_fd_set(int fd, const char *attribute, const void *data, ssize_t length, Eina_Xattr_Flags flags);
36 Eina_Bool eina_xattr_del(const char *file, const char *attribute);
37 Eina_Bool eina_xattr_fd_del(int fd, const char *attribute);
38 Eina_Bool eina_xattr_string_set(const char *file, const char *attribute, const char *data, Eina_Xattr_Flags flags);
39 char *eina_xattr_string_get(const char *file, const char *attribute);
40 Eina_Bool eina_xattr_double_set(const char *file, const char *attribute, double value, Eina_Xattr_Flags flags);
41 Eina_Bool eina_xattr_double_get(const char *file, const char *attribute, double *value);
42 Eina_Bool eina_xattr_int_set(const char *file, const char *attribute, int value, Eina_Xattr_Flags flags);
43 Eina_Bool eina_xattr_int_get(const char *file, const char *attribute, int *value);
44
45 void free(void*);
46]]
47
48local cutil = require("cutil")
49local util = require("util")
50
51local M = {}
52
53local eina
54
55local init = function()
56 eina = util.lib_load("eina")
57end
58
59local shutdown = function()
60 util.lib_unload("eina")
61end
62
63cutil.init_module(init, shutdown)
64
65local Iterator = iterator.Iterator
66
67local Name_Iterator = Iterator:clone {
68 __ctor = function(self, selfmt, file)
69 return Iterator.__ctor(self, selfmt, eina.eina_xattr_ls(file))
70 end,
71 next = function(self)
72 local v = Iterator.next(self)
73 if not v then return nil end
74 return ffi.string(v)
75 end
76}
77
78M.ls = function(file) return Name_Iterator(file) end
79
80local Value_Iterator = Iterator:clone {
81 __ctor = function(self, selfmt, file)
82 return Iterator.__ctor(self, selfmt, eina.eina_xattr_value_ls(file))
83 end,
84 next = function(self)
85 local v = Iterator.next(self)
86 if not v then return nil end
87 v = ffi.cast(v, "Eina_Xattr*")
88 return ffi.string(v.name), ffi.string(v.value, v.length)
89 end
90}
91
92M.value_ls = function(file) return Value_Iterator(file) end
93
94M.copy = function(src, dst)
95 return eina.eina_xatr_copy(src, dst) ~= 0
96end
97
98M.get = function(file, attribute)
99 local size = ffi.new("size_t[1]")
100 local v = eina.eina_xattr_get(file, attribute, size)
101 if v == ffi.nullptr then return nil end
102 local r = ffi.string(v, size[0])
103 C.free(v)
104 return r
105end
106
107M.flags = {
108 INSERT = 0,
109 REPLACE = 1,
110 CREATED = 2
111}
112
113M.set = function(file, attribute, data, flags)
114 if not data then return false end
115 return eina.eina_xattr_set(file, attribute, data, #data, flags or 0) ~= 0
116end
117
118M.del = function(file, attribute)
119 return eina.eina_xattr_del(file, attribute) ~= 0
120end
121
122M.string_set = function(file, attribute, data, flags)
123 return eina.eina_xattr_set(file, attribute, data, #data + 1,
124 flags or 0) ~= 0
125end
126
127M.string_get = function(file, attribute)
128 local v = eina.eina_xattr_string_get(file, attribute)
129 if v == ffi.nullptr then return nil end
130 local r = ffi.string(v)
131 C.free(v)
132 return r
133end
134
135M.double_set = function(file, attribute, value, flags)
136 return eina.eina_xattr_double_set(file, attribute, value, flags) ~= 0
137end
138
139M.double_get = function(file, attribute)
140 local v = ffi.new("double[1]")
141 local r = eina.eina_xattr_double_get(file, attribute, v)
142 if r == 0 then return false end
143 return true, tonumber(v[0])
144end
145
146M.int_set = function(file, attribute, value, flags)
147 return eina.eina_xattr_int_set(file, attribute, value, flags) ~= 0
148end
149
150M.int_get = function(file, attribute)
151 local v = ffi.new("int[1]")
152 local r = eina.eina_xattr_int_get(file, attribute, v)
153 if r == 0 then return false end
154 return true, tonumber(v[0])
155end
156
157return M
diff --git a/src/bindings/lua/eo.lua b/src/bindings/lua/eo.lua
new file mode 100644
index 0000000000..42531aa153
--- /dev/null
+++ b/src/bindings/lua/eo.lua
@@ -0,0 +1,471 @@
1-- EFL LuaJIT bindings: Eo
2-- For use with Elua
3
4local ffi = require("ffi")
5
6ffi.cdef [[
7 typedef unsigned char Eina_Bool;
8 typedef struct _Eina_Iterator Eina_Iterator;
9
10 typedef struct _Eo_Opaque Eo;
11 typedef Eo Eo_Class;
12
13 typedef short Eo_Callback_Priority;
14
15 typedef void (*eo_key_data_free_func)(void *);
16
17 struct _Eo_Event_Description {
18 const char *name;
19 const char *doc;
20 Eina_Bool unfreezable;
21 };
22 typedef struct _Eo_Event_Description Eo_Event_Description;
23
24 typedef Eina_Bool (*Eo_Event_Cb)(void *data, Eo *obj,
25 const Eo_Event_Description *desc, void *event_info);
26
27 struct _Eo_Callback_Array_Item {
28 const Eo_Event_Description *desc;
29 Eo_Event_Cb func;
30 };
31 typedef struct _Eo_Callback_Array_Item Eo_Callback_Array_Item;
32
33 Eina_Bool eo_init(void);
34 Eina_Bool eo_shutdown(void);
35
36 Eina_Bool eo_isa(const Eo *obj, const Eo_Class *klass);
37
38 const char *eo_class_name_get(const Eo_Class *klass);
39
40 void eo_constructor(void);
41 void eo_destructor(void);
42
43 Eo *_eo_add_internal_start(const char *file, int line,
44 const Eo_Class *klass_id, Eo *parent, Eina_Bool ref);
45
46 Eina_Bool _eo_do_start(const Eo *obj, const Eo_Class *cur_klass,
47 Eina_Bool is_super, const char *file, const char *func, int line);
48 void _eo_do_end (const Eo **ojb);
49
50 const Eo_Class *eo_class_get(const Eo *obj);
51
52 void *eo_data_xref_internal(const char *file, int line, const Eo *obj,
53 const Eo_Class *klass, const Eo *ref_obj);
54 void eo_data_xunref_internal(const Eo *obj, void *data, const Eo *ref_obj);
55 Eo *eo_xref_internal(const char *file, int line, Eo *obj, const Eo *ref_obj);
56 void eo_xunref(Eo *obj, const Eo *ref_obj);
57 Eo *eo_ref(const Eo *obj);
58 void eo_unref(const Eo *obj);
59 int eo_ref_get(const Eo *obj);
60 void eo_wref_add(Eo **wref);
61 void eo_wref_del(Eo **wref);
62
63 void eo_del(const Eo *obj);
64
65 void eo_manual_free_set(Eo *obj, Eina_Bool manual_free);
66 Eina_Bool eo_manual_free(Eo *obj);
67 Eina_Bool eo_destructed_is(const Eo *obj);
68
69 Eina_Bool eo_composite_attach(Eo *comp_obj, Eo *parent);
70 Eina_Bool eo_composite_detach(Eo *comp_obj, Eo *parent);
71 Eina_Bool eo_composite_is(const Eo *comp_obj);
72
73 void eo_parent_set(Eo *parent);
74 Eo *eo_parent_get(void);
75
76 void eo_event_freeze(void);
77 void eo_event_thaw(void);
78 int eo_event_freeze_count_get(void);
79 void eo_event_global_freeze(void);
80 void eo_event_global_thaw(void);
81 int eo_event_global_freeze_count_get(void);
82
83 Eina_Bool eo_finalized_get(void);
84 Eo *eo_finalize(void);
85
86 void eo_event_callback_forwarder_add(const Eo_Event_Description *desc,
87 Eo *new_obj);
88 void eo_event_callback_forwarder_del(const Eo_Event_Description *desc,
89 Eo *new_obj);
90 void eo_event_callback_priority_add(const Eo_Event_Description *desc,
91 Eo_Callback_Priority priority, Eo_Event_Cb cb, const void *data);
92 void eo_event_callback_del(const Eo_Event_Description *desc,
93 Eo_Event_Cb func, const void *user_data);
94 void eo_event_callback_array_priority_add(const Eo_Callback_Array_Item *array,
95 Eo_Callback_Priority priority, const void *data);
96 void eo_event_callback_array_del(const Eo_Callback_Array_Item *array,
97 const void *user_data);
98 Eina_Bool eo_event_callback_call(const Eo_Event_Description *desc,
99 void *event_info);
100
101 void eo_key_data_set(const char *key, const void *data,
102 eo_key_data_free_func free_func);
103 void *eo_key_data_get(const char *key);
104
105 Eina_Iterator *eo_children_iterator_new(void);
106
107 const Eo_Class *eo_base_class_get(void);
108
109 extern const Eo_Event_Description _EO_BASE_EVENT_DEL;
110]]
111
112local addr_d = ffi.typeof("union { double d; const Eo *p; }")
113local eo_obj_addr_get = function(x)
114 local v = addr_d()
115 v.p = x
116 return tonumber(v.d)
117end
118
119local cutil = require("cutil")
120local util = require("util")
121
122local M = {}
123
124local eo
125
126local classes = {}
127local eo_classes = {}
128
129-- event system
130
131local eo_callbacks, eo_cbidcache = {}, {}
132
133local eo_event_del, eo_event_cb
134
135local eo_event_del_fun = function(data, obj, desc, einfo)
136 local addr = eo_obj_addr_get(obj)
137 if eo_callbacks[addr] then
138 eo_callbacks[addr], eo_cbidcache[addr] = nil, nil
139 end
140end
141
142local eo_event_cb_fun = function(data, obj, desc, einfo)
143 local addr = eo_obj_addr_get(obj)
144 local cbs = eo_callbacks[addr]
145 assert(cbs)
146 local cidx = tonumber(ffi.cast("intptr_t", data))
147 local fun = cbs[cidx]
148 assert(fun)
149 return fun() ~= false
150end
151
152local connect = function(self, ename, func, priority)
153 local ev = self.__events[ename]
154 if not ev then
155 return false, "attempt to connect an invalid event '" .. ename .. "'"
156 end
157 local cl = eo_classes["Eo_Base"]
158 -- add the callback to the respective array
159 local cdel = false
160 local addr = eo_obj_addr_get(self)
161 local cbs = eo_callbacks[addr]
162 local cbi = eo_cbidcache[addr]
163 if not cbs then
164 cbs, cbi = {}, {}
165 eo_callbacks[addr], eo_cbidcache[addr] = cbs, cbi
166 cdel = true
167 end
168 local cidx = #cbs + 1
169 cbs[cidx], cbi[func] = func, cidx
170 M.__do_start(self, cl)
171 eo.eo_event_callback_priority_add(ev, priority or 0,
172 eo_event_cb, ffi.cast("void *", cidx))
173 eo.eo_event_callback_priority_add(eo._EO_BASE_EVENT_DEL, 0, eo_event_del,
174 nil)
175 M.__do_end()
176 return true
177end
178
179local disconnect = function(self, ename, func)
180 local ev = self.__events[ename]
181 if not ev then
182 return false, "attempt to disconnect an invalid event '" .. ename .. "'"
183 end
184 local cl = eo_classes["Eo_Base"]
185 -- like connect, but the other way around
186 local addr = eo_obj_addr_get(self)
187 local cbs = eo_callbacks[addr]
188 if not cbs then
189 return false
190 end
191 local cbi = eo_cbidcache[addr]
192 assert(cbi)
193 local cidx = cbi[func]
194 if not cidx then
195 return false
196 end
197 cbs[cidx] = nil
198 cbi[func] = nil
199 M.__do_start(self, cl)
200 eo.eo_event_callback_del(ev, eo_event_cb, ffi.cast("void *", cidx))
201 M.__do_end()
202 return true
203end
204
205local init = function()
206 eo = util.lib_load("eo")
207 eo.eo_init()
208 local eocl = eo.eo_base_class_get()
209 local addr = eo_obj_addr_get(eocl)
210 classes["Eo_Base"] = util.Object:clone {
211 connect = connect,
212 disconnect = disconnect,
213 __events = util.Object:clone {},
214 __properties = util.Object:clone {}
215 }
216 classes[addr] = classes["Eo_Base"]
217 eo_classes["Eo_Base"] = eocl
218 eo_classes[addr] = eocl
219 eo_event_del = ffi.cast("Eo_Event_Cb", eo_event_del_fun)
220 eo_event_cb = ffi.cast("Eo_Event_Cb", eo_event_cb_fun)
221end
222
223local shutdown = function()
224 classes, eo_classes = {}, {}
225 eo.eo_shutdown()
226 eo_event_del:free()
227 eo_event_cb:free()
228 eo_event_del = nil
229 eo_event_cb = nil
230 eo_callbacks = {}
231 eo_cbidcache = {}
232 util.lib_unload("eo")
233end
234
235local getinfo = debug.getinfo
236
237local getfuncname = function(info)
238 return info.name or "<" .. tostring(info.func) .. ">"
239end
240
241M.class_get = function(name)
242 return classes[name]
243end
244
245M.eo_class_get = function(name)
246 return eo_classes[name]
247end
248
249local inherit_meta = function(body, field, parents, mixins)
250 local o = body[field]
251 if o then
252 o = parents[1][field]:clone(o)
253 for i = 2, #parents do o:add_parent(parents[i][field]) end
254 for i = 1, #mixins do o:add_mixin (mixins [i][field]) end
255 body[field] = o
256 end
257end
258
259M.class_register = function(name, parents, mixins, body, eocl)
260 -- map given names to objects
261 local pars = {}
262 for i = 1, #parents do pars[i] = classes[parents[i]] end
263 -- for mixins, we need to check if it hasn't already been mixed in
264 -- in some parent (doesn't matter how deep down the tree), because
265 -- if it has, we need to skip it (for proper inheritance lookup order)
266 local mins = {}
267 local midx = 1
268 for i = 1, #mixins do
269 local mixin = mixins[i]
270 local ck, hasmi = "__mixin_" .. mixin, false
271 if mixin[ck] then
272 for i = 1, #pars do
273 if pars[i][ck] then
274 hasmi = true
275 break
276 end
277 end
278 end
279 if not hasmi then
280 mins[midx] = mixin
281 midx = midx + 1
282 end
283 end
284
285 inherit_meta(body, "__events" , pars, mins)
286 inherit_meta(body, "__properties", pars, mins)
287
288 local lcl = pars[1]:clone(body)
289 for i = 2, #pars do lcl:add_parent(pars[i]) end
290 for i = 1, #mins do lcl:add_mixin (mins[i]) end
291
292 local addr = eo_obj_addr_get(eocl)
293 classes [name], classes [addr] = lcl , lcl
294 eo_classes[name], eo_classes[addr] = eocl, eocl
295end
296
297M.class_unregister = function(name)
298 local addr = eo_obj_addr_get(eo_classes[name])
299 classes [name], classes [addr] = nil
300 eo_classes[name], eo_classes[addr] = nil
301end
302
303local obj_gccb = function(obj)
304 eo.eo_unref(obj)
305end
306
307M.__ctor_common = function(klass, parent, ctor, loff, ...)
308 local info = getinfo(2 + (loff or 0), "nlSf")
309 local source = info.source
310 local func = getfuncname(info)
311 local line = info.currentline
312 local ret = eo._eo_add_internal_start(source, line, klass, parent, true)
313 local retval
314 if eo._eo_do_start(ret, nil, false, source, func, line) ~= 0 then
315 eo.eo_constructor()
316 if ctor then ctor(ret, ...) end
317 ret = eo.eo_finalize()
318 eo._eo_do_end(nil)
319 end
320 ffi.gc(ret, obj_gccb)
321 return ret
322end
323
324M.__do_start = function(self, klass)
325 if eo.eo_isa(self, klass) == 0 then
326 error("method call on an invalid object", 3)
327 end
328 local info = getinfo(3, "nlSf")
329 return eo._eo_do_start(self, nil, false, info.source,
330 getfuncname(info), info.currentline) ~= 0
331end
332
333M.__do_end = function()
334 eo._eo_do_end(nil) -- the parameter is unused and originally there
335 -- only for cleanup (dtor)
336end
337
338local get_obj_mt = function(obj)
339 local cl = eo.eo_class_get(obj)
340 if cl == ffi.nullptr then return nil end
341 return classes[eo_obj_addr_get(cl)]
342end
343
344local prop_proxy_meta = {
345 __index = function(self, key)
346 local ngkeys = self.ngkeys
347 if ngkeys <= 0 then
348 error("property '" .. self.key .. "' has no getter keys", 2)
349 end
350 if ngkeys > 1 and type(key) == "table" then
351 if self.ngvals > 1 then
352 return { self(unpack(key)) }
353 else
354 return self(unpack(key))
355 end
356 else
357 if self.ngvals > 1 then
358 return { self(key) }
359 else
360 return self(key)
361 end
362 end
363 end,
364
365 __newindex = function(self, key, val)
366 local nskeys = self.nskeys
367 if nskeys <= 0 then
368 error("property '" .. self.key .. "' has no setter keys", 2)
369 end
370 if nskeys > 1 then
371 -- ultra slow path, q66 failed optimizing this
372 -- if you ever get to touch this, increment this
373 -- counter to let others know you failed too.
374 --
375 -- failures: 1
376 --
377 -- fortunately this one is not very commonly used.
378 local atbl
379 if type(key) == "table" then
380 atbl = { unpack(key) }
381 else
382 atbl = { key }
383 end
384 if self.nsvals > 1 and type(val) == "table" then
385 for i, v in ipairs(val) do atbl[nskeys + i] = v end
386 else
387 atbl[nskeys + 1] = val
388 end
389 self.mt[self.key .. "_set"](self.obj, unpack(atbl))
390 else
391 if self.nsvals > 1 and type(val) == "table" then
392 -- somewhat less slow but still slow path
393 self.mt[self.key .. "_set"](self.obj, key, unpack(val))
394 else
395 -- least slow, no unpacks, no temporaries, just proxy
396 self.mt[self.key .. "_set"](self.obj, key, val)
397 end
398 end
399 end,
400
401 -- provides alt syntax for getters with keys
402 __call = function(self, ...)
403 return self.mt[self.key .. "_get"](self.obj, ...)
404 end,
405
406 -- locks out the proxy
407 __metatable = false
408}
409
410-- each __properties field looks like this:
411--
412-- { NUM_GET_KEYS, NUM_SET_KEYS, NUM_GET_VALS, NUM_SET_VALS, GETTABLE, SETTABLE }
413--
414-- the last two are booleans (determining if the property can be get and set).
415ffi.metatype("Eo", {
416 -- handles property getting with no keys and also properties with keys
417 __index = function(self, key)
418 local mt = get_obj_mt(self)
419 if not mt then return nil end
420 local pt = mt.__properties
421 local pp = pt[key]
422 if not pp then
423 return mt[key]
424 end
425 local ngkeys, nskeys = pp[1], pp[2]
426 if ngkeys ~= 0 or nskeys ~= 0 then
427 -- proxy - slow path, but no way around it
428 -- basically the proxy is needed because we want nice syntax and
429 -- lua can't do it by default. so we help ourselves a bit with this
430 return setmetatable({ ngkeys = ngkeys, nskeys = nskeys,
431 ngvals = pp[3], nsvals = pp[4], obj = self, key = key,
432 mt = mt }, prop_proxy_meta)
433 end
434 if not pp[5] then
435 error("property '" .. key .. "' is not gettable", 2)
436 end
437 if pp[3] > 1 then
438 return { mt[key .. "_get"](self) }
439 else
440 return mt[key .. "_get"](self)
441 end
442 end,
443
444 -- handles property setting with no keys
445 __newindex = function(self, key, val)
446 local mt = get_obj_mt(self)
447 if not mt then return nil end
448 local pt = mt.__properties
449 local pp = pt[key]
450 if not pp then
451 error("no such property '" .. key .. "'", 2)
452 end
453 if not pp[6] then
454 error("property '" .. key .. "' is not settable", 2)
455 end
456 local nkeys = pp[2]
457 if nkeys ~= 0 then
458 error("property '" .. key .. "' requires " .. nkeys .. " keys", 2)
459 end
460 local nvals = pp[4]
461 if nvals > 1 and type(val) == "table" then
462 mt[key .. "_set"](self, unpack(val))
463 else
464 mt[key .. "_set"](self, val)
465 end
466 end
467})
468
469cutil.init_module(init, shutdown)
470
471return M
diff --git a/src/bindings/lua/eolian.lua b/src/bindings/lua/eolian.lua
new file mode 100644
index 0000000000..e9001dbc66
--- /dev/null
+++ b/src/bindings/lua/eolian.lua
@@ -0,0 +1,1867 @@
1-- EFL LuaJIT bindings: Eolian
2-- For use with Elua
3
4local ffi = require("ffi")
5
6ffi.cdef [[
7 void eina_stringshare_del(const char *str);
8 void free(void *ptr);
9]]
10
11ffi.cdef [[
12 typedef unsigned char Eina_Bool;
13 typedef struct _Eina_Iterator Eina_Iterator;
14
15 typedef struct _Eolian_State Eolian_State;
16 typedef struct _Eolian_Object Eolian_Object;
17 typedef struct _Eolian_Class Eolian_Class;
18 typedef struct _Eolian_Function Eolian_Function;
19 typedef struct _Eolian_Part Eolian_Part;
20 typedef struct _Eolian_Type Eolian_Type;
21 typedef struct _Eolian_Typedecl Eolian_Typedecl;
22 typedef struct _Eolian_Function_Parameter Eolian_Function_Parameter;
23 typedef struct _Eolian_Implement Eolian_Implement;
24 typedef struct _Eolian_Constructor Eolian_Constructor;
25 typedef struct _Eolian_Event Eolian_Event;
26 typedef struct _Eolian_Expression Eolian_Expression;
27 typedef struct _Eolian_Constant Eolian_Constant;
28 typedef struct _Eolian_Error Eolian_Error;
29 typedef struct _Eolian_Struct_Type_Field Eolian_Struct_Type_Field;
30 typedef struct _Eolian_Enum_Type_Field Eolian_Enum_Type_Field;
31 typedef struct _Eolian_Documentation Eolian_Documentation;
32 typedef struct _Eolian_Value Eolian_Value;
33 typedef struct _Eolian_Unit Eolian_Unit;
34
35 typedef void (*Eolian_Panic_Cb)(const Eolian_State *state, const char *msg);
36 typedef void (*Eolian_Error_Cb)(const Eolian_Object *obj, const char *msg, void *data);
37
38 typedef enum {
39 EOLIAN_OBJECT_UNKNOWN = 0,
40 EOLIAN_OBJECT_CLASS,
41 EOLIAN_OBJECT_TYPEDECL,
42 EOLIAN_OBJECT_STRUCT_FIELD,
43 EOLIAN_OBJECT_ENUM_FIELD,
44 EOLIAN_OBJECT_TYPE,
45 EOLIAN_OBJECT_CONSTANT,
46 EOLIAN_OBJECT_EXPRESSION,
47 EOLIAN_OBJECT_FUNCTION,
48 EOLIAN_OBJECT_FUNCTION_PARAMETER,
49 EOLIAN_OBJECT_EVENT,
50 EOLIAN_OBJECT_PART,
51 EOLIAN_OBJECT_IMPLEMENT,
52 EOLIAN_OBJECT_CONSTRUCTOR,
53 EOLIAN_OBJECT_DOCUMENTATION,
54 EOLIAN_OBJECT_ERROR
55 } Eolian_Object_Type;
56
57 typedef enum
58 {
59 EOLIAN_UNRESOLVED = 0,
60 EOLIAN_PROPERTY,
61 EOLIAN_PROP_SET,
62 EOLIAN_PROP_GET,
63 EOLIAN_METHOD,
64 EOLIAN_FUNCTION_POINTER
65 } Eolian_Function_Type;
66
67 typedef enum
68 {
69 EOLIAN_PARAMETER_UNKNOWN = 0,
70 EOLIAN_PARAMETER_IN,
71 EOLIAN_PARAMETER_OUT,
72 EOLIAN_PARAMETER_INOUT
73 } Eolian_Parameter_Direction;
74
75 typedef enum
76 {
77 EOLIAN_CLASS_UNKNOWN_TYPE = 0,
78 EOLIAN_CLASS_REGULAR,
79 EOLIAN_CLASS_ABSTRACT,
80 EOLIAN_CLASS_MIXIN,
81 EOLIAN_CLASS_INTERFACE
82 } Eolian_Class_Type;
83
84 typedef enum
85 {
86 EOLIAN_SCOPE_UNKNOWN = 0,
87 EOLIAN_SCOPE_PUBLIC,
88 EOLIAN_SCOPE_PRIVATE,
89 EOLIAN_SCOPE_PROTECTED
90 } Eolian_Object_Scope;
91
92 typedef enum {
93 EOLIAN_TYPEDECL_UNKNOWN = 0,
94 EOLIAN_TYPEDECL_STRUCT,
95 EOLIAN_TYPEDECL_STRUCT_OPAQUE,
96 EOLIAN_TYPEDECL_ENUM,
97 EOLIAN_TYPEDECL_ALIAS,
98 EOLIAN_TYPEDECL_FUNCTION_POINTER
99 } Eolian_Typedecl_Type;
100
101 typedef enum
102 {
103 EOLIAN_TYPE_UNKNOWN_TYPE = 0,
104 EOLIAN_TYPE_VOID,
105 EOLIAN_TYPE_REGULAR,
106 EOLIAN_TYPE_CLASS,
107 EOLIAN_TYPE_UNDEFINED
108 } Eolian_Type_Type;
109
110 typedef enum
111 {
112 EOLIAN_TYPE_BUILTIN_INVALID = 0,
113
114 EOLIAN_TYPE_BUILTIN_BYTE,
115 EOLIAN_TYPE_BUILTIN_UBYTE,
116 EOLIAN_TYPE_BUILTIN_CHAR,
117 EOLIAN_TYPE_BUILTIN_SHORT,
118 EOLIAN_TYPE_BUILTIN_USHORT,
119 EOLIAN_TYPE_BUILTIN_INT,
120 EOLIAN_TYPE_BUILTIN_UINT,
121 EOLIAN_TYPE_BUILTIN_LONG,
122 EOLIAN_TYPE_BUILTIN_ULONG,
123 EOLIAN_TYPE_BUILTIN_LLONG,
124 EOLIAN_TYPE_BUILTIN_ULLONG,
125
126 EOLIAN_TYPE_BUILTIN_INT8,
127 EOLIAN_TYPE_BUILTIN_UINT8,
128 EOLIAN_TYPE_BUILTIN_INT16,
129 EOLIAN_TYPE_BUILTIN_UINT16,
130 EOLIAN_TYPE_BUILTIN_INT32,
131 EOLIAN_TYPE_BUILTIN_UINT32,
132 EOLIAN_TYPE_BUILTIN_INT64,
133 EOLIAN_TYPE_BUILTIN_UINT64,
134 EOLIAN_TYPE_BUILTIN_INT128,
135 EOLIAN_TYPE_BUILTIN_UINT128,
136
137 EOLIAN_TYPE_BUILTIN_SIZE,
138 EOLIAN_TYPE_BUILTIN_SSIZE,
139 EOLIAN_TYPE_BUILTIN_INTPTR,
140 EOLIAN_TYPE_BUILTIN_UINTPTR,
141 EOLIAN_TYPE_BUILTIN_PTRDIFF,
142
143 EOLIAN_TYPE_BUILTIN_TIME,
144
145 EOLIAN_TYPE_BUILTIN_FLOAT,
146 EOLIAN_TYPE_BUILTIN_DOUBLE,
147
148 EOLIAN_TYPE_BUILTIN_BOOL,
149
150 EOLIAN_TYPE_BUILTIN_SLICE,
151 EOLIAN_TYPE_BUILTIN_RW_SLICE,
152
153 EOLIAN_TYPE_BUILTIN_VOID,
154
155 EOLIAN_TYPE_BUILTIN_ACCESSOR,
156 EOLIAN_TYPE_BUILTIN_ARRAY,
157 EOLIAN_TYPE_BUILTIN_FUTURE,
158 EOLIAN_TYPE_BUILTIN_ITERATOR,
159 EOLIAN_TYPE_BUILTIN_LIST,
160
161 EOLIAN_TYPE_BUILTIN_ANY_VALUE,
162 EOLIAN_TYPE_BUILTIN_ANY_VALUE_REF,
163 EOLIAN_TYPE_BUILTIN_BINBUF,
164 EOLIAN_TYPE_BUILTIN_EVENT,
165 EOLIAN_TYPE_BUILTIN_MSTRING,
166 EOLIAN_TYPE_BUILTIN_STRING,
167 EOLIAN_TYPE_BUILTIN_STRINGSHARE,
168 EOLIAN_TYPE_BUILTIN_STRBUF,
169
170 EOLIAN_TYPE_BUILTIN_HASH,
171 EOLIAN_TYPE_BUILTIN_VOID_PTR
172 } Eolian_Type_Builtin_Type;
173
174 typedef enum {
175 EOLIAN_EXPR_UNKNOWN = 0,
176 EOLIAN_EXPR_INT,
177 EOLIAN_EXPR_UINT,
178 EOLIAN_EXPR_LONG,
179 EOLIAN_EXPR_ULONG,
180 EOLIAN_EXPR_LLONG,
181 EOLIAN_EXPR_ULLONG,
182 EOLIAN_EXPR_FLOAT,
183 EOLIAN_EXPR_DOUBLE,
184 EOLIAN_EXPR_STRING,
185 EOLIAN_EXPR_CHAR,
186 EOLIAN_EXPR_NULL,
187 EOLIAN_EXPR_BOOL,
188 EOLIAN_EXPR_NAME,
189 EOLIAN_EXPR_UNARY,
190 EOLIAN_EXPR_BINARY
191 } Eolian_Expression_Type;
192
193 typedef enum {
194 EOLIAN_MASK_SINT = 1 << 0,
195 EOLIAN_MASK_UINT = 1 << 1,
196 EOLIAN_MASK_INT = EOLIAN_MASK_SINT | EOLIAN_MASK_UINT,
197 EOLIAN_MASK_FLOAT = 1 << 2,
198 EOLIAN_MASK_BOOL = 1 << 3,
199 EOLIAN_MASK_STRING = 1 << 4,
200 EOLIAN_MASK_CHAR = 1 << 5,
201 EOLIAN_MASK_NULL = 1 << 6,
202 EOLIAN_MASK_SIGNED = EOLIAN_MASK_SINT | EOLIAN_MASK_FLOAT,
203 EOLIAN_MASK_NUMBER = EOLIAN_MASK_INT | EOLIAN_MASK_FLOAT,
204 EOLIAN_MASK_ALL = EOLIAN_MASK_NUMBER | EOLIAN_MASK_BOOL
205 | EOLIAN_MASK_STRING | EOLIAN_MASK_CHAR
206 | EOLIAN_MASK_NULL
207 } Eolian_Expression_Mask;
208
209 typedef union {
210 char c;
211 Eina_Bool b;
212 const char *s;
213 signed int i;
214 unsigned int u;
215 signed long l;
216 unsigned long ul;
217 signed long long ll;
218 unsigned long long ull;
219 float f;
220 double d;
221 } Eolian_Value_Union;
222
223 typedef struct _Eolian_Value_t {
224 Eolian_Expression_Type type;
225 Eolian_Value_Union value;
226 } Eolian_Value_t;
227
228 typedef enum {
229 EOLIAN_BINOP_INVALID = 0,
230
231 EOLIAN_BINOP_ADD, /* + int, float */
232 EOLIAN_BINOP_SUB, /* - int, float */
233 EOLIAN_BINOP_MUL, /* * int, float */
234 EOLIAN_BINOP_DIV, /* / int, float */
235 EOLIAN_BINOP_MOD, /* % int */
236
237 EOLIAN_BINOP_EQ, /* == all types */
238 EOLIAN_BINOP_NQ, /* != all types */
239 EOLIAN_BINOP_GT, /* > int, float */
240 EOLIAN_BINOP_LT, /* < int, float */
241 EOLIAN_BINOP_GE, /* >= int, float */
242 EOLIAN_BINOP_LE, /* <= int, float */
243
244 EOLIAN_BINOP_AND, /* && all types */
245 EOLIAN_BINOP_OR, /* || all types */
246
247 EOLIAN_BINOP_BAND, /* & int */
248 EOLIAN_BINOP_BOR, /* | int */
249 EOLIAN_BINOP_BXOR, /* ^ int */
250 EOLIAN_BINOP_LSH, /* << int */
251 EOLIAN_BINOP_RSH /* >> int */
252 } Eolian_Binary_Operator;
253
254 typedef enum {
255 EOLIAN_UNOP_INVALID = 0,
256
257 EOLIAN_UNOP_UNM, /* - sint */
258 EOLIAN_UNOP_UNP, /* + sint */
259
260 EOLIAN_UNOP_NOT, /* ! int, float, bool */
261 EOLIAN_UNOP_BNOT, /* ~ int */
262 } Eolian_Unary_Operator;
263
264 typedef enum {
265 EOLIAN_DOC_TOKEN_UNKNOWN = 0,
266 EOLIAN_DOC_TOKEN_TEXT,
267 EOLIAN_DOC_TOKEN_REF,
268 EOLIAN_DOC_TOKEN_MARK_NOTE,
269 EOLIAN_DOC_TOKEN_MARK_WARNING,
270 EOLIAN_DOC_TOKEN_MARK_REMARK,
271 EOLIAN_DOC_TOKEN_MARK_TODO,
272 EOLIAN_DOC_TOKEN_MARKUP_MONOSPACE
273 } Eolian_Doc_Token_Type;
274
275 typedef struct _Eolian_Doc_Token {
276 Eolian_Doc_Token_Type type;
277 const char *text, *text_end;
278 } Eolian_Doc_Token;
279
280 int eolian_init(void);
281 int eolian_shutdown(void);
282 unsigned short eolian_file_format_version_get(void);
283 Eolian_State *eolian_state_new(void);
284 void eolian_state_free(Eolian_State *state);
285 Eolian_Panic_Cb eolian_state_panic_cb_set(Eolian_State *state, Eolian_Panic_Cb cb);
286 Eolian_Error_Cb eolian_state_error_cb_set(Eolian_State *state, Eolian_Error_Cb cb);
287 void *eolian_state_error_data_set(Eolian_State *state, void *data);
288 Eolian_Object_Type eolian_object_type_get(const Eolian_Object *obj);
289 const Eolian_Unit *eolian_object_unit_get(const Eolian_Object *obj);
290 const char *eolian_object_file_get(const Eolian_Object *obj);
291 int eolian_object_line_get(const Eolian_Object *obj);
292 int eolian_object_column_get(const Eolian_Object *obj);
293 const char *eolian_object_name_get(const Eolian_Object *obj);
294 const char *eolian_object_c_name_get(const Eolian_Object *obj);
295 const char *eolian_object_short_name_get(const Eolian_Object *obj);
296 Eina_Iterator *eolian_object_namespaces_get(const Eolian_Object *obj);
297 Eina_Bool eolian_object_is_beta(const Eolian_Object *obj);
298 Eina_Bool eolian_state_directory_add(Eolian_State *state, const char *dir);
299 Eina_Bool eolian_state_system_directory_add(Eolian_State *state);
300 Eina_Iterator *eolian_state_eo_file_paths_get(const Eolian_State *state);
301 Eina_Iterator *eolian_state_eot_file_paths_get(const Eolian_State *state);
302 Eina_Iterator *eolian_state_eo_files_get(const Eolian_State *state);
303 Eina_Iterator *eolian_state_eot_files_get(const Eolian_State *state);
304 const Eolian_Unit *eolian_state_file_parse(Eolian_State *state, const char *filename);
305 const Eolian_Unit *eolian_state_file_path_parse(Eolian_State *state, const char *filepath);
306 Eina_Bool eolian_state_all_eo_files_parse(Eolian_State *state);
307 Eina_Bool eolian_state_all_eot_files_parse(Eolian_State *state);
308 Eina_Bool eolian_state_check(const Eolian_State *state);
309 const Eolian_Unit *eolian_state_unit_by_file_get(const Eolian_State *state, const char *file_name);
310 Eina_Iterator *eolian_state_units_get(const Eolian_State *state);
311
312 const Eolian_State *eolian_unit_state_get(const Eolian_Unit *unit);
313 Eina_Iterator *eolian_unit_children_get(const Eolian_Unit *unit);
314 const char *eolian_unit_file_get(const Eolian_Unit *unit);
315 const char *eolian_unit_file_path_get(const Eolian_Unit *unit);
316 unsigned short eolian_unit_version_get(const Eolian_Unit *unit);
317 const Eolian_Object *eolian_unit_object_by_name_get(const Eolian_Unit *unit, const char *name);
318 Eina_Iterator *eolian_unit_objects_get(const Eolian_Unit *unit);
319 const Eolian_Class *eolian_unit_class_by_name_get(const Eolian_Unit *unit, const char *class_name);
320 Eina_Iterator *eolian_unit_classes_get(const Eolian_Unit *unit);
321 const Eolian_Constant *eolian_unit_constant_by_name_get(const Eolian_Unit *unit, const char *name);
322 const Eolian_Error *eolian_unit_error_by_name_get(const Eolian_Unit *unit, const char *name);
323 Eina_Iterator *eolian_unit_constants_get(const Eolian_Unit *unit);
324 Eina_Iterator *eolian_unit_errors_get(const Eolian_Unit *unit);
325 const Eolian_Typedecl *eolian_unit_alias_by_name_get(const Eolian_Unit *unit, const char *name);
326 const Eolian_Typedecl *eolian_unit_struct_by_name_get(const Eolian_Unit *unit, const char *name);
327 const Eolian_Typedecl *eolian_unit_enum_by_name_get(const Eolian_Unit *unit, const char *name);
328 Eina_Iterator *eolian_unit_aliases_get(const Eolian_Unit *unit);
329 Eina_Iterator *eolian_unit_structs_get(const Eolian_Unit *unit);
330 Eina_Iterator *eolian_unit_enums_get(const Eolian_Unit *unit);
331 Eina_Iterator *eolian_state_objects_by_file_get(const Eolian_State *state, const char *file_name);
332 const Eolian_Class *eolian_state_class_by_file_get(const Eolian_State *state, const char *file_name);
333 Eina_Iterator *eolian_state_constants_by_file_get(const Eolian_State *state, const char *file_name);
334 Eina_Iterator *eolian_state_errors_by_file_get(const Eolian_State *state, const char *file_name);
335 Eina_Iterator *eolian_state_aliases_by_file_get(const Eolian_State *state, const char *file_name);
336 Eina_Iterator *eolian_state_structs_by_file_get(const Eolian_State *state, const char *file_name);
337 Eina_Iterator *eolian_state_enums_by_file_get(const Eolian_State *state, const char *file_name);
338
339 Eolian_Class_Type eolian_class_type_get(const Eolian_Class *klass);
340 const Eolian_Documentation *eolian_class_documentation_get(const Eolian_Class *klass);
341 const char *eolian_class_c_prefix_get(const Eolian_Class *klass);
342 const char *eolian_class_event_c_prefix_get(const Eolian_Class *klass);
343 const char *eolian_class_data_type_get(const Eolian_Class *klass);
344 const Eolian_Class *eolian_class_parent_get(const Eolian_Class *klass);
345 Eina_Iterator *eolian_class_requires_get(const Eolian_Class *klass);
346 Eina_Iterator *eolian_class_extensions_get(const Eolian_Class *klass);
347 Eina_Iterator *eolian_class_functions_get(const Eolian_Class *klass, Eolian_Function_Type func_type);
348 Eolian_Function_Type eolian_function_type_get(const Eolian_Function *function_id);
349 Eolian_Object_Scope eolian_function_scope_get(const Eolian_Function *function_id, Eolian_Function_Type ftype);
350 const char *eolian_function_full_c_name_get(const Eolian_Function *function_id, Eolian_Function_Type ftype);
351 const Eolian_Function *eolian_class_function_by_name_get(const Eolian_Class *klass, const char *func_name, Eolian_Function_Type f_type);
352 const Eolian_Implement *eolian_function_implement_get(const Eolian_Function *function_id);
353 Eina_Bool eolian_function_is_static(const Eolian_Function *function_id);
354 Eina_Bool eolian_function_is_constructor(const Eolian_Function *function_id, const Eolian_Class *klass);
355 Eina_Bool eolian_function_is_function_pointer(const Eolian_Function *function_id);
356 Eina_Iterator *eolian_property_keys_get(const Eolian_Function *foo_id, Eolian_Function_Type ftype);
357 Eina_Iterator *eolian_property_values_get(const Eolian_Function *foo_id, Eolian_Function_Type ftype);
358 Eina_Iterator *eolian_function_parameters_get(const Eolian_Function *function_id);
359 Eolian_Parameter_Direction eolian_parameter_direction_get(const Eolian_Function_Parameter *param);
360 const Eolian_Type *eolian_parameter_type_get(const Eolian_Function_Parameter *param);
361 const Eolian_Expression *eolian_parameter_default_value_get(const Eolian_Function_Parameter *param);
362 const Eolian_Documentation *eolian_parameter_documentation_get(const Eolian_Function_Parameter *param);
363 Eina_Bool eolian_parameter_is_optional(const Eolian_Function_Parameter *param_desc);
364 Eina_Bool eolian_parameter_is_by_ref(const Eolian_Function_Parameter *param_desc);
365 Eina_Bool eolian_parameter_is_move(const Eolian_Function_Parameter *param_desc);
366 const Eolian_Type *eolian_function_return_type_get(const Eolian_Function *function_id, Eolian_Function_Type ftype);
367 const Eolian_Expression *eolian_function_return_default_value_get(const Eolian_Function *foo_id, Eolian_Function_Type ftype);
368 const Eolian_Documentation *eolian_function_return_documentation_get(const Eolian_Function *foo_id, Eolian_Function_Type ftype);
369 Eina_Bool eolian_function_return_allow_unused(const Eolian_Function *foo_id, Eolian_Function_Type ftype);
370 Eina_Bool eolian_function_return_is_by_ref(const Eolian_Function *foo_id, Eolian_Function_Type ftype);
371 Eina_Bool eolian_function_return_is_move(const Eolian_Function *foo_id, Eolian_Function_Type ftype);
372 Eina_Bool eolian_function_object_is_const(const Eolian_Function *function_id);
373 const Eolian_Class *eolian_function_class_get(const Eolian_Function *function_id);
374 const Eolian_Class *eolian_implement_class_get(const Eolian_Implement *impl);
375 const Eolian_Class *eolian_implement_implementing_class_get(const Eolian_Implement *impl);
376 const Eolian_Function *eolian_implement_function_get(const Eolian_Implement *impl, Eolian_Function_Type *func_type);
377 const Eolian_Documentation *eolian_implement_documentation_get(const Eolian_Implement *impl, Eolian_Function_Type f_type);
378 Eina_Bool eolian_implement_is_auto(const Eolian_Implement *impl, Eolian_Function_Type ftype);
379 Eina_Bool eolian_implement_is_empty(const Eolian_Implement *impl, Eolian_Function_Type ftype);
380 Eina_Bool eolian_implement_is_pure_virtual(const Eolian_Implement *impl, Eolian_Function_Type ftype);
381 Eina_Bool eolian_implement_is_prop_get(const Eolian_Implement *impl);
382 Eina_Bool eolian_implement_is_prop_set(const Eolian_Implement *impl);
383 Eina_Iterator *eolian_class_implements_get(const Eolian_Class *klass);
384 const Eolian_Class *eolian_constructor_class_get(const Eolian_Constructor *ctor);
385 const Eolian_Function *eolian_constructor_function_get(const Eolian_Constructor *ctor);
386 Eina_Bool eolian_constructor_is_optional(const Eolian_Constructor *ctor);
387 Eina_Iterator *eolian_class_constructors_get(const Eolian_Class *klass);
388 Eina_Iterator *eolian_class_events_get(const Eolian_Class *klass);
389 const Eolian_Type *eolian_event_type_get(const Eolian_Event *event);
390 const Eolian_Class *eolian_event_class_get(const Eolian_Event *event);
391 const Eolian_Documentation *eolian_event_documentation_get(const Eolian_Event *event);
392 Eolian_Object_Scope eolian_event_scope_get(const Eolian_Event *event);
393 Eina_Bool eolian_event_is_hot(const Eolian_Event *event);
394 Eina_Bool eolian_event_is_restart(const Eolian_Event *event);
395 Eina_Iterator *eolian_class_parts_get(const Eolian_Class *klass);
396 const char *eolian_event_c_macro_get(const Eolian_Event *event);
397 const Eolian_Class *eolian_part_class_get(const Eolian_Part *part);
398 const Eolian_Documentation *eolian_part_documentation_get(const Eolian_Part *part);
399 const Eolian_Event *eolian_class_event_by_name_get(const Eolian_Class *klass, const char *event_name);
400 Eina_Bool eolian_class_ctor_enable_get(const Eolian_Class *klass);
401 Eina_Bool eolian_class_dtor_enable_get(const Eolian_Class *klass);
402 const char *eolian_class_c_get_function_name_get(const Eolian_Class *klass);
403 Eolian_Type_Type eolian_type_type_get(const Eolian_Type *tp);
404 Eolian_Type_Builtin_Type eolian_type_builtin_type_get(const Eolian_Type *tp);
405 const char *eolian_class_c_macro_get(const Eolian_Class *klass);
406 const char *eolian_class_c_data_type_get(const Eolian_Class *klass);
407 Eolian_Typedecl_Type eolian_typedecl_type_get(const Eolian_Typedecl *tp);
408 Eina_Iterator *eolian_typedecl_struct_fields_get(const Eolian_Typedecl *tp);
409 const Eolian_Struct_Type_Field *eolian_typedecl_struct_field_get(const Eolian_Typedecl *tp, const char *field);
410 const Eolian_Documentation *eolian_typedecl_struct_field_documentation_get(const Eolian_Struct_Type_Field *fl);
411 const Eolian_Type *eolian_typedecl_struct_field_type_get(const Eolian_Struct_Type_Field *fl);
412 Eina_Bool eolian_typedecl_struct_field_is_by_ref(const Eolian_Struct_Type_Field *fl);
413 Eina_Bool eolian_typedecl_struct_field_is_move(const Eolian_Struct_Type_Field *fl);
414 Eina_Iterator *eolian_typedecl_enum_fields_get(const Eolian_Typedecl *tp);
415 const Eolian_Enum_Type_Field *eolian_typedecl_enum_field_get(const Eolian_Typedecl *tp, const char *field);
416 const char *eolian_typedecl_enum_field_c_constant_get(const Eolian_Enum_Type_Field *fl);
417 const Eolian_Documentation *eolian_typedecl_enum_field_documentation_get(const Eolian_Enum_Type_Field *fl);
418 const Eolian_Expression *eolian_typedecl_enum_field_value_get(const Eolian_Enum_Type_Field *fl, Eina_Bool force);
419
420 const char *eolian_typedecl_enum_legacy_prefix_get(const Eolian_Typedecl *tp);
421 const Eolian_Documentation *eolian_typedecl_documentation_get(const Eolian_Typedecl *tp);
422
423 const Eolian_Type *eolian_type_base_type_get(const Eolian_Type *tp);
424 const Eolian_Type *eolian_type_next_type_get(const Eolian_Type *tp);
425 const Eolian_Type *eolian_typedecl_base_type_get(const Eolian_Typedecl *tp);
426 const Eolian_Typedecl *eolian_type_typedecl_get(const Eolian_Type *tp);
427
428 const Eolian_Type *eolian_type_aliased_base_get(const Eolian_Type *tp);
429 const Eolian_Type *eolian_typedecl_aliased_base_get(const Eolian_Typedecl *tp);
430
431 const Eolian_Class *eolian_type_class_get(const Eolian_Type *tp);
432 const Eolian_Error *eolian_type_error_get(const Eolian_Type *tp);
433 Eina_Bool eolian_type_is_move(const Eolian_Type *tp);
434 Eina_Bool eolian_type_is_const(const Eolian_Type *tp);
435 Eina_Bool eolian_type_is_ptr(const Eolian_Type *tp);
436
437 Eina_Bool eolian_typedecl_is_extern(const Eolian_Typedecl *tp);
438
439 const char *eolian_type_c_type_get(const Eolian_Type *tp);
440 const char *eolian_typedecl_c_type_get(const Eolian_Typedecl *tp);
441 const char *eolian_typedecl_free_func_get(const Eolian_Typedecl *tp);
442
443 const Eolian_Function *eolian_typedecl_function_pointer_get(const Eolian_Typedecl *tp);
444
445 Eolian_Value_t eolian_expression_eval(const Eolian_Expression *expr, Eolian_Expression_Mask m);
446 const char *eolian_expression_value_to_literal(const Eolian_Value *v);
447 const char *eolian_expression_serialize(const Eolian_Expression *expr);
448 Eolian_Expression_Type eolian_expression_type_get(const Eolian_Expression *expr);
449 Eolian_Binary_Operator eolian_expression_binary_operator_get(const Eolian_Expression *expr);
450 const Eolian_Expression *eolian_expression_binary_lhs_get(const Eolian_Expression *expr);
451 const Eolian_Expression *eolian_expression_binary_rhs_get(const Eolian_Expression *expr);
452 Eolian_Unary_Operator eolian_expression_unary_operator_get(const Eolian_Expression *expr);
453 const Eolian_Expression *eolian_expression_unary_expression_get(const Eolian_Expression *expr);
454 Eolian_Value_t eolian_expression_value_get(const Eolian_Expression *expr);
455 const Eolian_Documentation *eolian_constant_documentation_get(const Eolian_Constant *var);
456 const Eolian_Type *eolian_constant_type_get(const Eolian_Constant *var);
457 const Eolian_Expression *eolian_constant_value_get(const Eolian_Constant *var);
458 Eina_Bool eolian_constant_is_extern(const Eolian_Constant *var);
459 const char *eolian_documentation_summary_get(const Eolian_Documentation *doc);
460 const char *eolian_documentation_description_get(const Eolian_Documentation *doc);
461 const char *eolian_documentation_since_get(const Eolian_Documentation *doc);
462
463 const char *eolian_documentation_tokenize(const char *doc, Eolian_Doc_Token *ret);
464 void eolian_doc_token_init(Eolian_Doc_Token *tok);
465 Eolian_Doc_Token_Type eolian_doc_token_type_get(const Eolian_Doc_Token *tok);
466 char *eolian_doc_token_text_get(const Eolian_Doc_Token *tok);
467 Eolian_Object_Type eolian_doc_token_ref_resolve(const Eolian_Doc_Token *tok, const Eolian_State *state, const Eolian_Object **data, const Eolian_Object **data2);
468
469 const char *eolian_error_message_get(const Eolian_Error *err);
470 const Eolian_Documentation *eolian_error_documentation_get(const Eolian_Error *err);
471 Eina_Bool eolian_error_is_extern(const Eolian_Error *err);
472]]
473
474local cutil = require("cutil")
475local util = require("util")
476
477local iterator = require("eina.iterator")
478
479local Ptr_Iterator = iterator.Ptr_Iterator
480
481local M = {}
482
483local eolian
484local eina
485
486local init = function()
487 eolian = util.lib_load("eolian")
488 eina = util.lib_load("eina")
489 eolian.eolian_init()
490 M.file_format_version = eolian.eolian_file_format_version_get()
491end
492
493local shutdown = function()
494 eolian.eolian_shutdown()
495 util.lib_unload("eolian")
496 util.lib_unload("eina")
497end
498
499local ffi_stringshare = function(s)
500 local r = ffi.string(s)
501 eina.eina_stringshare_del(s)
502 return r
503end
504
505cutil.init_module(init, shutdown)
506
507M.object_type = {
508 UNKNOWN = 0,
509 CLASS = 1,
510 TYPEDECL = 2,
511 STRUCT_FIELD = 3,
512 ENUM_FIELD = 4,
513 TYPE = 5,
514 CONSTANT = 6,
515 EXPRESSION = 7,
516 FUNCTION = 8,
517 FUNCTION_PARAMETER = 9,
518 EVENT = 10,
519 PART = 11,
520 IMPLEMENT = 12,
521 CONSTRUCTOR = 13,
522 DOCUMENTATION = 14,
523 ERROR = 15
524}
525
526M.object_scope = {
527 UNKNOWN = 0,
528 PUBLIC = 1,
529 PRIVATE = 2,
530 PROTECTED = 3
531}
532
533local cast_obj = function(self)
534 return ffi.cast("const Eolian_Object *", self)
535end
536
537local cast_unit = function(self)
538 return ffi.cast("const Eolian_Unit *", self)
539end
540
541local gen_wrap = function(t)
542 return t, function(tt)
543 return setmetatable(tt, { __index = t })
544 end
545end
546
547local object_idx, wrap_object = gen_wrap {
548 object_get = function(self)
549 return cast_obj(self)
550 end,
551
552 type_get = function(self)
553 return tonumber(eolian.eolian_object_type_get(cast_obj(self)))
554 end,
555
556 unit_get = function(self)
557 local v = eolian.eolian_object_unit_get(cast_obj(self))
558 if v == ffi.nullptr then
559 return nil
560 end
561 return v
562 end,
563
564 line_get = function(self)
565 return tonumber(eolian.eolian_object_line_get(cast_obj(self)))
566 end,
567
568 column_get = function(self)
569 return tonumber(eolian.eolian_object_column_get(cast_obj(self)))
570 end,
571
572 file_get = function(self)
573 local v = eolian.eolian_object_file_get(cast_obj(self))
574 if v == ffi.nullptr then
575 return nil
576 end
577 return ffi.string(v)
578 end,
579
580 name_get = function(self)
581 local v = eolian.eolian_object_name_get(cast_obj(self))
582 if v == ffi.nullptr then
583 return nil
584 end
585 return ffi.string(v)
586 end,
587
588 c_name_get = function(self)
589 local v = eolian.eolian_object_c_name_get(cast_obj(self))
590 if v == ffi.nullptr then
591 return nil
592 end
593 return ffi.string(v)
594 end,
595
596 short_name_get = function(self)
597 local v = eolian.eolian_object_short_name_get(cast_obj(self))
598 if v == ffi.nullptr then
599 return nil
600 end
601 return ffi.string(v)
602 end,
603
604 namespaces_get = function(self)
605 return iterator.String_Iterator(
606 eolian.eolian_object_namespaces_get(cast_obj(self)))
607 end,
608
609 is_beta = function(self)
610 return eolian.eolian_object_is_beta(cast_obj(self)) ~= 0
611 end
612}
613
614ffi.metatype("Eolian_Object", { __index = object_idx })
615
616local unit_idx, wrap_unit = gen_wrap {
617 state_get = function(self)
618 local v = eolian.eolian_unit_state_get(cast_unit(self))
619 if v == ffi.nullptr then return nil end
620 return v
621 end,
622
623 children_get = function(self)
624 return Ptr_Iterator("const Eolian_Unit*",
625 eolian.eolian_unit_children_get(cast_unit(self)))
626 end,
627
628 file_get = function(self)
629 local v = eolian.eolian_unit_file_get(cast_unit(self))
630 if v == ffi.nullptr then return nil end
631 return ffi.string(v)
632 end,
633
634 file_path_get = function(self)
635 local v = eolian.eolian_unit_file_path_get(cast_unit(self))
636 if v == ffi.nullptr then return nil end
637 return ffi.string(v)
638 end,
639
640 version_get = function(self)
641 return tonumber(eolian.eolian_unit_version_get(cast_unit(self)))
642 end,
643
644 object_by_name_get = function(self, name)
645 local v = eolian.eolian_unit_object_by_name_get(cast_unit(self), name)
646 if v == ffi.nullptr then return nil end
647 return v
648 end,
649
650 objects_get = function(self, fname)
651 return Ptr_Iterator("const Eolian_Object *",
652 eolian.eolian_unit_objects_get(cast_unit(self), fname))
653 end,
654
655 class_by_name_get = function(self, cname)
656 local v = eolian.eolian_unit_class_by_name_get(cast_unit(self), cname)
657 if v == ffi.nullptr then return nil end
658 return v
659 end,
660
661 classes_get = function(self)
662 return Ptr_Iterator("const Eolian_Class*",
663 eolian.eolian_unit_classes_get(cast_unit(self)))
664 end,
665
666 constant_by_name_get = function(self, name)
667 local v = eolian.eolian_unit_constant_by_name_get(cast_unit(self), name)
668 if v == ffi.nullptr then return nil end
669 return v
670 end,
671
672 error_by_name_get = function(self, name)
673 local v = eolian.eolian_unit_error_by_name_get(cast_unit(self), name)
674 if v == ffi.nullptr then return nil end
675 return v
676 end,
677
678 constants_get = function(self)
679 return Ptr_Iterator("const Eolian_Constant *",
680 eolian.eolian_unit_constants_get(cast_unit(self)))
681 end,
682
683 errors_get = function(self)
684 return Ptr_Iterator("const Eolian_Error *",
685 eolian.eolian_unit_errors_get(cast_unit(self)))
686 end,
687
688 alias_by_name_get = function(self, name)
689 local v = eolian.eolian_unit_alias_by_name_get(cast_unit(self), name)
690 if v == ffi.nullptr then return nil end
691 return v
692 end,
693
694 struct_by_name_get = function(self, name)
695 local v = eolian.eolian_unit_struct_by_name_get(cast_unit(self), name)
696 if v == ffi.nullptr then return nil end
697 return v
698 end,
699
700 enum_by_name_get = function(self, name)
701 local v = eolian.eolian_unit_enum_by_name_get(cast_unit(self), name)
702 if v == ffi.nullptr then return nil end
703 return v
704 end,
705
706 aliases_get = function(self)
707 return Ptr_Iterator("const Eolian_Typedecl *",
708 eolian.eolian_unit_aliases_get(cast_unit(self)))
709 end,
710
711 structs_get = function(self)
712 return Ptr_Iterator("const Eolian_Typedecl *",
713 eolian.eolian_unit_structs_get(cast_unit(self)))
714 end,
715
716 enums_get = function(self)
717 return Ptr_Iterator("const Eolian_Typedecl *",
718 eolian.eolian_unit_enums_get(cast_unit(self)))
719 end
720}
721
722ffi.metatype("Eolian_Unit", { __index = unit_idx })
723
724local panic_cbs = {}
725local error_cbs = {}
726
727local obj_to_idx = function(obj)
728 return tonumber(ffi.cast("size_t", obj))
729end
730
731local panic_cb, err_cb
732
733panic_cb = ffi.gc(ffi.cast("Eolian_Panic_Cb", function(state, msg)
734 local pcb = panic_cbs[obj_to_idx(self)]
735 assert(pcb, "internal error: no prror cb")
736 pcb(state, ffi.string(msg))
737end), function(cb)
738 cb:free()
739end)
740
741err_cb = ffi.gc(ffi.cast("Eolian_Panic_Cb", function(obj, msg, data)
742 local ecb = error_cbs[obj_to_idx(self)]
743 assert(ecb, "internal error: no error cb")
744 ecb(obj, ffi.string(msg))
745end), function(cb)
746 cb:free()
747end)
748
749ffi.metatype("Eolian_State", {
750 __index = wrap_unit {
751 panic_cb_set = function(self, cb)
752 panic_cbs[obj_to_idx(self)] = cb
753 eolian.eolian_state_panic_cb_set(self, panic_cb)
754 end,
755
756 error_cb_set = function(self, cb)
757 error_cbs[obj_to_idx(self)] = cb
758 eolian.eolian_state_error_cb_set(self, err_cb)
759 end,
760
761 directory_add = function(self, dir)
762 return eolian.eolian_state_directory_add(self, dir) ~= 0
763 end,
764
765 system_directory_add = function(self)
766 return eolian.eolian_state_system_directory_add(self) ~= 0
767 end,
768
769 file_parse = function(self, fname)
770 local v = eolian.eolian_state_file_parse(self, fname)
771 if v == ffi.nullptr then
772 return nil
773 end
774 return v
775 end,
776
777 file_path_parse = function(self, fpath)
778 local v = eolian.eolian_state_file_path_parse(self, fpath)
779 if v == ffi.nullptr then
780 return nil
781 end
782 return v
783 end,
784
785 all_eo_files_parse = function(self)
786 return eolian.eolian_state_all_eo_files_parse(self) ~= 0
787 end,
788
789 all_eot_files_parse = function(self)
790 return eolian.eolian_state_all_eot_files_parse(self) ~= 0
791 end,
792
793 check = function(self)
794 return eolian.eolian_state_check(self) ~= 0
795 end,
796
797 eo_file_paths_get = function(self)
798 return iterator.String_Iterator(eolian.eolian_state_eo_file_paths_get(self))
799 end,
800
801 eot_file_paths_get = function(self)
802 return iterator.String_Iterator(eolian.eolian_state_eot_file_paths_get(self))
803 end,
804
805 eo_files_get = function(self)
806 return iterator.String_Iterator(eolian.eolian_state_eo_files_get(self))
807 end,
808
809 eot_files_get = function(self)
810 return iterator.String_Iterator(eolian.eolian_state_eot_files_get(self))
811 end,
812
813 unit_get = function(self)
814 return ffi.cast("Eolian_Unit *", self)
815 end,
816
817 unit_by_file_get = function(self, fname)
818 local v = eolian.eolian_state_unit_by_file_get(state, fname)
819 if v == ffi.nullptr then
820 return nil
821 end
822 return v
823 end,
824
825 units_get = function(self)
826 return Ptr_Iterator("const Eolian_Unit*",
827 eolian.eolian_state_units_get(self))
828 end,
829
830 objects_by_file_get = function(self, fname)
831 return Ptr_Iterator("const Eolian_Object *",
832 eolian.eolian_state_objects_by_file_get(self, fname))
833 end,
834
835 class_by_file_get = function(self, fname)
836 local v = eolian.eolian_state_class_by_file_get(self, fname)
837 if v == ffi.nullptr then return nil end
838 return v
839 end,
840
841 constants_by_file_get = function(unit, fname)
842 return Ptr_Iterator("const Eolian_Constant*",
843 eolian.eolian_state_constants_by_file_get(self, fname))
844 end,
845
846 errors_by_file_get = function(unit, fname)
847 return Ptr_Iterator("const Eolian_Error*",
848 eolian.eolian_state_errors_by_file_get(self, fname))
849 end,
850
851 aliases_by_file_get = function(self, fname)
852 return Ptr_Iterator("const Eolian_Typedecl *",
853 eolian.eolian_state_aliases_by_file_get(self, fname))
854 end,
855
856 structs_by_file_get = function(self, fname)
857 return Ptr_Iterator("const Eolian_Typedecl *",
858 eolian.eolian_state_structs_by_file_get(self, fname))
859 end,
860
861 enums_by_file_get = function(self, fname)
862 return Ptr_Iterator("const Eolian_Typedecl *",
863 eolian.eolian_state_enums_by_file_get(self, fname))
864 end
865 },
866 __gc = function(self)
867 local idx = obj_to_idx(self)
868 panic_cbs[idx] = nil
869 error_cbs[idx] = nil
870 eolian.eolian_state_free(self)
871 end
872})
873
874M.new = function()
875 return eolian.eolian_state_new()
876end
877
878M.type_type = {
879 UNKNOWN = 0,
880 VOID = 1,
881 REGULAR = 2,
882 CLASS = 3,
883 ERROR = 4,
884 UNDEFINED = 5
885}
886
887M.type_builtin_type = {
888 INVALID = 0,
889
890 BYTE = 1,
891 UBYTE = 2,
892 CHAR = 3,
893 SHORT = 4,
894 USHORT = 5,
895 INT = 6,
896 UINT = 7,
897 LONG = 8,
898 ULONG = 9,
899 LLONG = 10,
900 ULLONG = 11,
901
902 INT8 = 12,
903 UINT8 = 13,
904 INT16 = 14,
905 UINT16 = 15,
906 INT32 = 16,
907 UINT32 = 17,
908 INT64 = 18,
909 UINT64 = 19,
910 INT128 = 20,
911 UINT128 = 21,
912
913 SIZE = 22,
914 SSIZE = 23,
915 INTPTR = 24,
916 UINTPTR = 25,
917 PTRDIFF = 26,
918
919 TIME = 27,
920
921 FLOAT = 28,
922 DOUBLE = 29,
923
924 BOOL = 30,
925
926 SLICE = 31,
927 RW_SLICE = 32,
928
929 VOID = 33,
930
931 ACCESSOR = 34,
932 ARRAY = 35,
933 FUTURE = 36,
934 ITERATOR = 37,
935 LIST = 38,
936
937 ANY_VALUE = 39,
938 ANY_VALUE_REF = 40,
939 BINBUF = 41,
940 EVENT = 42,
941 MSTRING = 43,
942 STRING = 44,
943 STRINGSHARE = 45,
944 STRBUF = 46,
945
946 HASH = 47,
947 VOID_PTR = 48
948}
949
950M.typedecl_type = {
951 UNKNOWN = 0,
952 STRUCT = 1,
953 STRUCT_OPAQUE = 2,
954 ENUM = 3,
955 ALIAS = 4,
956 FUNCTION_POINTER = 5
957}
958
959ffi.metatype("Eolian_Struct_Type_Field", {
960 __index = wrap_object {
961 documentation_get = function(self)
962 local v = eolian.eolian_typedecl_struct_field_documentation_get(self)
963 if v == ffi.nullptr then return nil end
964 return v
965 end,
966
967 type_get = function(self)
968 local v = eolian.eolian_typedecl_struct_field_type_get(self)
969 if v == ffi.nullptr then return nil end
970 return v
971 end,
972
973 is_by_ref = function(self)
974 return eolian.eolian_typedecl_struct_field_is_by_ref(self) ~= 0
975 end,
976
977 is_move = function(self)
978 return eolian.eolian_typedecl_struct_field_is_move(self) ~= 0
979 end
980 }
981})
982
983ffi.metatype("Eolian_Enum_Type_Field", {
984 __index = wrap_object {
985 c_name_get = function(self)
986 local v = eolian.eolian_typedecl_enum_field_c_constant_get(self)
987 if v == ffi.nullptr then return nil end
988 return ffi_stringshare(v)
989 end,
990
991 documentation_get = function(self)
992 local v = eolian.eolian_typedecl_enum_field_documentation_get(self)
993 if v == ffi.nullptr then return nil end
994 return v
995 end,
996
997 value_get = function(self, force)
998 local v = eolian.eolian_typedecl_enum_field_value_get(self, force and 1 or 0)
999 if v == ffi.nullptr then return nil end
1000 return v
1001 end
1002 }
1003})
1004
1005M.Typedecl = ffi.metatype("Eolian_Typedecl", {
1006 __index = wrap_object {
1007 type_get = function(self)
1008 return tonumber(eolian.eolian_typedecl_type_get(self))
1009 end,
1010
1011 struct_fields_get = function(self)
1012 return Ptr_Iterator("const Eolian_Struct_Type_Field*",
1013 eolian.eolian_typedecl_struct_fields_get(self))
1014 end,
1015
1016 struct_field_get = function(self, name)
1017 local v = eolian.eolian_typedecl_struct_field_get(self, name)
1018 if v == ffi.nullptr then return nil end
1019 return v
1020 end,
1021
1022 enum_fields_get = function(self)
1023 return Ptr_Iterator("const Eolian_Enum_Type_Field*",
1024 eolian.eolian_typedecl_enum_fields_get(self))
1025 end,
1026
1027 enum_field_get = function(self, field)
1028 local v = eolian.eolian_typedecl_enum_field_get(self, field)
1029 if v == ffi.nullptr then return nil end
1030 return v
1031 end,
1032
1033 enum_legacy_prefix_get = function(self)
1034 local v = eolian.eolian_typedecl_enum_legacy_prefix_get(self)
1035 if v == ffi.nullptr then return nil end
1036 return ffi.string(v)
1037 end,
1038
1039 documentation_get = function(self, name)
1040 local v = eolian.eolian_typedecl_documentation_get(self)
1041 if v == ffi.nullptr then return nil end
1042 return v
1043 end,
1044
1045 base_type_get = function(self)
1046 local v = eolian.eolian_typedecl_base_type_get(self)
1047 if v == ffi.nullptr then return nil end
1048 return v
1049 end,
1050
1051 aliased_base_get = function(self)
1052 local v = eolian.eolian_typedecl_aliased_byse_get(self)
1053 if v == ffi.nullptr then return nil end
1054 return v
1055 end,
1056
1057 is_extern = function(self)
1058 return eolian.eolian_typedecl_is_extern(self) ~= 0
1059 end,
1060
1061 c_type_get = function(self)
1062 local v = eolian.eolian_typedecl_c_type_get(self)
1063 if v == ffi.nullptr then return nil end
1064 return ffi_stringshare(v)
1065 end,
1066
1067 free_func_get = function(self)
1068 local v = eolian.eolian_typedecl_free_func_get(self)
1069 if v == ffi.nullptr then return nil end
1070 return ffi.string(v)
1071 end,
1072
1073 function_pointer_get = function(self)
1074 local v = eolian.eolian_typedecl_function_pointer_get(self)
1075 if v == ffi.nullptr then return nil end
1076 return v
1077 end
1078 }
1079})
1080
1081M.Type = ffi.metatype("Eolian_Type", {
1082 __index = wrap_object {
1083 type_get = function(self)
1084 return tonumber(eolian.eolian_type_type_get(self))
1085 end,
1086
1087 builtin_type_get = function(self)
1088 return tonumber(eolian.eolian_type_builtin_type_get(self))
1089 end,
1090
1091 base_type_get = function(self)
1092 local v = eolian.eolian_type_base_type_get(self)
1093 if v == ffi.nullptr then return nil end
1094 return v
1095 end,
1096
1097 next_type_get = function(self)
1098 local v = eolian.eolian_type_next_type_get(self)
1099 if v == ffi.nullptr then return nil end
1100 return v
1101 end,
1102
1103 typedecl_get = function(self)
1104 local v = eolian.eolian_type_typedecl_get(self)
1105 if v == ffi.nullptr then return nil end
1106 return v
1107 end,
1108
1109 aliased_base_get = function(self)
1110 local v = eolian.eolian_type_aliased_byse_get(self)
1111 if v == ffi.nullptr then return nil end
1112 return v
1113 end,
1114
1115 class_get = function(self)
1116 local v = eolian.eolian_type_class_get(self)
1117 if v == ffi.nullptr then return nil end
1118 return v
1119 end,
1120
1121 error_get = function(self)
1122 local v = eolian.eolian_type_error_get(self)
1123 if v == ffi.nullptr then return nil end
1124 return v
1125 end,
1126
1127 is_move = function(self)
1128 return eolian.eolian_type_is_move(self) ~= 0
1129 end,
1130
1131 is_const = function(self)
1132 return eolian.eolian_type_is_const(self) ~= 0
1133 end,
1134
1135 is_ptr = function(self)
1136 return eolian.eolian_type_is_ptr(self) ~= 0
1137 end,
1138
1139 c_type_get = function(self)
1140 local v = eolian.eolian_type_c_type_get(self)
1141 if v == ffi.nullptr then return nil end
1142 return ffi_stringshare(v)
1143 end
1144 }
1145})
1146
1147M.function_type = {
1148 UNRESOLVED = 0,
1149 PROPERTY = 1,
1150 PROP_SET = 2,
1151 PROP_GET = 3,
1152 METHOD = 4,
1153 FUNCTION_POINTER = 5
1154}
1155
1156M.Function = ffi.metatype("Eolian_Function", {
1157 __index = wrap_object {
1158 type_get = function(self)
1159 return tonumber(eolian.eolian_function_type_get(self))
1160 end,
1161
1162 scope_get = function(self, ftype)
1163 return tonumber(eolian.eolian_function_scope_get(self, ftype))
1164 end,
1165
1166 full_c_name_get = function(self, ftype)
1167 local v = eolian.eolian_function_full_c_name_get(self, ftype)
1168 if v == ffi.nullptr then return nil end
1169 return ffi_stringshare(v)
1170 end,
1171
1172 implement_get = function(self)
1173 local v = eolian.eolian_function_implement_get(self)
1174 if v == ffi.nullptr then return nil end
1175 return v
1176 end,
1177
1178 is_static = function(self)
1179 return eolian.eolian_function_is_static(self) ~= 0
1180 end,
1181
1182 is_constructor = function(self, klass)
1183 return eolian.eolian_function_is_constructor(self, klass) ~= 0
1184 end,
1185
1186 is_function_pointer = function(self)
1187 return eolian.eolian_function_is_function_pointer(self) ~= 0
1188 end,
1189
1190 property_keys_get = function(self, ftype)
1191 return Ptr_Iterator("const Eolian_Function_Parameter*",
1192 eolian.eolian_property_keys_get(self, ftype))
1193 end,
1194
1195 property_values_get = function(self, ftype)
1196 return Ptr_Iterator("const Eolian_Function_Parameter*",
1197 eolian.eolian_property_values_get(self, ftype))
1198 end,
1199
1200 parameters_get = function(self)
1201 return Ptr_Iterator("const Eolian_Function_Parameter*",
1202 eolian.eolian_function_parameters_get(self))
1203 end,
1204
1205 return_type_get = function(self, ftype)
1206 local v = eolian.eolian_function_return_type_get(self, ftype)
1207 if v == ffi.nullptr then return nil end
1208 return v
1209 end,
1210
1211 return_default_value_get = function(self, ftype)
1212 local v = eolian.eolian_function_return_default_value_get(self, ftype)
1213 if v == ffi.nullptr then return nil end
1214 return v
1215 end,
1216
1217 return_documentation_get = function(self, ftype)
1218 local v = eolian.eolian_function_return_documentation_get(self, ftype)
1219 if v == ffi.nullptr then return nil end
1220 return v
1221 end,
1222
1223 return_allow_unused = function(self, ftype)
1224 return eolian.eolian_function_return_allow_unused(self,
1225 ftype) ~= 0
1226 end,
1227
1228 return_is_by_ref = function(self, ftype)
1229 return eolian.eolian_function_return_is_by_ref(self, ftype) ~= 0
1230 end,
1231
1232 return_is_move = function(self, ftype)
1233 return eolian.eolian_function_return_is_move(self, ftype) ~= 0
1234 end,
1235
1236 is_const = function(self)
1237 return eolian.eolian_function_object_is_const(self) ~= 0
1238 end,
1239
1240 class_get = function(self)
1241 local v = eolian.eolian_function_class_get(self)
1242 if v == ffi.nullptr then return nil end
1243 return v
1244 end
1245 }
1246})
1247
1248M.parameter_dir = {
1249 UNKNOWN = 0,
1250 IN = 1,
1251 OUT = 2,
1252 INOUT = 3
1253}
1254
1255ffi.metatype("Eolian_Function_Parameter", {
1256 __index = wrap_object {
1257 direction_get = function(self)
1258 return tonumber(eolian.eolian_parameter_direction_get(self))
1259 end,
1260
1261 type_get = function(self)
1262 local v = eolian.eolian_parameter_type_get(self)
1263 if v == ffi.nullptr then return nil end
1264 return v
1265 end,
1266
1267 default_value_get = function(self)
1268 local v = eolian.eolian_parameter_default_value_get(self)
1269 if v == ffi.nullptr then return nil end
1270 return v
1271 end,
1272
1273 documentation_get = function(self)
1274 local v = eolian.eolian_parameter_documentation_get(self)
1275 if v == ffi.nullptr then return nil end
1276 return v
1277 end,
1278
1279 is_optional = function(self)
1280 return eolian.eolian_parameter_is_optional(self) ~= 0
1281 end,
1282
1283 is_by_ref = function(self)
1284 return eolian.eolian_parameter_is_by_ref(self) ~= 0
1285 end,
1286
1287 is_move = function(self)
1288 return eolian.eolian_parameter_is_move(self) ~= 0
1289 end
1290 }
1291})
1292
1293ffi.metatype("Eolian_Implement", {
1294 __index = wrap_object {
1295 class_get = function(self)
1296 local v = eolian.eolian_implement_class_get(self)
1297 if v == ffi.nullptr then return nil end
1298 return v
1299 end,
1300
1301 implementing_class_get = function(self)
1302 local v = eolian.eolian_implement_implementing_class_get(self)
1303 if v == ffi.nullptr then return nil end
1304 return v
1305 end,
1306
1307 function_get = function(self)
1308 local tp = ffi.new("Eolian_Function_Type[1]")
1309 local v = eolian.eolian_implement_function_get(self, tp)
1310 if v == ffi.nullptr then return nil end
1311 return v, tp[0]
1312 end,
1313
1314 documentation_get = function(self, ftype)
1315 local v = eolian.eolian_implement_documentation_get(self, ftype)
1316 if v == ffi.nullptr then return nil end
1317 return v
1318 end,
1319
1320 is_auto = function(self, ftype)
1321 return eolian.eolian_implement_is_auto(self, ftype) ~= 0
1322 end,
1323
1324 is_empty = function(self, ftype)
1325 return eolian.eolian_implement_is_empty(self, ftype) ~= 0
1326 end,
1327
1328 is_pure_virtual = function(self, ftype)
1329 return eolian.eolian_implement_is_pure_virtual(self, ftype) ~= 0
1330 end,
1331
1332 is_prop_get = function(self)
1333 return eolian.eolian_implement_is_prop_get(self) ~= 0
1334 end,
1335
1336 is_prop_set = function(self)
1337 return eolian.eolian_implement_is_prop_set(self) ~= 0
1338 end
1339 }
1340})
1341
1342ffi.metatype("Eolian_Constructor", {
1343 __index = wrap_object {
1344 class_get = function(self)
1345 local v = eolian.eolian_constructor_class_get(self)
1346 if v == ffi.nullptr then return nil end
1347 return v
1348 end,
1349
1350 function_get = function(self)
1351 local v = eolian.eolian_constructor_function_get(self)
1352 if v == ffi.nullptr then return nil end
1353 return v
1354 end,
1355
1356 is_optional = function(self)
1357 return eolian.eolian_constructor_is_optional(self) ~= 0
1358 end
1359 }
1360})
1361
1362ffi.metatype("Eolian_Event", {
1363 __index = wrap_object {
1364 type_get = function(self)
1365 local v = eolian.eolian_event_type_get(self)
1366 if v == ffi.nullptr then return nil end
1367 return v
1368 end,
1369
1370 class_get = function(self)
1371 local v = eolian.eolian_event_class_get(self)
1372 if v == ffi.nullptr then return nil end
1373 return v
1374 end,
1375
1376 documentation_get = function(self)
1377 local v = eolian.eolian_event_documentation_get(self)
1378 if v == ffi.nullptr then return nil end
1379 return v
1380 end,
1381
1382 scope_get = function(self)
1383 return tonumber(eolian.eolian_event_scope_get(self))
1384 end,
1385
1386 c_macro_get = function(self)
1387 local v = eolian.eolian_event_c_macro_get(self)
1388 if v == ffi.nullptr then return nil end
1389 return ffi_stringshare(v)
1390 end,
1391
1392 is_hot = function(self)
1393 return eolian.eolian_event_is_hot(self) ~= 0
1394 end,
1395
1396 is_restart = function(self)
1397 return eolian.eolian_event_is_restart(self) ~= 0
1398 end
1399 }
1400})
1401
1402ffi.metatype("Eolian_Part", {
1403 __index = wrap_object {
1404 class_get = function(self)
1405 local v = eolian.eolian_part_class_get(self)
1406 if v == ffi.nullptr then return nil end
1407 return v
1408 end,
1409
1410 documentation_get = function(self)
1411 local v = eolian.eolian_part_documentation_get(self)
1412 if v == ffi.nullptr then return nil end
1413 return v
1414 end
1415 }
1416})
1417
1418M.class_type = {
1419 UNKNOWN = 0,
1420 REGULAR = 1,
1421 ABSTRACT = 2,
1422 MIXIN = 3,
1423 INTERFACE = 4
1424}
1425
1426M.Class = ffi.metatype("Eolian_Class", {
1427 __index = wrap_object {
1428 type_get = function(self)
1429 return tonumber(eolian.eolian_class_type_get(self))
1430 end,
1431
1432 documentation_get = function(self)
1433 local v = eolian.eolian_class_documentation_get(self)
1434 if v == ffi.nullptr then return nil end
1435 return v
1436 end,
1437
1438 c_prefix_get = function(self)
1439 local v = eolian.eolian_class_c_prefix_get(self)
1440 if v == ffi.nullptr then
1441 local buf = self:namespaces_get()
1442 buf[#buf + 1] = self:short_name_get()
1443 return table.concat(buf, "_"):lower()
1444 end
1445 return ffi.string(v)
1446 end,
1447
1448 event_c_prefix_get = function(self)
1449 local v = eolian.eolian_class_event_c_prefix_get(self)
1450 if v == ffi.nullptr then
1451 return self:c_prefix_get()
1452 end
1453 return ffi.string(v)
1454 end,
1455
1456 data_type_get = function(self)
1457 local v = eolian.eolian_class_data_type_get(self)
1458 if v == ffi.nullptr then return nil end
1459 return ffi.string(v)
1460 end,
1461
1462 parent_get = function(self)
1463 local v = eolian.eolian_class_parent_get(self)
1464 if v == ffi.nullptr then return nil end
1465 return v
1466 end,
1467
1468 extensions_get = function(self)
1469 return Ptr_Iterator("const Eolian_Class*",
1470 eolian.eolian_class_extensions_get(self))
1471 end,
1472
1473 requires_get = function(self)
1474 return Ptr_Iterator("const Eolian_Class*",
1475 eolian.eolian_class_requires_get(self))
1476 end,
1477
1478 functions_get = function(self, func_type)
1479 return Ptr_Iterator("const Eolian_Function*",
1480 eolian.eolian_class_functions_get(self, func_type))
1481 end,
1482
1483 function_by_name_get = function(self, fname, ftype)
1484 local v = eolian.eolian_class_function_by_name_get(self, fname,
1485 ftype)
1486 if v == ffi.nullptr then return nil end
1487 return v
1488 end,
1489
1490 implements_get = function(self)
1491 return Ptr_Iterator("const Eolian_Implement*",
1492 eolian.eolian_class_implements_get(self))
1493 end,
1494
1495 constructors_get = function(self)
1496 return Ptr_Iterator("const Eolian_Constructor*",
1497 eolian.eolian_class_constructors_get(self))
1498 end,
1499
1500 events_get = function(self)
1501 return Ptr_Iterator("const Eolian_Event*",
1502 eolian.eolian_class_events_get(self))
1503 end,
1504
1505 event_by_name_get = function(self, name)
1506 local v = eolian.eolian_class_event_by_name_get(self, name)
1507 if v == ffi.nullptr then return nil end
1508 return v
1509 end,
1510
1511 parts_get = function(self)
1512 return Ptr_Iterator("const Eolian_Part*",
1513 eolian.eolian_class_parts_get(self))
1514 end,
1515
1516 ctor_enable_get = function(self)
1517 return eolian.eolian_class_ctor_enable_get(self) ~= 0
1518 end,
1519
1520 dtor_enable_get = function(self)
1521 return eolian.eolian_class_dtor_enable_get(self) ~= 0
1522 end,
1523
1524 c_get_function_name_get = function(self)
1525 local v = eolian.eolian_class_c_get_function_name_get(self)
1526 if v == ffi.nullptr then return nil end
1527 return ffi_stringshare(v)
1528 end,
1529
1530 c_macro_get = function(self)
1531 local v = eolian.eolian_class_c_macro_get(self)
1532 if v == ffi.nullptr then return nil end
1533 return ffi_stringshare(v)
1534 end,
1535
1536 c_data_type_get = function(self)
1537 local v = eolian.eolian_class_c_data_type_get(self)
1538 if v == ffi.nullptr then return nil end
1539 return ffi_stringshare(v)
1540 end
1541 }
1542})
1543
1544M.expression_type = {
1545 UNKNOWN = 0,
1546 INT = 1,
1547 UINT = 2,
1548 LONG = 3,
1549 ULONG = 4,
1550 LLONG = 5,
1551 ULLONG = 6,
1552 FLOAT = 7,
1553 DOUBLE = 8,
1554 STRING = 9,
1555 CHAR = 10,
1556 NULL = 11,
1557 BOOL = 12,
1558 NAME = 13,
1559 UNARY = 15,
1560 BINARY = 16
1561}
1562
1563local etype = M.expression_type
1564
1565M.expression_mask = {
1566 SINT = 2 ^ 0,
1567 UINT = 2 ^ 1,
1568 FLOAT = 2 ^ 2,
1569 BOOL = 2 ^ 3,
1570 STRING = 2 ^ 4,
1571 CHAR = 2 ^ 5,
1572 NULL = 2 ^ 6
1573}
1574
1575local emask = M.expression_mask
1576
1577emask.INT = emask.SINT + emask.UINT
1578emask.SIGNED = emask.SINT + emask.FLOAT
1579emask.NUMBER = emask.INT + emask.FLOAT
1580emask.ALL = emask.NUMBER + emask.BOOL + emask.STRING + emask.CHAR + emask.NULL
1581
1582local value_con = {
1583 [etype.INT ] = function(v) return tonumber(v.value.i ) end,
1584 [etype.UINT ] = function(v) return tonumber(v.value.u ) end,
1585 [etype.LONG ] = function(v) return v.value.l end,
1586 [etype.ULONG ] = function(v) return v.value.ul end,
1587 [etype.LLONG ] = function(v) return v.value.ll end,
1588 [etype.ULLONG] = function(v) return v.value.ull end,
1589 [etype.FLOAT ] = function(v) return tonumber(v.value.f ) end,
1590 [etype.DOUBLE] = function(v) return tonumber(v.value.d ) end,
1591 [etype.STRING] = function(v) return ffi.string(v.value.s ) end,
1592 [etype.CHAR ] = function(v) return string.char(v.value.c) end,