Closed GoogleCodeExporter closed 8 years ago
You are right about the issue being the dynamic typing of Lua. It doesn't see
a problem with passing string arguments of your second method call to the int
versions and vice versa, so it goes with the first one it finds that matches.
A method of getting around this does exist in LuaInterface. I've never used it
personally in my own scripts (I'm new to the project :P), but there is a method
named get_method_bysig that takes an object instance and a list of types and
gets the proper method signature. You can then use that signature to call the
proper overload. There is a good example of it in the TestLuaInterface.cs file
of the current trunk. Do a search for GetMethodBySignatureFromObj. There is
also an example of it getting a signature by Type rather than instance just
below that one.
Let me know how that works for you or not so I know whether we can close this
issue.
Thanks!
Original comment by eonstorm@gmail.com
on 2 Jul 2010 at 12:59
Yes that worked.
void Main()
{
LuaInterface.Lua e = new LuaInterface.Lua();
Join j = new Join();
e["Join"] = j;
e.DoString("f = luanet.get_method_bysig(Join, 'oload', 'System.Int32', 'System.Int32') return f(1,2)").Dump();
e.DoString("f = luanet.get_method_bysig(Join, 'oload', 'System.String', 'System.String')return Join:oload(\"1\",\"2\")").Dump();
}
public class Join {
public string oload(int i1, int i2) {
return i1 + "-" + i2;
}
public string oload(string i1, string i2) {
return i1 + ":" + i2;
}
}
Produces the correct result.
Original comment by dmartens...@gmail.com
on 2 Jul 2010 at 1:20
Excellent. I'm going to go ahead and close this then.
Original comment by eonstorm@gmail.com
on 2 Jul 2010 at 1:35
Original issue reported on code.google.com by
dmartens...@gmail.com
on 2 Jul 2010 at 12:34