Closures
Inspect, hook, wrap, and restore Luau and C closures at runtime, with helpers to identify origin and hide frames from traces.
A closure is anything in Luau you can call. This library tells you what kind of closure something is, lets you copy it, wrap it so it looks like something else, or replace it completely while keeping the original callable.
Hooking is what most people are here for, and it's worth understanding properly before you use it. The Guide: Hooking chapter goes through the whole thing. Short version:
How every hook looks
local original
original = hookfunction(someFunction, function(...)
print("called with", ...)
return original(...) -- always call through
end)
-- Later, put it back.
restorefunction(someFunction)- checkcaller() tells your own calls apart from the game's. You need this inside a hook so you don't end up logging yourself.
- newcclosure makes a Luau function look like a C closure, which gets past the usual iscclosure check.
- clonefunction gives you a separate copy, so hooking the copy doesn't touch the original.
- setstackhidden hides your frames from anything the game reads through debug.traceback.