reduce a conditional branch in wrapped __index function

This commit is contained in:
Chao Yin 2019-10-18 18:50:22 +08:00
parent fd25b1a006
commit 63f83ea0ef

View File

@ -31,14 +31,22 @@ local middleclass = {
local function _createIndexWrapper(aClass, f) local function _createIndexWrapper(aClass, f)
if f == nil then if f == nil then
return aClass.__instanceDict return aClass.__instanceDict
else elseif type(f) == "function" then
return function(self, name) return function(self, name)
local value = aClass.__instanceDict[name] local value = aClass.__instanceDict[name]
if value ~= nil then if value ~= nil then
return value return value
elseif type(f) == "function" then else
return (f(self, name)) return (f(self, name))
end
end
else -- if type(f) == "table" then
return function(self, name)
local value = aClass.__instanceDict[name]
if value ~= nil then
return value
else else
return f[name] return f[name]
end end