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)
if f == nil then
return aClass.__instanceDict
else
elseif type(f) == "function" then
return function(self, name)
local value = aClass.__instanceDict[name]
if value ~= nil then
return value
elseif type(f) == "function" then
else
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
return f[name]
end