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

# hookmetamethod

> Mencari metamethod function pada value dan melakukan hook pada function tersebut melalui hookfunction. First argument dapat berupa value apa pun yang diterima raw metafield lookup. Second argument harus berupa string metamethod name, dan third argument harus berupa function replacement. Jika raw metafield lookup tidak menemukan named metafield, function memunculkan "Metamethod doesn't exist" untuk argument 2. Jika metafield ada tetapi bukan function, function memunculkan "Metamethod isn't a function" untuk argument 2. Saat metafield adalah function, hookmetamethod memanggil hookfunction dengan found metamethod function sebagai target dan mengembalikan cloned original closure dari hookfunction.

<div className="real-function-page">
  ```lua theme={null}
  hookmetamethod(object: any, metamethod: string, replacement: function): function
  ```

  ## Argumen

  <ParamField path={"object"} type={"any"} required>
    Value yang methods-nya diperiksa dengan raw metafield lookup.
  </ParamField>

  <ParamField path={"metamethod"} type={"string"} required>
    Metafield name yang diteruskan ke raw metafield lookup.
  </ParamField>

  <ParamField path={"replacement"} type={"function"} required>
    Function yang diteruskan ke hookfunction sebagai replacement untuk found metamethod function.
  </ParamField>

  ## Return

  <ResponseField name={"original"} type={"function"}>
    Cloned original metamethod closure yang dikembalikan oleh hookfunction.
  </ResponseField>

  ## Contoh

  Hook an existing metamethod function.

  ```lua theme={null}
  local object = setmetatable({}, {
      __index = function(_, key)
          return key
      end,
  })

  local original
  original = hookmetamethod(object, "__index", function(self, key)
      if key == "Name" then
          return "Real"
      end

      return original(self, key)
  end)
  ```
</div>
