Skip to content

Commit

Permalink
Fix: Member select failed.
Browse files Browse the repository at this point in the history
  • Loading branch information
neolithos committed Dec 8, 2015
1 parent 34ab3f2 commit afe0510
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 12 deletions.
12 changes: 12 additions & 0 deletions NeoLua.Test/LuaType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ public void DrawLine(string pen, Point pt1, Point pt2)
{
Console.WriteLine(string.Format(@"DrawLine '{4}' with Point: {0},{1}, {2},{3}", pt1.x, pt1.y, pt2.x, pt2.y, pen));
}

public void Info(string text)
{
Console.WriteLine("Info(text)");
}

public void Info(string text, params object[] args)
{
Console.WriteLine("Info(text, args)");
}
}

public class SubClass
Expand Down Expand Up @@ -463,6 +473,8 @@ public void OverloadTest02()
{
TestCode(Lines(
"graph = clr.LuaDLR.Test.LuaTypeTests.Graph();",
"graph:Info('test12', 1, 2);",
"graph:Info('test');",
"graph.DrawLine('a', 1, 1, 1, 1);",
"graph.DrawLine('b', 1, 1, 1, 1.0);",
"graph.DrawLine('c', 1, 1, 1.0, 1);",
Expand Down
45 changes: 33 additions & 12 deletions NeoLua/LuaEmit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1897,15 +1897,15 @@ private enum MemberMatchValue
private sealed class MemberMatchInfo<TMEMBERTYPE>
where TMEMBERTYPE : MemberInfo
{
private readonly int argumentsLength; // number of arguments we need to match
private readonly bool unboundedArguments; // is the number endless (LuaResult as last argument)
private int matchesOnBeginning;
private int exactMatches;
private readonly int argumentsLength; // number of arguments we need to match
private readonly bool unboundedArguments; // is the number endless (LuaResult as last argument)
internal int matchesOnBeginning;
internal int exactMatches;
private int implicitMatches;
internal int explicitMatches;

private TMEMBERTYPE currentMember;
private int currentParameterLength;
internal int currentParameterLength;

public MemberMatchInfo(bool unboundedArguments, int argumentsLength)
{
Expand Down Expand Up @@ -1934,7 +1934,7 @@ public void SetMatch(MemberMatchValue value, bool positional)
switch (value)
{
case MemberMatchValue.Exact:
if (positional && explicitMatches == 0)
if (positional && explicitMatches == matchesOnBeginning)
matchesOnBeginning++;
exactMatches++;
goto case MemberMatchValue.Implicit;
Expand Down Expand Up @@ -2054,18 +2054,39 @@ private static ParameterInfo[] GetMemberParameter(TMEMBERTYPE mi, bool isMemberC
}
} // func GetMemberParameter

private void ResetPositional(ParameterInfo[] parameterInfo, MemberMatchInfo<TMEMBERTYPE> target)
{
var length = Math.Min(parameterInfo.Length, arguments.Length);
ResetPositionalPart(parameterInfo, length, target);
} // proc ResetPositional

private void ResetPositionalPart(ParameterInfo[] parameterInfo, int length, MemberMatchInfo<TMEMBERTYPE> target)
{
for (var i = 0; i < length; i++)
target.SetMatch(GetParameterMatch(parameterInfo[i].ParameterType.GetTypeInfo(), getType(arguments[i]).GetTypeInfo()), true);
} // proc ResetPositionalPart

private void ResetPositional(ParameterInfo[] parameterInfo, MemberMatchInfo<TMEMBERTYPE> target)
{
if (target.currentParameterLength == Int32.MaxValue)
{
// check first part
var length = Math.Min(parameterInfo.Length - 1, arguments.Length);
ResetPositionalPart(parameterInfo, length, target);

// test the array
var rest = lastIsExpandable ? Int32.MaxValue - length : arguments.Length - length;
var elementType = parameterInfo[parameterInfo.Length - 1].ParameterType.GetElementType();
if (elementType == typeof(object)) // all is possible
{
if (target.explicitMatches == target.matchesOnBeginning)
target.matchesOnBeginning += rest;
target.exactMatches += rest;
}
else
target.explicitMatches += rest;
}
else
{
var length = Math.Min(parameterInfo.Length, arguments.Length);
ResetPositionalPart(parameterInfo, length, target);
}
} // proc ResetPositional

private void ResetPositionalMax(ParameterInfo[] parameterInfo, MemberMatchInfo<TMEMBERTYPE> target)
{
var checkArguments = arguments.Length - 1;
Expand Down

0 comments on commit afe0510

Please sign in to comment.