> ## 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

> クロージャを検査、作成、複製、および置換します。

<div className="real-category-page">
  クロージャを検査、作成、複製、および置換します。

  ## 利用できる関数

  <CardGroup cols={2}>
    <Card title="checkcaller" href="./checkcaller">
      current Luau thread が Real caller context に存在するかを返します。この function は arguments を取らず、the current caller context の boolean result を push します。function は Lua call stack や 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">
      2 つの function values を function identity で比較します。両方の arguments は functions である必要があります。この function は function identity(L, 1) == function identity(L, 2) の boolean result を返します。function bytecode, source, behavior, hashes, upvalues, newcclosure mappings は比較しません。comparefunction は同じ function の alias です。
    </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">
      target function を replacement function で hook し、original target closure の cloned copy を返します。両方の arguments は functions である必要があります。function はまず pending C function swaps を flush し、function cloning で target を cloning し、replacement closure またはその mapped newcclosure target を hidden stack tracking に追加し、target と cloned original に FixCallstack を呼び、C closure, Luau closure, newcclosure-specific path のいずれかで target closure を patch します。target がまだ hook records にない場合、restorefunction 用に cloned original がそこへ保存されます。returned function は cloned original closure です。
    </Card>

    <Card title="hookmetamethod" href="./hookmetamethod">
      value 上の metamethod function を検索し、その function を hookfunction で hook します。first argument は raw metafield lookup が受け付ける任意の value です。second argument は string metamethod name、third argument は function replacement である必要があります。raw metafield lookup が named metafield を見つけられない場合、この function は argument 2 に対して "Metamethod doesn't exist" を発生させます。metafield が存在しても function でない場合、argument 2 に対して "Metamethod isn't a function" を発生させます。metafield が function の場合、hookmetamethod は found metamethod function を target として hookfunction を呼び、hookfunction の cloned original closure を返します。
    </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">
      内部で function hook operation を呼び出して function を復元または置き換え、values は返しません。first argument は function である必要があります。function argument が 1 つの場合、function は the saved original function を検索します。entry が存在しない場合は "Function is not hooked" を発生させます。その後、hooked closure と stored original closure で function hook operation を呼び出し、Lua stack をクリアし、stored original が使われた場合は restored closure を hook records から削除します。second argument も function の場合、function は firstFunction をインストールする original function、secondFunction を patch する closure として扱います。この形式では、保存された hook records 値に対する missing-original check は行われません。保存された値は final remove check でのみ比較されます。 にのみ使われます。non-function second arguments は branch condition によって無視されます。restorefunc と restoreclosure は同じ function の aliases です。
    </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>
