Skip to content

Commit

Permalink
Fixed #117 Problem with same method in class and base class.
Browse files Browse the repository at this point in the history
+ Unit Tests.
  • Loading branch information
viniciusjarina committed Oct 27, 2014
1 parent d41c103 commit 29ebdf9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
14 changes: 13 additions & 1 deletion Core/NLua/Method/LuaMethodWrapper.cs
Expand Up @@ -25,6 +25,7 @@
using System;
using System.Reflection;
using System.Collections.Generic;
using System.Linq;
using NLua.Exceptions;
using NLua.Extensions;

Expand Down Expand Up @@ -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 ();
}

/// <summary>
Expand Down
35 changes: 34 additions & 1 deletion tests/LuaTests.cs
Expand Up @@ -21,6 +21,11 @@

namespace NLuaTest
{
public class parameter
{
public string field1 = "parameter-field1";
}

#if MONOTOUCH
[Preserve (AllMembers = true)]
#endif
Expand All @@ -30,6 +35,11 @@ public static string read()
{
return "test-master";
}

public static string read( parameter test )
{
return test.field1;
}
}

#if MONOTOUCH
Expand All @@ -43,6 +53,11 @@ public static string read2()
{
return "test";
}

public static string read( int test )
{
return "int-test";
}
}

#if MONOTOUCH
Expand Down Expand Up @@ -2301,14 +2316,32 @@ public void TestCallDelegateWithWrongParametersShouldFail ()
try {
l.DoString (" d (10) ");
}
catch (LuaScriptException e) {
catch (LuaScriptException ) {
fail = true;
}
}

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;

}
Expand Down

0 comments on commit 29ebdf9

Please sign in to comment.