diff --git a/Core/NLua/Method/LuaMethodWrapper.cs b/Core/NLua/Method/LuaMethodWrapper.cs index 6c2db1cf..c36e5300 100755 --- a/Core/NLua/Method/LuaMethodWrapper.cs +++ b/Core/NLua/Method/LuaMethodWrapper.cs @@ -25,6 +25,7 @@ using System; using System.Reflection; using System.Collections.Generic; +using System.Linq; using NLua.Exceptions; using NLua.Extensions; @@ -94,7 +95,18 @@ public LuaMethodWrapper (ObjectTranslator translator, ProxyType targetType, stri _ExtractTarget = translator.typeChecker.GetExtractor (targetType); _IsStatic = (bindingType & BindingFlags.Static) == BindingFlags.Static; - _Members = targetType.UnderlyingSystemType.GetMethods (methodName, bindingType | BindingFlags.Public); + _Members = GetMethodsRecursively (targetType.UnderlyingSystemType, methodName, bindingType | BindingFlags.Public); + } + + MethodInfo [] GetMethodsRecursively (Type type, string methodName, BindingFlags bindingType) + { + if (type == typeof(object)) + return type.GetMethods (methodName, bindingType | BindingFlags.Public); + + var methods = type.GetMethods (methodName, bindingType | BindingFlags.Public); + var baseMethods = GetMethodsRecursively (type.BaseType, methodName, bindingType); + + return methods.Concat (baseMethods).ToArray (); } /// diff --git a/tests/LuaTests.cs b/tests/LuaTests.cs index 29291bc8..4e60b441 100755 --- a/tests/LuaTests.cs +++ b/tests/LuaTests.cs @@ -21,6 +21,11 @@ namespace NLuaTest { + public class parameter + { + public string field1 = "parameter-field1"; + } + #if MONOTOUCH [Preserve (AllMembers = true)] #endif @@ -30,6 +35,11 @@ public static string read() { return "test-master"; } + + public static string read( parameter test ) + { + return test.field1; + } } #if MONOTOUCH @@ -43,6 +53,11 @@ public static string read2() { return "test"; } + + public static string read( int test ) + { + return "int-test"; + } } #if MONOTOUCH @@ -2301,7 +2316,7 @@ public void TestCallDelegateWithWrongParametersShouldFail () try { l.DoString (" d (10) "); } - catch (LuaScriptException e) { + catch (LuaScriptException ) { fail = true; } } @@ -2309,6 +2324,24 @@ public void TestCallDelegateWithWrongParametersShouldFail () Assert.True (fail); } + [Test] + public void TestOverloadedMethodCallOnBase () + { + using (var l = new Lua ()) { + l.LoadCLRPackage (); + l.DoString (" import ('NLuaTest') "); + l.DoString (@" + p=parameter() + r1 = testClass.read(p) -- is not working. it is also not working if the method in base class has two parameters instead of one + r2 = testClass.read(1) -- is working + "); + string r1 = (string) l ["r1"]; + string r2 = (string) l ["r2"]; + Assert.AreEqual ("parameter-field1", r1, "#1"); + Assert.AreEqual ("int-test" , r2, "#2"); + } + } + static Lua m_lua; }