"LuaInterfaceTest/LuaInterfaceTest.csproj" did not exist on "2a7bdd795ca6b0ebaa3ce39df3cbe9f08e1e9dfb"
Commit 35dcffb0 authored by Vinicius Jarina's avatar Vinicius Jarina
Browse files

Fixed #355 new Guid

* Guid has a lot of ctor overload, the `byte[]` was being used instead the `string`.
Reorder ctor info before trying to match the parameters.
parent bb722827
...@@ -1258,6 +1258,19 @@ namespace NLua ...@@ -1258,6 +1258,19 @@ namespace NLua
return instance.CallConstructorInternal(luaState); return instance.CallConstructorInternal(luaState);
} }
private static ConstructorInfo[] ReorderConstructors(ConstructorInfo[] constructors)
{
int len = constructors.Length;
if (len < 2)
return constructors;
return constructors.
GroupBy(c => c.GetParameters().Length).
SelectMany(g => g.OrderByDescending(ci => ci.ToString())).
ToArray();
}
private int CallConstructorInternal(LuaState luaState) private int CallConstructorInternal(LuaState luaState)
{ {
var klass = _translator.GetRawNetObject(luaState, 1) as ProxyType; var klass = _translator.GetRawNetObject(luaState, 1) as ProxyType;
...@@ -1273,7 +1286,7 @@ namespace NLua ...@@ -1273,7 +1286,7 @@ namespace NLua
luaState.Remove(1); luaState.Remove(1);
ConstructorInfo[] constructors = klass.UnderlyingSystemType.GetConstructors(); ConstructorInfo[] constructors = klass.UnderlyingSystemType.GetConstructors();
constructors = ReorderConstructors(constructors);
foreach (var constructor in constructors) foreach (var constructor in constructors)
{ {
bool isConstructor = MatchParameters(luaState, constructor, validConstructor, 0); bool isConstructor = MatchParameters(luaState, constructor, validConstructor, 0);
......
using System; using System;
using System.Reflection; using System.Reflection;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
...@@ -67,9 +67,23 @@ namespace NLua.Method ...@@ -67,9 +67,23 @@ namespace NLua.Method
_lastCalledMethod = new MethodCache(); _lastCalledMethod = new MethodCache();
_isStatic = (bindingType & BindingFlags.Static) == BindingFlags.Static; _isStatic = (bindingType & BindingFlags.Static) == BindingFlags.Static;
_members = GetMethodsRecursively(targetType.UnderlyingSystemType, MethodInfo [] methods = GetMethodsRecursively(targetType.UnderlyingSystemType,
methodName, methodName,
bindingType | BindingFlags.Public); bindingType | BindingFlags.Public);
_members = ReorderMethods(methods);
}
private static MethodInfo[] ReorderMethods(MethodInfo[] m)
{
int len = m.Length;
if (len < 2)
return m;
return m.
GroupBy(c => c.GetParameters().Length).
SelectMany(g => g.OrderByDescending(ci => ci.ToString())).
ToArray();
} }
MethodInfo[] GetMethodsRecursively(Type type, string methodName, BindingFlags bindingType) MethodInfo[] GetMethodsRecursively(Type type, string methodName, BindingFlags bindingType)
...@@ -338,4 +352,4 @@ namespace NLua.Method ...@@ -338,4 +352,4 @@ namespace NLua.Method
return CallInvoke(luaState, _lastCalledMethod.cachedMethod, targetObject); return CallInvoke(luaState, _lastCalledMethod.cachedMethod, targetObject);
} }
} }
} }
\ No newline at end of file
...@@ -2780,6 +2780,20 @@ namespace NLuaTest ...@@ -2780,6 +2780,20 @@ namespace NLuaTest
Assert.AreNotEqual(null, errMsg.InnerException); Assert.AreNotEqual(null, errMsg.InnerException);
Assert.AreEqual("exception test", errMsg.InnerException.Message); Assert.AreEqual("exception test", errMsg.InnerException.Message);
} }
}
[Test]
public void TestGuid()
{
using (Lua lua = new Lua())
{
lua.LoadCLRPackage();
object o = lua.DoString(@" import ('mscorlib','System')
return Guid('adc70ae1-769e-4ace-aa83-928a604c5739')
")[0];
Assert.AreEqual(new Guid("adc70ae1-769e-4ace-aa83-928a604c5739"), o);
}
} }
......
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