summaryrefslogtreecommitdiff
path: root/src/bindings
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2015-03-03 16:16:59 +0000
committerDaniel Kolesa <d.kolesa@samsung.com>2015-03-03 16:16:59 +0000
commitadbac89310e26920ac168ebecda557dcde9b3750 (patch)
treef5e1114eb7eac808b121b229b4750dbd45693586 /src/bindings
parente55ecf6d4c830dc0a4c1d9612bd4f71e55043929 (diff)
elua: implement callback disconnect + better error handling
Diffstat (limited to 'src/bindings')
-rw-r--r--src/bindings/luajit/eo.lua43
1 files changed, 31 insertions, 12 deletions
diff --git a/src/bindings/luajit/eo.lua b/src/bindings/luajit/eo.lua
index 856de56ca6..9d15aa4661 100644
--- a/src/bindings/luajit/eo.lua
+++ b/src/bindings/luajit/eo.lua
@@ -133,15 +133,7 @@ local eo_classes = {}
133 133
134local callbacks = {} 134local callbacks = {}
135 135
136local eo_event_cb_add, eo_event_cb_del, eo_event_del, eo_event_cb 136local eo_event_del, eo_event_cb
137
138eo_event_cb_add = ffi.cast("Eo_Event_Cb", function(data, obj, desc, einfo)
139 local acb = ffi.cast("Eo_Callback_Array_Item *", data)
140end)
141
142eo_event_cb_del = ffi.cast("Eo_Event_Cb", function(data, obj, desc, einfo)
143 local dcb = ffi.cast("Eo_Callback_Array_Item *", data)
144end)
145 137
146eo_event_del = ffi.cast("Eo_Event_Cb", function(data, obj, desc, einfo) 138eo_event_del = ffi.cast("Eo_Event_Cb", function(data, obj, desc, einfo)
147end) 139end)
@@ -159,10 +151,9 @@ end)
159local connect = function(self, ename, func, priority) 151local connect = function(self, ename, func, priority)
160 local ev = self.__events[ename] 152 local ev = self.__events[ename]
161 if not ev then 153 if not ev then
162 error("invalid event '" .. ename .. "'", 2) 154 return false, "attempt to connect an invalid event '" .. ename .. "'"
163 end 155 end
164 local cl = eo_classes["Eo_Base"] 156 local cl = eo_classes["Eo_Base"]
165 M.__do_start(self, cl)
166 -- add the callback to the respective array 157 -- add the callback to the respective array
167 local addr = eo_obj_addr_get(self) 158 local addr = eo_obj_addr_get(self)
168 local cbs = callbacks[addr] 159 local cbs = callbacks[addr]
@@ -172,13 +163,41 @@ local connect = function(self, ename, func, priority)
172 end 163 end
173 local cidx = #cbs + 1 164 local cidx = #cbs + 1
174 cbs[cidx] = func 165 cbs[cidx] = func
166 M.__do_start(self, cl)
175 eo.eo_event_callback_priority_add(ev, priority or 0, 167 eo.eo_event_callback_priority_add(ev, priority or 0,
176 eo_event_cb, ffi.cast("void *", cidx)) 168 eo_event_cb, ffi.cast("void *", cidx))
177 M.__do_end() 169 M.__do_end()
170 return true
178end 171end
179 172
180local disconnect = function(self, ename, func) 173local disconnect = function(self, ename, func)
181 -- TODO: implement 174 local ev = self.__events[ename]
175 if not ev then
176 return false, "attempt to disconnect an invalid event '" .. ename .. "'"
177 end
178 local cl = eo_classes["Eo_Base"]
179 -- like connect, but the other way around
180 local addr = eo_obj_addr_get(self)
181 local cbs = callbacks[addr]
182 if not cbs then
183 return false
184 end
185 -- TODO: make a hash table for func-to-index conversions
186 local cidx = -1
187 for i = 1, #cbs do
188 if cbs[i] == func then
189 cidx = i
190 break
191 end
192 end
193 if cidx < 0 then
194 return false
195 end
196 cbs[cidx] = nil
197 M.__do_start(self, cl)
198 eo.eo_event_callback_del(ev, eo_event_cb, ffi.cast("void *", cidx))
199 M.__do_end()
200 return true
182end 201end
183 202
184local init = function() 203local init = function()