forked from enlightenment/efl
elua: fix object system on lua 5.2 onwards
This is a quick hacky fix, but it enables elua to work well with lua 5.2+. Notably Eolian bindings work now. Later this will be rewritten to use __gc directly on object instances, with a fallback for newproxy for 5.1/luajit.
This commit is contained in:
parent
38bf0be7d0
commit
b953b99a66
|
@ -13,6 +13,17 @@ local M = {}
|
||||||
|
|
||||||
local getmetatable, setmetatable = getmetatable, setmetatable
|
local getmetatable, setmetatable = getmetatable, setmetatable
|
||||||
local dgetmt = debug.getmetatable
|
local dgetmt = debug.getmetatable
|
||||||
|
local newproxy = newproxy
|
||||||
|
|
||||||
|
if not newproxy then
|
||||||
|
-- tables can have __gc from 5.2
|
||||||
|
newproxy = function(b)
|
||||||
|
if b then
|
||||||
|
return setmetatable({}, {})
|
||||||
|
end
|
||||||
|
return {}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- multiple inheritance index with depth-first search
|
-- multiple inheritance index with depth-first search
|
||||||
local proto_lookup = function(protos, name)
|
local proto_lookup = function(protos, name)
|
||||||
|
@ -98,8 +109,6 @@ M.Object = {
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
local newproxy = newproxy
|
|
||||||
|
|
||||||
local robj_gc = function(px)
|
local robj_gc = function(px)
|
||||||
local dtor = px.__dtor
|
local dtor = px.__dtor
|
||||||
if dtor then dtor(px) end
|
if dtor then dtor(px) end
|
||||||
|
@ -108,7 +117,7 @@ end
|
||||||
M.Readonly_Object = M.Object:clone {}
|
M.Readonly_Object = M.Object:clone {}
|
||||||
M.Readonly_Object.__call = function(self, ...)
|
M.Readonly_Object.__call = function(self, ...)
|
||||||
local r = newproxy(true)
|
local r = newproxy(true)
|
||||||
local rmt = getmetatable(r)
|
local rmt = dgetmt(r)
|
||||||
rmt.__index = self
|
rmt.__index = self
|
||||||
rmt.__tostring = Object_MT.__tostring
|
rmt.__tostring = Object_MT.__tostring
|
||||||
rmt.__metatable = false
|
rmt.__metatable = false
|
||||||
|
|
Loading…
Reference in New Issue