• Hooking a function
    7 replies, posted
Just want to call a function when another function is called. Example: OnFunctionRun(print, function() print("Ran print!") end) print("Hello") The function that appears to be the closest was debug.sethook() but seems like the wiki is outdated, arguments aren't valid.
You'd have to detour the original function. Though I'm fairly certain this is an XY issue, what exactly are you trying to do with this?
Oh yeah sorry, i forgot to mention. I can't detour the original function. I know this is a lil stupid but i'm trying to test my anticheat. Wanted to do an anti-detour function.
For that you could use debug.getinfo, jit.util.funcinfo, and check that all the arguments and returns are what they should be. You could also try to make the functions error inside a coroutine and use debug.traceback to see if it errored somewhere it shouldn't have.
I already do that, but i additionally need to call a func whenever another func is called. Thanks still. :/
local OwO = {} local debug_getinfo = debug.getinfo local function UwU() local e = OwO[debug_getinfo(2, "f").func] if (e) then e() end end debug.sethook(UwU, "c") local OnFunctionRun = function(fn, callback) OwO[fn] = callback end OnFunctionRun(print, function() print("Ran print!") end)
Exactly what i needed, thanks a lot!
Correct me if I'm wrong but when a function is jit compiled debug.sethook callbacks wont be invoked. If that is the case a good solution would be to call 'jit.off' and 'jit.flush', then 'jit.on' when you're done.
Sorry, you need to Log In to post a reply to this thread.