summaryrefslogtreecommitdiff
path: root/src/bindings
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2015-03-03 16:28:24 +0000
committerDaniel Kolesa <d.kolesa@samsung.com>2015-03-03 16:28:41 +0000
commita8cfea6911c6f05031d79e761532c59ff5fad232 (patch)
treefafb36f856d5aa72064519d47048fba0e796af56 /src/bindings
parentadbac89310e26920ac168ebecda557dcde9b3750 (diff)
elua: better callback resource handling
Diffstat (limited to 'src/bindings')
-rw-r--r--src/bindings/luajit/eo.lua29
1 files changed, 20 insertions, 9 deletions
diff --git a/src/bindings/luajit/eo.lua b/src/bindings/luajit/eo.lua
index 9d15aa4661..5aad9e0bef 100644
--- a/src/bindings/luajit/eo.lua
+++ b/src/bindings/luajit/eo.lua
@@ -131,22 +131,26 @@ local eo_classes = {}
131 131
132-- event system 132-- event system
133 133
134local callbacks = {} 134local eo_callbacks = {}
135 135
136local eo_event_del, eo_event_cb 136local eo_event_del, eo_event_cb
137 137
138eo_event_del = ffi.cast("Eo_Event_Cb", function(data, obj, desc, einfo) 138local eo_event_del_fun = function(data, obj, desc, einfo)
139end) 139 local addr = eo_obj_addr_get(obj)
140 if eo_callbacks[addr] then
141 eo_callbacks[addr] = nil
142 end
143end
140 144
141eo_event_cb = ffi.cast("Eo_Event_Cb", function(data, obj, desc, einfo) 145local eo_event_cb_fun = function(data, obj, desc, einfo)
142 local addr = eo_obj_addr_get(obj) 146 local addr = eo_obj_addr_get(obj)
143 local cbs = callbacks[addr] 147 local cbs = eo_callbacks[addr]
144 assert(cbs) 148 assert(cbs)
145 local cidx = tonumber(ffi.cast("intptr_t", cbs)) 149 local cidx = tonumber(ffi.cast("intptr_t", cbs))
146 local fun = cbs[cidx] 150 local fun = cbs[cidx]
147 assert(fun) 151 assert(fun)
148 return fun() ~= false 152 return fun() ~= false
149end) 153end
150 154
151local connect = function(self, ename, func, priority) 155local connect = function(self, ename, func, priority)
152 local ev = self.__events[ename] 156 local ev = self.__events[ename]
@@ -156,10 +160,10 @@ local connect = function(self, ename, func, priority)
156 local cl = eo_classes["Eo_Base"] 160 local cl = eo_classes["Eo_Base"]
157 -- add the callback to the respective array 161 -- add the callback to the respective array
158 local addr = eo_obj_addr_get(self) 162 local addr = eo_obj_addr_get(self)
159 local cbs = callbacks[addr] 163 local cbs = eo_callbacks[addr]
160 if not cbs then 164 if not cbs then
161 cbs = {} 165 cbs = {}
162 callbacks[addr] = cbs 166 eo_callbacks[addr] = cbs
163 end 167 end
164 local cidx = #cbs + 1 168 local cidx = #cbs + 1
165 cbs[cidx] = func 169 cbs[cidx] = func
@@ -178,7 +182,7 @@ local disconnect = function(self, ename, func)
178 local cl = eo_classes["Eo_Base"] 182 local cl = eo_classes["Eo_Base"]
179 -- like connect, but the other way around 183 -- like connect, but the other way around
180 local addr = eo_obj_addr_get(self) 184 local addr = eo_obj_addr_get(self)
181 local cbs = callbacks[addr] 185 local cbs = eo_callbacks[addr]
182 if not cbs then 186 if not cbs then
183 return false 187 return false
184 end 188 end
@@ -214,11 +218,18 @@ local init = function()
214 classes[addr] = classes["Eo_Base"] 218 classes[addr] = classes["Eo_Base"]
215 eo_classes["Eo_Base"] = eocl 219 eo_classes["Eo_Base"] = eocl
216 eo_classes[addr] = eocl 220 eo_classes[addr] = eocl
221 eo_event_del = ffi.cast("Eo_Event_Cb", eo_event_del_fun)
222 eo_event_cb = ffi.cast("Eo_Event_Cb", eo_event_cb_fun)
217end 223end
218 224
219local shutdown = function() 225local shutdown = function()
220 classes, eo_classes = {}, {} 226 classes, eo_classes = {}, {}
221 eo.eo_shutdown() 227 eo.eo_shutdown()
228 eo_event_del:free()
229 eo_event_cb:free()
230 eo_event_del = nil
231 eo_event_cb = nil
232 eo_callbacks = {}
222 util.lib_unload("eo") 233 util.lib_unload("eo")
223end 234end
224 235