summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2015-03-02 13:51:22 +0000
committerDaniel Kolesa <d.kolesa@samsung.com>2015-03-02 13:51:22 +0000
commit356ed88525c73d13533c3335b07ff4cb2a2fa71a (patch)
tree5588fad6539d7ed7bd3fcf419eace175d61792d1
parent21051d3252055aadfbd65b99b191b990839d6bba (diff)
elua: add transparent destructor support to elua objects
-rw-r--r--src/scripts/elua/core/util.lua16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/scripts/elua/core/util.lua b/src/scripts/elua/core/util.lua
index 1ef16fb645..99a7203948 100644
--- a/src/scripts/elua/core/util.lua
+++ b/src/scripts/elua/core/util.lua
@@ -12,6 +12,7 @@ local C = ffi.C
12local M = {} 12local M = {}
13 13
14local getmetatable, setmetatable = getmetatable, setmetatable 14local getmetatable, setmetatable = getmetatable, setmetatable
15local dgetmt = debug.getmetatable
15 16
16-- multiple inheritance index with depth-first search 17-- multiple inheritance index with depth-first search
17local proto_lookup = function(protos, name) 18local proto_lookup = function(protos, name)
@@ -46,9 +47,24 @@ local Object_MT = {
46 end 47 end
47} 48}
48 49
50local obj_gc = function(px)
51 local obj = dgetmt(px).__obj
52 local dtor = obj and obj.__dtor or nil
53 if dtor then dtor(obj) end
54end
55
49M.Object = { 56M.Object = {
57 __enable_dtor = false,
58
50 __call = function(self, ...) 59 __call = function(self, ...)
51 local r = self:clone() 60 local r = self:clone()
61 if self.__enable_dtor then
62 local px = newproxy(true)
63 local pxmt = dgetmt(px)
64 r.__gcproxy = px
65 pxmt.__gc = obj_gc
66 pxmt.__obj = r
67 end
52 if self.__ctor then return r, self.__ctor(r, ...) end 68 if self.__ctor then return r, self.__ctor(r, ...) end
53 return r 69 return r
54 end, 70 end,