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

> Делает 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.

<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>
    Function для patch. Передача non-function вызывает type error.
  </ParamField>

  <ParamField path={"replacement"} type={"function"} required>
    Function, чья function install или map на target. Передача non-function вызывает type error.
  </ParamField>

  ## Возвраты

  <ResponseField name={"original"} type={"function"}>
    Cloned copy original target closure, созданная до установки hook.
  </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>
