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

> Hookuje target function przez replacement function i zwraca cloned copy original target closure. Oba arguments muszą być functions. Function najpierw flushuje pending C function swaps, robi cloning target przez function cloning, dodaje replacement closure albo jej mapped newcclosure target do hidden stack tracking, wywołuje FixCallstack dla target i cloned original, a potem patchuje target closure przez C closure, Luau closure albo newcclosure-specific path. Jeśli target nie jest jeszcze w hook records, cloned original jest tam zapisywany dla restorefunction. Returned function to cloned original closure.

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

  ## Aliasy

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

  ## Argumenty

  <ParamField path={"target"} type={"function"} required>
    Function do patch. Przekazanie non-function powoduje type error.
  </ParamField>

  <ParamField path={"replacement"} type={"function"} required>
    Function, której function jest install albo map na target. Przekazanie non-function powoduje type error.
  </ParamField>

  ## Zwroty

  <ResponseField name={"original"} type={"function"}>
    Cloned copy original target closure utworzona przed zainstalowaniem hook.
  </ResponseField>

  ## Przykład

  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>
