NamecallFilter. new Synchronous
Match a namecall only when its current method name equals the supplied name. Use it with an argument filter when the same namecall hook should handle one method on one receiver.
Luau
NamecallFilter.new(name: string) -> HookFilterParameters
| Parameter | Type | Description |
|---|---|---|
name | string | Nonempty, case-sensitive method name, such as "GetChildren". This is the method name, not the metamethod name "__namecall". |
Returns
HookFilterA HookFilter table to pass as the optional filter argument of hookfunction, hookmetamethod, or oth.hook. It does not run until a hooked call is evaluated.
Usage notes
This filter needs an active namecall context. An ordinary direct function call has no current namecall method and does not match.
A match calls the replacement. A miss continues through the preceding hook or original function. Omit the filter or pass nil to handle every call.
Example
Luau
local folder = Instance.new("Folder")
local original = getrawmetatable(folder).__namecall
local previous
previous = hookmetamethod(folder, "__namecall", function(self, ...)
print("Observed:", getnamecallmethod())
return previous(self, ...)
end, nil, AllFilter.new({
ArgumentFilter.new(1, folder),
NamecallFilter.new("GetChildren"),
}))
folder:GetChildren() -- Only this folder's GetChildren namecall is observed.
restorefunction(original)
folder:Destroy()