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