summaryrefslogtreecommitdiff
path: root/src/bindings/luajit/eina
diff options
context:
space:
mode:
authorDaniel Kolesa <quaker66@gmail.com>2014-04-11 14:36:04 +0100
committerDaniel Kolesa <d.kolesa@samsung.com>2014-06-10 15:48:47 +0100
commit3ff16331807ecb9d93caad0e5b5a77482b61eaa2 (patch)
treefcb4245ddf691bafbb5d4f12dcf4dde7c153df05 /src/bindings/luajit/eina
parentf4d34ce1ab690e7343bb5d3523141a27540f48cd (diff)
elua: bindings for eina_accessor, accesor support in eina_list bindings, iterator updates
Diffstat (limited to 'src/bindings/luajit/eina')
-rw-r--r--src/bindings/luajit/eina/accessor.lua135
-rw-r--r--src/bindings/luajit/eina/iterator.lua10
-rw-r--r--src/bindings/luajit/eina/list.lua18
3 files changed, 157 insertions, 6 deletions
diff --git a/src/bindings/luajit/eina/accessor.lua b/src/bindings/luajit/eina/accessor.lua
new file mode 100644
index 0000000000..705f82cfd5
--- /dev/null
+++ b/src/bindings/luajit/eina/accessor.lua
@@ -0,0 +1,135 @@
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 == nil 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 == nil then return nil end
55 return v
56 end
57 }
58})
59
60cutil.init_module(init, shutdown)
61
62M.Accessor = util.Object:clone {
63 __ctor = function(self, acc)
64 -- prevent null stuff
65 if acc == nil then acc = nil end
66 if acc then ffi.gc(acc, acc.free) end
67 self.__eq = function(self, other)
68 return self.__accessor == other.__accessor
69 end
70 self.__call = function(self)
71 return self:next()
72 end
73 local oi = self.__index
74 self.__index = function(self, name)
75 if type(name) == "number" then return self:data_get(name) end
76 return oi[name]
77 end
78 self.__accessor = acc
79 end,
80
81 free = function(self)
82 if not self.__accessor then return end
83 self.__accessor:free()
84 self._accessor = nil
85 end,
86
87 disown = function(self)
88 local acc = self.__accessor
89 self.__accessor = nil
90 return acc
91 end,
92
93 rebase = function(self, acc)
94 self:free()
95 self.__accessor = acc:disown()
96 end,
97
98 lock = function(self)
99 if not self.__accessor then return false end
100 return self.__accessor:lock()
101 end,
102
103 unlock = function(self)
104 if not self.__accessor then return false end
105 return self.__accessor:unlock()
106 end,
107
108 clone = function(self)
109 if not self.__accessor then return nil end
110 return self.__proto(self.__accessor:clone())
111 end,
112
113 data_get = function(self, pos)
114 if not self.__accessor then return nil end
115 return self.__accessor:data_get(pos)
116 end,
117
118 container_get = function(self)
119 if not self.__accessor then return end
120 return self.__accessor:container_get()
121 end,
122
123 each = function(self)
124 local acc = self.__accessor
125 if not acc then return nil end
126 local cnt = 0
127 return function()
128 cnt = cnt + 1
129 local v = self:data_get(cnt)
130 if v then return cnt, v end
131 end
132 end
133}
134
135return M \ No newline at end of file
diff --git a/src/bindings/luajit/eina/iterator.lua b/src/bindings/luajit/eina/iterator.lua
index 5f37f00cbc..11b81da268 100644
--- a/src/bindings/luajit/eina/iterator.lua
+++ b/src/bindings/luajit/eina/iterator.lua
@@ -36,7 +36,7 @@ ffi.metatype("Eina_Iterator", {
36 next = function(self) 36 next = function(self)
37 local data = ffi.new("void*[1]") 37 local data = ffi.new("void*[1]")
38 local r = eina.eina_iterator_next(self, data) 38 local r = eina.eina_iterator_next(self, data)
39 if r == nil then return nil end 39 if r == 0 then return nil end
40 return data[0] 40 return data[0]
41 end, 41 end,
42 lock = function(self) return eina.eina_iterator_lock (self) ~= 0 end, 42 lock = function(self) return eina.eina_iterator_lock (self) ~= 0 end,
@@ -83,22 +83,22 @@ M.Iterator = util.Object:clone {
83 end, 83 end,
84 84
85 next = function(self) 85 next = function(self)
86 if not self.__iterator then return end 86 if not self.__iterator then return nil end
87 return self.__iterator:next() 87 return self.__iterator:next()
88 end, 88 end,
89 89
90 lock = function(self) 90 lock = function(self)
91 if not self.__iterator then return end 91 if not self.__iterator then return false end
92 return self.__iterator:lock() 92 return self.__iterator:lock()
93 end, 93 end,
94 94
95 unlock = function(self) 95 unlock = function(self)
96 if not self.__iterator then return end 96 if not self.__iterator then return false end
97 return self.__iterator:unlock() 97 return self.__iterator:unlock()
98 end, 98 end,
99 99
100 container_get = function(self) 100 container_get = function(self)
101 if not self.__iterator then return end 101 if not self.__iterator then return nil end
102 return self.__iterator:container_get() 102 return self.__iterator:container_get()
103 end 103 end
104} 104}
diff --git a/src/bindings/luajit/eina/list.lua b/src/bindings/luajit/eina/list.lua
index 66d11cc3d9..a21d11e005 100644
--- a/src/bindings/luajit/eina/list.lua
+++ b/src/bindings/luajit/eina/list.lua
@@ -4,6 +4,7 @@
4local ffi = require("ffi") 4local ffi = require("ffi")
5 5
6local iterator = require("eina.iterator") 6local iterator = require("eina.iterator")
7local accessor = require("eina.accessor")
7 8
8ffi.cdef [[ 9ffi.cdef [[
9 typedef unsigned char Eina_Bool; 10 typedef unsigned char Eina_Bool;
@@ -54,7 +55,7 @@ ffi.cdef [[
54 void *eina_list_search_unsorted(const Eina_List *list, Eina_Compare_Cb func, const void *data); 55 void *eina_list_search_unsorted(const Eina_List *list, Eina_Compare_Cb func, const void *data);
55 Eina_Iterator *eina_list_iterator_new(const Eina_List *list); 56 Eina_Iterator *eina_list_iterator_new(const Eina_List *list);
56 Eina_Iterator *eina_list_iterator_reversed_new(const Eina_List *list); 57 Eina_Iterator *eina_list_iterator_reversed_new(const Eina_List *list);
57// Eina_Accessor *eina_list_accessor_new(const Eina_List *list); 58 Eina_Accessor *eina_list_accessor_new(const Eina_List *list);
58]] 59]]
59 60
60local cutil = require("cutil") 61local cutil = require("cutil")
@@ -103,6 +104,21 @@ M.Reverse_Iterator = Iterator:clone {
103 end 104 end
104} 105}
105 106
107local Accessor = accessor.Accessor
108
109M.Accessor = Accessor:clone {
110 __ctor = function(self, list)
111 self.__list = list
112 return Accessor.__ctor(self, eina.eina_list_accessor_new(list.__list))
113 end,
114
115 data_get = function(self, pos)
116 local v = Accessor.data_get(self, pos)
117 if not v then return nil end
118 return self.__list:data_get(v)
119 end
120}
121
106local get_list_t = function(list) 122local get_list_t = function(list)
107 return ffi.cast("Eina_List_T*", list) 123 return ffi.cast("Eina_List_T*", list)
108end 124end