Commit f886f3da authored by Vinicius Jarina's avatar Vinicius Jarina
Browse files

Merge pull request #124 from isaacbrodsky/master

Enum values do not evaluate to equal
parents d618441e bb09d303
...@@ -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;
......
...@@ -201,9 +201,9 @@ You can get (or set) any property using `.` notation from Lua. ...@@ -201,9 +201,9 @@ You can get (or set) any property using `.` notation from Lua.
All methods, events or property need to be public available, NLua will fail to call non-public members. All methods, events or property need to be public available, NLua will fail to call non-public members.
If you are using Xamarin.iOS you need to [`Preserve`](http://developer.xamarin.com/guides/ios/advanced_topics/linker/) the class you wan't use inside NLua, otherwise the Linker will remove the class from final binary if the class is not in use. If you are using Xamarin.iOS you need to [`Preserve`](http://developer.xamarin.com/guides/ios/advanced_topics/linker/) the class you want to use inside NLua, otherwise the Linker will remove the class from final binary if the class is not in use.
##Sendboxing## ##Sandboxing##
There is many ways to sandbox scripts inside your application. I strongly recomend you to use plain Lua to do your sandbox. There is many ways to sandbox scripts inside your application. I strongly recomend you to use plain Lua to do your sandbox.
You can re-write the `import` function before load the user script and if the user try to import a .NET assembly nothing will happen. You can re-write the `import` function before load the user script and if the user try to import a .NET assembly nothing will happen.
......
...@@ -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
...@@ -215,19 +215,33 @@ namespace NLuaTest ...@@ -215,19 +215,33 @@ namespace NLuaTest
} }
} }
[Test] [Test]
public void TestStructHashesEqual() public void TestStructHashesEqual()
{ {
using (Lua lua = new Lua()) using (Lua lua = new Lua())
{ {
lua.DoString("luanet.load_assembly('NLuaTest')"); lua.DoString("luanet.load_assembly('NLuaTest')");
lua.DoString("TestStruct=luanet.import_type('NLuaTest.Mock.TestStruct')"); lua.DoString("TestStruct=luanet.import_type('NLuaTest.Mock.TestStruct')");
lua.DoString("struct1=TestStruct(0)"); lua.DoString("struct1=TestStruct(0)");
lua.DoString("struct2=TestStruct(0)"); lua.DoString("struct2=TestStruct(0)");
lua.DoString("struct2.val=1"); lua.DoString("struct2.val=1");
Assert.AreEqual(0, (double)lua["struct1.val"]); Assert.AreEqual(0, (double)lua["struct1.val"]);
} }
} }
[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("return enum1 ~= enum2")[0]);
Assert.AreEqual(false, (bool)lua.DoString("return enum1 == enum2")[0]);
}
}
[Test] [Test]
public void TestMethodOverloads () public void TestMethodOverloads ()
......
...@@ -192,23 +192,33 @@ namespace NLuaTest.Mock ...@@ -192,23 +192,33 @@ namespace NLuaTest.Mock
} }
} }
/// <summary> /// <summary>
/// test structure passing /// test structure passing
/// </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; } {
set { v = value; } get { return v; }
} 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
......
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