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
7c178c3d
Commit
7c178c3d
authored
Mar 31, 2015
by
Vinicius Jarina
Browse files
Merge pull request #153 from Mervill/master
Quick updates to Unity3D compatibility
parents
20873726
f7eea5c0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Core/NLua/Extensions/GeneralExtensions.cs
View file @
7c178c3d
...
...
@@ -253,14 +253,14 @@ namespace NLua.Extensions
#endif
}
#if NETFX_CORE
// Missing Reflection methods from WinRT
#if NETFX_CORE
// Missing Reflection methods from WinRT
public
const
BindingFlags
Default
=
BindingFlags
.
Public
|
BindingFlags
.
Static
|
BindingFlags
.
Instance
;
public
static
MethodInfo
GetMethod
(
this
Type
type
,
string
name
,
BindingFlags
flags
,
Type
[]
signature
)
{
return
GetMethods
(
type
,
flags
).
FirstOrDefault
(
c
=>
c
.
Name
==
name
&&
c
.
GetParameters
().
Select
(
p
=>
p
.
ParameterType
).
SequenceEqual
(
signature
));
public
static
MethodInfo
GetMethod
(
this
Type
type
,
string
name
,
BindingFlags
flags
,
Type
[]
signature
)
{
return
GetMethods
(
type
,
flags
).
FirstOrDefault
(
c
=>
c
.
Name
==
name
&&
c
.
GetParameters
().
Select
(
p
=>
p
.
ParameterType
).
SequenceEqual
(
signature
));
}
static
IEnumerable
<
Type
>
GetTypes
(
this
Assembly
assembly
)
...
...
@@ -271,116 +271,116 @@ namespace NLua.Extensions
public
static
bool
IsAssignableFrom
(
this
Type
t
,
Type
t2
)
{
return
t
.
GetTypeInfo
().
IsAssignableFrom
(
t2
.
GetTypeInfo
());
}
public
static
MemberInfo
[]
GetMember
(
this
Type
type
,
string
name
,
BindingFlags
flags
)
{
return
GetMembers
(
type
,
flags
).
Where
(
m
=>
m
.
Name
==
name
).
ToArray
();
}
public
static
MemberInfo
[]
GetMembers
(
this
Type
type
,
BindingFlags
flags
)
{
// Metro does have DeclaredMembers but nothing otherwise
return
GetEvents
(
type
,
flags
).
Cast
<
MemberInfo
>
()
.
Concat
(
GetFields
(
type
,
flags
).
Cast
<
MemberInfo
>
())
.
Concat
(
GetMethods
(
type
,
flags
).
Cast
<
MemberInfo
>
())
.
Concat
(
GetProperties
(
type
,
flags
).
Cast
<
MemberInfo
>
())
.
ToArray
();
}
public
static
MethodInfo
GetMethod
(
this
Type
type
,
string
name
)
{
return
GetMethod
(
type
,
name
,
Default
);
}
public
static
MethodInfo
GetMethod
(
this
Type
type
,
string
name
,
BindingFlags
flags
)
{
return
GetMethods
(
type
,
flags
).
FirstOrDefault
(
m
=>
m
.
Name
==
name
);
}
public
static
MethodInfo
[]
GetMethods
(
this
Type
type
)
{
return
GetMethods
(
type
,
Default
);
}
public
static
MethodInfo
[]
GetMethods
(
this
Type
type
,
BindingFlags
flags
)
{
var
methods
=
type
.
GetRuntimeMethods
();
return
methods
.
Where
(
m
=>
((
flags
.
HasFlag
(
BindingFlags
.
Static
)
==
m
.
IsStatic
)
||
(
flags
.
HasFlag
(
BindingFlags
.
Instance
)
==
!
m
.
IsStatic
)
)
&&
(
flags
.
HasFlag
(
BindingFlags
.
Public
)
==
m
.
IsPublic
)
).
ToArray
();
}
public
static
PropertyInfo
[]
GetProperties
(
this
Type
type
,
BindingFlags
flags
)
{
var
props
=
type
.
GetRuntimeProperties
();
return
props
.
Where
(
p
=>
((
flags
.
HasFlag
(
BindingFlags
.
Static
)
==
(
p
.
GetMethod
!=
null
&&
p
.
GetMethod
.
IsStatic
))
||
(
flags
.
HasFlag
(
BindingFlags
.
Instance
)
==
(
p
.
GetMethod
!=
null
&&
!
p
.
GetMethod
.
IsStatic
))
)
&&
(
flags
.
HasFlag
(
BindingFlags
.
Public
)
==
(
p
.
GetMethod
!=
null
&&
p
.
GetMethod
.
IsPublic
)
)).
ToArray
();
}
public
static
ConstructorInfo
GetConstructor
(
this
Type
type
,
Type
[]
paramTypes
)
{
return
GetConstructors
(
type
,
Default
).
FirstOrDefault
(
c
=>
c
.
GetParameters
().
Select
(
p
=>
p
.
ParameterType
).
SequenceEqual
(
paramTypes
));
}
public
static
ConstructorInfo
[]
GetConstructors
(
this
Type
type
)
{
return
GetConstructors
(
type
,
Default
);
}
public
static
ConstructorInfo
[]
GetConstructors
(
this
Type
type
,
BindingFlags
flags
)
{
var
props
=
type
.
GetTypeInfo
().
DeclaredConstructors
;
return
props
.
Where
(
p
=>
((
flags
.
HasFlag
(
BindingFlags
.
Static
)
==
p
.
IsStatic
)
||
(
flags
.
HasFlag
(
BindingFlags
.
Instance
)
==
!
p
.
IsStatic
)
)
&&
(
flags
.
HasFlag
(
BindingFlags
.
Public
)
==
p
.
IsPublic
)
).
ToArray
();
}
public
static
EventInfo
[]
GetEvents
(
this
Type
type
,
BindingFlags
flags
)
{
var
props
=
type
.
GetRuntimeEvents
();
return
props
.
Where
(
p
=>
((
flags
.
HasFlag
(
BindingFlags
.
Static
)
==
p
.
AddMethod
.
IsStatic
)
||
(
flags
.
HasFlag
(
BindingFlags
.
Instance
)
==
!
p
.
AddMethod
.
IsStatic
)
)
&&
(
flags
.
HasFlag
(
BindingFlags
.
Public
)
==
p
.
AddMethod
.
IsPublic
)
).
ToArray
();
}
public
static
FieldInfo
GetField
(
this
Type
type
,
string
name
)
{
return
GetField
(
type
,
name
,
Default
);
}
public
static
FieldInfo
GetField
(
this
Type
type
,
string
name
,
BindingFlags
flags
)
{
return
GetFields
(
type
,
flags
).
FirstOrDefault
(
f
=>
f
.
Name
==
name
);
}
public
static
FieldInfo
[]
GetFields
(
this
Type
type
,
BindingFlags
flags
)
{
var
fields
=
type
.
GetRuntimeFields
();
return
fields
.
Where
(
p
=>
((
flags
.
HasFlag
(
BindingFlags
.
Static
)
==
p
.
IsStatic
)
||
(
flags
.
HasFlag
(
BindingFlags
.
Instance
)
==
!
p
.
IsStatic
)
)
&&
(
flags
.
HasFlag
(
BindingFlags
.
Public
)
==
p
.
IsPublic
)
).
ToArray
();
}
public
static
bool
ImplementInterface
(
this
Type
t
,
string
name
)
{
return
t
.
GetTypeInfo
().
ImplementedInterfaces
.
Any
(
i
=>
i
.
Name
==
name
);
}
public
static
MemberInfo
[]
GetMember
(
this
Type
type
,
string
name
,
BindingFlags
flags
)
{
return
GetMembers
(
type
,
flags
).
Where
(
m
=>
m
.
Name
==
name
).
ToArray
();
}
public
static
MemberInfo
[]
GetMembers
(
this
Type
type
,
BindingFlags
flags
)
{
// Metro does have DeclaredMembers but nothing otherwise
return
GetEvents
(
type
,
flags
).
Cast
<
MemberInfo
>
()
.
Concat
(
GetFields
(
type
,
flags
).
Cast
<
MemberInfo
>
())
.
Concat
(
GetMethods
(
type
,
flags
).
Cast
<
MemberInfo
>
())
.
Concat
(
GetProperties
(
type
,
flags
).
Cast
<
MemberInfo
>
())
.
ToArray
();
}
public
static
MethodInfo
GetMethod
(
this
Type
type
,
string
name
)
{
return
GetMethod
(
type
,
name
,
Default
);
}
public
static
MethodInfo
GetMethod
(
this
Type
type
,
string
name
,
BindingFlags
flags
)
{
return
GetMethods
(
type
,
flags
).
FirstOrDefault
(
m
=>
m
.
Name
==
name
);
}
public
static
MethodInfo
[]
GetMethods
(
this
Type
type
)
{
return
GetMethods
(
type
,
Default
);
}
public
static
MethodInfo
[]
GetMethods
(
this
Type
type
,
BindingFlags
flags
)
{
var
methods
=
type
.
GetRuntimeMethods
();
return
methods
.
Where
(
m
=>
((
flags
.
HasFlag
(
BindingFlags
.
Static
)
==
m
.
IsStatic
)
||
(
flags
.
HasFlag
(
BindingFlags
.
Instance
)
==
!
m
.
IsStatic
)
)
&&
(
flags
.
HasFlag
(
BindingFlags
.
Public
)
==
m
.
IsPublic
)
).
ToArray
();
}
public
static
PropertyInfo
[]
GetProperties
(
this
Type
type
,
BindingFlags
flags
)
{
var
props
=
type
.
GetRuntimeProperties
();
return
props
.
Where
(
p
=>
((
flags
.
HasFlag
(
BindingFlags
.
Static
)
==
(
p
.
GetMethod
!=
null
&&
p
.
GetMethod
.
IsStatic
))
||
(
flags
.
HasFlag
(
BindingFlags
.
Instance
)
==
(
p
.
GetMethod
!=
null
&&
!
p
.
GetMethod
.
IsStatic
))
)
&&
(
flags
.
HasFlag
(
BindingFlags
.
Public
)
==
(
p
.
GetMethod
!=
null
&&
p
.
GetMethod
.
IsPublic
)
)).
ToArray
();
}
public
static
ConstructorInfo
GetConstructor
(
this
Type
type
,
Type
[]
paramTypes
)
{
return
GetConstructors
(
type
,
Default
).
FirstOrDefault
(
c
=>
c
.
GetParameters
().
Select
(
p
=>
p
.
ParameterType
).
SequenceEqual
(
paramTypes
));
}
public
static
ConstructorInfo
[]
GetConstructors
(
this
Type
type
)
{
return
GetConstructors
(
type
,
Default
);
}
public
static
ConstructorInfo
[]
GetConstructors
(
this
Type
type
,
BindingFlags
flags
)
{
var
props
=
type
.
GetTypeInfo
().
DeclaredConstructors
;
return
props
.
Where
(
p
=>
((
flags
.
HasFlag
(
BindingFlags
.
Static
)
==
p
.
IsStatic
)
||
(
flags
.
HasFlag
(
BindingFlags
.
Instance
)
==
!
p
.
IsStatic
)
)
&&
(
flags
.
HasFlag
(
BindingFlags
.
Public
)
==
p
.
IsPublic
)
).
ToArray
();
}
public
static
EventInfo
[]
GetEvents
(
this
Type
type
,
BindingFlags
flags
)
{
var
props
=
type
.
GetRuntimeEvents
();
return
props
.
Where
(
p
=>
((
flags
.
HasFlag
(
BindingFlags
.
Static
)
==
p
.
AddMethod
.
IsStatic
)
||
(
flags
.
HasFlag
(
BindingFlags
.
Instance
)
==
!
p
.
AddMethod
.
IsStatic
)
)
&&
(
flags
.
HasFlag
(
BindingFlags
.
Public
)
==
p
.
AddMethod
.
IsPublic
)
).
ToArray
();
}
public
static
FieldInfo
GetField
(
this
Type
type
,
string
name
)
{
return
GetField
(
type
,
name
,
Default
);
}
public
static
FieldInfo
GetField
(
this
Type
type
,
string
name
,
BindingFlags
flags
)
{
return
GetFields
(
type
,
flags
).
FirstOrDefault
(
f
=>
f
.
Name
==
name
);
}
public
static
FieldInfo
[]
GetFields
(
this
Type
type
,
BindingFlags
flags
)
{
var
fields
=
type
.
GetRuntimeFields
();
return
fields
.
Where
(
p
=>
((
flags
.
HasFlag
(
BindingFlags
.
Static
)
==
p
.
IsStatic
)
||
(
flags
.
HasFlag
(
BindingFlags
.
Instance
)
==
!
p
.
IsStatic
)
)
&&
(
flags
.
HasFlag
(
BindingFlags
.
Public
)
==
p
.
IsPublic
)
).
ToArray
();
}
public
static
bool
ImplementInterface
(
this
Type
t
,
string
name
)
{
return
t
.
GetTypeInfo
().
ImplementedInterfaces
.
Any
(
i
=>
i
.
Name
==
name
);
}
#endif
...
...
Core/NLua/ObjectTranslator.cs
View file @
7c178c3d
...
...
@@ -283,13 +283,13 @@ namespace NLua
assembly
=
Assembly
.
Load
(
new
AssemblyName
(
assemblyName
));
#else
assembly
=
Assembly
.
Load
(
assemblyName
);
#endif
#endif
}
catch
(
BadImageFormatException
)
{
// The assemblyName was invalid. It is most likely a path.
}
catch
(
FileNotFoundException
e
)
{
exception
=
e
;
}
exception
=
e
;
}
#if !SILVERLIGHT && !NETFX_CORE
if
(
assembly
==
null
)
{
try
{
...
...
@@ -314,7 +314,7 @@ namespace NLua
if
(
exception
!=
null
)
ThrowError
(
luaState
,
exception
);
}
#endif
#endif
if
(
assembly
!=
null
&&
!
assemblies
.
Contains
(
assembly
))
assemblies
.
Add
(
assembly
);
}
catch
(
Exception
e
)
{
...
...
@@ -593,7 +593,7 @@ namespace NLua
// Object already in the list of Lua objects? Push the stored reference.
#if NETFX_CORE
bool
found
=
(!
o
.
GetType
().
GetTypeInfo
().
IsValueType
||
o
.
GetType
().
GetTypeInfo
().
IsEnum
)
&&
objectsBackMap
.
TryGetValue
(
o
,
out
index
);
#else
#else
bool
found
=
(!
o
.
GetType
().
IsValueType
||
o
.
GetType
().
IsEnum
)
&&
objectsBackMap
.
TryGetValue
(
o
,
out
index
);
#endif
...
...
@@ -767,7 +767,7 @@ namespace NLua
if
(!
o
.
GetType
().
GetTypeInfo
().
IsValueType
||
o
.
GetType
().
GetTypeInfo
().
IsEnum
)
#else
if
(!
o
.
GetType
().
IsValueType
||
o
.
GetType
().
IsEnum
)
#endif
#endif
objectsBackMap
.
Remove
(
o
);
}
...
...
@@ -776,12 +776,12 @@ namespace NLua
// New object: inserts it in the list
int
index
=
nextObj
++;
objects
[
index
]
=
obj
;
#if NETFX_CORE
#if NETFX_CORE
if
(!
obj
.
GetType
().
GetTypeInfo
().
IsValueType
||
obj
.
GetType
().
GetTypeInfo
().
IsValueType
)
#else
#else
if
(!
obj
.
GetType
().
IsValueType
||
obj
.
GetType
().
IsValueType
)
#endif
#endif
objectsBackMap
[
obj
]
=
index
;
return
index
;
}
...
...
@@ -829,10 +829,10 @@ namespace NLua
*/
internal
LuaTable
GetTable
(
LuaState
luaState
,
int
index
)
{
LuaLib
.
LuaPushValue
(
luaState
,
index
);
int
reference
=
LuaLib
.
LuaRef
(
luaState
,
1
);
if
(
reference
==
-
1
)
return
null
;
LuaLib
.
LuaPushValue
(
luaState
,
index
);
int
reference
=
LuaLib
.
LuaRef
(
luaState
,
1
);
if
(
reference
==
-
1
)
return
null
;
return
new
LuaTable
(
reference
,
interpreter
);
}
...
...
@@ -841,10 +841,10 @@ namespace NLua
*/
internal
LuaUserData
GetUserData
(
LuaState
luaState
,
int
index
)
{
LuaLib
.
LuaPushValue
(
luaState
,
index
);
int
reference
=
LuaLib
.
LuaRef
(
luaState
,
1
);
if
(
reference
==
-
1
)
return
null
;
LuaLib
.
LuaPushValue
(
luaState
,
index
);
int
reference
=
LuaLib
.
LuaRef
(
luaState
,
1
);
if
(
reference
==
-
1
)
return
null
;
return
new
LuaUserData
(
reference
,
interpreter
);
}
...
...
@@ -853,9 +853,9 @@ namespace NLua
*/
internal
LuaFunction
GetFunction
(
LuaState
luaState
,
int
index
)
{
LuaLib
.
LuaPushValue
(
luaState
,
index
);
int
reference
=
LuaLib
.
LuaRef
(
luaState
,
1
);
if
(
reference
==
-
1
)
LuaLib
.
LuaPushValue
(
luaState
,
index
);
int
reference
=
LuaLib
.
LuaRef
(
luaState
,
1
);
if
(
reference
==
-
1
)
return
null
;
return
new
LuaFunction
(
reference
,
interpreter
);
}
...
...
@@ -942,7 +942,7 @@ namespace NLua
return
typ
.
ImplementInterface
(
"ILuaGeneratedType"
);
#else
return
typ
.
GetInterface
(
"ILuaGeneratedType"
,
true
)
!=
null
;
#endif
#endif
}
return
false
;
}
...
...
Core/NLua/Platform/BindFlags.cs
View file @
7c178c3d
using
System
;
#if !UNITY_3D
namespace
System.Reflection
{
public
enum
BindingFlags
...
...
@@ -10,3 +10,4 @@ namespace System.Reflection
Public
=
16
,
}
}
#
endif
\ No newline at end of file
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