How do I get namecall method?

I am trying to make a metatable wrapper for Roblox instances to get more functionality. I then found the __namecall metamethod and tried to get the method name, however I didn’t get anything.

local test_proxy = newproxy(true)
local test_meta = getmetatable(test_proxy)

function test_meta:__namecall(...)
	local args = {...}
 	print(self, args)
end 

test_proxy:a()
--> Expectation: userdata: 0x..., a, {}
--> Reality: userdata: 0x..., {}

I don’t see that metamethod anywhere.

It’s only used on proxies.
Let Me Google That for you…

__namecall doesn’t work like that anymore. Since it’s builtin now, it changes a value internally that holds the namecall method on C-side, which is something you can’t access on Luau.
So __namecall isn’t really usable as a metamethod anyways.

1 Like

__namecall is a hidden optimisation might I add. With the update of LuaVM a couple of years ago, method name is no longer passed as a consequence of further optimisation efforts. Even before, Roblox didn’t approve of it in production code because of possible breaking changes.

__index can mimic it just fine.

local proxy = newproxy(true)
local meta = getmetatable(proxy)

function meta:__index(key)
	if key == "print" then
		return function(self, ...)
			print(...)
		end
	end
	return self[key]
end

proxy.print(proxy, "OK") --> OK
proxy:print("OK") --> OK
print(proxy.print) --> function: 0x...

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.