> ## 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을 찾고 hookfunction을 통해 해당 function을 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>
