From 7c5787015c28b2c551bbd1016512fcb8baf5d3e8 Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Tue, 6 Dec 2016 17:33:37 +0100 Subject: [PATCH] Decorate as high as possible in the class hierarchy. --- profiler.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/profiler.lua b/profiler.lua index f57c9d8..77461b3 100644 --- a/profiler.lua +++ b/profiler.lua @@ -64,15 +64,20 @@ function profiler.decorate(model, functionsToDecorate) -- save models anymore. if rawget(model, name) then - error('We decorate the class, not the objects, and there is a `' + error('We decorate the classes, not the objects, and there is a `' .. name .. '\' function in ' .. tostring(model)) end - local toDecorate = getmetatable(model) + local toDecorate = model - if toDecorate[name] and not toDecorate[nameOrig] then + while not rawget(toDecorate, name) do + toDecorate = getmetatable(toDecorate) + end + + if not toDecorate[nameOrig] then + print('Decorating ' .. toDecorate.__typename .. '.' .. name) toDecorate[nameOrig] = toDecorate[name] toDecorate[name] = function(self, ...) local startTime = sys.clock() -- 2.20.1