> ## Documentation Index
> Fetch the complete documentation index at: https://docs.projectreal.gg/llms.txt
> Use this file to discover all available pages before exploring further.

# Closures

> Inspecione, crie, clone e substitua fechamentos.

<div className="real-category-page">
  Inspecione, crie, clone e substitua fechamentos.

  ## Funções disponíveis

  <CardGroup cols={2}>
    <Card title="checkcaller" href="./checkcaller">
      Retorna se o current Luau thread está presente em Real caller context. A function não recebe arguments e faz push do boolean result de the current caller context. A function não inspeciona o Lua call stack nem um function object.
    </Card>

    <Card title="clonefunction" href="./clonefunction">
      Creates and returns a separate function value for the function passed as the first argument. The argument must be a function.
    </Card>

    <Card title="comparefunctions" href="./comparefunctions">
      Compara dois function values pelo function identity. Ambos arguments devem ser functions. A function retorna o boolean result de function identity(L, 1) == function identity(L, 2). Ela não compara function bytecode, source, behavior, hashes, upvalues nem newcclosure mappings. comparefunction é um alias da mesma function.
    </Card>

    <Card title="getfunctionhash" href="./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.
    </Card>

    <Card title="hookfunction" href="./hookfunction">
      Faz hook de uma target function com uma replacement function e retorna uma cloned copy da original target closure. Ambos arguments devem ser functions. A function primeiro faz flush de pending C function swaps, faz cloning do target por function cloning, adiciona a replacement closure ou seu mapped newcclosure target a hidden stack tracking, chama FixCallstack para target e cloned original, e então aplica patch na target closure pelo C closure, Luau closure ou newcclosure-specific path. Se target ainda não estiver em hook records, o cloned original é armazenado ali para restorefunction. A returned function é a cloned original closure.
    </Card>

    <Card title="hookmetamethod" href="./hookmetamethod">
      Procura uma metamethod function em um value e faz hook dessa function por hookfunction. O first argument pode ser qualquer value aceito por raw metafield lookup. O second argument deve ser um string metamethod name, e o third argument deve ser uma function replacement. Se raw metafield lookup não encontrar o named metafield, a function gera "Metamethod doesn't exist" para argument 2. Se o metafield existir mas não for uma function, gera "Metamethod isn't a function" para argument 2. Quando o metafield é uma function, hookmetamethod chama hookfunction com a found metamethod function como target e retorna a cloned original closure de hookfunction.
    </Card>

    <Card title="iscclosure" href="./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.
    </Card>

    <Card title="isexecutorclosure" href="./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.
    </Card>

    <Card title="isfunctionhooked" href="./isfunctionhooked">
      Returns whether the provided function currently has a hook record. The argument must be a function.
    </Card>

    <Card title="ishiddenstack" href="./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.
    </Card>

    <Card title="islclosure" href="./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.
    </Card>

    <Card title="isnewcclosure" href="./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.
    </Card>

    <Card title="newcclosure" href="./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.
    </Card>

    <Card title="newlclosure" href="./newlclosure">
      Returns a Luau closure that calls the provided function. The first argument must be a function.
    </Card>

    <Card title="restorefunction" href="./restorefunction">
      Restaura ou substitui uma function chamando function hook operation internamente e não retorna values. O first argument deve ser uma function. Com um function argument, a function procura the saved original function; se nenhum entry existir, gera "Function is not hooked". Em seguida chama function hook operation com a hooked closure e a stored original closure, limpa o Lua stack e remove a restored closure de hook records quando a stored original foi usada. Se o second argument também for uma function, a function trata firstFunction como a original function a instalar e secondFunction como a closure a corrigir. Nessa forma, nenhum missing-original check e feito contra o valor armazenado em hook records; o valor armazenado e apenas comparado durante o final remove check. Non-function second arguments são ignorados pela branch condition. restorefunc e restoreclosure são aliases da mesma function.
    </Card>

    <Card title="sethiddenstack" href="./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.
    </Card>
  </CardGroup>
</div>
