Commit 6b8eeedc authored by Isaac Brodsky's avatar Isaac Brodsky
Browse files

Enum values evaluate to the same object

parent d618441e
...@@ -592,9 +592,9 @@ namespace NLua ...@@ -592,9 +592,9 @@ namespace NLua
// Object already in the list of Lua objects? Push the stored reference. // Object already in the list of Lua objects? Push the stored reference.
#if NETFX_CORE #if NETFX_CORE
bool found = (!o.GetType().GetTypeInfo().IsValueType) && objectsBackMap.TryGetValue (o, out index); bool found = (!o.GetType().GetTypeInfo().IsValueType || o.GetType().GetTypeInfo().IsEnum) && objectsBackMap.TryGetValue (o, out index);
#else #else
bool found = (!o.GetType().IsValueType) && objectsBackMap.TryGetValue (o, out index); bool found = (!o.GetType().IsValueType || o.GetType().IsEnum) && objectsBackMap.TryGetValue(o, out index);
#endif #endif
if (found) { if (found) {
...@@ -764,9 +764,9 @@ namespace NLua ...@@ -764,9 +764,9 @@ namespace NLua
{ {
objects.Remove (udata); objects.Remove (udata);
#if NETFX_CORE #if NETFX_CORE
if (!o.GetType ().GetTypeInfo ().IsValueType) if (!o.GetType ().GetTypeInfo ().IsValueType || o.GetType().GetTypeInfo().IsEnum)
#else #else
if (!o.GetType ().IsValueType) if (!o.GetType ().IsValueType || o.GetType().IsEnum)
#endif #endif
objectsBackMap.Remove (o); objectsBackMap.Remove (o);
} }
...@@ -777,9 +777,9 @@ namespace NLua ...@@ -777,9 +777,9 @@ namespace NLua
int index = nextObj++; int index = nextObj++;
objects [index] = obj; objects [index] = obj;
#if NETFX_CORE #if NETFX_CORE
if (!obj.GetType ().GetTypeInfo().IsValueType) if (!obj.GetType ().GetTypeInfo().IsValueType || obj.GetType ().GetTypeInfo().IsValueType)
#else #else
if (!obj.GetType().IsValueType) if (!obj.GetType().IsValueType || obj.GetType().IsValueType)
#endif #endif
objectsBackMap [obj] = index; objectsBackMap [obj] = index;
......
...@@ -7,7 +7,7 @@ using System.Threading; ...@@ -7,7 +7,7 @@ using System.Threading;
using NLua; using NLua;
using NLua.Exceptions; using NLua.Exceptions;
#if MONOTOUCH #if MONOTOUCH
using Foundation; using MonoTouch.Foundation;
#endif #endif
#if WINDOWS_PHONE #if WINDOWS_PHONE
...@@ -229,6 +229,20 @@ namespace NLuaTest ...@@ -229,6 +229,20 @@ namespace NLuaTest
} }
} }
[Test]
public void TestEnumEqual()
{
using (Lua lua = new Lua())
{
lua.DoString("luanet.load_assembly('NLuaTest')");
lua.DoString("TestEnum=luanet.import_type('NLuaTest.Mock.TestEnum')");
lua.DoString("enum1=TestEnum.ValueA");
lua.DoString("enum2=TestEnum.ValueB");
Assert.AreEqual(true, (bool)lua.DoString("enum1==enum2")[0]);
Assert.AreEqual(false, (bool)lua.DoString("enum1!=enum2")[0]);
}
}
[Test] [Test]
public void TestMethodOverloads () public void TestMethodOverloads ()
{ {
......
...@@ -197,19 +197,29 @@ namespace NLuaTest.Mock ...@@ -197,19 +197,29 @@ namespace NLuaTest.Mock
/// </summary> /// </summary>
public struct TestStruct public struct TestStruct
{ {
public TestStruct (float val) public TestStruct(float val)
{ {
v = val; v = val;
} }
public float v; public float v;
public float val { public float val
{
get { return v; } get { return v; }
set { v = value; } set { v = value; }
} }
} }
/// <summary>
/// test enum
/// </summary>
public enum TestEnum
{
ValueA,
ValueB
}
/// <summary> /// <summary>
/// Generic class with generic and non-generic methods /// Generic class with generic and non-generic methods
/// </summary> /// </summary>
......
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