Closures
The Closures library enables the inspection, modification and creation of Luau closures with precise control.
It is one of the most powerful tools available, exposing internals in a way that Luau does not natively support out of the box.
This library is incredibly useful for hooking functions to modify game logic to your own advantage, and any other creative uses you can think of.
What is a closure?
The term "closure" comes from functional programming and refers to a function plus the environment it carries (its upvalues).
In Luau (and Lua), every function is implemented as a closure implicitly, even if it doesn't capture anything.
What can you do?
With the Closures
library, you can:
- Hook existing functions or metamethods with
hookfunction
andhookmetamethod
- Check whether the current execution is from your script using
checkcaller
for hooking - Clone a function while keeping the same behavior to avoid tampering, with
clonefunction
- Wrap a Luau closure into a C closure using
newcclosure
- Check a function's closure type with
iscclosure
,islclosure
orisexecutorclosure
. - Hash a function with
getfunctionhash
What can't you do?
Although closure capabilities are powerful, there are natural boundaries:
- You cannot inspect true C closures' internals - they are not Lua-defined, compiled, and therefore opaque by design.
- Attempting to implement
newcclosure
in Lua (e.g. viacoroutine.wrap
) will fail sUNC verification.