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

> Procura uma metamethod function em um value e faz hook dessa function por hookfunction. O first argument pode ser qualquer value aceito por raw metafield lookup. O second argument deve ser um string metamethod name, e o third argument deve ser uma function replacement. Se raw metafield lookup não encontrar o named metafield, a function gera "Metamethod doesn't exist" para argument 2. Se o metafield existir mas não for uma function, gera "Metamethod isn't a function" para argument 2. Quando o metafield é uma function, hookmetamethod chama hookfunction com a found metamethod function como target e retorna a cloned original closure de hookfunction.

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

  ## Argumentos

  <ParamField path={"object"} type={"any"} required>
    Value cujo methods é inspecionado com raw metafield lookup.
  </ParamField>

  <ParamField path={"metamethod"} type={"string"} required>
    Metafield name passado para raw metafield lookup.
  </ParamField>

  <ParamField path={"replacement"} type={"function"} required>
    Function passada para hookfunction como replacement da found metamethod function.
  </ParamField>

  ## Retornos

  <ResponseField name={"original"} type={"function"}>
    Cloned original metamethod closure retornada por hookfunction.
  </ResponseField>

  ## Exemplo

  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>
