> ## 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 une target function avec une replacement function et renvoie une cloned copy de l'original target closure. Les deux arguments doivent être des functions. L'function flush d'abord les pending C function swaps, clone le target with function cloning, ajoute la replacement closure ou son mapped newcclosure target à hidden stack tracking, appelle FixCallstack pour target et cloned original, puis patch la target closure with le C closure, Luau closure ou newcclosure-specific path. Si target n'est pas déjà dans hook records, le cloned original y est stocké pour restorefunction. La returned function est la cloned original closure.

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

  ## Alias

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

  ## Arguments

  <ParamField path={"target"} type={"function"} required>
    Function à patch. Passer une non-function lève un type error.
  </ParamField>

  <ParamField path={"replacement"} type={"function"} required>
    Function dont l'function est install ou map sur target. Passer une non-function lève un type error.
  </ParamField>

  ## Retours

  <ResponseField name={"original"} type={"function"}>
    Cloned copy de l'original target closure créée avant l'installation du hook.
  </ResponseField>

  ## Exemple

  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>
