World Executor · Roblox VM

Closures

Inspect, hook, wrap, and restore Luau and C closures at runtime, with helpers to identify origin and hide frames from traces.

Overview

A closure is any Luau value you can call. This library lets you ask what kind of closure something is, make copies of it, wrap it so it passes for something else, and replace it outright while keeping the original callable.

Hooking is what most people come here for, and it is the one thing worth understanding properly before you use it — the Guide: Hooking chapter walks through it end to end. The short version:

The shape of every hook
local original
original = hookfunction(someFunction, function(...)
    print("called with", ...)
    return original(...)          -- always call through
end)

-- Later, put it back.
restorefunction(someFunction)
  • checkcaller() distinguishes your own calls from the game's — essential inside a hook so you do not log yourself.
  • newcclosure disguises a Luau function as a C closure, which defeats the usual iscclosure check.
  • clonefunction gives you an independent copy, so hooking the copy leaves the original alone.
  • setstackhidden keeps your frames out of anything the game reads from debug.traceback.

Identifying closures

Cloning & wrapping

Hooking