APEX docs
Reference

Closures

Create, inspect, clone and hook functions.

checkcaller

Also available as check_caller

Returns true when the code that called the current function is your own code, and false when it came from the game. Hooks use it to tell their own calls from the game's.

function checkcaller(): boolean

checkclosure

Also available as isexecutorclosure isexecutorfunction isourclosure check_closure is_executor_closure is_our_closure

Returns true if the function was created by your own code rather than by the game.

function isexecutorclosure(func: (...any) -> (...any)): boolean

clonefunc

Also available as clonefunction clone_function

Returns a copy of a function that behaves the same but is a separate object. Hooking the original does not affect the copy.

function clonefunction<A..., R...>(functionToClone: (A...) -> R...): (A...) -> R...

comparefunction

Also available as comparefunctions

Returns true if two functions are the same underlying function, even if one has been cloned or wrapped.

debug.traceback

Returns a text traceback of the current call stack.

getfunctionhash

Also available as get_function_hash

Returns a hash of the function's compiled code. Two functions with identical code give the same hash.

function getfunctionhash(functionToHash: (...any) -> (...any)): string

hookfunc

Also available as hookfunction replaceclosure hook_func hook_function replace_closure

Replaces a function with another one and returns the original, so the hook can still call it. Calls to the hooked function run your replacement.

function hookfunction<A1..., R1..., A2..., R2...>(functionToHook: (A1...) -> R1..., hook: (A2...) -> R2...): (A1...) -> R1...

hookmetamethod

Also available as hook_meta_method

Hooks one metamethod, such as __index or __namecall, on an object's metatable, and returns the original. The usual way to intercept property reads or method calls on game objects.

function hookmetamethod(object: { [any]: any } | Instance | userdata, metamethodName: string, hook: (...any) -> (...any)): (...any) -> (...any)

iscclosure

Also available as is_c_closure

Returns true if the function is implemented in C (a built-in), and false if it is written in Lua.

function iscclosure(func: (...any) -> (...any)): boolean

islclosure

Also available as isluaclosure is_l_closure

Returns true if the function is written in Lua, and false if it is a C function.

function islclosure(func: (...any) -> (...any)): boolean

isstackhidden

Also available as setstackhidden is_stack_hidden set_stack_hidden

Reports, or with the set form changes, whether a function or call level is hidden from stack inspection such as tracebacks.

loadstring

Also available as load_string

Compiles a string of Lua code and returns it as a function you can call. On a syntax error it returns nil and the error message instead of raising.

function loadstring<A...>(source: string, chunkname: string?): (((A...) -> any) | nil, string?)

newcclosure

Also available as new_c_closure

Wraps a Lua function so it looks like a C function. The wrapper reports as a C closure and hides your function's own frames from simple inspection.

function newcclosure<A..., R...>(functionToWrap: (A...) -> R...): (A...) -> R...

restoreclosure

Also available as restorefunc restorefunction restore_function

Undoes a hookfunction on a function, putting the original back. It raises an error if the function is not currently hooked.

function restorefunction(functionToRestore: (...any) -> (...any)): ()

trampolinecall

Also available as trampoline_call

Calls a function as though it were called from frames you describe. Takes the function, a list of caller frames (use an empty list for none), a table of thread options (also may be empty), and the arguments. Returns true followed by the results, or false and the error.