forked from enlightenment/efl
elua: make eo bindings work with the new generated format
This commit is contained in:
parent
59ecddb55e
commit
3aabb41d1d
|
@ -344,14 +344,18 @@ end
|
||||||
|
|
||||||
local prop_proxy_meta = {
|
local prop_proxy_meta = {
|
||||||
__index = function(self, key)
|
__index = function(self, key)
|
||||||
if self.nkeys > 1 and type(key) == "table" then
|
local ngkeys = self.ngkeys
|
||||||
if self.nvals > 1 then
|
if ngkeys <= 0 then
|
||||||
|
error("property '" .. self.key .. "' has no getter keys", 2)
|
||||||
|
end
|
||||||
|
if ngkeys > 1 and type(key) == "table" then
|
||||||
|
if self.ngvals > 1 then
|
||||||
return { self(unpack(key)) }
|
return { self(unpack(key)) }
|
||||||
else
|
else
|
||||||
return self(unpack(key))
|
return self(unpack(key))
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if self.nvals > 1 then
|
if self.ngvals > 1 then
|
||||||
return { self(key) }
|
return { self(key) }
|
||||||
else
|
else
|
||||||
return self(key)
|
return self(key)
|
||||||
|
@ -360,8 +364,11 @@ local prop_proxy_meta = {
|
||||||
end,
|
end,
|
||||||
|
|
||||||
__newindex = function(self, key, val)
|
__newindex = function(self, key, val)
|
||||||
local nkeys = self.nkeys
|
local nskeys = self.nskeys
|
||||||
if nkeys > 1 then
|
if nskeys <= 0 then
|
||||||
|
error("property '" .. self.key .. "' has no setter keys", 2)
|
||||||
|
end
|
||||||
|
if nskeys > 1 then
|
||||||
-- ultra slow path, q66 failed optimizing this
|
-- ultra slow path, q66 failed optimizing this
|
||||||
-- if you ever get to touch this, increment this
|
-- if you ever get to touch this, increment this
|
||||||
-- counter to let others know you failed too.
|
-- counter to let others know you failed too.
|
||||||
|
@ -375,14 +382,14 @@ local prop_proxy_meta = {
|
||||||
else
|
else
|
||||||
atbl = { key }
|
atbl = { key }
|
||||||
end
|
end
|
||||||
if self.nvals > 1 and type(val) == "table" then
|
if self.nsvals > 1 and type(val) == "table" then
|
||||||
for i, v in ipairs(val) do atbl[nkeys + i] = v end
|
for i, v in ipairs(val) do atbl[nskeys + i] = v end
|
||||||
else
|
else
|
||||||
atbl[nkeys + 1] = val
|
atbl[nskeys + 1] = val
|
||||||
end
|
end
|
||||||
self.mt[self.key .. "_set"](self.obj, unpack(atbl))
|
self.mt[self.key .. "_set"](self.obj, unpack(atbl))
|
||||||
else
|
else
|
||||||
if self.nvals > 1 and type(val) == "table" then
|
if self.nsvals > 1 and type(val) == "table" then
|
||||||
-- somewhat less slow but still slow path
|
-- somewhat less slow but still slow path
|
||||||
self.mt[self.key .. "_set"](self.obj, key, unpack(val))
|
self.mt[self.key .. "_set"](self.obj, key, unpack(val))
|
||||||
else
|
else
|
||||||
|
@ -403,11 +410,11 @@ local prop_proxy_meta = {
|
||||||
|
|
||||||
-- each __properties field looks like this:
|
-- each __properties field looks like this:
|
||||||
--
|
--
|
||||||
-- { NUMBER_OF_KEYS, NUMBER_OF_VALUES, GETTABLE, SETTABLE }
|
-- { NUM_GET_KEYS, NUM_SET_KEYS, NUM_GET_VALS, NUM_SET_VALS, GETTABLE, SETTABLE }
|
||||||
--
|
--
|
||||||
-- the last two are booleans (determining if the property can be get and set).
|
-- the last two are booleans (determining if the property can be get and set).
|
||||||
ffi.metatype("Eo", {
|
ffi.metatype("Eo", {
|
||||||
-- handles property getting with no keys and also property setting with keys
|
-- handles property getting with no keys and also properties with keys
|
||||||
__index = function(self, key)
|
__index = function(self, key)
|
||||||
local mt = get_obj_mt(self)
|
local mt = get_obj_mt(self)
|
||||||
if mt == nil then return nil end
|
if mt == nil then return nil end
|
||||||
|
@ -416,18 +423,19 @@ ffi.metatype("Eo", {
|
||||||
if not pp then
|
if not pp then
|
||||||
return mt[key]
|
return mt[key]
|
||||||
end
|
end
|
||||||
local nkeys, nvals = pp[1], pp[2]
|
local ngkeys, nskeys = pp[1], pp[2]
|
||||||
if nkeys ~= 0 then
|
if ngkeys ~= 0 or nskeys ~= 0 then
|
||||||
-- proxy - slow path, but no way around it
|
-- proxy - slow path, but no way around it
|
||||||
-- basically the proxy is needed because we want nice syntax and
|
-- basically the proxy is needed because we want nice syntax and
|
||||||
-- lua can't do it by default. so we help ourselves a bit with this
|
-- lua can't do it by default. so we help ourselves a bit with this
|
||||||
return setmetatable({ nkeys = nkeys, nvals = nvals,
|
return setmetatable({ ngkeys = ngkeys, nskeys = nskeys,
|
||||||
obj = self, key = key, mt = mt }, prop_proxy_meta)
|
ngvals = pp[3], nsvals = pp[4], obj = self, key = key,
|
||||||
|
mt = mt }, prop_proxy_meta)
|
||||||
end
|
end
|
||||||
if not pp[3] then
|
if not pp[5] then
|
||||||
error("property '" .. key .. "' is not gettable", 2)
|
error("property '" .. key .. "' is not gettable", 2)
|
||||||
end
|
end
|
||||||
if nvals > 1 then
|
if pp[3] > 1 then
|
||||||
return { mt[key .. "_get"](self) }
|
return { mt[key .. "_get"](self) }
|
||||||
else
|
else
|
||||||
return mt[key .. "_get"](self)
|
return mt[key .. "_get"](self)
|
||||||
|
@ -443,13 +451,14 @@ ffi.metatype("Eo", {
|
||||||
if not pp then
|
if not pp then
|
||||||
error("no such property '" .. key .. "'", 2)
|
error("no such property '" .. key .. "'", 2)
|
||||||
end
|
end
|
||||||
if not pp[4] then
|
if not pp[6] then
|
||||||
error("property '" .. key .. "' is not settable", 2)
|
error("property '" .. key .. "' is not settable", 2)
|
||||||
end
|
end
|
||||||
if pp[1] ~= 0 then
|
local nkeys = pp[2]
|
||||||
error("property '" .. key .. "' requires " .. pp[1] .. " keys", 2)
|
if nkeys ~= 0 then
|
||||||
|
error("property '" .. key .. "' requires " .. nkeys .. " keys", 2)
|
||||||
end
|
end
|
||||||
local nvals = pp[2]
|
local nvals = pp[4]
|
||||||
if nvals > 1 and type(val) == "table" then
|
if nvals > 1 and type(val) == "table" then
|
||||||
mt[key .. "_set"](self, unpack(val))
|
mt[key .. "_set"](self, unpack(val))
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue