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

> تبحث عن metamethod function على value وتعمل hook لتلك function عبر hookfunction. يمكن أن يكون first argument أي value يقبلها raw metafield lookup. يجب أن يكون second argument عبارة عن string metamethod name، ويجب أن يكون third argument عبارة عن function replacement. إذا لم يجد raw metafield lookup الـ named metafield، ترفع function "Metamethod doesn't exist" للـ argument 2. إذا كان metafield موجودا لكنه ليس function، ترفع "Metamethod isn't a function" للـ argument 2. عندما يكون metafield عبارة عن function، تستدعي hookmetamethod hookfunction باستخدام found metamethod function كـ target وتعيد cloned original closure الخاصة بـ hookfunction.

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

  ## الوسائط

  <ParamField path={"object"} type={"any"} required>
    Value يتم فحص methods الخاص بها باستخدام raw metafield lookup.
  </ParamField>

  <ParamField path={"metamethod"} type={"string"} required>
    Metafield name يتم تمريره إلى raw metafield lookup.
  </ParamField>

  <ParamField path={"replacement"} type={"function"} required>
    Function يتم تمريرها إلى hookfunction كـ replacement للـ found metamethod function.
  </ParamField>

  ## القيم الراجعة

  <ResponseField name={"original"} type={"function"}>
    Cloned original metamethod closure تعيدها hookfunction.
  </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>
