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

> value 上の metamethod function を検索し、その function を hookfunction で hook します。first argument は raw metafield lookup が受け付ける任意の value です。second argument は string metamethod name、third argument は function replacement である必要があります。raw metafield lookup が named metafield を見つけられない場合、この function は argument 2 に対して "Metamethod doesn't exist" を発生させます。metafield が存在しても function でない場合、argument 2 に対して "Metamethod isn't a function" を発生させます。metafield が function の場合、hookmetamethod は found metamethod function を target として hookfunction を呼び、hookfunction の cloned original closure を返します。

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

  ## 引数

  <ParamField path={"object"} type={"any"} required>
    raw metafield lookup で methods を検査する value。
  </ParamField>

  <ParamField path={"metamethod"} type={"string"} required>
    raw metafield lookup に渡される Metafield name。
  </ParamField>

  <ParamField path={"replacement"} type={"function"} required>
    found metamethod function の replacement として hookfunction に渡される Function。
  </ParamField>

  ## 戻り値

  <ResponseField name={"original"} type={"function"}>
    hookfunction から返される cloned original metamethod closure。
  </ResponseField>

  ## 例

  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>
