Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
NLua
Commits
6b8eeedc
Commit
6b8eeedc
authored
Nov 21, 2014
by
Isaac Brodsky
Browse files
Enum values evaluate to the same object
parent
d618441e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Core/NLua/ObjectTranslator.cs
View file @
6b8eeedc
...
@@ -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
;
...
...
tests/LuaTests.cs
View file @
6b8eeedc
...
@@ -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
(
"enum1==enum2"
)[
0
]);
Assert
.
AreEqual
(
false
,
(
bool
)
lua
.
DoString
(
"enum1!=enum2"
)[
0
]);
}
}
[
Test
]
[
Test
]
public
void
TestMethodOverloads
()
public
void
TestMethodOverloads
()
...
...
tests/TestLua.cs
View file @
6b8eeedc
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment