Skip to main content
Проверяйте, создавайте, клонируйте и заменяйте замыкания.

Доступные функции

checkcaller

Возвращает, присутствует ли current Luau thread в Real caller context. Function не принимает arguments и push-ит boolean result от the current caller context. Function не проверяет Lua call stack или function object.

clonefunction

Creates and returns a separate function value for the function passed as the first argument. The argument must be a function.

comparefunctions

Сравнивает два function values по их function identity. Оба arguments должны быть functions. Function возвращает boolean result выражения function identity(L, 1) == function identity(L, 2). Она не сравнивает function bytecode, source, behavior, hashes, upvalues или newcclosure mappings. comparefunction является alias для той же function.

getfunctionhash

Returns an uppercase SHA384 hex digest derived from a Luau function. The argument must be a function, and C closures raise “Lua function expected”. If no hashable function content is available, the function returns nil.

hookfunction

Делает hook для target function через replacement function и возвращает cloned copy original target closure. Оба arguments должны быть functions. Function сначала flush-ит pending C function swaps, делает cloning target через function cloning, добавляет replacement closure или ее mapped newcclosure target в hidden stack tracking, вызывает FixCallstack для target и cloned original, затем patch-ит target closure через C closure, Luau closure или newcclosure-specific path. Если target еще нет в hook records, cloned original сохраняется там для restorefunction. Returned function является cloned original closure.

hookmetamethod

Ищет metamethod function у value и hook-ит эту function через hookfunction. First argument может быть любым value, который принимает raw metafield lookup. Second argument должен быть string metamethod name, а third argument должен быть function replacement. Если raw metafield lookup не находит named metafield, function вызывает “Metamethod doesn’t exist” для argument 2. Если metafield существует, но не является function, вызывает “Metamethod isn’t a function” для argument 2. Когда metafield является function, hookmetamethod вызывает hookfunction с found metamethod function как target и возвращает cloned original closure из hookfunction.

iscclosure

Returns whether the provided function is a C closure. The argument must be a function; passing any other type raises a type error. The function does not inspect executor ownership, source, bytecode, or upvalues.

isexecutorclosure

Returns whether the provided function is classified as executor-owned. The argument must be a function. The function does not inspect source text, debug names, bytecode hashes, or call stack ownership.

isfunctionhooked

Returns whether the provided function currently has a hook record. The argument must be a function.

ishiddenstack

Returns whether a function, or the function at a stack level, is marked as hidden. target must be a function or stack level number. Invalid stack levels raise “Level out of range”. isstackhidden is an alias.

islclosure

Returns whether the provided function is a Lua closure. The argument must be a function; passing a non-function raises a type error. isluaclosure is an alias.

isnewcclosure

Returns whether the provided function is a newcclosure-created C closure. The first argument must be a function; passing a non-function raises a type error. Documented usage is a single function argument; extra arguments are not part of the supported signature.

newcclosure

Returns a C closure for the provided function. If the function is already a C closure, the same function is returned. Passing a non-function raises a type error.

newlclosure

Returns a Luau closure that calls the provided function. The first argument must be a function.

restorefunction

Восстанавливает или заменяет function, внутренне вызывая function hook operation, и не возвращает values. First argument должен быть function. С одним function argument function ищет the saved original function; если entry отсутствует, вызывает “Function is not hooked”. Затем вызывает function hook operation с hooked closure и stored original closure, очищает Lua stack и удаляет restored closure из hook records, когда использовалась stored original. Если second argument тоже является function, function вместо этого рассматривает firstFunction как original function для установки, а secondFunction как closure для patch. В этой форме missing-original check по сохраненному значению hook records не выполняется; сохраненное значение только сравнивается во время final remove check. Non-function second arguments игнорируются branch condition. restorefunc и restoreclosure являются aliases той же function.

sethiddenstack

Marks or unmarks a function, or the function at a stack level, as hidden. target must be a function or stack level number. hidden defaults to true. Invalid stack levels raise “Level out of range”. setstackhidden is an alias.