RbxStu V3 Docs
  • Welcome
  • Information
    • Engine Information
      • Luau API Security
  • Stunc
    • Overview
    • Connections
    • Filesystem
      • readfile
      • writefile
      • appendfile
      • isfile
      • isfolder
      • listfiles
      • makefolder
      • delfile
      • delfolder
      • loadfile
      • dofile
  • Memory
    • getgc
    • reference_object
    • unreference_object
    • get_gc_threshold
  • Closures
    • isunhookable
    • makeunhookable
    • ishooked
    • restorefunction
    • hookfunction
    • hookmetamethod
    • isourclosure
    • iscclosure
    • islclosure
    • clonefunction
    • newcclosure
    • newlclosure
    • loadstring
Powered by GitBook
On this page
  1. Closures

hookmetamethod

Overview of the hookmetamethod function.

Function definition
function hookmetamethod(
        object: any,
        metamethod: string,
        hookWith: (...any) -> (...any)
): (...any) -> (...any)

Errors

  • This function cannot be hooked from Luau.

    • inherited from hookfunction

  • invalid metafield '...'

    • This error occurs when the provided metamethod is not valid.

  • the metafield in the objects' metatable is not a function, and thus, cannot be hooked, use getrawmetatable and override it instead.

    • Read remarks.

  • cannot hookmetamethod on an object with no metatable, or that its metafield does not exist.

    • The provided metamethod is not present on the metatable of object.

  • object has no metatable.

    • The provided object has no metatable.

High-Level Overview

Utilises hookfunction to hook the metamethod metamethodof object with hookWith.

This function does not have an argument guard.

Remarks

Inherits remarks from hookfunction

This function will temporarily set the metatable to be readable and writable and will ignore the __metatable metafield.

This function cannot hook metamethods __index or __newindex if they're being used as proxies into another table, as they're not functions.

As the name implies, this function hooks, it does not create a metamethod. If the metamethod does not exist, it will error.

Low-Level Overview

The metatable of the object is obtained utilising getrawmetatable, then the metafield is validated utilising the luaT_eventname string array. Once that is complete, the metafield is validated, and if it is not present, hooking will not proceed.

Once it is complete, hookfunction is utilised, and the metamethod is hooked with hookWith.

PrevioushookfunctionNextisourclosure

Last updated 4 months ago