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