Is it possible to tell the different between a func that uses table as first argument and regular func?

recently, I have been having this problem where I couldn’t tell the difference between func that uses the table as the first argument.

local module = {}

function module:Test(agrs)
	print(agrs)
end

local TestModule = {}

function TestModule.Init(func)
	func(TestModule, "Test")
end


TestModule.Init(module.Test) -- this uses table as first agrument
TestModule.Init(function(ags)
	print(ags)
end) -- this doesn't use the table as first agrument (this would print the table)

The first call to Init was actually supposed to throw an error, because the argument you’ve passed is not a function (and so it can’t be called), but it doesn’t have a __call metamethod either.

The second call to Init simply calls the first argument, passing TestModule and "Test" to it.

What were you trying to achieve here?

Lua does not support function overloading.

1 Like