Metatables. Add functionality into metamethod without overriding

Hello.
Is there way to extend Panel’s metatable methods like:

PANEL:OnCursorEntered
PANEL:OnCursorExited

Without loosing initial functionality. (Kinda like adding event listeners in JS)

For example I have a panel that highlights on CursorEntered.

But I want to create custom tooltip meta method like:




local meta = FindMetaTable("Panel")

function meta:CustomTip(str)
	self.OnCursorEntered = function() -- Here we override the method and it loses it's functionality and panel no more highlights itself :(
		-- Show custom tooltip
	end
	self.OnCursorExited = function()
		-- Hife custom tooltip
	end
end



Detours.



mt._Function = mt.Function
function mt:Function() 
    -- code here 
    mt:_function()
end


Yes, but it’s a little bit hacky way.

Popping out of the blue here a little bit, but what is the nature of detours? I’ve never used them and have no idea what that code does, it seems really useful.

The code does exactly what it looks like it does, it saves the current function and then overwrites it.

Just like if I want to know whenever something printed shit



local old_print = print

function print(...)
  -- Print was called, do our stuff here

  old_print(...) -- Call old print to retain functionality
end


ninja’d

vanilla gmod code does this in quite a few spots, i wouldn’t worry too much about it being hacky. if you really must have a cleaner syntax, you’d have to implement a hooking system for your panel yourself.