Commit 29ebdf90 authored by Vinicius Jarina's avatar Vinicius Jarina
Browse files

Fixed #117 Problem with same method in class and base class.

+ Unit Tests.
parent d41c103a
......@@ -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 @@ namespace NLua.Method
_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>
......
......@@ -21,6 +21,11 @@ using NUnit.Framework;
namespace NLuaTest
{
public class parameter
{
public string field1 = "parameter-field1";
}
#if MONOTOUCH
[Preserve (AllMembers = true)]
#endif
......@@ -30,6 +35,11 @@ namespace NLuaTest
{
return "test-master";
}
public static string read( parameter test )
{
return test.field1;
}
}
#if MONOTOUCH
......@@ -43,6 +53,11 @@ namespace NLuaTest
{
return "test";
}
public static string read( int test )
{
return "int-test";
}
}
#if MONOTOUCH
......@@ -2301,7 +2316,7 @@ namespace NLuaTest
try {
l.DoString (" d (10) ");
}
catch (LuaScriptException e) {
catch (LuaScriptException ) {
fail = true;
}
}
......@@ -2309,6 +2324,24 @@ namespace NLuaTest
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;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment