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

# 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 です。

<div className="real-function-page">
  ```lua theme={null}
  hookfunction(target: function, replacement: function): function
  ```

  ## エイリアス

  * `hookfunc`
  * `replaceclosure`
  * `detourfunction`
  * `detour_function`

  ## 引数

  <ParamField path={"target"} type={"function"} required>
    patch する Function。non-function を渡すと type error が発生します。
  </ParamField>

  <ParamField path={"replacement"} type={"function"} required>
    function が target に install または map される Function。non-function を渡すと type error が発生します。
  </ParamField>

  ## 戻り値

  <ResponseField name={"original"} type={"function"}>
    hook が install される前に作成された original target closure の cloned copy。
  </ResponseField>

  ## 例

  Patch a function closure and keep a cloned original.

  ```lua theme={null}
  local function target(value)
      return value + 1
  end

  local original
  original = hookfunction(target, function(value)
      return original(value) * 2
  end)
  ```
</div>
