getnamecallmethod
Returns the method name used in the current __namecall invocation.
function getnamecallmethod(): stringSynopsis
How it works
When Luau compiles colon-call syntax like
obj:Method(args), it emits a NAMECALL opcode that stores the method name as a string constant. The VM then invokes __namecall on the object's metatableMetatableA table attached to another table (or userdata) that defines operator overloading via metamethods (__index, __newindex, __call, etc.). Roblox Instances use shared read-only metatables for method dispatch.. Inside that metamethodMetamethodA function in a metatable that overrides default behavior for operations like indexing (__index), assignment (__newindex), calling (__call), comparison (__eq), and arithmetic (__add, __mul, etc.)., getnamecallmethod() retrieves the stored method name string from the VM's internal namecall register.VM internals
The
NAMECALL instruction sets a hidden register on the current lua_State:
struct lua_State {
// ...
TString* namecall; // method name from last NAMECALL opcode
// ...
};
When NAMECALL R(A), R(B), K(AUX) executes, the VM stores K(AUX) (the method name string) in L->namecall. getnamecallmethod() reads this field and pushes the string. The value persists until the nextnext()Table traversal primitive. next(t, key) returns the next key-value pair after key, or nil when done. next(t, nil) returns the first pair. The underlying function used by pairs(). Traversal order is not guaranteed. NAMECALL or CALL instruction. Calling it outside a __namecall hook returns garbage or nil.Usage
Branch inside a namecall hook
hookmetamethod(game, "__namecall", newcclosure(function(self, ...)
local method = getnamecallmethod()
if method == "HttpGet" then
print("HttpGet called with:", ...)
end
return hookmetamethod_original(self, ...)
end))Returns
string The method name being dispatched through __namecall.