debug.sethook

there is the CodeaCommunity and it has an autorun function which uses debug.sethook to auto-install its setup() routine into the current projects setup(). But what if I wanted to encapsulate this functionality to allow ALL my projects to be in-hook-able? Say I have 3 projects:

  1. “Backup” : (which has some parameter.integer sliders in its setup())

  2. “Monitor” : (which displays parameter.watch’es for monitoring fps and memory usage)

  3. “PingPongGame” : (the actual game, which should include the other 2 projects and hook-in their BOTH setup()'s)

How would I write the debug.sethook ? I tried undless possibilities, but the only the last project I inlude into my game gets hooked. The first one gets overriden on import… Any ideas?

PS: Here’s the function from CC

local s_setup

debug.sethook(function(event)
    if setup and setup ~= s_setup then
        o_setup = setup
        setup = function()
            debug.sethook()
            if hook then hook() end
            o_setup()
        end
        s_setup = setup
    end
end, "r")

I’m a bit confused by debug.sethook(), but I can achieve the same result like this (in a separate tab in a dependency):

tween.delay(0, function() -- runs this next code on the first frame, after everything is loaded
    local _draw = draw -- store the old draw() function in a local variable
    draw = function(...) -- overwrite draw
        --pre-draw code
        _draw(...) -- run the old draw() function
        --post-draw code
    end
end)