summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2020-05-31 03:39:49 +0200
committerDaniel Kolesa <d.kolesa@samsung.com>2020-05-31 03:39:49 +0200
commitb953b99a6607535a860269d835b8447ea9497508 (patch)
treed3620dfb8b3053f08f2619a34dc36a3f1616c1d7
parent38bf0be7d002c578392039b57f518ae5eb112ad9 (diff)
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.
-rw-r--r--src/scripts/elua/core/util.lua15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/scripts/elua/core/util.lua b/src/scripts/elua/core/util.lua
index 019a424e61..b184921b33 100644
--- a/src/scripts/elua/core/util.lua
+++ b/src/scripts/elua/core/util.lua
@@ -13,6 +13,17 @@ local M = {}
13 13
14local getmetatable, setmetatable = getmetatable, setmetatable 14local getmetatable, setmetatable = getmetatable, setmetatable
15local dgetmt = debug.getmetatable 15local dgetmt = debug.getmetatable
16local newproxy = newproxy
17
18if not newproxy then
19 -- tables can have __gc from 5.2
20 newproxy = function(b)
21 if b then
22 return setmetatable({}, {})
23 end
24 return {}
25 end
26end
16 27
17-- multiple inheritance index with depth-first search 28-- multiple inheritance index with depth-first search
18local proto_lookup = function(protos, name) 29local proto_lookup = function(protos, name)
@@ -98,8 +109,6 @@ M.Object = {
98 end 109 end
99} 110}
100 111
101local newproxy = newproxy
102
103local robj_gc = function(px) 112local robj_gc = function(px)
104 local dtor = px.__dtor 113 local dtor = px.__dtor
105 if dtor then dtor(px) end 114 if dtor then dtor(px) end
@@ -108,7 +117,7 @@ end
108M.Readonly_Object = M.Object:clone {} 117M.Readonly_Object = M.Object:clone {}
109M.Readonly_Object.__call = function(self, ...) 118M.Readonly_Object.__call = function(self, ...)
110 local r = newproxy(true) 119 local r = newproxy(true)
111 local rmt = getmetatable(r) 120 local rmt = dgetmt(r)
112 rmt.__index = self 121 rmt.__index = self
113 rmt.__tostring = Object_MT.__tostring 122 rmt.__tostring = Object_MT.__tostring
114 rmt.__metatable = false 123 rmt.__metatable = false