I'm trying to integrate Lua to my C# app when I hit a little snag. I was hoping someone with more expertise could help point me to the right direction.
Let's say I have the following C# methods:
public void MyMethod(int foo) { ... }
public void MyMethod(int foo, int bar) { ... }
I would like to register it to my Lua script environment so that I can do something like this:
-- call method with one param
MyMethod(123)
-- call method with two params
MyMethod(123, 456)
I tried RegisterFunction("MyMethod", this, this.GetType().GetMethod("MyMethod")) but it reasonably complains about ambiguous match. Any ideas?
You could register the functions with different names and then use a pure Lua function to dispatch to the right method by checking the arguments
function MyMethod(foo, bar)
if bar then
MyMethod1(foo, bar)
else
MyMethod2(foo)
end
end
Alternatively, you could implement this proxy function in C# and bind that instead directly binding each overloaded method.