forked from enlightenment/efl
elua: wrap multiple-return properties
This commit is contained in:
parent
b2aa896932
commit
6e119370e9
|
@ -48,6 +48,15 @@ local init_setters = function(self)
|
||||||
return strs
|
return strs
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local wrap_retvals = function(f)
|
||||||
|
return function()
|
||||||
|
local vals = { f() }
|
||||||
|
if #vals == 0 then return end
|
||||||
|
if #vals > 1 then return vals end
|
||||||
|
return vals[1]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
M.Object = {
|
M.Object = {
|
||||||
__call = function(self, ...)
|
__call = function(self, ...)
|
||||||
local r = self:clone()
|
local r = self:clone()
|
||||||
|
@ -78,14 +87,16 @@ M.Object = {
|
||||||
|
|
||||||
define_property = function(self, propname, get, set)
|
define_property = function(self, propname, get, set)
|
||||||
if get then
|
if get then
|
||||||
init_getters(self)[propname] = get
|
init_getters(self)[propname] = wrap_retvals(get)
|
||||||
end
|
end
|
||||||
if set then
|
if set then
|
||||||
init_setters(self)[propname] = set
|
init_setters(self)[propname] = wrap_retvals(set)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
define_property_key = function(self, propname, get, set)
|
define_property_key = function(self, propname, get, set)
|
||||||
|
if get then get = wrap_retvals(get) end
|
||||||
|
if set then set = wrap_retvals(set) end
|
||||||
local proxy = setmetatable({}, {
|
local proxy = setmetatable({}, {
|
||||||
__index = function(proxy, key)
|
__index = function(proxy, key)
|
||||||
if get then return get(self, key) end
|
if get then return get(self, key) end
|
||||||
|
|
Loading…
Reference in New Issue