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
be0bfcc8
Commit
be0bfcc8
authored
Oct 07, 2014
by
Mervill
Browse files
Forced consistent line endings.
parent
e5330179
Changes
14
Hide whitespace changes
Inline
Side-by-side
Core/NLua/CheckType.cs
View file @
be0bfcc8
...
@@ -22,7 +22,7 @@
...
@@ -22,7 +22,7 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* THE SOFTWARE.
*/
*/
using
System
;
using
System
;
using
System.Reflection
;
using
System.Reflection
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
...
@@ -47,7 +47,7 @@ namespace NLua
...
@@ -47,7 +47,7 @@ namespace NLua
*/
*/
sealed
class
CheckType
sealed
class
CheckType
{
{
#if SILVERLIGHT
#if SILVERLIGHT
private
Dictionary
<
Type
,
ExtractValue
>
extractValues
=
new
Dictionary
<
Type
,
ExtractValue
>();
private
Dictionary
<
Type
,
ExtractValue
>
extractValues
=
new
Dictionary
<
Type
,
ExtractValue
>();
#else
#else
private
Dictionary
<
long
,
ExtractValue
>
extractValues
=
new
Dictionary
<
long
,
ExtractValue
>
();
private
Dictionary
<
long
,
ExtractValue
>
extractValues
=
new
Dictionary
<
long
,
ExtractValue
>
();
...
@@ -57,25 +57,25 @@ namespace NLua
...
@@ -57,25 +57,25 @@ namespace NLua
public
CheckType
(
ObjectTranslator
translator
)
public
CheckType
(
ObjectTranslator
translator
)
{
{
this
.
translator
=
translator
;
this
.
translator
=
translator
;
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
object
)),
new
ExtractValue
(
GetAsObject
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
object
)),
new
ExtractValue
(
GetAsObject
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
sbyte
)),
new
ExtractValue
(
GetAsSbyte
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
sbyte
)),
new
ExtractValue
(
GetAsSbyte
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
byte
)),
new
ExtractValue
(
GetAsByte
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
byte
)),
new
ExtractValue
(
GetAsByte
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
short
)),
new
ExtractValue
(
GetAsShort
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
short
)),
new
ExtractValue
(
GetAsShort
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
ushort
)),
new
ExtractValue
(
GetAsUshort
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
ushort
)),
new
ExtractValue
(
GetAsUshort
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
int
)),
new
ExtractValue
(
GetAsInt
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
int
)),
new
ExtractValue
(
GetAsInt
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
uint
)),
new
ExtractValue
(
GetAsUint
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
uint
)),
new
ExtractValue
(
GetAsUint
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
long
)),
new
ExtractValue
(
GetAsLong
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
long
)),
new
ExtractValue
(
GetAsLong
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
ulong
)),
new
ExtractValue
(
GetAsUlong
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
ulong
)),
new
ExtractValue
(
GetAsUlong
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
double
)),
new
ExtractValue
(
GetAsDouble
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
double
)),
new
ExtractValue
(
GetAsDouble
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
char
)),
new
ExtractValue
(
GetAsChar
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
char
)),
new
ExtractValue
(
GetAsChar
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
float
)),
new
ExtractValue
(
GetAsFloat
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
float
)),
new
ExtractValue
(
GetAsFloat
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
decimal
)),
new
ExtractValue
(
GetAsDecimal
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
decimal
)),
new
ExtractValue
(
GetAsDecimal
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
bool
)),
new
ExtractValue
(
GetAsBoolean
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
bool
)),
new
ExtractValue
(
GetAsBoolean
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
string
)),
new
ExtractValue
(
GetAsString
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
string
)),
new
ExtractValue
(
GetAsString
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
char
[])),
new
ExtractValue
(
GetAsCharArray
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
char
[])),
new
ExtractValue
(
GetAsCharArray
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
LuaFunction
)),
new
ExtractValue
(
GetAsFunction
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
LuaFunction
)),
new
ExtractValue
(
GetAsFunction
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
LuaTable
)),
new
ExtractValue
(
GetAsTable
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
LuaTable
)),
new
ExtractValue
(
GetAsTable
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
LuaUserData
)),
new
ExtractValue
(
GetAsUserdata
));
extractValues
.
Add
(
GetExtractDictionaryKey
(
typeof
(
LuaUserData
)),
new
ExtractValue
(
GetAsUserdata
));
extractNetObject
=
new
ExtractValue
(
GetAsNetObject
);
extractNetObject
=
new
ExtractValue
(
GetAsNetObject
);
}
}
...
@@ -93,8 +93,8 @@ namespace NLua
...
@@ -93,8 +93,8 @@ namespace NLua
{
{
if
(
paramType
.
IsByRef
)
if
(
paramType
.
IsByRef
)
paramType
=
paramType
.
GetElementType
();
paramType
=
paramType
.
GetElementType
();
var
extractKey
=
GetExtractDictionaryKey
(
paramType
);
var
extractKey
=
GetExtractDictionaryKey
(
paramType
);
return
extractValues
.
ContainsKey
(
extractKey
)
?
extractValues
[
extractKey
]
:
extractNetObject
;
return
extractValues
.
ContainsKey
(
extractKey
)
?
extractValues
[
extractKey
]
:
extractNetObject
;
}
}
...
@@ -109,7 +109,7 @@ namespace NLua
...
@@ -109,7 +109,7 @@ namespace NLua
if
(
underlyingType
!=
null
)
if
(
underlyingType
!=
null
)
paramType
=
underlyingType
;
// Silently convert nullable types to their non null requics
paramType
=
underlyingType
;
// Silently convert nullable types to their non null requics
var
extractKey
=
GetExtractDictionaryKey
(
paramType
);
var
extractKey
=
GetExtractDictionaryKey
(
paramType
);
if
(
paramType
.
Equals
(
typeof
(
object
)))
if
(
paramType
.
Equals
(
typeof
(
object
)))
...
@@ -119,7 +119,7 @@ namespace NLua
...
@@ -119,7 +119,7 @@ namespace NLua
if
(
paramType
.
IsGenericParameter
)
{
if
(
paramType
.
IsGenericParameter
)
{
if
(
luatype
==
LuaTypes
.
Boolean
)
if
(
luatype
==
LuaTypes
.
Boolean
)
return
extractValues
[
GetExtractDictionaryKey
(
typeof
(
bool
))];
return
extractValues
[
GetExtractDictionaryKey
(
typeof
(
bool
))];
else
if
(
luatype
==
LuaTypes
.
String
)
else
if
(
luatype
==
LuaTypes
.
String
)
return
extractValues
[
GetExtractDictionaryKey
(
typeof
(
string
))];
return
extractValues
[
GetExtractDictionaryKey
(
typeof
(
string
))];
else
if
(
luatype
==
LuaTypes
.
Table
)
else
if
(
luatype
==
LuaTypes
.
Table
)
return
extractValues
[
GetExtractDictionaryKey
(
typeof
(
LuaTable
))];
return
extractValues
[
GetExtractDictionaryKey
(
typeof
(
LuaTable
))];
...
@@ -130,23 +130,23 @@ namespace NLua
...
@@ -130,23 +130,23 @@ namespace NLua
else
if
(
luatype
==
LuaTypes
.
Number
)
else
if
(
luatype
==
LuaTypes
.
Number
)
return
extractValues
[
GetExtractDictionaryKey
(
typeof
(
double
))];
return
extractValues
[
GetExtractDictionaryKey
(
typeof
(
double
))];
}
}
bool
netParamIsString
=
paramType
==
typeof
(
string
)
||
paramType
==
typeof
(
char
[]);
bool
netParamIsString
=
paramType
==
typeof
(
string
)
||
paramType
==
typeof
(
char
[]);
bool
netParamIsNumeric
=
paramType
==
typeof
(
int
)
||
bool
netParamIsNumeric
=
paramType
==
typeof
(
int
)
||
paramType
==
typeof
(
uint
)
||
paramType
==
typeof
(
uint
)
||
paramType
==
typeof
(
long
)
||
paramType
==
typeof
(
long
)
||
paramType
==
typeof
(
ulong
)
||
paramType
==
typeof
(
ulong
)
||
paramType
==
typeof
(
short
)
||
paramType
==
typeof
(
short
)
||
paramType
==
typeof
(
float
)
||
paramType
==
typeof
(
float
)
||
paramType
==
typeof
(
double
)
||
paramType
==
typeof
(
double
)
||
paramType
==
typeof
(
decimal
)
||
paramType
==
typeof
(
decimal
)
||
paramType
==
typeof
(
byte
);
paramType
==
typeof
(
byte
);
if
(
netParamIsNumeric
)
{
if
(
netParamIsNumeric
)
{
if
(
LuaLib
.
LuaIsNumber
(
luaState
,
stackPos
)
&&
!
netParamIsString
)
if
(
LuaLib
.
LuaIsNumber
(
luaState
,
stackPos
)
&&
!
netParamIsString
)
return
extractValues
[
extractKey
];
return
extractValues
[
extractKey
];
}
else
if
(
paramType
==
typeof
(
bool
))
{
}
else
if
(
paramType
==
typeof
(
bool
))
{
if
(
LuaLib
.
LuaIsBoolean
(
luaState
,
stackPos
))
if
(
LuaLib
.
LuaIsBoolean
(
luaState
,
stackPos
))
return
extractValues
[
extractKey
];
return
extractValues
[
extractKey
];
}
else
if
(
netParamIsString
)
{
}
else
if
(
netParamIsString
)
{
if
(
LuaLib
.
LuaNetIsStringStrict
(
luaState
,
stackPos
))
if
(
LuaLib
.
LuaNetIsStringStrict
(
luaState
,
stackPos
))
return
extractValues
[
extractKey
];
return
extractValues
[
extractKey
];
...
@@ -183,17 +183,17 @@ namespace NLua
...
@@ -183,17 +183,17 @@ namespace NLua
}
}
return
null
;
return
null
;
}
}
#if SILVERLIGHT
#if SILVERLIGHT
private
Type
GetExtractDictionaryKey
(
Type
targetType
)
private
Type
GetExtractDictionaryKey
(
Type
targetType
)
{
{
return
targetType
;
return
targetType
;
}
}
#else
#else
private
long
GetExtractDictionaryKey
(
Type
targetType
)
private
long
GetExtractDictionaryKey
(
Type
targetType
)
{
{
return
targetType
.
TypeHandle
.
Value
.
ToInt64
();
return
targetType
.
TypeHandle
.
Value
.
ToInt64
();
}
}
#endif
#endif
...
@@ -313,10 +313,10 @@ namespace NLua
...
@@ -313,10 +313,10 @@ namespace NLua
private
object
GetAsBoolean
(
LuaState
luaState
,
int
stackPos
)
private
object
GetAsBoolean
(
LuaState
luaState
,
int
stackPos
)
{
{
return
LuaLib
.
LuaToBoolean
(
luaState
,
stackPos
);
return
LuaLib
.
LuaToBoolean
(
luaState
,
stackPos
);
}
}
private
object
GetAsCharArray
(
LuaState
luaState
,
int
stackPos
)
private
object
GetAsCharArray
(
LuaState
luaState
,
int
stackPos
)
{
{
if
(!
LuaLib
.
LuaNetIsStringStrict
(
luaState
,
stackPos
))
if
(!
LuaLib
.
LuaNetIsStringStrict
(
luaState
,
stackPos
))
...
@@ -326,7 +326,7 @@ namespace NLua
...
@@ -326,7 +326,7 @@ namespace NLua
}
}
private
object
GetAsString
(
LuaState
luaState
,
int
stackPos
)
private
object
GetAsString
(
LuaState
luaState
,
int
stackPos
)
{
{
if
(!
LuaLib
.
LuaNetIsStringStrict
(
luaState
,
stackPos
))
if
(!
LuaLib
.
LuaNetIsStringStrict
(
luaState
,
stackPos
))
return
null
;
return
null
;
string
retVal
=
LuaLib
.
LuaToString
(
luaState
,
stackPos
).
ToString
();
string
retVal
=
LuaLib
.
LuaToString
(
luaState
,
stackPos
).
ToString
();
...
...
Core/NLua/Event/DebugHookEventArgs.cs
View file @
be0bfcc8
...
@@ -22,7 +22,7 @@
...
@@ -22,7 +22,7 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* THE SOFTWARE.
*/
*/
using
System
;
using
System
;
namespace
NLua.Event
namespace
NLua.Event
...
...
Core/NLua/Extensions/GeneralExtensions.cs
View file @
be0bfcc8
...
@@ -21,11 +21,11 @@
...
@@ -21,11 +21,11 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* THE SOFTWARE.
*/
*/
using
System
;
using
System
;
using
System.Linq
;
using
System.Linq
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Reflection
;
using
System.Reflection
;
using
System.Runtime.CompilerServices
;
using
System.Runtime.CompilerServices
;
namespace
NLua.Extensions
namespace
NLua.Extensions
...
@@ -42,7 +42,7 @@ namespace NLua.Extensions
...
@@ -42,7 +42,7 @@ namespace NLua.Extensions
/// <returns>
/// <returns>
/// <c>true</c> if the specified obj is null; otherwise, <c>false</c>.
/// <c>true</c> if the specified obj is null; otherwise, <c>false</c>.
/// </returns>
/// </returns>
///
///
#if USE_KOPILUA
#if USE_KOPILUA
public
static
bool
IsNull
(
object
obj
)
public
static
bool
IsNull
(
object
obj
)
...
@@ -58,152 +58,152 @@ namespace NLua.Extensions
...
@@ -58,152 +58,152 @@ namespace NLua.Extensions
#endif
#endif
}
}
static
class
TypeExtensions
static
class
TypeExtensions
{
{
public
static
bool
HasMethod
(
this
Type
t
,
string
name
)
public
static
bool
HasMethod
(
this
Type
t
,
string
name
)
{
{
var
op
=
t
.
GetMethods
(
BindingFlags
.
Public
|
BindingFlags
.
Instance
|
BindingFlags
.
Static
);
var
op
=
t
.
GetMethods
(
BindingFlags
.
Public
|
BindingFlags
.
Instance
|
BindingFlags
.
Static
);
return
op
.
Count
(
m
=>
m
.
Name
==
name
)
>
0
;
return
op
.
Count
(
m
=>
m
.
Name
==
name
)
>
0
;
}
}
public
static
bool
HasAdditionOpertator
(
this
Type
t
)
public
static
bool
HasAdditionOpertator
(
this
Type
t
)
{
{
if
(
t
.
IsPrimitive
)
if
(
t
.
IsPrimitive
)
return
true
;
return
true
;
return
t
.
HasMethod
(
"op_Addition"
);
return
t
.
HasMethod
(
"op_Addition"
);
}
}
public
static
bool
HasSubtractionOpertator
(
this
Type
t
)
public
static
bool
HasSubtractionOpertator
(
this
Type
t
)
{
{
if
(
t
.
IsPrimitive
)
if
(
t
.
IsPrimitive
)
return
true
;
return
true
;
return
t
.
HasMethod
(
"op_Subtraction"
);
return
t
.
HasMethod
(
"op_Subtraction"
);
}
}
public
static
bool
HasMultiplyOpertator
(
this
Type
t
)
public
static
bool
HasMultiplyOpertator
(
this
Type
t
)
{
{
if
(
t
.
IsPrimitive
)
if
(
t
.
IsPrimitive
)
return
true
;
return
true
;
return
t
.
HasMethod
(
"op_Multiply"
);
return
t
.
HasMethod
(
"op_Multiply"
);
}
}
public
static
bool
HasDivisionOpertator
(
this
Type
t
)
public
static
bool
HasDivisionOpertator
(
this
Type
t
)
{
{
if
(
t
.
IsPrimitive
)
if
(
t
.
IsPrimitive
)
return
true
;
return
true
;
return
t
.
HasMethod
(
"op_Division"
);
return
t
.
HasMethod
(
"op_Division"
);
}
}
public
static
bool
HasModulusOpertator
(
this
Type
t
)
public
static
bool
HasModulusOpertator
(
this
Type
t
)
{
{
if
(
t
.
IsPrimitive
)
if
(
t
.
IsPrimitive
)
return
true
;
return
true
;
return
t
.
HasMethod
(
"op_Modulus"
);
return
t
.
HasMethod
(
"op_Modulus"
);
}
}
public
static
bool
HasUnaryNegationOpertator
(
this
Type
t
)
public
static
bool
HasUnaryNegationOpertator
(
this
Type
t
)
{
{
if
(
t
.
IsPrimitive
)
if
(
t
.
IsPrimitive
)
return
true
;
return
true
;
// Unary - will always have only one version.
// Unary - will always have only one version.
var
op
=
t
.
GetMethod
(
"op_UnaryNegation"
,
BindingFlags
.
Public
|
BindingFlags
.
Instance
|
BindingFlags
.
Static
);
var
op
=
t
.
GetMethod
(
"op_UnaryNegation"
,
BindingFlags
.
Public
|
BindingFlags
.
Instance
|
BindingFlags
.
Static
);
return
op
!=
null
;
return
op
!=
null
;
}
}
public
static
bool
HasEqualityOpertator
(
this
Type
t
)
public
static
bool
HasEqualityOpertator
(
this
Type
t
)
{
{
if
(
t
.
IsPrimitive
)
if
(
t
.
IsPrimitive
)
return
true
;
return
true
;
return
t
.
HasMethod
(
"op_Equality"
);
return
t
.
HasMethod
(
"op_Equality"
);
}
}
public
static
bool
HasLessThanOpertator
(
this
Type
t
)
public
static
bool
HasLessThanOpertator
(
this
Type
t
)
{
{
if
(
t
.
IsPrimitive
)
if
(
t
.
IsPrimitive
)
return
true
;
return
true
;
return
t
.
HasMethod
(
"op_LessThan"
);
return
t
.
HasMethod
(
"op_LessThan"
);
}
}
public
static
bool
HasLessThanOrEqualOpertator
(
this
Type
t
)
public
static
bool
HasLessThanOrEqualOpertator
(
this
Type
t
)
{
{
if
(
t
.
IsPrimitive
)
if
(
t
.
IsPrimitive
)
return
true
;
return
true
;
return
t
.
HasMethod
(
"op_LessThanOrEqual"
);
return
t
.
HasMethod
(
"op_LessThanOrEqual"
);
}
}
public
static
IEnumerable
<
MethodInfo
>
GetMethods
(
this
Type
t
,
string
name
,
BindingFlags
flags
)
public
static
IEnumerable
<
MethodInfo
>
GetMethods
(
this
Type
t
,
string
name
,
BindingFlags
flags
)
{
{
return
t
.
GetMethods
(
flags
).
Where
(
m
=>
m
.
Name
==
name
);
return
t
.
GetMethods
(
flags
).
Where
(
m
=>
m
.
Name
==
name
);
}
}
public
static
MethodInfo
[]
GetExtensionMethods
(
this
Type
type
,
IEnumerable
<
Assembly
>
assemblies
=
null
)
public
static
MethodInfo
[]
GetExtensionMethods
(
this
Type
type
,
IEnumerable
<
Assembly
>
assemblies
=
null
)
{
{
List
<
Type
>
types
=
new
List
<
Type
>
();
List
<
Type
>
types
=
new
List
<
Type
>
();
types
.
AddRange
(
type
.
Assembly
.
GetTypes
().
Where
(
t
=>
t
.
IsPublic
));
types
.
AddRange
(
type
.
Assembly
.
GetTypes
().
Where
(
t
=>
t
.
IsPublic
));
if
(
assemblies
!=
null
)
{
if
(
assemblies
!=
null
)
{
foreach
(
Assembly
item
in
assemblies
)
{
foreach
(
Assembly
item
in
assemblies
)
{
if
(
item
==
type
.
Assembly
)
if
(
item
==
type
.
Assembly
)
continue
;
continue
;
types
.
AddRange
(
item
.
GetTypes
().
Where
(
t
=>
t
.
IsPublic
));
types
.
AddRange
(
item
.
GetTypes
().
Where
(
t
=>
t
.
IsPublic
));
}
}
}
}
var
query
=
from
extensionType
in
types
var
query
=
from
extensionType
in
types
where
extensionType
.
IsSealed
&&
!
extensionType
.
IsGenericType
&&
!
extensionType
.
IsNested
where
extensionType
.
IsSealed
&&
!
extensionType
.
IsGenericType
&&
!
extensionType
.
IsNested
from
method
in
extensionType
.
GetMethods
(
BindingFlags
.
Static
|
BindingFlags
.
Public
)
from
method
in
extensionType
.
GetMethods
(
BindingFlags
.
Static
|
BindingFlags
.
Public
)
where
method
.
IsDefined
(
typeof
(
ExtensionAttribute
),
false
)
where
method
.
IsDefined
(
typeof
(
ExtensionAttribute
),
false
)
where
method
.
GetParameters
()
[
0
].
ParameterType
==
type
where
method
.
GetParameters
()
[
0
].
ParameterType
==
type
select
method
;
select
method
;
return
query
.
ToArray
<
MethodInfo
>
();
return
query
.
ToArray
<
MethodInfo
>
();
}
}
/// <summary>
/// <summary>
/// Extends the System.Type-type to search for a given extended MethodeName.
/// Extends the System.Type-type to search for a given extended MethodeName.
/// </summary>
/// </summary>
/// <param name="MethodeName">Name of the Methode</param>
/// <param name="MethodeName">Name of the Methode</param>
/// <returns>the found Methode or null</returns>
/// <returns>the found Methode or null</returns>
public
static
MethodInfo
GetExtensionMethod
(
this
Type
t
,
string
name
,
IEnumerable
<
Assembly
>
assemblies
=
null
)
public
static
MethodInfo
GetExtensionMethod
(
this
Type
t
,
string
name
,
IEnumerable
<
Assembly
>
assemblies
=
null
)
{
{
var
mi
=
from
methode
in
t
.
GetExtensionMethods
(
assemblies
)
var
mi
=
from
methode
in
t
.
GetExtensionMethods
(
assemblies
)
where
methode
.
Name
==
name
where
methode
.
Name
==
name
select
methode
;
select
methode
;
if
(!
mi
.
Any
<
MethodInfo
>
())
if
(!
mi
.
Any
<
MethodInfo
>
())
return
null
;
return
null
;
else
else
return
mi
.
First
<
MethodInfo
>
();
return
mi
.
First
<
MethodInfo
>
();
}
}
}
}
static
class
StringExtensions
static
class
StringExtensions
{
{
public
static
IEnumerable
<
string
>
SplitWithEscape
(
this
string
input
,
char
separator
,
char
escapeCharacter
)
public
static
IEnumerable
<
string
>
SplitWithEscape
(
this
string
input
,
char
separator
,
char
escapeCharacter
)
{
{
int
start
=
0
;
int
start
=
0
;
int
index
=
0
;
int
index
=
0
;
while
(
index
<
input
.
Length
)
{
while
(
index
<
input
.
Length
)
{
index
=
input
.
IndexOf
(
separator
,
index
);
index
=
input
.
IndexOf
(
separator
,
index
);
if
(
index
==
-
1
)
if
(
index
==
-
1
)
break
;
break
;
if
(
input
[
index
-
1
]
==
escapeCharacter
)
{
if
(
input
[
index
-
1
]
==
escapeCharacter
)
{
input
=
input
.
Remove
(
index
-
1
,
1
);
input
=
input
.
Remove
(
index
-
1
,
1
);
continue
;
continue
;
}
}
yield
return
input
.
Substring
(
start
,
index
-
start
);
yield
return
input
.
Substring
(
start
,
index
-
start
);
index
++;
index
++;
start
=
index
;
start
=
index
;
}
}
yield
return
input
.
Substring
(
start
);
yield
return
input
.
Substring
(
start
);
}
}
}
}
}
}
\ No newline at end of file
Core/NLua/GenerateEventAssembly/ClassGenerator.cs
View file @
be0bfcc8
...
@@ -22,7 +22,7 @@
...
@@ -22,7 +22,7 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* THE SOFTWARE.
*/
*/
using
System
;
using
System
;
namespace
NLua
namespace
NLua
...
...
Core/NLua/GenerateEventAssembly/DelegateGenerator.cs
View file @
be0bfcc8
...
@@ -22,7 +22,7 @@
...
@@ -22,7 +22,7 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* THE SOFTWARE.
*/
*/
using
System
;
using
System
;
namespace
NLua
namespace
NLua
...
...
Core/NLua/Lua.cs
View file @
be0bfcc8
...
@@ -22,9 +22,9 @@
...
@@ -22,9 +22,9 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* THE SOFTWARE.
*/
*/
using
System
;
using
System
;
using
System.IO
;
using
System.IO
;
using
System.Linq
;
using
System.Linq
;
using
System.Threading
;
using
System.Threading
;
using
System.Reflection
;
using
System.Reflection
;
...
@@ -101,45 +101,45 @@ namespace NLua
...
@@ -101,45 +101,45 @@ namespace NLua
//private object luaLock = new object();
//private object luaLock = new object();
private
bool
_StatePassed
;
private
bool
_StatePassed
;
private
bool
executing
;
private
bool
executing
;
static
string
initLuanet
=
static
string
initLuanet
=
@"local metatable = {}
@"local metatable = {}
local rawget = rawget
local rawget = rawget
local import_type = luanet.import_type
local import_type = luanet.import_type
local load_assembly = luanet.load_assembly
local load_assembly = luanet.load_assembly
luanet.error, luanet.type = error, type
luanet.error, luanet.type = error, type
-- Lookup a .NET identifier component.
-- Lookup a .NET identifier component.
function metatable:__index(key) -- key is e.g. 'Form'
function metatable:__index(key) -- key is e.g. 'Form'
-- Get the fully-qualified name, e.g. 'System.Windows.Forms.Form'
-- Get the fully-qualified name, e.g. 'System.Windows.Forms.Form'
local fqn = rawget(self,'.fqn')
local fqn = rawget(self,'.fqn')
fqn = ((fqn and fqn .. '.') or '') .. key
fqn = ((fqn and fqn .. '.') or '') .. key
-- Try to find either a luanet function or a CLR type
-- Try to find either a luanet function or a CLR type
local obj = rawget(luanet,key) or import_type(fqn)
local obj = rawget(luanet,key) or import_type(fqn)
-- If key is neither a luanet function or a CLR type, then it is simply
-- If key is neither a luanet function or a CLR type, then it is simply
-- an identifier component.
-- an identifier component.
if obj == nil then
if obj == nil then
-- It might be an assembly, so we load it too.
-- It might be an assembly, so we load it too.
pcall(load_assembly,fqn)
pcall(load_assembly,fqn)
obj = { ['.fqn'] = fqn }
obj = { ['.fqn'] = fqn }
setmetatable(obj, metatable)
setmetatable(obj, metatable)
end
end
-- Cache this lookup
-- Cache this lookup
rawset(self, key, obj)
rawset(self, key, obj)
return obj
return obj
end
end
-- A non-type has been called; e.g. foo = System.Foo()
-- A non-type has been called; e.g. foo = System.Foo()
function metatable:__call(...)
function metatable:__call(...)
error('No such type: ' .. rawget(self,'.fqn'), 2)
error('No such type: ' .. rawget(self,'.fqn'), 2)
end
end
-- This is the root of the .NET namespace
-- This is the root of the .NET namespace
luanet['.fqn'] = false
luanet['.fqn'] = false
setmetatable(luanet, metatable)
setmetatable(luanet, metatable)
-- Preload the mscorlib assembly
-- Preload the mscorlib assembly
luanet.load_assembly('mscorlib')"
;
luanet.load_assembly('mscorlib')"
;
static
string
clr_package
=
@"---
static
string
clr_package
=
@"---
...
@@ -267,56 +267,56 @@ end
...
@@ -267,56 +267,56 @@ end
return
globals
;
return
globals
;
}
}
}
}
#
endregion
#
endregion
public
Lua
()
public
Lua
()
{
{
luaState
=
LuaLib
.
LuaLNewState
();
luaState
=
LuaLib
.
LuaLNewState
();
LuaLib
.
LuaLOpenLibs
(
luaState
);
LuaLib
.
LuaLOpenLibs
(
luaState
);
Init
();
Init
();
// We need to keep this in a managed reference so the delegate doesn't get garbage collected
// We need to keep this in a managed reference so the delegate doesn't get garbage collected
panicCallback
=
new
LuaNativeFunction
(
PanicCallback
);
panicCallback
=
new
LuaNativeFunction
(
PanicCallback
);
LuaLib
.
LuaAtPanic
(
luaState
,
panicCallback
);
LuaLib
.
LuaAtPanic
(
luaState
,
panicCallback
);
}
}
/*
/*
* CAUTION: NLua.Lua instances can't share the same lua state!
* CAUTION: NLua.Lua instances can't share the same lua state!
*/
*/
public
Lua
(
LuaState
lState
)
public
Lua
(
LuaState
lState
)
{
{
LuaLib
.
LuaPushString
(
lState
,
"LUAINTERFACE LOADED"
);
LuaLib
.
LuaPushString
(
lState
,
"LUAINTERFACE LOADED"
);
LuaLib
.
LuaGetTable
(
lState
,
(
int
)
LuaIndexes
.
Registry
);
LuaLib
.
LuaGetTable
(
lState
,
(
int
)
LuaIndexes
.
Registry
);
if
(
LuaLib
.
LuaToBoolean
(
lState
,
-
1
))
{
if
(
LuaLib
.
LuaToBoolean
(
lState
,
-
1
))
{
LuaLib
.
LuaSetTop
(
lState
,
-
2
);
LuaLib
.
LuaSetTop
(
lState
,
-
2
);
throw
new
LuaException
(
"There is already a NLua.Lua instance associated with this Lua state"
);
throw
new
LuaException
(
"There is already a NLua.Lua instance associated with this Lua state"
);
}
else
{
}
else
{
luaState
=
lState
;
luaState
=
lState
;
_StatePassed
=
true
;
_StatePassed
=
true
;
LuaLib
.
LuaSetTop
(
luaState
,
-
2
);
LuaLib
.
LuaSetTop
(
luaState
,
-
2
);
Init
();
Init
();
}
}
}
}
void
Init
()
void
Init
()
{
{
LuaLib
.
LuaPushString
(
luaState
,
"LUAINTERFACE LOADED"
);
LuaLib
.
LuaPushString
(
luaState
,
"LUAINTERFACE LOADED"
);
LuaLib
.
LuaPushBoolean
(
luaState
,
true
);
LuaLib
.
LuaPushBoolean
(
luaState
,
true
);
LuaLib
.
LuaSetTable
(
luaState
,
(
int
)
LuaIndexes
.
Registry
);
LuaLib
.
LuaSetTable
(
luaState
,
(
int
)
LuaIndexes
.
Registry
);
if
(
_StatePassed
==
false
)
{
if
(
_StatePassed
==
false
)
{
LuaLib
.
LuaNewTable
(
luaState
);
LuaLib
.
LuaNewTable
(
luaState
);
LuaLib
.
LuaSetGlobal
(
luaState
,
"luanet"
);
LuaLib
.
LuaSetGlobal
(
luaState
,
"luanet"
);
}
}
LuaLib
.
LuaNetPushGlobalTable
(
luaState
);
LuaLib
.
LuaNetPushGlobalTable
(
luaState
);
LuaLib
.
LuaGetGlobal
(
luaState
,
"luanet"
);
LuaLib
.
LuaGetGlobal
(
luaState
,
"luanet"
);
LuaLib
.
LuaPushString
(
luaState
,
"getmetatable"
);
LuaLib
.
LuaPushString
(
luaState
,
"getmetatable"
);
LuaLib
.
LuaGetGlobal
(
luaState
,
"getmetatable"
);
LuaLib
.
LuaGetGlobal
(
luaState
,
"getmetatable"
);
LuaLib
.
LuaSetTable
(
luaState
,
-
3
);
LuaLib
.
LuaSetTable
(
luaState
,
-
3
);
LuaLib
.
LuaNetPopGlobalTable
(
luaState
);
LuaLib
.
LuaNetPopGlobalTable
(
luaState
);
translator
=
new
ObjectTranslator
(
this
,
luaState
);
translator
=
new
ObjectTranslator
(
this
,
luaState
);
ObjectTranslatorPool
.
Instance
.
Add
(
luaState
,
translator
);
ObjectTranslatorPool
.
Instance
.
Add
(
luaState
,
translator
);
LuaLib
.
LuaNetPopGlobalTable
(
luaState
);
LuaLib
.
LuaNetPopGlobalTable
(
luaState
);
LuaLib
.
LuaLDoString
(
luaState
,
Lua
.
initLuanet
);
LuaLib
.
LuaLDoString
(
luaState
,
Lua
.
initLuanet
);
}
}
public
void
Close
()
public
void
Close
()
...
@@ -440,68 +440,68 @@ end
...
@@ -440,68 +440,68 @@ end
var
result
=
translator
.
GetFunction
(
luaState
,
-
1
);
var
result
=
translator
.
GetFunction
(
luaState
,
-
1
);
translator
.
PopValues
(
luaState
,
oldTop
);
translator
.
PopValues
(
luaState
,
oldTop
);
return
result
;
return
result
;
}
}
/// <summary>
/// <summary>
/// Executes a Lua chunk and returns all the chunk's return values in an array.
/// Executes a Lua chunk and returns all the chunk's return values in an array.
/// </summary>
/// </summary>
/// <param name = "chunk">Chunk to execute</param>
/// <param name = "chunk">Chunk to execute</param>
/// <param name = "chunkName">Name to associate with the chunk. Defaults to "chunk".</param>
/// <param name = "chunkName">Name to associate with the chunk. Defaults to "chunk".</param>
/// <returns></returns>
/// <returns></returns>
public
object
[]
DoString
(
byte
[]
chunk
,
string
chunkName
=
"chunk"
)
public
object
[]
DoString
(
byte
[]
chunk
,
string
chunkName
=
"chunk"
)
{
{
int
oldTop
=
LuaLib
.
LuaGetTop
(
luaState
);
int
oldTop
=
LuaLib
.
LuaGetTop
(
luaState
);
executing
=
true
;
executing
=
true
;
if
(
LuaLib
.
LuaLLoadBuffer
(
luaState
,
chunk
,
chunkName
)
==
0
)
if
(
LuaLib
.
LuaLLoadBuffer
(
luaState
,
chunk
,
chunkName
)
==
0
)
{
{
try
try
{
{
if
(
LuaLib
.
LuaPCall
(
luaState
,
0
,
-
1
,
0
)
==
0
)
if
(
LuaLib
.
LuaPCall
(
luaState
,
0
,
-
1
,
0
)
==
0
)
return
translator
.
PopValues
(
luaState
,
oldTop
);
return
translator
.
PopValues
(
luaState
,
oldTop
);
else
else
ThrowExceptionFromError
(
oldTop
);
ThrowExceptionFromError
(
oldTop
);
}
}
finally
finally
{
{
executing
=
false
;
executing
=
false
;
}
}
}
}
else
else
ThrowExceptionFromError
(
oldTop
);
ThrowExceptionFromError
(
oldTop
);
return
null
;
// Never reached - keeps compiler happy
return
null
;
// Never reached - keeps compiler happy
}
}
/// <summary>
/// <summary>
/// Executes a Lua chunk and returns all the chunk's return values in an array.
/// Executes a Lua chunk and returns all the chunk's return values in an array.
/// </summary>
/// </summary>
/// <param name = "chunk">Chunk to execute</param>
/// <param name = "chunk">Chunk to execute</param>
/// <param name = "chunkName">Name to associate with the chunk. Defaults to "chunk".</param>
/// <param name = "chunkName">Name to associate with the chunk. Defaults to "chunk".</param>
/// <returns></returns>
/// <returns></returns>
public
object
[]
DoString
(
string
chunk
,
string
chunkName
=
"chunk"
)
public
object
[]
DoString
(
string
chunk
,
string
chunkName
=
"chunk"
)
{
{
int
oldTop
=
LuaLib
.
LuaGetTop
(
luaState
);
int
oldTop
=
LuaLib
.
LuaGetTop
(
luaState
);
executing
=
true
;
executing
=
true
;
if
(
LuaLib
.
LuaLLoadBuffer
(
luaState
,
chunk
,
chunkName
)
==
0
)
if
(
LuaLib
.
LuaLLoadBuffer
(
luaState
,
chunk
,
chunkName
)
==
0
)
{
{
try
try
{
{
if
(
LuaLib
.
LuaPCall
(
luaState
,
0
,
-
1
,
0
)
==
0
)
if
(
LuaLib
.
LuaPCall
(
luaState
,
0
,
-
1
,
0
)
==
0
)
return
translator
.
PopValues
(
luaState
,
oldTop
);
return
translator
.
PopValues
(
luaState
,
oldTop
);
else
else
ThrowExceptionFromError
(
oldTop
);
ThrowExceptionFromError
(
oldTop
);
}
}
finally
finally
{
{
executing
=
false
;
executing
=
false
;
}
}
}
}
else
else
ThrowExceptionFromError
(
oldTop
);
ThrowExceptionFromError
(
oldTop
);
return
null
;
// Never reached - keeps compiler happy
return
null
;
// Never reached - keeps compiler happy
}
}
/*
/*
...
@@ -537,18 +537,18 @@ end
...
@@ -537,18 +537,18 @@ end
public
object
this
[
string
fullPath
]
{
public
object
this
[
string
fullPath
]
{
get
{
get
{
object
returnValue
=
null
;
object
returnValue
=
null
;
int
oldTop
=
LuaLib
.
LuaGetTop
(
luaState
);
int
oldTop
=
LuaLib
.
LuaGetTop
(
luaState
);
string
[]
path
=
FullPathToArray
(
fullPath
);
string
[]
path
=
FullPathToArray
(
fullPath
);
LuaLib
.
LuaGetGlobal
(
luaState
,
path
[
0
]);
LuaLib
.
LuaGetGlobal
(
luaState
,
path
[
0
]);
returnValue
=
translator
.
GetObject
(
luaState
,
-
1
);
returnValue
=
translator
.
GetObject
(
luaState
,
-
1
);
LuaBase
dispose
=
null
;
LuaBase
dispose
=
null
;
if
(
path
.
Length
>
1
)
{
if
(
path
.
Length
>
1
)
{
dispose
=
returnValue
as
LuaBase
;
dispose
=
returnValue
as
LuaBase
;
string
[]
remainingPath
=
new
string
[
path
.
Length
-
1
];
string
[]
remainingPath
=
new
string
[
path
.
Length
-
1
];
Array
.
Copy
(
path
,
1
,
remainingPath
,
0
,
path
.
Length
-
1
);
Array
.
Copy
(
path
,
1
,
remainingPath
,
0
,
path
.
Length
-
1
);
returnValue
=
GetObject
(
remainingPath
);
returnValue
=
GetObject
(
remainingPath
);
if
(
dispose
!=
null
)
if
(
dispose
!=
null
)
dispose
.
Dispose
();
dispose
.
Dispose
();
}
}
...
@@ -556,7 +556,7 @@ end
...
@@ -556,7 +556,7 @@ end
return
returnValue
;
return
returnValue
;
}
}
set
{
set
{
int
oldTop
=
LuaLib
.
LuaGetTop
(
luaState
);
int
oldTop
=
LuaLib
.
LuaGetTop
(
luaState
);
string
[]
path
=
FullPathToArray
(
fullPath
);
string
[]
path
=
FullPathToArray
(
fullPath
);
if
(
path
.
Length
==
1
)
{
if
(
path
.
Length
==
1
)
{
translator
.
Push
(
luaState
,
value
);
translator
.
Push
(
luaState
,
value
);
...
@@ -804,16 +804,16 @@ end
...
@@ -804,16 +804,16 @@ end
LuaLib
.
LuaSetTable
(
luaState
,
-
3
);
LuaLib
.
LuaSetTable
(
luaState
,
-
3
);
}
}
string
[]
FullPathToArray
(
string
fullPath
)
string
[]
FullPathToArray
(
string
fullPath
)
{
{
return
fullPath
.
SplitWithEscape
(
'.'
,
'\\'
).
ToArray
();
return
fullPath
.
SplitWithEscape
(
'.'
,
'\\'
).
ToArray
();
}
}
/*
/*
* Creates a new table as a global variable or as a field
* Creates a new table as a global variable or as a field
* inside an existing table
* inside an existing table
*/
*/
public
void
NewTable
(
string
fullPath
)
public
void
NewTable
(
string
fullPath
)
{
{
string
[]
path
=
FullPathToArray
(
fullPath
);
string
[]
path
=
FullPathToArray
(
fullPath
);
int
oldTop
=
LuaLib
.
LuaGetTop
(
luaState
);
int
oldTop
=
LuaLib
.
LuaGetTop
(
luaState
);
...
@@ -924,14 +924,14 @@ end
...
@@ -924,14 +924,14 @@ end
return
LuaCore
.
LuaSetLocal
(
luaState
,
luaDebug
,
n
).
ToString
();
return
LuaCore
.
LuaSetLocal
(
luaState
,
luaDebug
,
n
).
ToString
();
}
}
public
int
GetStack
(
int
level
,
ref
LuaDebug
ar
)
public
int
GetStack
(
int
level
,
ref
LuaDebug
ar
)
{
{
return
LuaCore
.
LuaGetStack
(
luaState
,
level
,
ref
ar
);
return
LuaCore
.
LuaGetStack
(
luaState
,
level
,
ref
ar
);
}
}
public
int
GetInfo
(
string
what
,
ref
LuaDebug
ar
)
public
int
GetInfo
(
string
what
,
ref
LuaDebug
ar
)
{
{
return
LuaCore
.
LuaGetInfo
(
luaState
,
what
,
ref
ar
);
return
LuaCore
.
LuaGetInfo
(
luaState
,
what
,
ref
ar
);
}
}
/// <summary>
/// <summary>
...
@@ -966,16 +966,16 @@ end
...
@@ -966,16 +966,16 @@ end
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaHook
))]
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaHook
))]
#endif
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
#if USE_KOPILUA
#if USE_KOPILUA
static
void
DebugHookCallback
(
LuaState
luaState
,
LuaDebug
debug
)
static
void
DebugHookCallback
(
LuaState
luaState
,
LuaDebug
debug
)
{
{
#else
#else
static
void
DebugHookCallback
(
LuaState
luaState
,
IntPtr
luaDebug
)
static
void
DebugHookCallback
(
LuaState
luaState
,
IntPtr
luaDebug
)
{
{
LuaDebug
debug
=
(
LuaDebug
)
System
.
Runtime
.
InteropServices
.
Marshal
.
PtrToStructure
(
luaDebug
,
typeof
(
LuaDebug
));
LuaDebug
debug
=
(
LuaDebug
)
System
.
Runtime
.
InteropServices
.
Marshal
.
PtrToStructure
(
luaDebug
,
typeof
(
LuaDebug
));
#endif
#endif
ObjectTranslator
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
ObjectTranslator
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
Lua
lua
=
translator
.
Interpreter
;
Lua
lua
=
translator
.
Interpreter
;
lua
.
DebugHookCallbackInternal
(
luaState
,
debug
);
lua
.
DebugHookCallbackInternal
(
luaState
,
debug
);
}
}
...
...
Core/NLua/LuaFunction.cs
View file @
be0bfcc8
...
@@ -22,7 +22,7 @@
...
@@ -22,7 +22,7 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* THE SOFTWARE.
*/
*/
using
System
;
using
System
;
using
System.Text
;
using
System.Text
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
...
...
Core/NLua/LuaLib/LuaLib.cs
View file @
be0bfcc8
...
@@ -23,7 +23,7 @@
...
@@ -23,7 +23,7 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* THE SOFTWARE.
*/
*/
using
System
;
using
System
;
using
System.IO
;
using
System.IO
;
using
NLua.Extensions
;
using
NLua.Extensions
;
...
@@ -130,12 +130,12 @@ namespace NLua
...
@@ -130,12 +130,12 @@ namespace NLua
}
}
public
static
void
LuaGetGlobal
(
LuaState
luaState
,
string
name
)
public
static
void
LuaGetGlobal
(
LuaState
luaState
,
string
name
)
{
{
LuaCore
.
LuaNetGetGlobal
(
luaState
,
name
);
LuaCore
.
LuaNetGetGlobal
(
luaState
,
name
);
}
}
public
static
void
LuaSetGlobal
(
LuaState
luaState
,
string
name
)
public
static
void
LuaSetGlobal
(
LuaState
luaState
,
string
name
)
{
{
LuaCore
.
LuaNetSetGlobal
(
luaState
,
name
);
LuaCore
.
LuaNetSetGlobal
(
luaState
,
name
);
}
}
...
@@ -272,11 +272,11 @@ namespace NLua
...
@@ -272,11 +272,11 @@ namespace NLua
public
static
bool
LuaIsString
(
LuaState
luaState
,
int
index
)
public
static
bool
LuaIsString
(
LuaState
luaState
,
int
index
)
{
{
return
LuaCore
.
LuaIsString
(
luaState
,
index
)
!=
0
;
return
LuaCore
.
LuaIsString
(
luaState
,
index
)
!=
0
;
}
}
public
static
bool
LuaNetIsStringStrict
(
LuaState
luaState
,
int
index
)
public
static
bool
LuaNetIsStringStrict
(
LuaState
luaState
,
int
index
)
{
{
return
LuaCore
.
LuaNetIsStringStrict
(
luaState
,
index
)
!=
0
;
return
LuaCore
.
LuaNetIsStringStrict
(
luaState
,
index
)
!=
0
;
}
}
public
static
bool
LuaIsCFunction
(
LuaState
luaState
,
int
index
)
public
static
bool
LuaIsCFunction
(
LuaState
luaState
,
int
index
)
...
@@ -383,7 +383,7 @@ namespace NLua
...
@@ -383,7 +383,7 @@ namespace NLua
}
}
public
static
int
LuaLLoadBuffer
(
LuaState
luaState
,
string
buff
,
string
name
)
public
static
int
LuaLLoadBuffer
(
LuaState
luaState
,
string
buff
,
string
name
)
{
{
return
LuaCore
.
LuaNetLoadBuffer
(
luaState
,
buff
,
(
uint
)
0
,
name
);
return
LuaCore
.
LuaNetLoadBuffer
(
luaState
,
buff
,
(
uint
)
0
,
name
);
}
}
...
@@ -400,12 +400,12 @@ namespace NLua
...
@@ -400,12 +400,12 @@ namespace NLua
public
static
bool
LuaLCheckMetatable
(
LuaState
luaState
,
int
index
)
public
static
bool
LuaLCheckMetatable
(
LuaState
luaState
,
int
index
)
{
{
return
LuaCore
.
LuaLCheckMetatable
(
luaState
,
index
);
return
LuaCore
.
LuaLCheckMetatable
(
luaState
,
index
);
}
}
public
static
int
LuaNetRegistryIndex
()
public
static
int
LuaNetRegistryIndex
()
{
{
return
LuaCore
.
LuaNetRegistryIndex
();
return
LuaCore
.
LuaNetRegistryIndex
();
}
}
public
static
int
LuaNetToNetObject
(
LuaState
luaState
,
int
index
)
public
static
int
LuaNetToNetObject
(
LuaState
luaState
,
int
index
)
{
{
...
@@ -452,14 +452,14 @@ namespace NLua
...
@@ -452,14 +452,14 @@ namespace NLua
return
LuaCore
.
LuaNetGetTag
();
return
LuaCore
.
LuaNetGetTag
();
}
}
public
static
void
LuaNetPushGlobalTable
(
LuaState
luaState
)
public
static
void
LuaNetPushGlobalTable
(
LuaState
luaState
)
{
{
LuaCore
.
LuaNetPushGlobalTable
(
luaState
);
LuaCore
.
LuaNetPushGlobalTable
(
luaState
);
}
}
public
static
void
LuaNetPopGlobalTable
(
LuaState
luaState
)
public
static
void
LuaNetPopGlobalTable
(
LuaState
luaState
)
{
{
LuaCore
.
LuaNetPopGlobalTable
(
luaState
);
LuaCore
.
LuaNetPopGlobalTable
(
luaState
);
}
}
}
}
}
}
\ No newline at end of file
Core/NLua/LuaTable.cs
View file @
be0bfcc8
...
@@ -22,7 +22,7 @@
...
@@ -22,7 +22,7 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* THE SOFTWARE.
*/
*/
using
System
;
using
System
;
using
System.Text
;
using
System.Text
;
using
System.Collections
;
using
System.Collections
;
...
...
Core/NLua/LuaUserData.cs
View file @
be0bfcc8
...
@@ -22,7 +22,7 @@
...
@@ -22,7 +22,7 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* THE SOFTWARE.
*/
*/
using
System
;
using
System
;
using
System.Text
;
using
System.Text
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
...
...
Core/NLua/Metatables.cs
View file @
be0bfcc8
...
@@ -22,7 +22,7 @@
...
@@ -22,7 +22,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* THE SOFTWARE.
*/
*/
using
System
;
using
System
;
using
System.Linq
;
using
System.Linq
;
using
System.IO
;
using
System.IO
;
using
System.Collections
;
using
System.Collections
;
...
@@ -51,11 +51,11 @@ namespace NLua
...
@@ -51,11 +51,11 @@ namespace NLua
*
*
*/
*/
public
class
MetaFunctions
public
class
MetaFunctions
{
{
public
LuaNativeFunction
GcFunction
{
get
;
private
set
;
}
public
LuaNativeFunction
GcFunction
{
get
;
private
set
;
}
public
LuaNativeFunction
IndexFunction
{
get
;
private
set
;
}
public
LuaNativeFunction
IndexFunction
{
get
;
private
set
;
}
public
LuaNativeFunction
NewIndexFunction
{
get
;
private
set
;
}
public
LuaNativeFunction
NewIndexFunction
{
get
;
private
set
;
}
public
LuaNativeFunction
BaseIndexFunction
{
get
;
private
set
;
}
public
LuaNativeFunction
BaseIndexFunction
{
get
;
private
set
;
}
public
LuaNativeFunction
ClassIndexFunction
{
get
;
private
set
;
}
public
LuaNativeFunction
ClassIndexFunction
{
get
;
private
set
;
}
public
LuaNativeFunction
ClassNewindexFunction
{
get
;
private
set
;
}
public
LuaNativeFunction
ClassNewindexFunction
{
get
;
private
set
;
}
public
LuaNativeFunction
ExecuteDelegateFunction
{
get
;
private
set
;
}
public
LuaNativeFunction
ExecuteDelegateFunction
{
get
;
private
set
;
}
...
@@ -63,13 +63,13 @@ namespace NLua
...
@@ -63,13 +63,13 @@ namespace NLua
public
LuaNativeFunction
ToStringFunction
{
get
;
private
set
;
}
public
LuaNativeFunction
ToStringFunction
{
get
;
private
set
;
}
public
LuaNativeFunction
AddFunction
{
get
;
private
set
;
}
public
LuaNativeFunction
AddFunction
{
get
;
private
set
;
}
public
LuaNativeFunction
SubtractFunction
{
get
;
private
set
;
}
public
LuaNativeFunction
SubtractFunction
{
get
;
private
set
;
}
public
LuaNativeFunction
MultiplyFunction
{
get
;
private
set
;
}
public
LuaNativeFunction
MultiplyFunction
{
get
;
private
set
;
}
public
LuaNativeFunction
DivisionFunction
{
get
;
private
set
;
}
public
LuaNativeFunction
DivisionFunction
{
get
;
private
set
;
}
public
LuaNativeFunction
ModulosFunction
{
get
;
private
set
;
}
public
LuaNativeFunction
ModulosFunction
{
get
;
private
set
;
}
public
LuaNativeFunction
UnaryNegationFunction
{
get
;
private
set
;
}
public
LuaNativeFunction
UnaryNegationFunction
{
get
;
private
set
;
}
public
LuaNativeFunction
EqualFunction
{
get
;
private
set
;
}
public
LuaNativeFunction
EqualFunction
{
get
;
private
set
;
}
public
LuaNativeFunction
LessThanFunction
{
get
;
private
set
;
}
public
LuaNativeFunction
LessThanFunction
{
get
;
private
set
;
}
public
LuaNativeFunction
LessThanOrEqualFunction
{
get
;
private
set
;
}
public
LuaNativeFunction
LessThanOrEqualFunction
{
get
;
private
set
;
}
Dictionary
<
object
,
object
>
memberCache
=
new
Dictionary
<
object
,
object
>
();
Dictionary
<
object
,
object
>
memberCache
=
new
Dictionary
<
object
,
object
>
();
...
@@ -77,25 +77,25 @@ namespace NLua
...
@@ -77,25 +77,25 @@ namespace NLua
/*
/*
* __index metafunction for CLR objects. Implemented in Lua.
* __index metafunction for CLR objects. Implemented in Lua.
*/
*/
static
string
luaIndexFunction
=
static
string
luaIndexFunction
=
@"local function index(obj,name)
@"local function index(obj,name)
local meta = getmetatable(obj)
local meta = getmetatable(obj)
local cached = meta.cache[name]
local cached = meta.cache[name]
if cached ~= nil then
if cached ~= nil then
return cached
return cached
else
else
local value,isFunc = get_object_member(obj,name)
local value,isFunc = get_object_member(obj,name)
if isFunc then
if isFunc then
meta.cache[name]=value
meta.cache[name]=value
end
end
return value
return value
end
end
end
end
return index"
;
return index"
;
public
static
string
LuaIndexFunction
{
public
static
string
LuaIndexFunction
{
get
{
return
luaIndexFunction
;
}
get
{
return
luaIndexFunction
;
}
}
}
public
MetaFunctions
(
ObjectTranslator
translator
)
public
MetaFunctions
(
ObjectTranslator
translator
)
{
{
...
@@ -108,15 +108,15 @@ namespace NLua
...
@@ -108,15 +108,15 @@ namespace NLua
CallConstructorFunction
=
new
LuaNativeFunction
(
MetaFunctions
.
CallConstructor
);
CallConstructorFunction
=
new
LuaNativeFunction
(
MetaFunctions
.
CallConstructor
);
ClassIndexFunction
=
new
LuaNativeFunction
(
MetaFunctions
.
GetClassMethod
);
ClassIndexFunction
=
new
LuaNativeFunction
(
MetaFunctions
.
GetClassMethod
);
ClassNewindexFunction
=
new
LuaNativeFunction
(
MetaFunctions
.
SetClassFieldOrProperty
);
ClassNewindexFunction
=
new
LuaNativeFunction
(
MetaFunctions
.
SetClassFieldOrProperty
);
ExecuteDelegateFunction
=
new
LuaNativeFunction
(
MetaFunctions
.
RunFunctionDelegate
);
ExecuteDelegateFunction
=
new
LuaNativeFunction
(
MetaFunctions
.
RunFunctionDelegate
);
AddFunction
=
new
LuaNativeFunction
(
MetaFunctions
.
AddLua
);
AddFunction
=
new
LuaNativeFunction
(
MetaFunctions
.
AddLua
);
SubtractFunction
=
new
LuaNativeFunction
(
MetaFunctions
.
SubtractLua
);
SubtractFunction
=
new
LuaNativeFunction
(
MetaFunctions
.
SubtractLua
);
MultiplyFunction
=
new
LuaNativeFunction
(
MetaFunctions
.
MultiplyLua
);
MultiplyFunction
=
new
LuaNativeFunction
(
MetaFunctions
.
MultiplyLua
);
DivisionFunction
=
new
LuaNativeFunction
(
MetaFunctions
.
DivideLua
);
DivisionFunction
=
new
LuaNativeFunction
(
MetaFunctions
.
DivideLua
);
ModulosFunction
=
new
LuaNativeFunction
(
MetaFunctions
.
ModLua
);
ModulosFunction
=
new
LuaNativeFunction
(
MetaFunctions
.
ModLua
);
UnaryNegationFunction
=
new
LuaNativeFunction
(
MetaFunctions
.
UnaryNegationLua
);
UnaryNegationFunction
=
new
LuaNativeFunction
(
MetaFunctions
.
UnaryNegationLua
);
EqualFunction
=
new
LuaNativeFunction
(
MetaFunctions
.
EqualLua
);
EqualFunction
=
new
LuaNativeFunction
(
MetaFunctions
.
EqualLua
);
LessThanFunction
=
new
LuaNativeFunction
(
MetaFunctions
.
LessThanLua
);
LessThanFunction
=
new
LuaNativeFunction
(
MetaFunctions
.
LessThanLua
);
LessThanOrEqualFunction
=
new
LuaNativeFunction
(
MetaFunctions
.
LessThanOrEqualLua
);
LessThanOrEqualFunction
=
new
LuaNativeFunction
(
MetaFunctions
.
LessThanOrEqualLua
);
}
}
...
@@ -186,147 +186,147 @@ namespace NLua
...
@@ -186,147 +186,147 @@ namespace NLua
LuaLib
.
LuaPushNil
(
luaState
);
LuaLib
.
LuaPushNil
(
luaState
);
return
1
;
return
1
;
}
}
/*
/*
* __add metafunction of CLR objects.
* __add metafunction of CLR objects.
*/
*/
#if MONOTOUCH
#if MONOTOUCH
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaNativeFunction
))]
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaNativeFunction
))]
#endif
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
static
int
AddLua
(
LuaState
luaState
)
static
int
AddLua
(
LuaState
luaState
)
{
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
return
MatchOperator
(
luaState
,
"op_Addition"
,
translator
);
return
MatchOperator
(
luaState
,
"op_Addition"
,
translator
);
}
}
/*
/*
* __sub metafunction of CLR objects.
* __sub metafunction of CLR objects.
*/
*/
#if MONOTOUCH
#if MONOTOUCH
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaNativeFunction
))]
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaNativeFunction
))]
#endif
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
static
int
SubtractLua
(
LuaState
luaState
)
static
int
SubtractLua
(
LuaState
luaState
)
{
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
return
MatchOperator
(
luaState
,
"op_Subtraction"
,
translator
);
return
MatchOperator
(
luaState
,
"op_Subtraction"
,
translator
);
}
}
/*
/*
* __mul metafunction of CLR objects.
* __mul metafunction of CLR objects.
*/
*/
#if MONOTOUCH
#if MONOTOUCH
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaNativeFunction
))]
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaNativeFunction
))]
#endif
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
static
int
MultiplyLua
(
LuaState
luaState
)
static
int
MultiplyLua
(
LuaState
luaState
)
{
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
return
MatchOperator
(
luaState
,
"op_Multiply"
,
translator
);
return
MatchOperator
(
luaState
,
"op_Multiply"
,
translator
);
}
}
/*
/*
* __div metafunction of CLR objects.
* __div metafunction of CLR objects.
*/
*/
#if MONOTOUCH
#if MONOTOUCH
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaNativeFunction
))]
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaNativeFunction
))]
#endif
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
static
int
DivideLua
(
LuaState
luaState
)
static
int
DivideLua
(
LuaState
luaState
)
{
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
return
MatchOperator
(
luaState
,
"op_Division"
,
translator
);
return
MatchOperator
(
luaState
,
"op_Division"
,
translator
);
}
}
/*
/*
* __mod metafunction of CLR objects.
* __mod metafunction of CLR objects.
*/
*/
#if MONOTOUCH
#if MONOTOUCH
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaNativeFunction
))]
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaNativeFunction
))]
#endif
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
static
int
ModLua
(
LuaState
luaState
)
static
int
ModLua
(
LuaState
luaState
)
{
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
return
MatchOperator
(
luaState
,
"op_Modulus"
,
translator
);
return
MatchOperator
(
luaState
,
"op_Modulus"
,
translator
);
}
}
/*
/*
* __unm metafunction of CLR objects.
* __unm metafunction of CLR objects.
*/
*/
#if MONOTOUCH
#if MONOTOUCH
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaNativeFunction
))]
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaNativeFunction
))]
#endif
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
static
int
UnaryNegationLua
(
LuaState
luaState
)
static
int
UnaryNegationLua
(
LuaState
luaState
)
{
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
return
UnaryNegationLua
(
luaState
,
translator
);
return
UnaryNegationLua
(
luaState
,
translator
);
}
}
static
int
UnaryNegationLua
(
LuaState
luaState
,
ObjectTranslator
translator
)
static
int
UnaryNegationLua
(
LuaState
luaState
,
ObjectTranslator
translator
)
{
{
object
obj1
=
translator
.
GetRawNetObject
(
luaState
,
1
);
object
obj1
=
translator
.
GetRawNetObject
(
luaState
,
1
);
if
(
obj1
==
null
)
{
if
(
obj1
==
null
)
{
translator
.
ThrowError
(
luaState
,
"Cannot negate a nil object"
);
translator
.
ThrowError
(
luaState
,
"Cannot negate a nil object"
);
LuaLib
.
LuaPushNil
(
luaState
);
LuaLib
.
LuaPushNil
(
luaState
);
return
1
;
return
1
;
}
}
Type
type
=
obj1
.
GetType
();
Type
type
=
obj1
.
GetType
();
MethodInfo
opUnaryNegation
=
type
.
GetMethod
(
"op_UnaryNegation"
);
MethodInfo
opUnaryNegation
=
type
.
GetMethod
(
"op_UnaryNegation"
);
if
(
opUnaryNegation
==
null
)
{
if
(
opUnaryNegation
==
null
)
{
translator
.
ThrowError
(
luaState
,
"Cannot negate object ("
+
type
.
Name
+
" does not overload the operator -)"
);
translator
.
ThrowError
(
luaState
,
"Cannot negate object ("
+
type
.
Name
+
" does not overload the operator -)"
);
LuaLib
.
LuaPushNil
(
luaState
);
LuaLib
.
LuaPushNil
(
luaState
);
return
1
;
return
1
;
}
}
obj1
=
opUnaryNegation
.
Invoke
(
obj1
,
new
object
[]
{
obj1
});
obj1
=
opUnaryNegation
.
Invoke
(
obj1
,
new
object
[]
{
obj1
});
translator
.
Push
(
luaState
,
obj1
);
translator
.
Push
(
luaState
,
obj1
);
return
1
;
return
1
;
}
}
/*
/*
* __eq metafunction of CLR objects.
* __eq metafunction of CLR objects.
*/
*/
#if MONOTOUCH
#if MONOTOUCH
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaNativeFunction
))]
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaNativeFunction
))]
#endif
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
static
int
EqualLua
(
LuaState
luaState
)
static
int
EqualLua
(
LuaState
luaState
)
{
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
return
MatchOperator
(
luaState
,
"op_Equality"
,
translator
);
return
MatchOperator
(
luaState
,
"op_Equality"
,
translator
);
}
}
/*
/*
* __lt metafunction of CLR objects.
* __lt metafunction of CLR objects.
*/
*/
#if MONOTOUCH
#if MONOTOUCH
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaNativeFunction
))]
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaNativeFunction
))]
#endif
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
static
int
LessThanLua
(
LuaState
luaState
)
static
int
LessThanLua
(
LuaState
luaState
)
{
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
return
MatchOperator
(
luaState
,
"op_LessThan"
,
translator
);
return
MatchOperator
(
luaState
,
"op_LessThan"
,
translator
);
}
}
/*
/*
* __le metafunction of CLR objects.
* __le metafunction of CLR objects.
*/
*/
#if MONOTOUCH
#if MONOTOUCH
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaNativeFunction
))]
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaNativeFunction
))]
#endif
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
static
int
LessThanOrEqualLua
(
LuaState
luaState
)
static
int
LessThanOrEqualLua
(
LuaState
luaState
)
{
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
return
MatchOperator
(
luaState
,
"op_LessThanOrEqual"
,
translator
);
return
MatchOperator
(
luaState
,
"op_LessThanOrEqual"
,
translator
);
}
}
/// <summary>
/// <summary>
...
@@ -339,6 +339,8 @@ namespace NLua
...
@@ -339,6 +339,8 @@ namespace NLua
#if WINDOWS_PHONE
#if WINDOWS_PHONE
Debug
.
WriteLine
(
"lua stack depth: {0}"
,
depth
);
Debug
.
WriteLine
(
"lua stack depth: {0}"
,
depth
);
#elif UNITY_3D
UnityEngine
.
Debug
.
Log
(
string
.
Format
(
"lua stack depth: {0}"
,
depth
));
#elif !SILVERLIGHT
#elif !SILVERLIGHT
Debug
.
Print
(
"lua stack depth: {0}"
,
depth
);
Debug
.
Print
(
"lua stack depth: {0}"
,
depth
);
#endif
#endif
...
@@ -356,6 +358,8 @@ namespace NLua
...
@@ -356,6 +358,8 @@ namespace NLua
#if WINDOWS_PHONE
#if WINDOWS_PHONE
Debug
.
WriteLine
(
"{0}: ({1}) {2}"
,
i
,
typestr
,
strrep
);
Debug
.
WriteLine
(
"{0}: ({1}) {2}"
,
i
,
typestr
,
strrep
);
#elif UNITY_3D
UnityEngine
.
Debug
.
Log
(
string
.
Format
(
"{0}: ({1}) {2}"
,
i
,
typestr
,
strrep
));
#elif !SILVERLIGHT
#elif !SILVERLIGHT
Debug
.
Print
(
"{0}: ({1}) {2}"
,
i
,
typestr
,
strrep
);
Debug
.
Print
(
"{0}: ({1}) {2}"
,
i
,
typestr
,
strrep
);
#endif
#endif
...
@@ -422,10 +426,10 @@ namespace NLua
...
@@ -422,10 +426,10 @@ namespace NLua
object
[]
arr
=
(
object
[])
obj
;
object
[]
arr
=
(
object
[])
obj
;
translator
.
Push
(
luaState
,
arr
[
intIndex
]);
translator
.
Push
(
luaState
,
arr
[
intIndex
]);
}
}
}
else
{
}
else
{
if
(!
string
.
IsNullOrEmpty
(
methodName
)
&&
IsExtensionMethodPresent
(
objType
,
methodName
))
{
if
(!
string
.
IsNullOrEmpty
(
methodName
)
&&
IsExtensionMethodPresent
(
objType
,
methodName
))
{
return
GetExtensionMethod
(
luaState
,
objType
,
obj
,
methodName
);
return
GetExtensionMethod
(
luaState
,
objType
,
obj
,
methodName
);
}
}
// Try to use get_Item to index into this .net object
// Try to use get_Item to index into this .net object
var
methods
=
objType
.
GetMethods
();
var
methods
=
objType
.
GetMethods
();
...
@@ -531,36 +535,36 @@ namespace NLua
...
@@ -531,36 +535,36 @@ namespace NLua
var
members
=
objType
.
GetMember
(
methodName
,
BindingFlags
.
Static
|
BindingFlags
.
Instance
|
BindingFlags
.
Public
);
var
members
=
objType
.
GetMember
(
methodName
,
BindingFlags
.
Static
|
BindingFlags
.
Instance
|
BindingFlags
.
Public
);
return
(
members
.
Length
>
0
);
return
(
members
.
Length
>
0
);
}
}
bool
IsExtensionMethodPresent
(
Type
type
,
string
name
)
bool
IsExtensionMethodPresent
(
Type
type
,
string
name
)
{
{
object
cachedMember
=
CheckMemberCache
(
memberCache
,
type
,
name
);
object
cachedMember
=
CheckMemberCache
(
memberCache
,
type
,
name
);
if
(
cachedMember
!=
null
)
if
(
cachedMember
!=
null
)
return
true
;
return
true
;
return
translator
.
IsExtensionMethodPresent
(
type
,
name
);
return
translator
.
IsExtensionMethodPresent
(
type
,
name
);
}
}
int
GetExtensionMethod
(
LuaState
luaState
,
Type
type
,
object
obj
,
string
name
)
int
GetExtensionMethod
(
LuaState
luaState
,
Type
type
,
object
obj
,
string
name
)
{
{
object
cachedMember
=
CheckMemberCache
(
memberCache
,
type
,
name
);
object
cachedMember
=
CheckMemberCache
(
memberCache
,
type
,
name
);
if
(
cachedMember
!=
null
&&
cachedMember
is
LuaNativeFunction
)
{
if
(
cachedMember
!=
null
&&
cachedMember
is
LuaNativeFunction
)
{
translator
.
PushFunction
(
luaState
,
(
LuaNativeFunction
)
cachedMember
);
translator
.
PushFunction
(
luaState
,
(
LuaNativeFunction
)
cachedMember
);
translator
.
Push
(
luaState
,
true
);
translator
.
Push
(
luaState
,
true
);
return
2
;
return
2
;
}
}
MethodInfo
methodInfo
=
translator
.
GetExtensionMethod
(
type
,
name
);
MethodInfo
methodInfo
=
translator
.
GetExtensionMethod
(
type
,
name
);
var
wrapper
=
new
LuaNativeFunction
((
new
LuaMethodWrapper
(
translator
,
obj
,
type
,
methodInfo
)).
invokeFunction
);
var
wrapper
=
new
LuaNativeFunction
((
new
LuaMethodWrapper
(
translator
,
obj
,
type
,
methodInfo
)).
invokeFunction
);
SetMemberCache
(
memberCache
,
type
,
name
,
wrapper
);
SetMemberCache
(
memberCache
,
type
,
name
,
wrapper
);
translator
.
PushFunction
(
luaState
,
wrapper
);
translator
.
PushFunction
(
luaState
,
wrapper
);
translator
.
Push
(
luaState
,
true
);
translator
.
Push
(
luaState
,
true
);
return
2
;
return
2
;
}
}
/*
/*
...
@@ -1023,110 +1027,110 @@ namespace NLua
...
@@ -1023,110 +1027,110 @@ namespace NLua
}
}
static
bool
IsInteger
(
double
x
)
{
static
bool
IsInteger
(
double
x
)
{
return
Math
.
Ceiling
(
x
)
==
x
;
return
Math
.
Ceiling
(
x
)
==
x
;
}
}
static
object
GetTargetObject
(
LuaState
luaState
,
string
operation
,
ObjectTranslator
translator
)
static
object
GetTargetObject
(
LuaState
luaState
,
string
operation
,
ObjectTranslator
translator
)
{
{
Type
t
;
Type
t
;
object
target
=
translator
.
GetRawNetObject
(
luaState
,
1
);
object
target
=
translator
.
GetRawNetObject
(
luaState
,
1
);
if
(
target
!=
null
)
{
if
(
target
!=
null
)
{
t
=
target
.
GetType
();
t
=
target
.
GetType
();
if
(
t
.
HasMethod
(
operation
))
if
(
t
.
HasMethod
(
operation
))
return
target
;
return
target
;
}
}
target
=
translator
.
GetRawNetObject
(
luaState
,
2
);
target
=
translator
.
GetRawNetObject
(
luaState
,
2
);
if
(
target
!=
null
)
{
if
(
target
!=
null
)
{
t
=
target
.
GetType
();
t
=
target
.
GetType
();
if
(
t
.
HasMethod
(
operation
))
if
(
t
.
HasMethod
(
operation
))
return
target
;
return
target
;
}
}
return
null
;
return
null
;
}
}
static
int
MatchOperator
(
LuaState
luaState
,
string
operation
,
ObjectTranslator
translator
)
static
int
MatchOperator
(
LuaState
luaState
,
string
operation
,
ObjectTranslator
translator
)
{
{
var
validOperator
=
new
MethodCache
();
var
validOperator
=
new
MethodCache
();
object
target
=
GetTargetObject
(
luaState
,
operation
,
translator
);
object
target
=
GetTargetObject
(
luaState
,
operation
,
translator
);
if
(
target
==
null
)
{
if
(
target
==
null
)
{
translator
.
ThrowError
(
luaState
,
"Cannot call "
+
operation
+
" on a nil object"
);
translator
.
ThrowError
(
luaState
,
"Cannot call "
+
operation
+
" on a nil object"
);
LuaLib
.
LuaPushNil
(
luaState
);
LuaLib
.
LuaPushNil
(
luaState
);
return
1
;
return
1
;
}
}
Type
type
=
target
.
GetType
();
Type
type
=
target
.
GetType
();
var
operators
=
type
.
GetMethods
(
operation
,
BindingFlags
.
Public
|
BindingFlags
.
Instance
|
BindingFlags
.
Static
);
var
operators
=
type
.
GetMethods
(
operation
,
BindingFlags
.
Public
|
BindingFlags
.
Instance
|
BindingFlags
.
Static
);
foreach
(
var
op
in
operators
)
{
foreach
(
var
op
in
operators
)
{
bool
isOk
=
translator
.
MatchParameters
(
luaState
,
op
,
ref
validOperator
);
bool
isOk
=
translator
.
MatchParameters
(
luaState
,
op
,
ref
validOperator
);
if
(!
isOk
)
if
(!
isOk
)
continue
;
continue
;
object
result
;
object
result
;
if
(
op
.
IsStatic
)
if
(
op
.
IsStatic
)
result
=
op
.
Invoke
(
null
,
validOperator
.
args
);
result
=
op
.
Invoke
(
null
,
validOperator
.
args
);
else
else
result
=
op
.
Invoke
(
target
,
validOperator
.
args
);
result
=
op
.
Invoke
(
target
,
validOperator
.
args
);
translator
.
Push
(
luaState
,
result
);
translator
.
Push
(
luaState
,
result
);
return
1
;
return
1
;
}
}
translator
.
ThrowError
(
luaState
,
"Cannot call ("
+
operation
+
") on object type "
+
type
.
Name
);
translator
.
ThrowError
(
luaState
,
"Cannot call ("
+
operation
+
") on object type "
+
type
.
Name
);
LuaLib
.
LuaPushNil
(
luaState
);
LuaLib
.
LuaPushNil
(
luaState
);
return
1
;
return
1
;
}
}
internal
Array
TableToArray
(
Func
<
int
,
object
>
luaParamValueExtractor
,
Type
paramArrayType
,
int
startIndex
,
int
count
)
internal
Array
TableToArray
(
Func
<
int
,
object
>
luaParamValueExtractor
,
Type
paramArrayType
,
int
startIndex
,
int
count
)
{
{
Array
paramArray
;
Array
paramArray
;
if
(
count
==
0
)
if
(
count
==
0
)
return
Array
.
CreateInstance
(
paramArrayType
,
0
);
return
Array
.
CreateInstance
(
paramArrayType
,
0
);
var
luaParamValue
=
luaParamValueExtractor
(
startIndex
);
var
luaParamValue
=
luaParamValueExtractor
(
startIndex
);
if
(
luaParamValue
is
LuaTable
)
{
if
(
luaParamValue
is
LuaTable
)
{
LuaTable
table
=
(
LuaTable
)
luaParamValue
;
LuaTable
table
=
(
LuaTable
)
luaParamValue
;
IDictionaryEnumerator
tableEnumerator
=
table
.
GetEnumerator
();
IDictionaryEnumerator
tableEnumerator
=
table
.
GetEnumerator
();
tableEnumerator
.
Reset
();
tableEnumerator
.
Reset
();
paramArray
=
Array
.
CreateInstance
(
paramArrayType
,
table
.
Values
.
Count
);
paramArray
=
Array
.
CreateInstance
(
paramArrayType
,
table
.
Values
.
Count
);
int
paramArrayIndex
=
0
;
int
paramArrayIndex
=
0
;
while
(
tableEnumerator
.
MoveNext
())
{
while
(
tableEnumerator
.
MoveNext
())
{
object
value
=
tableEnumerator
.
Value
;
object
value
=
tableEnumerator
.
Value
;
if
(
paramArrayType
==
typeof
(
object
))
{
if
(
paramArrayType
==
typeof
(
object
))
{
if
(
value
!=
null
&&
value
.
GetType
()
==
typeof
(
double
)
&&
IsInteger
((
double
)
value
))
if
(
value
!=
null
&&
value
.
GetType
()
==
typeof
(
double
)
&&
IsInteger
((
double
)
value
))
value
=
Convert
.
ToInt32
((
double
)
value
);
value
=
Convert
.
ToInt32
((
double
)
value
);
}
}
#if SILVERLIGHT
#if SILVERLIGHT
paramArray
.
SetValue
(
Convert
.
ChangeType
(
value
,
paramArrayType
,
System
.
Globalization
.
CultureInfo
.
InvariantCulture
),
paramArrayIndex
);
paramArray
.
SetValue
(
Convert
.
ChangeType
(
value
,
paramArrayType
,
System
.
Globalization
.
CultureInfo
.
InvariantCulture
),
paramArrayIndex
);
#else
#else
paramArray
.
SetValue
(
Convert
.
ChangeType
(
value
,
paramArrayType
),
paramArrayIndex
);
paramArray
.
SetValue
(
Convert
.
ChangeType
(
value
,
paramArrayType
),
paramArrayIndex
);
#endif
#endif
paramArrayIndex
++;
paramArrayIndex
++;
}
}
}
else
{
}
else
{
paramArray
=
Array
.
CreateInstance
(
paramArrayType
,
count
);
paramArray
=
Array
.
CreateInstance
(
paramArrayType
,
count
);
paramArray
.
SetValue
(
luaParamValue
,
0
);
paramArray
.
SetValue
(
luaParamValue
,
0
);
for
(
int
i
=
1
;
i
<
count
;
i
++)
{
for
(
int
i
=
1
;
i
<
count
;
i
++)
{
startIndex
++;
startIndex
++;
var
value
=
luaParamValueExtractor
(
startIndex
);
var
value
=
luaParamValueExtractor
(
startIndex
);
paramArray
.
SetValue
(
value
,
i
);
paramArray
.
SetValue
(
value
,
i
);
}
}
}
}
return
paramArray
;
return
paramArray
;
}
}
/*
/*
...
@@ -1176,7 +1180,7 @@ namespace NLua
...
@@ -1176,7 +1180,7 @@ namespace NLua
currentLuaParam
++;
currentLuaParam
++;
return
extractValue
(
luaState
,
currentParam
);
return
extractValue
(
luaState
,
currentParam
);
};
};
int
count
=
(
nLuaParams
-
currentLuaParam
)
+
1
;
int
count
=
(
nLuaParams
-
currentLuaParam
)
+
1
;
Array
paramArray
=
TableToArray
(
extractDelegate
,
paramArrayType
,
currentLuaParam
,
count
);
Array
paramArray
=
TableToArray
(
extractDelegate
,
paramArrayType
,
currentLuaParam
,
count
);
paramList
.
Add
(
paramArray
);
paramList
.
Add
(
paramArray
);
...
...
Core/NLua/Method/LuaMethodWrapper.cs
View file @
be0bfcc8
...
@@ -136,31 +136,31 @@ namespace NLua.Method
...
@@ -136,31 +136,31 @@ namespace NLua.Method
if
(
_LastCalledMethod
.
cachedMethod
!=
null
)
{
// Cached?
if
(
_LastCalledMethod
.
cachedMethod
!=
null
)
{
// Cached?
int
numStackToSkip
=
isStatic
?
0
:
1
;
// If this is an instance invoe we will have an extra arg on the stack for the targetObject
int
numStackToSkip
=
isStatic
?
0
:
1
;
// If this is an instance invoe we will have an extra arg on the stack for the targetObject
int
numArgsPassed
=
LuaLib
.
LuaGetTop
(
luaState
)
-
numStackToSkip
;
int
numArgsPassed
=
LuaLib
.
LuaGetTop
(
luaState
)
-
numStackToSkip
;
MethodBase
method
=
_LastCalledMethod
.
cachedMethod
;
MethodBase
method
=
_LastCalledMethod
.
cachedMethod
;
if
(
numArgsPassed
==
_LastCalledMethod
.
argTypes
.
Length
)
{
// No. of args match?
if
(
numArgsPassed
==
_LastCalledMethod
.
argTypes
.
Length
)
{
// No. of args match?
if
(!
LuaLib
.
LuaCheckStack
(
luaState
,
_LastCalledMethod
.
outList
.
Length
+
6
))
if
(!
LuaLib
.
LuaCheckStack
(
luaState
,
_LastCalledMethod
.
outList
.
Length
+
6
))
throw
new
LuaException
(
"Lua stack overflow"
);
throw
new
LuaException
(
"Lua stack overflow"
);
object
[]
args
=
_LastCalledMethod
.
args
;
object
[]
args
=
_LastCalledMethod
.
args
;
try
{
try
{
for
(
int
i
=
0
;
i
<
_LastCalledMethod
.
argTypes
.
Length
;
i
++)
{
for
(
int
i
=
0
;
i
<
_LastCalledMethod
.
argTypes
.
Length
;
i
++)
{
MethodArgs
type
=
_LastCalledMethod
.
argTypes
[
i
];
MethodArgs
type
=
_LastCalledMethod
.
argTypes
[
i
];
int
index
=
i
+
1
+
numStackToSkip
;
int
index
=
i
+
1
+
numStackToSkip
;
Func
<
int
,
object
>
valueExtractor
=
(
currentParam
)
=>
{
Func
<
int
,
object
>
valueExtractor
=
(
currentParam
)
=>
{
return
type
.
extractValue
(
luaState
,
currentParam
);
return
type
.
extractValue
(
luaState
,
currentParam
);
};
};
if
(
_LastCalledMethod
.
argTypes
[
i
].
isParamsArray
)
{
if
(
_LastCalledMethod
.
argTypes
[
i
].
isParamsArray
)
{
int
count
=
index
-
_LastCalledMethod
.
argTypes
.
Length
;
int
count
=
index
-
_LastCalledMethod
.
argTypes
.
Length
;
Array
paramArray
=
_Translator
.
TableToArray
(
valueExtractor
,
type
.
paramsArrayType
,
index
,
count
);
Array
paramArray
=
_Translator
.
TableToArray
(
valueExtractor
,
type
.
paramsArrayType
,
index
,
count
);
args
[
_LastCalledMethod
.
argTypes
[
i
].
index
]
=
paramArray
;
args
[
_LastCalledMethod
.
argTypes
[
i
].
index
]
=
paramArray
;
}
else
{
}
else
{
args
[
type
.
index
]
=
valueExtractor
(
index
);
args
[
type
.
index
]
=
valueExtractor
(
index
);
}
}
...
...
Core/NLua/ObjectTranslator.cs
View file @
be0bfcc8
...
@@ -22,7 +22,7 @@
...
@@ -22,7 +22,7 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* THE SOFTWARE.
*/
*/
using
System
;
using
System
;
using
System.IO
;
using
System.IO
;
using
System.Reflection
;
using
System.Reflection
;
...
@@ -94,8 +94,8 @@ namespace NLua
...
@@ -94,8 +94,8 @@ namespace NLua
registerTableFunction
=
new
LuaNativeFunction
(
ObjectTranslator
.
RegisterTable
);
registerTableFunction
=
new
LuaNativeFunction
(
ObjectTranslator
.
RegisterTable
);
unregisterTableFunction
=
new
LuaNativeFunction
(
ObjectTranslator
.
UnregisterTable
);
unregisterTableFunction
=
new
LuaNativeFunction
(
ObjectTranslator
.
UnregisterTable
);
getMethodSigFunction
=
new
LuaNativeFunction
(
ObjectTranslator
.
GetMethodSignature
);
getMethodSigFunction
=
new
LuaNativeFunction
(
ObjectTranslator
.
GetMethodSignature
);
getConstructorSigFunction
=
new
LuaNativeFunction
(
ObjectTranslator
.
GetConstructorSignature
);
getConstructorSigFunction
=
new
LuaNativeFunction
(
ObjectTranslator
.
GetConstructorSignature
);
ctypeFunction
=
new
LuaNativeFunction
(
ObjectTranslator
.
CType
);
ctypeFunction
=
new
LuaNativeFunction
(
ObjectTranslator
.
CType
);
enumFromIntFunction
=
new
LuaNativeFunction
(
ObjectTranslator
.
EnumFromInt
);
enumFromIntFunction
=
new
LuaNativeFunction
(
ObjectTranslator
.
EnumFromInt
);
CreateLuaObjectList
(
luaState
);
CreateLuaObjectList
(
luaState
);
...
@@ -127,7 +127,7 @@ namespace NLua
...
@@ -127,7 +127,7 @@ namespace NLua
*/
*/
private
void
CreateIndexingMetaFunction
(
LuaState
luaState
)
private
void
CreateIndexingMetaFunction
(
LuaState
luaState
)
{
{
LuaLib
.
LuaPushString
(
luaState
,
"luaNet_indexfunction"
);
LuaLib
.
LuaPushString
(
luaState
,
"luaNet_indexfunction"
);
LuaLib
.
LuaLDoString
(
luaState
,
MetaFunctions
.
LuaIndexFunction
);
LuaLib
.
LuaLDoString
(
luaState
,
MetaFunctions
.
LuaIndexFunction
);
LuaLib
.
LuaRawSet
(
luaState
,
(
int
)
LuaIndexes
.
Registry
);
LuaLib
.
LuaRawSet
(
luaState
,
(
int
)
LuaIndexes
.
Registry
);
}
}
...
@@ -197,9 +197,9 @@ namespace NLua
...
@@ -197,9 +197,9 @@ namespace NLua
LuaLib
.
LuaSetGlobal
(
luaState
,
"get_method_bysig"
);
LuaLib
.
LuaSetGlobal
(
luaState
,
"get_method_bysig"
);
LuaLib
.
LuaPushStdCallCFunction
(
luaState
,
getConstructorSigFunction
);
LuaLib
.
LuaPushStdCallCFunction
(
luaState
,
getConstructorSigFunction
);
LuaLib
.
LuaSetGlobal
(
luaState
,
"get_constructor_bysig"
);
LuaLib
.
LuaSetGlobal
(
luaState
,
"get_constructor_bysig"
);
LuaLib
.
LuaPushStdCallCFunction
(
luaState
,
ctypeFunction
);
LuaLib
.
LuaPushStdCallCFunction
(
luaState
,
ctypeFunction
);
LuaLib
.
LuaSetGlobal
(
luaState
,
"ctype"
);
LuaLib
.
LuaSetGlobal
(
luaState
,
"ctype"
);
LuaLib
.
LuaPushStdCallCFunction
(
luaState
,
enumFromIntFunction
);
LuaLib
.
LuaPushStdCallCFunction
(
luaState
,
enumFromIntFunction
);
LuaLib
.
LuaSetGlobal
(
luaState
,
"enum"
);
LuaLib
.
LuaSetGlobal
(
luaState
,
"enum"
);
}
}
...
@@ -273,40 +273,40 @@ namespace NLua
...
@@ -273,40 +273,40 @@ namespace NLua
{
{
try
{
try
{
string
assemblyName
=
LuaLib
.
LuaToString
(
luaState
,
1
).
ToString
();
string
assemblyName
=
LuaLib
.
LuaToString
(
luaState
,
1
).
ToString
();
Assembly
assembly
=
null
;
Assembly
assembly
=
null
;
Exception
exception
=
null
;
Exception
exception
=
null
;
try
{
try
{
assembly
=
Assembly
.
Load
(
assemblyName
);
assembly
=
Assembly
.
Load
(
assemblyName
);
}
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
#if !SILVERLIGHT
if
(
assembly
==
null
)
{
if
(
assembly
==
null
)
{
try
{
try
{
assembly
=
Assembly
.
Load
(
AssemblyName
.
GetAssemblyName
(
assemblyName
));
assembly
=
Assembly
.
Load
(
AssemblyName
.
GetAssemblyName
(
assemblyName
));
}
catch
(
FileNotFoundException
e
)
{
}
catch
(
FileNotFoundException
e
)
{
exception
=
e
;
exception
=
e
;
}
}
if
(
assembly
==
null
)
{
if
(
assembly
==
null
)
{
AssemblyName
mscor
=
assemblies
[
0
].
GetName
();
AssemblyName
mscor
=
assemblies
[
0
].
GetName
();
AssemblyName
name
=
new
AssemblyName
();
AssemblyName
name
=
new
AssemblyName
();
name
.
Name
=
assemblyName
;
name
.
Name
=
assemblyName
;
name
.
CultureInfo
=
mscor
.
CultureInfo
;
name
.
CultureInfo
=
mscor
.
CultureInfo
;
name
.
Version
=
mscor
.
Version
;
name
.
Version
=
mscor
.
Version
;
name
.
SetPublicKeyToken
(
mscor
.
GetPublicKeyToken
());
name
.
SetPublicKeyToken
(
mscor
.
GetPublicKeyToken
());
name
.
SetPublicKey
(
mscor
.
GetPublicKey
());
name
.
SetPublicKey
(
mscor
.
GetPublicKey
());
assembly
=
Assembly
.
Load
(
name
);
assembly
=
Assembly
.
Load
(
name
);
if
(
assembly
!=
null
)
if
(
assembly
!=
null
)
exception
=
null
;
exception
=
null
;
}
}
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
))
...
@@ -327,16 +327,16 @@ namespace NLua
...
@@ -327,16 +327,16 @@ namespace NLua
return
klass
;
return
klass
;
}
}
return
null
;
return
null
;
}
public
bool
IsExtensionMethodPresent
(
Type
type
,
string
name
)
{
return
GetExtensionMethod
(
type
,
name
)
!=
null
;
}
}
public
MethodInfo
GetExtensionMethod
(
Type
type
,
string
name
)
public
bool
IsExtensionMethodPresent
(
Type
type
,
string
name
)
{
{
return
type
.
GetExtensionMethod
(
name
,
assemblies
);
return
GetExtensionMethod
(
type
,
name
)
!=
null
;
}
public
MethodInfo
GetExtensionMethod
(
Type
type
,
string
name
)
{
return
type
.
GetExtensionMethod
(
name
,
assemblies
);
}
}
/*
/*
...
@@ -588,7 +588,7 @@ namespace NLua
...
@@ -588,7 +588,7 @@ namespace NLua
return
;
return
;
}
}
// Object already in the list of Lua objects? Push the stored reference.
// Object already in the list of Lua objects? Push the stored reference.
bool
found
=
(!
o
.
GetType
().
IsValueType
)
&&
objectsBackMap
.
TryGetValue
(
o
,
out
index
);
bool
found
=
(!
o
.
GetType
().
IsValueType
)
&&
objectsBackMap
.
TryGetValue
(
o
,
out
index
);
if
(
found
)
{
if
(
found
)
{
...
@@ -647,8 +647,8 @@ namespace NLua
...
@@ -647,8 +647,8 @@ namespace NLua
LuaLib
.
LuaRawSet
(
luaState
,
-
3
);
LuaLib
.
LuaRawSet
(
luaState
,
-
3
);
LuaLib
.
LuaPushString
(
luaState
,
"__newindex"
);
LuaLib
.
LuaPushString
(
luaState
,
"__newindex"
);
LuaLib
.
LuaPushStdCallCFunction
(
luaState
,
metaFunctions
.
NewIndexFunction
);
LuaLib
.
LuaPushStdCallCFunction
(
luaState
,
metaFunctions
.
NewIndexFunction
);
LuaLib
.
LuaRawSet
(
luaState
,
-
3
);
LuaLib
.
LuaRawSet
(
luaState
,
-
3
);
// Bind C# operator with Lua metamethods (__add, __sub, __mul)
// Bind C# operator with Lua metamethods (__add, __sub, __mul)
RegisterOperatorsFunctions
(
luaState
,
o
.
GetType
());
RegisterOperatorsFunctions
(
luaState
,
o
.
GetType
());
}
}
}
else
}
else
...
@@ -667,52 +667,52 @@ namespace NLua
...
@@ -667,52 +667,52 @@ namespace NLua
}
}
void
RegisterOperatorsFunctions
(
LuaState
luaState
,
Type
type
)
void
RegisterOperatorsFunctions
(
LuaState
luaState
,
Type
type
)
{
{
if
(
type
.
HasAdditionOpertator
())
{
if
(
type
.
HasAdditionOpertator
())
{
LuaLib
.
LuaPushString
(
luaState
,
"__add"
);
LuaLib
.
LuaPushString
(
luaState
,
"__add"
);
LuaLib
.
LuaPushStdCallCFunction
(
luaState
,
metaFunctions
.
AddFunction
);
LuaLib
.
LuaPushStdCallCFunction
(
luaState
,
metaFunctions
.
AddFunction
);
LuaLib
.
LuaRawSet
(
luaState
,
-
3
);
LuaLib
.
LuaRawSet
(
luaState
,
-
3
);
}
}
if
(
type
.
HasSubtractionOpertator
())
{
if
(
type
.
HasSubtractionOpertator
())
{
LuaLib
.
LuaPushString
(
luaState
,
"__sub"
);
LuaLib
.
LuaPushString
(
luaState
,
"__sub"
);
LuaLib
.
LuaPushStdCallCFunction
(
luaState
,
metaFunctions
.
SubtractFunction
);
LuaLib
.
LuaPushStdCallCFunction
(
luaState
,
metaFunctions
.
SubtractFunction
);
LuaLib
.
LuaRawSet
(
luaState
,
-
3
);
LuaLib
.
LuaRawSet
(
luaState
,
-
3
);
}
}
if
(
type
.
HasMultiplyOpertator
())
{
if
(
type
.
HasMultiplyOpertator
())
{
LuaLib
.
LuaPushString
(
luaState
,
"__mul"
);
LuaLib
.
LuaPushString
(
luaState
,
"__mul"
);
LuaLib
.
LuaPushStdCallCFunction
(
luaState
,
metaFunctions
.
MultiplyFunction
);
LuaLib
.
LuaPushStdCallCFunction
(
luaState
,
metaFunctions
.
MultiplyFunction
);
LuaLib
.
LuaRawSet
(
luaState
,
-
3
);
LuaLib
.
LuaRawSet
(
luaState
,
-
3
);
}
}
if
(
type
.
HasDivisionOpertator
())
{
if
(
type
.
HasDivisionOpertator
())
{
LuaLib
.
LuaPushString
(
luaState
,
"__div"
);
LuaLib
.
LuaPushString
(
luaState
,
"__div"
);
LuaLib
.
LuaPushStdCallCFunction
(
luaState
,
metaFunctions
.
DivisionFunction
);
LuaLib
.
LuaPushStdCallCFunction
(
luaState
,
metaFunctions
.
DivisionFunction
);
LuaLib
.
LuaRawSet
(
luaState
,
-
3
);
LuaLib
.
LuaRawSet
(
luaState
,
-
3
);
}
}
if
(
type
.
HasModulusOpertator
())
{
if
(
type
.
HasModulusOpertator
())
{
LuaLib
.
LuaPushString
(
luaState
,
"__mod"
);
LuaLib
.
LuaPushString
(
luaState
,
"__mod"
);
LuaLib
.
LuaPushStdCallCFunction
(
luaState
,
metaFunctions
.
ModulosFunction
);
LuaLib
.
LuaPushStdCallCFunction
(
luaState
,
metaFunctions
.
ModulosFunction
);
LuaLib
.
LuaRawSet
(
luaState
,
-
3
);
LuaLib
.
LuaRawSet
(
luaState
,
-
3
);
}
}
if
(
type
.
HasUnaryNegationOpertator
())
{
if
(
type
.
HasUnaryNegationOpertator
())
{
LuaLib
.
LuaPushString
(
luaState
,
"__unm"
);
LuaLib
.
LuaPushString
(
luaState
,
"__unm"
);
LuaLib
.
LuaPushStdCallCFunction
(
luaState
,
metaFunctions
.
UnaryNegationFunction
);
LuaLib
.
LuaPushStdCallCFunction
(
luaState
,
metaFunctions
.
UnaryNegationFunction
);
LuaLib
.
LuaRawSet
(
luaState
,
-
3
);
LuaLib
.
LuaRawSet
(
luaState
,
-
3
);
}
}
if
(
type
.
HasEqualityOpertator
())
{
if
(
type
.
HasEqualityOpertator
())
{
LuaLib
.
LuaPushString
(
luaState
,
"__eq"
);
LuaLib
.
LuaPushString
(
luaState
,
"__eq"
);
LuaLib
.
LuaPushStdCallCFunction
(
luaState
,
metaFunctions
.
EqualFunction
);
LuaLib
.
LuaPushStdCallCFunction
(
luaState
,
metaFunctions
.
EqualFunction
);
LuaLib
.
LuaRawSet
(
luaState
,
-
3
);
LuaLib
.
LuaRawSet
(
luaState
,
-
3
);
}
}
if
(
type
.
HasLessThanOpertator
())
{
if
(
type
.
HasLessThanOpertator
())
{
LuaLib
.
LuaPushString
(
luaState
,
"__lt"
);
LuaLib
.
LuaPushString
(
luaState
,
"__lt"
);
LuaLib
.
LuaPushStdCallCFunction
(
luaState
,
metaFunctions
.
LessThanFunction
);
LuaLib
.
LuaPushStdCallCFunction
(
luaState
,
metaFunctions
.
LessThanFunction
);
LuaLib
.
LuaRawSet
(
luaState
,
-
3
);
LuaLib
.
LuaRawSet
(
luaState
,
-
3
);
}
}
if
(
type
.
HasLessThanOrEqualOpertator
())
{
if
(
type
.
HasLessThanOrEqualOpertator
())
{
LuaLib
.
LuaPushString
(
luaState
,
"__le"
);
LuaLib
.
LuaPushString
(
luaState
,
"__le"
);
LuaLib
.
LuaPushStdCallCFunction
(
luaState
,
metaFunctions
.
LessThanOrEqualFunction
);
LuaLib
.
LuaPushStdCallCFunction
(
luaState
,
metaFunctions
.
LessThanOrEqualFunction
);
LuaLib
.
LuaRawSet
(
luaState
,
-
3
);
LuaLib
.
LuaRawSet
(
luaState
,
-
3
);
}
}
}
}
/*
/*
...
@@ -735,7 +735,7 @@ namespace NLua
...
@@ -735,7 +735,7 @@ namespace NLua
bool
found
=
objects
.
TryGetValue
(
udata
,
out
o
);
bool
found
=
objects
.
TryGetValue
(
udata
,
out
o
);
// The other variant of collectObject might have gotten here first, in that case we will silently ignore the missing entry
// The other variant of collectObject might have gotten here first, in that case we will silently ignore the missing entry
if
(
found
)
if
(
found
)
CollectObject
(
o
,
udata
);
CollectObject
(
o
,
udata
);
}
}
...
@@ -954,80 +954,80 @@ namespace NLua
...
@@ -954,80 +954,80 @@ namespace NLua
return
metaFunctions
.
TableToArray
(
luaParamValue
,
paramArrayType
,
startIndex
,
count
);
return
metaFunctions
.
TableToArray
(
luaParamValue
,
paramArrayType
,
startIndex
,
count
);
}
}
private
Type
TypeOf
(
LuaState
luaState
,
int
idx
)
private
Type
TypeOf
(
LuaState
luaState
,
int
idx
)
{
{
int
udata
=
LuaLib
.
LuaNetCheckUData
(
luaState
,
1
,
"luaNet_class"
);
int
udata
=
LuaLib
.
LuaNetCheckUData
(
luaState
,
1
,
"luaNet_class"
);
if
(
udata
==
-
1
)
if
(
udata
==
-
1
)
return
null
;
return
null
;
ProxyType
pt
=
(
ProxyType
)
objects
[
udata
];
ProxyType
pt
=
(
ProxyType
)
objects
[
udata
];
return
pt
.
UnderlyingSystemType
;
return
pt
.
UnderlyingSystemType
;
}
}
static
int
PushError
(
LuaState
luaState
,
string
msg
)
static
int
PushError
(
LuaState
luaState
,
string
msg
)
{
{
LuaLib
.
LuaPushNil
(
luaState
);
LuaLib
.
LuaPushNil
(
luaState
);
LuaLib
.
LuaPushString
(
luaState
,
msg
);
LuaLib
.
LuaPushString
(
luaState
,
msg
);
return
2
;
return
2
;
}
}
#if MONOTOUCH
#if MONOTOUCH
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaNativeFunction
))]
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaNativeFunction
))]
#endif
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
private
static
int
CType
(
LuaState
luaState
)
private
static
int
CType
(
LuaState
luaState
)
{
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
return
translator
.
CTypeInternal
(
luaState
);
return
translator
.
CTypeInternal
(
luaState
);
}
}
int
CTypeInternal
(
LuaState
luaState
)
int
CTypeInternal
(
LuaState
luaState
)
{
{
Type
t
=
TypeOf
(
luaState
,
1
);
Type
t
=
TypeOf
(
luaState
,
1
);
if
(
t
==
null
)
if
(
t
==
null
)
return
PushError
(
luaState
,
"Not a CLR Class"
);
return
PushError
(
luaState
,
"Not a CLR Class"
);
PushObject
(
luaState
,
t
,
"luaNet_metatable"
);
PushObject
(
luaState
,
t
,
"luaNet_metatable"
);
return
1
;
return
1
;
}
}
#if MONOTOUCH
#if MONOTOUCH
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaNativeFunction
))]
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaNativeFunction
))]
#endif
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
private
static
int
EnumFromInt
(
LuaState
luaState
)
private
static
int
EnumFromInt
(
LuaState
luaState
)
{
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
return
translator
.
EnumFromIntInternal
(
luaState
);
return
translator
.
EnumFromIntInternal
(
luaState
);
}
}
int
EnumFromIntInternal
(
LuaState
luaState
)
int
EnumFromIntInternal
(
LuaState
luaState
)
{
{
Type
t
=
TypeOf
(
luaState
,
1
);
Type
t
=
TypeOf
(
luaState
,
1
);
if
(
t
==
null
||
!
t
.
IsEnum
)
if
(
t
==
null
||
!
t
.
IsEnum
)
return
PushError
(
luaState
,
"Not an Enum."
);
return
PushError
(
luaState
,
"Not an Enum."
);
object
res
=
null
;
object
res
=
null
;
LuaTypes
lt
=
LuaLib
.
LuaType
(
luaState
,
2
);
LuaTypes
lt
=
LuaLib
.
LuaType
(
luaState
,
2
);
if
(
lt
==
LuaTypes
.
Number
)
{
if
(
lt
==
LuaTypes
.
Number
)
{
int
ival
=
(
int
)
LuaLib
.
LuaToNumber
(
luaState
,
2
);
int
ival
=
(
int
)
LuaLib
.
LuaToNumber
(
luaState
,
2
);
res
=
Enum
.
ToObject
(
t
,
ival
);
res
=
Enum
.
ToObject
(
t
,
ival
);
}
else
}
else
if
(
lt
==
LuaTypes
.
String
)
{
if
(
lt
==
LuaTypes
.
String
)
{
string
sflags
=
LuaLib
.
LuaToString
(
luaState
,
2
);
string
sflags
=
LuaLib
.
LuaToString
(
luaState
,
2
);
string
err
=
null
;
string
err
=
null
;
try
{
try
{
res
=
Enum
.
Parse
(
t
,
sflags
,
true
);
res
=
Enum
.
Parse
(
t
,
sflags
,
true
);
}
catch
(
ArgumentException
e
)
{
}
catch
(
ArgumentException
e
)
{
err
=
e
.
Message
;
err
=
e
.
Message
;
}
}
if
(
err
!=
null
)
if
(
err
!=
null
)
return
PushError
(
luaState
,
err
);
return
PushError
(
luaState
,
err
);
}
else
{
}
else
{
return
PushError
(
luaState
,
"Second argument must be a integer or a string."
);
return
PushError
(
luaState
,
"Second argument must be a integer or a string."
);
}
}
PushObject
(
luaState
,
res
,
"luaNet_metatable"
);
PushObject
(
luaState
,
res
,
"luaNet_metatable"
);
return
1
;
return
1
;
}
}
}
}
}
}
\ No newline at end of file
Core/NLua/ObjectTranslatorPool.cs
View file @
be0bfcc8
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
/*
/*
* This file is part of NLua.
* This file is part of NLua.
*
*
...
@@ -58,13 +58,13 @@ namespace NLua
...
@@ -58,13 +58,13 @@ namespace NLua
}
}
public
ObjectTranslator
Find
(
LuaState
luaState
)
public
ObjectTranslator
Find
(
LuaState
luaState
)
{
{
if
(
translators
.
ContainsKey
(
luaState
))
if
(
translators
.
ContainsKey
(
luaState
))
return
translators
[
luaState
];
return
translators
[
luaState
];
LuaState
main
=
LuaCore
.
LuaNetGetMainState
(
luaState
);
LuaState
main
=
LuaCore
.
LuaNetGetMainState
(
luaState
);
if
(
translators
.
ContainsKey
(
main
))
if
(
translators
.
ContainsKey
(
main
))
return
translators
[
main
];
return
translators
[
main
];
return
null
;
return
null
;
...
...
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