Editing Module:Template test case
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 75: | Line 75: | ||
-- Memoize expensive method calls | -- Memoize expensive method calls | ||
local | local memoizedValues = {} | ||
return setmetatable(obj, { | return setmetatable(obj, { | ||
__index = function (t, key) | __index = function (t, key) | ||
if Template.memoizedMethods[key] then | if Template.memoizedMethods[key] then | ||
local | local val = memoizedValues[key] | ||
if | if val then | ||
return val | |||
else | |||
val = Template[key](t) | |||
memoizedValues[key] = val | |||
return val | |||
end | end | ||
else | else | ||
return Template[key] | return Template[key] |