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
2e501577
Commit
2e501577
authored
Jun 23, 2013
by
Vinicius Jarina
Browse files
Fixed gendarme warnings.
parent
c84425fd
Changes
20
Expand all
Hide whitespace changes
Inline
Side-by-side
Core/NLua/CheckType.cs
View file @
2e501577
...
@@ -45,7 +45,7 @@ namespace NLua
...
@@ -45,7 +45,7 @@ namespace NLua
* Author: Fabio Mascarenhas
* Author: Fabio Mascarenhas
* Version: 1.0
* Version: 1.0
*/
*/
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
>();
...
@@ -58,48 +58,48 @@ namespace NLua
...
@@ -58,48 +58,48 @@ namespace NLua
public
CheckType
(
ObjectTranslator
translator
)
public
CheckType
(
ObjectTranslator
translator
)
{
{
this
.
translator
=
translator
;
this
.
translator
=
translator
;
extractValues
.
Add
(
g
etExtractDictionaryKey
(
typeof
(
object
)),
new
ExtractValue
(
g
etAsObject
));
extractValues
.
Add
(
G
etExtractDictionaryKey
(
typeof
(
object
)),
new
ExtractValue
(
G
etAsObject
));
extractValues
.
Add
(
g
etExtractDictionaryKey
(
typeof
(
sbyte
)),
new
ExtractValue
(
g
etAsSbyte
));
extractValues
.
Add
(
G
etExtractDictionaryKey
(
typeof
(
sbyte
)),
new
ExtractValue
(
G
etAsSbyte
));
extractValues
.
Add
(
g
etExtractDictionaryKey
(
typeof
(
byte
)),
new
ExtractValue
(
g
etAsByte
));
extractValues
.
Add
(
G
etExtractDictionaryKey
(
typeof
(
byte
)),
new
ExtractValue
(
G
etAsByte
));
extractValues
.
Add
(
g
etExtractDictionaryKey
(
typeof
(
short
)),
new
ExtractValue
(
g
etAsShort
));
extractValues
.
Add
(
G
etExtractDictionaryKey
(
typeof
(
short
)),
new
ExtractValue
(
G
etAsShort
));
extractValues
.
Add
(
g
etExtractDictionaryKey
(
typeof
(
ushort
)),
new
ExtractValue
(
g
etAsUshort
));
extractValues
.
Add
(
G
etExtractDictionaryKey
(
typeof
(
ushort
)),
new
ExtractValue
(
G
etAsUshort
));
extractValues
.
Add
(
g
etExtractDictionaryKey
(
typeof
(
int
)),
new
ExtractValue
(
g
etAsInt
));
extractValues
.
Add
(
G
etExtractDictionaryKey
(
typeof
(
int
)),
new
ExtractValue
(
G
etAsInt
));
extractValues
.
Add
(
g
etExtractDictionaryKey
(
typeof
(
uint
)),
new
ExtractValue
(
g
etAsUint
));
extractValues
.
Add
(
G
etExtractDictionaryKey
(
typeof
(
uint
)),
new
ExtractValue
(
G
etAsUint
));
extractValues
.
Add
(
g
etExtractDictionaryKey
(
typeof
(
long
)),
new
ExtractValue
(
g
etAsLong
));
extractValues
.
Add
(
G
etExtractDictionaryKey
(
typeof
(
long
)),
new
ExtractValue
(
G
etAsLong
));
extractValues
.
Add
(
g
etExtractDictionaryKey
(
typeof
(
ulong
)),
new
ExtractValue
(
g
etAsUlong
));
extractValues
.
Add
(
G
etExtractDictionaryKey
(
typeof
(
ulong
)),
new
ExtractValue
(
G
etAsUlong
));
extractValues
.
Add
(
g
etExtractDictionaryKey
(
typeof
(
double
)),
new
ExtractValue
(
g
etAsDouble
));
extractValues
.
Add
(
G
etExtractDictionaryKey
(
typeof
(
double
)),
new
ExtractValue
(
G
etAsDouble
));
extractValues
.
Add
(
g
etExtractDictionaryKey
(
typeof
(
char
)),
new
ExtractValue
(
g
etAsChar
));
extractValues
.
Add
(
G
etExtractDictionaryKey
(
typeof
(
char
)),
new
ExtractValue
(
G
etAsChar
));
extractValues
.
Add
(
g
etExtractDictionaryKey
(
typeof
(
float
)),
new
ExtractValue
(
g
etAsFloat
));
extractValues
.
Add
(
G
etExtractDictionaryKey
(
typeof
(
float
)),
new
ExtractValue
(
G
etAsFloat
));
extractValues
.
Add
(
g
etExtractDictionaryKey
(
typeof
(
decimal
)),
new
ExtractValue
(
g
etAsDecimal
));
extractValues
.
Add
(
G
etExtractDictionaryKey
(
typeof
(
decimal
)),
new
ExtractValue
(
G
etAsDecimal
));
extractValues
.
Add
(
g
etExtractDictionaryKey
(
typeof
(
bool
)),
new
ExtractValue
(
g
etAsBoolean
));
extractValues
.
Add
(
G
etExtractDictionaryKey
(
typeof
(
bool
)),
new
ExtractValue
(
G
etAsBoolean
));
extractValues
.
Add
(
g
etExtractDictionaryKey
(
typeof
(
string
)),
new
ExtractValue
(
g
etAsString
));
extractValues
.
Add
(
G
etExtractDictionaryKey
(
typeof
(
string
)),
new
ExtractValue
(
G
etAsString
));
extractValues
.
Add
(
g
etExtractDictionaryKey
(
typeof
(
LuaFunction
)),
new
ExtractValue
(
g
etAsFunction
));
extractValues
.
Add
(
G
etExtractDictionaryKey
(
typeof
(
LuaFunction
)),
new
ExtractValue
(
G
etAsFunction
));
extractValues
.
Add
(
g
etExtractDictionaryKey
(
typeof
(
LuaTable
)),
new
ExtractValue
(
g
etAsTable
));
extractValues
.
Add
(
G
etExtractDictionaryKey
(
typeof
(
LuaTable
)),
new
ExtractValue
(
G
etAsTable
));
extractValues
.
Add
(
g
etExtractDictionaryKey
(
typeof
(
LuaUserData
)),
new
ExtractValue
(
g
etAsUserdata
));
extractValues
.
Add
(
G
etExtractDictionaryKey
(
typeof
(
LuaUserData
)),
new
ExtractValue
(
G
etAsUserdata
));
extractNetObject
=
new
ExtractValue
(
g
etAsNetObject
);
extractNetObject
=
new
ExtractValue
(
G
etAsNetObject
);
}
}
/*
/*
* Checks if the value at Lua stack index stackPos matches paramType,
* Checks if the value at Lua stack index stackPos matches paramType,
* returning a conversion function if it does and null otherwise.
* returning a conversion function if it does and null otherwise.
*/
*/
internal
ExtractValue
g
etExtractor
(
IReflect
paramType
)
internal
ExtractValue
G
etExtractor
(
IReflect
paramType
)
{
{
return
g
etExtractor
(
paramType
.
UnderlyingSystemType
);
return
G
etExtractor
(
paramType
.
UnderlyingSystemType
);
}
}
internal
ExtractValue
g
etExtractor
(
Type
paramType
)
internal
ExtractValue
G
etExtractor
(
Type
paramType
)
{
{
if
(
paramType
.
IsByRef
)
if
(
paramType
.
IsByRef
)
paramType
=
paramType
.
GetElementType
();
paramType
=
paramType
.
GetElementType
();
var
extractKey
=
g
etExtractDictionaryKey
(
paramType
);
var
extractKey
=
G
etExtractDictionaryKey
(
paramType
);
return
extractValues
.
ContainsKey
(
extractKey
)
?
extractValues
[
extractKey
]
:
extractNetObject
;
return
extractValues
.
ContainsKey
(
extractKey
)
?
extractValues
[
extractKey
]
:
extractNetObject
;
}
}
internal
ExtractValue
c
heckType
(
LuaState
luaState
,
int
stackPos
,
Type
paramType
)
internal
ExtractValue
C
heck
Lua
Type
(
LuaState
luaState
,
int
stackPos
,
Type
paramType
)
{
{
var
luatype
=
LuaLib
.
l
ua
_t
ype
(
luaState
,
stackPos
);
var
luatype
=
LuaLib
.
L
ua
T
ype
(
luaState
,
stackPos
);
if
(
paramType
.
IsByRef
)
if
(
paramType
.
IsByRef
)
paramType
=
paramType
.
GetElementType
();
paramType
=
paramType
.
GetElementType
();
...
@@ -109,7 +109,7 @@ namespace NLua
...
@@ -109,7 +109,7 @@ namespace NLua
if
(!
underlyingType
.
IsNull
())
if
(!
underlyingType
.
IsNull
())
paramType
=
underlyingType
;
// Silently convert nullable types to their non null requics
paramType
=
underlyingType
;
// Silently convert nullable types to their non null requics
var
extractKey
=
g
etExtractDictionaryKey
(
paramType
);
var
extractKey
=
G
etExtractDictionaryKey
(
paramType
);
if
(
paramType
.
Equals
(
typeof
(
object
)))
if
(
paramType
.
Equals
(
typeof
(
object
)))
return
extractValues
[
extractKey
];
return
extractValues
[
extractKey
];
...
@@ -117,27 +117,27 @@ namespace NLua
...
@@ -117,27 +117,27 @@ namespace NLua
//CP: Added support for generic parameters
//CP: Added support for generic parameters
if
(
paramType
.
IsGenericParameter
)
{
if
(
paramType
.
IsGenericParameter
)
{
if
(
luatype
==
LuaTypes
.
Boolean
)
if
(
luatype
==
LuaTypes
.
Boolean
)
return
extractValues
[
g
etExtractDictionaryKey
(
typeof
(
bool
))];
return
extractValues
[
G
etExtractDictionaryKey
(
typeof
(
bool
))];
else
if
(
luatype
==
LuaTypes
.
String
)
else
if
(
luatype
==
LuaTypes
.
String
)
return
extractValues
[
g
etExtractDictionaryKey
(
typeof
(
string
))];
return
extractValues
[
G
etExtractDictionaryKey
(
typeof
(
string
))];
else
if
(
luatype
==
LuaTypes
.
Table
)
else
if
(
luatype
==
LuaTypes
.
Table
)
return
extractValues
[
g
etExtractDictionaryKey
(
typeof
(
LuaTable
))];
return
extractValues
[
G
etExtractDictionaryKey
(
typeof
(
LuaTable
))];
else
if
(
luatype
==
LuaTypes
.
UserData
)
else
if
(
luatype
==
LuaTypes
.
UserData
)
return
extractValues
[
g
etExtractDictionaryKey
(
typeof
(
object
))];
return
extractValues
[
G
etExtractDictionaryKey
(
typeof
(
object
))];
else
if
(
luatype
==
LuaTypes
.
Function
)
else
if
(
luatype
==
LuaTypes
.
Function
)
return
extractValues
[
g
etExtractDictionaryKey
(
typeof
(
LuaFunction
))];
return
extractValues
[
G
etExtractDictionaryKey
(
typeof
(
LuaFunction
))];
else
if
(
luatype
==
LuaTypes
.
Number
)
else
if
(
luatype
==
LuaTypes
.
Number
)
return
extractValues
[
g
etExtractDictionaryKey
(
typeof
(
double
))];
return
extractValues
[
G
etExtractDictionaryKey
(
typeof
(
double
))];
}
}
if
(
LuaLib
.
l
ua
_isn
umber
(
luaState
,
stackPos
))
if
(
LuaLib
.
L
ua
IsN
umber
(
luaState
,
stackPos
))
return
extractValues
[
extractKey
];
return
extractValues
[
extractKey
];
if
(
paramType
==
typeof
(
bool
))
{
if
(
paramType
==
typeof
(
bool
))
{
if
(
LuaLib
.
l
ua
_isb
oolean
(
luaState
,
stackPos
))
if
(
LuaLib
.
L
ua
IsB
oolean
(
luaState
,
stackPos
))
return
extractValues
[
extractKey
];
return
extractValues
[
extractKey
];
}
else
if
(
paramType
==
typeof
(
string
))
{
}
else
if
(
paramType
==
typeof
(
string
))
{
if
(
LuaLib
.
l
ua
_iss
tring
(
luaState
,
stackPos
))
if
(
LuaLib
.
L
ua
IsS
tring
(
luaState
,
stackPos
))
return
extractValues
[
extractKey
];
return
extractValues
[
extractKey
];
else
if
(
luatype
==
LuaTypes
.
Nil
)
else
if
(
luatype
==
LuaTypes
.
Nil
)
return
extractNetObject
;
// kevinh - silently convert nil to a null string pointer
return
extractNetObject
;
// kevinh - silently convert nil to a null string pointer
...
@@ -151,22 +151,22 @@ namespace NLua
...
@@ -151,22 +151,22 @@ namespace NLua
if
(
luatype
==
LuaTypes
.
Function
)
if
(
luatype
==
LuaTypes
.
Function
)
return
extractValues
[
extractKey
];
return
extractValues
[
extractKey
];
}
else
if
(
typeof
(
Delegate
).
IsAssignableFrom
(
paramType
)
&&
luatype
==
LuaTypes
.
Function
)
}
else
if
(
typeof
(
Delegate
).
IsAssignableFrom
(
paramType
)
&&
luatype
==
LuaTypes
.
Function
)
return
new
ExtractValue
(
new
DelegateGenerator
(
translator
,
paramType
).
e
xtractGenerated
);
return
new
ExtractValue
(
new
DelegateGenerator
(
translator
,
paramType
).
E
xtractGenerated
);
else
if
(
paramType
.
IsInterface
&&
luatype
==
LuaTypes
.
Table
)
else
if
(
paramType
.
IsInterface
&&
luatype
==
LuaTypes
.
Table
)
return
new
ExtractValue
(
new
ClassGenerator
(
translator
,
paramType
).
e
xtractGenerated
);
return
new
ExtractValue
(
new
ClassGenerator
(
translator
,
paramType
).
E
xtractGenerated
);
else
if
((
paramType
.
IsInterface
||
paramType
.
IsClass
)
&&
luatype
==
LuaTypes
.
Nil
)
{
else
if
((
paramType
.
IsInterface
||
paramType
.
IsClass
)
&&
luatype
==
LuaTypes
.
Nil
)
{
// kevinh - allow nil to be silently converted to null - extractNetObject will return null when the item ain't found
// kevinh - allow nil to be silently converted to null - extractNetObject will return null when the item ain't found
return
extractNetObject
;
return
extractNetObject
;
}
else
if
(
LuaLib
.
l
ua
_t
ype
(
luaState
,
stackPos
)
==
LuaTypes
.
Table
)
{
}
else
if
(
LuaLib
.
L
ua
T
ype
(
luaState
,
stackPos
)
==
LuaTypes
.
Table
)
{
if
(
LuaLib
.
l
uaL
_g
et
m
etafield
(
luaState
,
stackPos
,
"__index"
))
{
if
(
LuaLib
.
L
uaL
G
et
M
etafield
(
luaState
,
stackPos
,
"__index"
))
{
object
obj
=
translator
.
g
etNetObject
(
luaState
,
-
1
);
object
obj
=
translator
.
G
etNetObject
(
luaState
,
-
1
);
LuaLib
.
l
ua
_s
et
t
op
(
luaState
,
-
2
);
LuaLib
.
L
ua
S
et
T
op
(
luaState
,
-
2
);
if
(!
obj
.
IsNull
()
&&
paramType
.
IsAssignableFrom
(
obj
.
GetType
()))
if
(!
obj
.
IsNull
()
&&
paramType
.
IsAssignableFrom
(
obj
.
GetType
()))
return
extractNetObject
;
return
extractNetObject
;
}
else
}
else
return
null
;
return
null
;
}
else
{
}
else
{
object
obj
=
translator
.
g
etNetObject
(
luaState
,
stackPos
);
object
obj
=
translator
.
G
etNetObject
(
luaState
,
stackPos
);
if
(!
obj
.
IsNull
()
&&
paramType
.
IsAssignableFrom
(
obj
.
GetType
()))
if
(!
obj
.
IsNull
()
&&
paramType
.
IsAssignableFrom
(
obj
.
GetType
()))
return
extractNetObject
;
return
extractNetObject
;
}
}
...
@@ -175,12 +175,12 @@ namespace NLua
...
@@ -175,12 +175,12 @@ namespace NLua
}
}
#if SILVERLIGHT
#if SILVERLIGHT
private
Type
g
etExtractDictionaryKey
(
Type
targetType
)
private
Type
G
etExtractDictionaryKey
(
Type
targetType
)
{
{
return
targetType
;
return
targetType
;
}
}
#else
#else
private
long
g
etExtractDictionaryKey
(
Type
targetType
)
private
long
G
etExtractDictionaryKey
(
Type
targetType
)
{
{
return
targetType
.
TypeHandle
.
Value
.
ToInt64
();
return
targetType
.
TypeHandle
.
Value
.
ToInt64
();
}
}
...
@@ -191,171 +191,171 @@ namespace NLua
...
@@ -191,171 +191,171 @@ namespace NLua
* index stackPos as the desired type if it can, or null
* index stackPos as the desired type if it can, or null
* otherwise.
* otherwise.
*/
*/
private
object
g
etAsSbyte
(
LuaState
luaState
,
int
stackPos
)
private
object
G
etAsSbyte
(
LuaState
luaState
,
int
stackPos
)
{
{
sbyte
retVal
=
(
sbyte
)
LuaLib
.
l
ua
_ton
umber
(
luaState
,
stackPos
);
sbyte
retVal
=
(
sbyte
)
LuaLib
.
L
ua
ToN
umber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
l
ua
_isn
umber
(
luaState
,
stackPos
))
if
(
retVal
==
0
&&
!
LuaLib
.
L
ua
IsN
umber
(
luaState
,
stackPos
))
return
null
;
return
null
;
return
retVal
;
return
retVal
;
}
}
private
object
g
etAsByte
(
LuaState
luaState
,
int
stackPos
)
private
object
G
etAsByte
(
LuaState
luaState
,
int
stackPos
)
{
{
byte
retVal
=
(
byte
)
LuaLib
.
l
ua
_ton
umber
(
luaState
,
stackPos
);
byte
retVal
=
(
byte
)
LuaLib
.
L
ua
ToN
umber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
l
ua
_isn
umber
(
luaState
,
stackPos
))
if
(
retVal
==
0
&&
!
LuaLib
.
L
ua
IsN
umber
(
luaState
,
stackPos
))
return
null
;
return
null
;
return
retVal
;
return
retVal
;
}
}
private
object
g
etAsShort
(
LuaState
luaState
,
int
stackPos
)
private
object
G
etAsShort
(
LuaState
luaState
,
int
stackPos
)
{
{
short
retVal
=
(
short
)
LuaLib
.
l
ua
_ton
umber
(
luaState
,
stackPos
);
short
retVal
=
(
short
)
LuaLib
.
L
ua
ToN
umber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
l
ua
_isn
umber
(
luaState
,
stackPos
))
if
(
retVal
==
0
&&
!
LuaLib
.
L
ua
IsN
umber
(
luaState
,
stackPos
))
return
null
;
return
null
;
return
retVal
;
return
retVal
;
}
}
private
object
g
etAsUshort
(
LuaState
luaState
,
int
stackPos
)
private
object
G
etAsUshort
(
LuaState
luaState
,
int
stackPos
)
{
{
ushort
retVal
=
(
ushort
)
LuaLib
.
l
ua
_ton
umber
(
luaState
,
stackPos
);
ushort
retVal
=
(
ushort
)
LuaLib
.
L
ua
ToN
umber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
l
ua
_isn
umber
(
luaState
,
stackPos
))
if
(
retVal
==
0
&&
!
LuaLib
.
L
ua
IsN
umber
(
luaState
,
stackPos
))
return
null
;
return
null
;
return
retVal
;
return
retVal
;
}
}
private
object
g
etAsInt
(
LuaState
luaState
,
int
stackPos
)
private
object
G
etAsInt
(
LuaState
luaState
,
int
stackPos
)
{
{
int
retVal
=
(
int
)
LuaLib
.
l
ua
_ton
umber
(
luaState
,
stackPos
);
int
retVal
=
(
int
)
LuaLib
.
L
ua
ToN
umber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
l
ua
_isn
umber
(
luaState
,
stackPos
))
if
(
retVal
==
0
&&
!
LuaLib
.
L
ua
IsN
umber
(
luaState
,
stackPos
))
return
null
;
return
null
;
return
retVal
;
return
retVal
;
}
}
private
object
g
etAsUint
(
LuaState
luaState
,
int
stackPos
)
private
object
G
etAsUint
(
LuaState
luaState
,
int
stackPos
)
{
{
uint
retVal
=
(
uint
)
LuaLib
.
l
ua
_ton
umber
(
luaState
,
stackPos
);
uint
retVal
=
(
uint
)
LuaLib
.
L
ua
ToN
umber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
l
ua
_isn
umber
(
luaState
,
stackPos
))
if
(
retVal
==
0
&&
!
LuaLib
.
L
ua
IsN
umber
(
luaState
,
stackPos
))
return
null
;
return
null
;
return
retVal
;
return
retVal
;
}
}
private
object
g
etAsLong
(
LuaState
luaState
,
int
stackPos
)
private
object
G
etAsLong
(
LuaState
luaState
,
int
stackPos
)
{
{
long
retVal
=
(
long
)
LuaLib
.
l
ua
_ton
umber
(
luaState
,
stackPos
);
long
retVal
=
(
long
)
LuaLib
.
L
ua
ToN
umber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
l
ua
_isn
umber
(
luaState
,
stackPos
))
if
(
retVal
==
0
&&
!
LuaLib
.
L
ua
IsN
umber
(
luaState
,
stackPos
))
return
null
;
return
null
;
return
retVal
;
return
retVal
;
}
}
private
object
g
etAsUlong
(
LuaState
luaState
,
int
stackPos
)
private
object
G
etAsUlong
(
LuaState
luaState
,
int
stackPos
)
{
{
ulong
retVal
=
(
ulong
)
LuaLib
.
l
ua
_ton
umber
(
luaState
,
stackPos
);
ulong
retVal
=
(
ulong
)
LuaLib
.
L
ua
ToN
umber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
l
ua
_isn
umber
(
luaState
,
stackPos
))
if
(
retVal
==
0
&&
!
LuaLib
.
L
ua
IsN
umber
(
luaState
,
stackPos
))
return
null
;
return
null
;
return
retVal
;
return
retVal
;
}
}
private
object
g
etAsDouble
(
LuaState
luaState
,
int
stackPos
)
private
object
G
etAsDouble
(
LuaState
luaState
,
int
stackPos
)
{
{
double
retVal
=
LuaLib
.
l
ua
_ton
umber
(
luaState
,
stackPos
);
double
retVal
=
LuaLib
.
L
ua
ToN
umber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
l
ua
_isn
umber
(
luaState
,
stackPos
))
if
(
retVal
==
0
&&
!
LuaLib
.
L
ua
IsN
umber
(
luaState
,
stackPos
))
return
null
;
return
null
;
return
retVal
;
return
retVal
;
}
}
private
object
g
etAsChar
(
LuaState
luaState
,
int
stackPos
)
private
object
G
etAsChar
(
LuaState
luaState
,
int
stackPos
)
{
{
char
retVal
=
(
char
)
LuaLib
.
l
ua
_ton
umber
(
luaState
,
stackPos
);
char
retVal
=
(
char
)
LuaLib
.
L
ua
ToN
umber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
l
ua
_isn
umber
(
luaState
,
stackPos
))
if
(
retVal
==
0
&&
!
LuaLib
.
L
ua
IsN
umber
(
luaState
,
stackPos
))
return
null
;
return
null
;
return
retVal
;
return
retVal
;
}
}
private
object
g
etAsFloat
(
LuaState
luaState
,
int
stackPos
)
private
object
G
etAsFloat
(
LuaState
luaState
,
int
stackPos
)
{
{
float
retVal
=
(
float
)
LuaLib
.
l
ua
_ton
umber
(
luaState
,
stackPos
);
float
retVal
=
(
float
)
LuaLib
.
L
ua
ToN
umber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
l
ua
_isn
umber
(
luaState
,
stackPos
))
if
(
retVal
==
0
&&
!
LuaLib
.
L
ua
IsN
umber
(
luaState
,
stackPos
))
return
null
;
return
null
;
return
retVal
;
return
retVal
;
}
}
private
object
g
etAsDecimal
(
LuaState
luaState
,
int
stackPos
)
private
object
G
etAsDecimal
(
LuaState
luaState
,
int
stackPos
)
{
{
decimal
retVal
=
(
decimal
)
LuaLib
.
l
ua
_ton
umber
(
luaState
,
stackPos
);
decimal
retVal
=
(
decimal
)
LuaLib
.
L
ua
ToN
umber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
l
ua
_isn
umber
(
luaState
,
stackPos
))
if
(
retVal
==
0
&&
!
LuaLib
.
L
ua
IsN
umber
(
luaState
,
stackPos
))
return
null
;
return
null
;
return
retVal
;
return
retVal
;
}
}
private
object
g
etAsBoolean
(
LuaState
luaState
,
int
stackPos
)
private
object
G
etAsBoolean
(
LuaState
luaState
,
int
stackPos
)
{
{
return
LuaLib
.
l
ua
_tob
oolean
(
luaState
,
stackPos
);
return
LuaLib
.
L
ua
ToB
oolean
(
luaState
,
stackPos
);
}
}
private
object
g
etAsString
(
LuaState
luaState
,
int
stackPos
)
private
object
G
etAsString
(
LuaState
luaState
,
int
stackPos
)
{
{
string
retVal
=
LuaLib
.
l
ua
_tos
tring
(
luaState
,
stackPos
).
ToString
();
string
retVal
=
LuaLib
.
L
ua
ToS
tring
(
luaState
,
stackPos
).
ToString
();
if
(
retVal
==
string
.
Empty
&&
!
LuaLib
.
l
ua
_iss
tring
(
luaState
,
stackPos
))
if
(
string
.
IsNullOrEmpty
(
retVal
)
&&
!
LuaLib
.
L
ua
IsS
tring
(
luaState
,
stackPos
))
return
null
;
return
null
;
return
retVal
;
return
retVal
;
}
}
private
object
g
etAsTable
(
LuaState
luaState
,
int
stackPos
)
private
object
G
etAsTable
(
LuaState
luaState
,
int
stackPos
)
{
{
return
translator
.
g
etTable
(
luaState
,
stackPos
);
return
translator
.
G
etTable
(
luaState
,
stackPos
);
}
}
private
object
g
etAsFunction
(
LuaState
luaState
,
int
stackPos
)
private
object
G
etAsFunction
(
LuaState
luaState
,
int
stackPos
)
{
{
return
translator
.
g
etFunction
(
luaState
,
stackPos
);
return
translator
.
G
etFunction
(
luaState
,
stackPos
);
}
}
private
object
g
etAsUserdata
(
LuaState
luaState
,
int
stackPos
)
private
object
G
etAsUserdata
(
LuaState
luaState
,
int
stackPos
)
{
{
return
translator
.
g
etUserData
(
luaState
,
stackPos
);
return
translator
.
G
etUserData
(
luaState
,
stackPos
);
}
}
public
object
g
etAsObject
(
LuaState
luaState
,
int
stackPos
)
public
object
G
etAsObject
(
LuaState
luaState
,
int
stackPos
)
{
{
if
(
LuaLib
.
l
ua
_t
ype
(
luaState
,
stackPos
)
==
LuaTypes
.
Table
)
{
if
(
LuaLib
.
L
ua
T
ype
(
luaState
,
stackPos
)
==
LuaTypes
.
Table
)
{
if
(
LuaLib
.
l
uaL
_g
et
m
etafield
(
luaState
,
stackPos
,
"__index"
))
{
if
(
LuaLib
.
L
uaL
G
et
M
etafield
(
luaState
,
stackPos
,
"__index"
))
{
if
(
LuaLib
.
l
uaL
_c
heck
m
etatable
(
luaState
,
-
1
))
{
if
(
LuaLib
.
L
uaL
C
heck
M
etatable
(
luaState
,
-
1
))
{
LuaLib
.
l
ua
_i
nsert
(
luaState
,
stackPos
);
LuaLib
.
L
ua
I
nsert
(
luaState
,
stackPos
);
LuaLib
.
l
ua
_r
emove
(
luaState
,
stackPos
+
1
);
LuaLib
.
L
ua
R
emove
(
luaState
,
stackPos
+
1
);
}
else
}
else
LuaLib
.
l
ua
_s
et
t
op
(
luaState
,
-
2
);
LuaLib
.
L
ua
S
et
T
op
(
luaState
,
-
2
);
}
}
}
}
object
obj
=
translator
.
g
etObject
(
luaState
,
stackPos
);
object
obj
=
translator
.
G
etObject
(
luaState
,
stackPos
);
return
obj
;
return
obj
;
}
}
public
object
g
etAsNetObject
(
LuaState
luaState
,
int
stackPos
)
public
object
G
etAsNetObject
(
LuaState
luaState
,
int
stackPos
)
{
{
object
obj
=
translator
.
g
etNetObject
(
luaState
,
stackPos
);
object
obj
=
translator
.
G
etNetObject
(
luaState
,
stackPos
);
if
(
obj
.
IsNull
()
&&
LuaLib
.
l
ua
_t
ype
(
luaState
,
stackPos
)
==
LuaTypes
.
Table
)
{
if
(
obj
.
IsNull
()
&&
LuaLib
.
L
ua
T
ype
(
luaState
,
stackPos
)
==
LuaTypes
.
Table
)
{
if
(
LuaLib
.
l
uaL
_g
et
m
etafield
(
luaState
,
stackPos
,
"__index"
))
{
if
(
LuaLib
.
L
uaL
G
et
M
etafield
(
luaState
,
stackPos
,
"__index"
))
{
if
(
LuaLib
.
l
uaL
_c
heck
m
etatable
(
luaState
,
-
1
))
{
if
(
LuaLib
.
L
uaL
C
heck
M
etatable
(
luaState
,
-
1
))
{
LuaLib
.
l
ua
_i
nsert
(
luaState
,
stackPos
);
LuaLib
.
L
ua
I
nsert
(
luaState
,
stackPos
);
LuaLib
.
l
ua
_r
emove
(
luaState
,
stackPos
+
1
);
LuaLib
.
L
ua
R
emove
(
luaState
,
stackPos
+
1
);
obj
=
translator
.
g
etNetObject
(
luaState
,
stackPos
);
obj
=
translator
.
G
etNetObject
(
luaState
,
stackPos
);
}
else
}
else
LuaLib
.
l
ua
_s
et
t
op
(
luaState
,
-
2
);
LuaLib
.
L
ua
S
et
T
op
(
luaState
,
-
2
);
}
}
}
}
...
...
Core/NLua/GenerateEventAssembly/ClassGenerator.cs
View file @
2e501577
...
@@ -46,15 +46,15 @@ namespace NLua
...
@@ -46,15 +46,15 @@ namespace NLua
private
ObjectTranslator
translator
;
private
ObjectTranslator
translator
;
private
Type
klass
;
private
Type
klass
;
public
ClassGenerator
(
ObjectTranslator
t
ranslator
,
Type
k
lass
)
public
ClassGenerator
(
ObjectTranslator
objT
ranslator
,
Type
typeC
lass
)
{
{
this
.
translator
=
t
ranslator
;
translator
=
objT
ranslator
;
this
.
klass
=
k
lass
;
klass
=
typeC
lass
;
}
}
public
object
e
xtractGenerated
(
LuaState
luaState
,
int
stackPos
)
public
object
E
xtractGenerated
(
LuaState
luaState
,
int
stackPos
)
{
{
return
CodeGeneration
.
Instance
.
GetClassInstance
(
klass
,
translator
.
g
etTable
(
luaState
,
stackPos
));
return
CodeGeneration
.
Instance
.
GetClassInstance
(
klass
,
translator
.
G
etTable
(
luaState
,
stackPos
));
}
}
}
}
}
}
\ No newline at end of file
Core/NLua/GenerateEventAssembly/CodeGeneration.cs
View file @
2e501577
...
@@ -67,9 +67,6 @@ namespace NLua
...
@@ -67,9 +67,6 @@ namespace NLua
private
CodeGeneration
()
private
CodeGeneration
()
{
{
// Create an assembly name
// Create an assembly name
assemblyName
=
new
AssemblyName
();
assemblyName
=
new
AssemblyName
();
assemblyName
.
Name
=
"NLua_generatedcode"
;
assemblyName
.
Name
=
"NLua_generatedcode"
;
...
@@ -78,7 +75,6 @@ namespace NLua
...
@@ -78,7 +75,6 @@ namespace NLua
newAssembly
=
Thread
.
GetDomain
().
DefineDynamicAssembly
(
assemblyName
,
AssemblyBuilderAccess
.
Run
);
newAssembly
=
Thread
.
GetDomain
().
DefineDynamicAssembly
(
assemblyName
,
AssemblyBuilderAccess
.
Run
);
newModule
=
newAssembly
.
DefineDynamicModule
(
"NLua_generatedcode"
);
newModule
=
newAssembly
.
DefineDynamicModule
(
"NLua_generatedcode"
);
#endif
#endif
}
}
/*
/*
...
...
Core/NLua/GenerateEventAssembly/DelegateGenerator.cs
View file @
2e501577
...
@@ -47,15 +47,15 @@ namespace NLua
...
@@ -47,15 +47,15 @@ namespace NLua
private
Type
delegateType
;
private
Type
delegateType
;
public
DelegateGenerator
(
ObjectTranslator
t
ranslator
,
Type
delegateT
ype
)
public
DelegateGenerator
(
ObjectTranslator
objectT
ranslator
,
Type
t
ype
)
{
{
this
.
translator
=
t
ranslator
;
translator
=
objectT
ranslator
;
this
.
delegateType
=
delegateT
ype
;
delegateType
=
t
ype
;
}
}
public
object
e
xtractGenerated
(
LuaState
luaState
,
int
stackPos
)
public
object
E
xtractGenerated
(
LuaState
luaState
,
int
stackPos
)
{
{
return
CodeGeneration
.
Instance
.
GetDelegate
(
delegateType
,
translator
.
g
etFunction
(
luaState
,
stackPos
));
return
CodeGeneration
.
Instance
.
GetDelegate
(
delegateType
,
translator
.
G
etFunction
(
luaState
,
stackPos
));
}
}
}
}
}
}
\ No newline at end of file
Core/NLua/Lua.cs
View file @
2e501577
This diff is collapsed.
Click to expand it.
Core/NLua/LuaBase.cs
View file @
2e501577
...
@@ -58,7 +58,7 @@ namespace NLua
...
@@ -58,7 +58,7 @@ namespace NLua
if
(!
_Disposed
)
{
if
(!
_Disposed
)
{
if
(
disposeManagedResources
)
{
if
(
disposeManagedResources
)
{
if
(
_Reference
!=
0
)
if
(
_Reference
!=
0
)
_Interpreter
.
d
ispose
(
_Reference
);
_Interpreter
.
D
ispose
Internal
(
_Reference
);
}
}
_Interpreter
=
null
;
_Interpreter
=
null
;
...
@@ -70,7 +70,7 @@ namespace NLua
...
@@ -70,7 +70,7 @@ namespace NLua
{
{
if
(
o
is
LuaBase
)
{
if
(
o
is
LuaBase
)
{
var
l
=
(
LuaBase
)
o
;
var
l
=
(
LuaBase
)
o
;
return
_Interpreter
.
c
ompareRef
(
l
.
_Reference
,
_Reference
);
return
_Interpreter
.
C
ompareRef
(
l
.
_Reference
,
_Reference
);
}
else
}
else
return
false
;
return
false
;
}
}
...
...
Core/NLua/LuaFunction.cs
View file @
2e501577
...
@@ -59,9 +59,9 @@ namespace NLua
...
@@ -59,9 +59,9 @@ namespace NLua
* Calls the function casting return values to the types
* Calls the function casting return values to the types
* in returnTypes
* in returnTypes
*/
*/
internal
object
[]
c
all
(
object
[]
args
,
Type
[]
returnTypes
)
internal
object
[]
C
all
(
object
[]
args
,
Type
[]
returnTypes
)
{
{
return
_Interpreter
.
c
allFunction
(
this
,
args
,
returnTypes
);
return
_Interpreter
.
C
allFunction
(
this
,
args
,
returnTypes
);
}
}
/*
/*
...
@@ -70,18 +70,18 @@ namespace NLua
...
@@ -70,18 +70,18 @@ namespace NLua
*/
*/
public
object
[]
Call
(
params
object
[]
args
)
public
object
[]
Call
(
params
object
[]
args
)
{
{
return
_Interpreter
.
c
allFunction
(
this
,
args
);
return
_Interpreter
.
C
allFunction
(
this
,
args
);
}
}
/*
/*
* Pushes the function into the Lua stack
* Pushes the function into the Lua stack
*/
*/
internal
void
p
ush
(
LuaState
luaState
)
internal
void
P
ush
(
LuaState
luaState
)
{
{
if
(
_Reference
!=
0
)
if
(
_Reference
!=
0
)
LuaLib
.
l
ua
_g
et
r
ef
(
luaState
,
_Reference
);
LuaLib
.
L
ua
G
et
R
ef
(
luaState
,
_Reference
);
else
else
_Interpreter
.
p
ushCSFunction
(
function
);
_Interpreter
.
P
ushCSFunction
(
function
);
}
}
public
override
string
ToString
()
public
override
string
ToString
()
...
@@ -95,7 +95,7 @@ namespace NLua
...
@@ -95,7 +95,7 @@ namespace NLua
var
l
=
(
LuaFunction
)
o
;
var
l
=
(
LuaFunction
)
o
;
if
(
this
.
_Reference
!=
0
&&
l
.
_Reference
!=
0
)
if
(
this
.
_Reference
!=
0
&&
l
.
_Reference
!=
0
)
return
_Interpreter
.
c
ompareRef
(
l
.
_Reference
,
this
.
_Reference
);
return
_Interpreter
.
C
ompareRef
(
l
.
_Reference
,
this
.
_Reference
);
else
else
return
this
.
function
==
l
.
function
;
return
this
.
function
==
l
.
function
;
}
else
}
else
...
...
Core/NLua/LuaLib/LuaIndexes.cs
View file @
2e501577
...
@@ -39,6 +39,7 @@ namespace NLua
...
@@ -39,6 +39,7 @@ namespace NLua
public
class
LuaIndexes
public
class
LuaIndexes
{
{
static
int
registryIndex
=
0
;
static
int
registryIndex
=
0
;
public
static
int
Registry
{
public
static
int
Registry
{
get
get
{
{
...
...
Core/NLua/LuaLib/LuaLib.cs
View file @
2e501577
...
@@ -42,95 +42,80 @@ namespace NLua
...
@@ -42,95 +42,80 @@ namespace NLua
public
class
LuaLib
public
class
LuaLib
{
{
// steffenj: BEGIN additional Lua API functions new in Lua 5.1
public
static
int
LuaGC
(
LuaState
luaState
,
GCOptions
what
,
int
data
)
public
static
int
lua_gc
(
LuaState
luaState
,
GCOptions
what
,
int
data
)
{
{
return
LuaCore
.
LuaGC
(
luaState
,
(
int
)
what
,
data
);
return
LuaCore
.
LuaGC
(
luaState
,
(
int
)
what
,
data
);
}
}
public
static
string
l
ua
_t
ype
n
ame
(
LuaState
luaState
,
LuaTypes
type
)
public
static
string
L
ua
T
ype
N
ame
(
LuaState
luaState
,
LuaTypes
type
)
{
{
return
LuaCore
.
LuaTypeName
(
luaState
,
(
int
)
type
).
ToString
();
return
LuaCore
.
LuaTypeName
(
luaState
,
(
int
)
type
).
ToString
();
}
}
public
static
string
l
uaL
_t
ype
n
ame
(
LuaState
luaState
,
int
stackPos
)
public
static
string
L
uaL
T
ype
N
ame
(
LuaState
luaState
,
int
stackPos
)
{
{
return
l
ua
_t
ype
n
ame
(
luaState
,
l
ua
_t
ype
(
luaState
,
stackPos
));
return
L
ua
T
ype
N
ame
(
luaState
,
L
ua
T
ype
(
luaState
,
stackPos
));
}
}
public
static
void
l
uaL
_e
rror
(
LuaState
luaState
,
string
message
)
public
static
void
L
uaL
E
rror
(
LuaState
luaState
,
string
message
)
{
{
LuaCore
.
LuaLError
(
luaState
,
message
);
LuaCore
.
LuaLError
(
luaState
,
message
);
}
}
public
static
void
l
uaL
_w
here
(
LuaState
luaState
,
int
level
)
public
static
void
L
uaL
W
here
(
LuaState
luaState
,
int
level
)
{
{
LuaCore
.
LuaLWhere
(
luaState
,
level
);
LuaCore
.
LuaLWhere
(
luaState
,
level
);
}
}
// steffenj: BEGIN Lua 5.1.1 API change (lua_open replaced by luaL_newstate)
public
static
LuaState
LuaLNewState
()
public
static
LuaState
luaL_newstate
()
{
{
return
LuaCore
.
LuaLNewState
();
return
LuaCore
.
LuaLNewState
();
}
}
// steffenj: BEGIN Lua 5.1.1 API change (new function luaL_openlibs)
public
static
void
LuaLOpenLibs
(
LuaState
luaState
)
public
static
void
luaL_openlibs
(
LuaState
luaState
)
{
{
LuaCore
.
LuaLOpenLibs
(
luaState
);
LuaCore
.
LuaLOpenLibs
(
luaState
);
}
}
// steffenj: END Lua 5.1.1 API change (lua_strlen is now lua_objlen)
public
static
int
LuaLLoadString
(
LuaState
luaState
,
string
chunk
)
// steffenj: BEGIN Lua 5.1.1 API change (lua_dostring is now a macro luaL_dostring)
public
static
int
luaL_loadstring
(
LuaState
luaState
,
string
chunk
)
{
{
return
LuaCore
.
LuaLLoadString
(
luaState
,
chunk
);
return
LuaCore
.
LuaLLoadString
(
luaState
,
chunk
);
}
}
public
static
int
l
uaL
_l
oad
s
tring
(
LuaState
luaState
,
byte
[]
chunk
)
public
static
int
L
uaL
L
oad
S
tring
(
LuaState
luaState
,
byte
[]
chunk
)
{
{
return
LuaCore
.
LuaLLoadString
(
luaState
,
chunk
);
return
LuaCore
.
LuaLLoadString
(
luaState
,
chunk
);
}
}
public
static
int
l
uaL
_dos
tring
(
LuaState
luaState
,
string
chunk
)
public
static
int
L
uaL
DoS
tring
(
LuaState
luaState
,
string
chunk
)
{
{
int
result
=
l
uaL
_l
oad
s
tring
(
luaState
,
chunk
);
int
result
=
L
uaL
L
oad
S
tring
(
luaState
,
chunk
);
if
(
result
!=
0
)
if
(
result
!=
0
)
return
result
;
return
result
;
return
l
ua
_pc
all
(
luaState
,
0
,
-
1
,
0
);
return
L
ua
PC
all
(
luaState
,
0
,
-
1
,
0
);
}
}
public
static
int
l
uaL
_dos
tring
(
LuaState
luaState
,
byte
[]
chunk
)
public
static
int
L
uaL
DoS
tring
(
LuaState
luaState
,
byte
[]
chunk
)
{
{
int
result
=
l
uaL
_l
oad
s
tring
(
luaState
,
chunk
);
int
result
=
L
uaL
L
oad
S
tring
(
luaState
,
chunk
);
if
(
result
!=
0
)
if
(
result
!=
0
)
return
result
;
return
result
;
return
l
ua
_pc
all
(
luaState
,
0
,
-
1
,
0
);
return
L
ua
PC
all
(
luaState
,
0
,
-
1
,
0
);
}
}
/// <summary>DEPRECATED - use luaL_dostring(LuaState luaState, string chunk) instead!</summary>
public
static
void
LuaCreateTable
(
LuaState
luaState
,
int
narr
,
int
nrec
)
public
static
int
lua_dostring
(
LuaState
luaState
,
string
chunk
)
{
return
luaL_dostring
(
luaState
,
chunk
);
}
// steffenj: END Lua 5.1.1 API change (lua_dostring is now a macro luaL_dostring)
// steffenj: BEGIN Lua 5.1.1 API change (lua_newtable is gone, lua_createtable is new)
public
static
void
lua_createtable
(
LuaState
luaState
,
int
narr
,
int
nrec
)
{
{
LuaCore
.
LuaCreateTable
(
luaState
,
narr
,
nrec
);
LuaCore
.
LuaCreateTable
(
luaState
,
narr
,
nrec
);
}
}
public
static
void
l
ua
_n
ew
t
able
(
LuaState
luaState
)
public
static
void
L
ua
N
ew
T
able
(
LuaState
luaState
)
{
{
l
ua
_c
reate
t
able
(
luaState
,
0
,
0
);
L
ua
C
reate
T
able
(
luaState
,
0
,
0
);
}
}
// steffenj: END Lua 5.1.1 API change (lua_newtable is gone, lua_createtable is new)
public
static
int
LuaLDoFile
(
LuaState
luaState
,
string
fileName
)
// steffenj: BEGIN Lua 5.1.1 API change (lua_dofile now in LuaLib as luaL_dofile macro)
public
static
int
luaL_dofile
(
LuaState
luaState
,
string
fileName
)
{
{
int
result
=
LuaCore
.
LuaNetLoadFile
(
luaState
,
fileName
);
int
result
=
LuaCore
.
LuaNetLoadFile
(
luaState
,
fileName
);
if
(
result
!=
0
)
if
(
result
!=
0
)
...
@@ -139,199 +124,198 @@ namespace NLua
...
@@ -139,199 +124,198 @@ namespace NLua
return
LuaCore
.
LuaNetPCall
(
luaState
,
0
,
-
1
,
0
);
return
LuaCore
.
LuaNetPCall
(
luaState
,
0
,
-
1
,
0
);
}
}
public
static
void
l
ua
_g
et
g
lobal
(
LuaState
luaState
,
string
name
)
public
static
void
L
ua
G
et
G
lobal
(
LuaState
luaState
,
string
name
)
{
{
LuaCore
.
LuaNetGetGlobal
(
luaState
,
name
);
LuaCore
.
LuaNetGetGlobal
(
luaState
,
name
);
}
}
public
static
void
l
ua
_s
et
g
lobal
(
LuaState
luaState
,
string
name
)
public
static
void
L
ua
S
et
G
lobal
(
LuaState
luaState
,
string
name
)
{
{
LuaCore
.
LuaNetSetGlobal
(
luaState
,
name
);
LuaCore
.
LuaNetSetGlobal
(
luaState
,
name
);
}
}
public
static
void
l
ua
_s
et
t
op
(
LuaState
luaState
,
int
newTop
)
public
static
void
L
ua
S
et
T
op
(
LuaState
luaState
,
int
newTop
)
{
{
LuaCore
.
LuaSetTop
(
luaState
,
newTop
);
LuaCore
.
LuaSetTop
(
luaState
,
newTop
);
}
}
public
static
void
l
ua
_p
op
(
LuaState
luaState
,
int
amount
)
public
static
void
L
ua
P
op
(
LuaState
luaState
,
int
amount
)
{
{
l
ua
_s
et
t
op
(
luaState
,
-(
amount
)
-
1
);
L
ua
S
et
T
op
(
luaState
,
-(
amount
)
-
1
);
}
}
public
static
void
l
ua
_i
nsert
(
LuaState
luaState
,
int
newTop
)
public
static
void
L
ua
I
nsert
(
LuaState
luaState
,
int
newTop
)
{
{
LuaCore
.
LuaInsert
(
luaState
,
newTop
);
LuaCore
.
LuaInsert
(
luaState
,
newTop
);
}
}
public
static
void
l
ua
_r
emove
(
LuaState
luaState
,
int
index
)
public
static
void
L
ua
R
emove
(
LuaState
luaState
,
int
index
)
{
{
LuaCore
.
LuaRemove
(
luaState
,
index
);
LuaCore
.
LuaRemove
(
luaState
,
index
);
}
}
public
static
void
l
ua
_g
et
t
able
(
LuaState
luaState
,
int
index
)
public
static
void
L
ua
G
et
T
able
(
LuaState
luaState
,
int
index
)
{
{
LuaCore
.
LuaGetTable
(
luaState
,
index
);
LuaCore
.
LuaGetTable
(
luaState
,
index
);
}
}
public
static
void
l
ua
_r
aw
g
et
(
LuaState
luaState
,
int
index
)
public
static
void
L
ua
R
aw
G
et
(
LuaState
luaState
,
int
index
)
{
{
LuaCore
.
LuaRawGet
(
luaState
,
index
);
LuaCore
.
LuaRawGet
(
luaState
,
index
);
}
}
public
static
void
l
ua
_s
et
t
able
(
LuaState
luaState
,
int
index
)
public
static
void
L
ua
S
et
T
able
(
LuaState
luaState
,
int
index
)
{
{
LuaCore
.
LuaSetTable
(
luaState
,
index
);
LuaCore
.
LuaSetTable
(
luaState
,
index
);
}
}
public
static
void
l
ua
_r
aw
s
et
(
LuaState
luaState
,
int
index
)
public
static
void
L
ua
R
aw
S
et
(
LuaState
luaState
,
int
index
)
{
{
LuaCore
.
LuaRawSet
(
luaState
,
index
);
LuaCore
.
LuaRawSet
(
luaState
,
index
);
}
}
public
static
void
l
ua
_s
et
m
etatable
(
LuaState
luaState
,
int
objIndex
)
public
static
void
L
ua
S
et
M
etatable
(
LuaState
luaState
,
int
objIndex
)
{
{
LuaCore
.
LuaSetMetatable
(
luaState
,
objIndex
);
LuaCore
.
LuaSetMetatable
(
luaState
,
objIndex
);
}
}
public
static
int
l
ua
_g
et
m
etatable
(
LuaState
luaState
,
int
objIndex
)
public
static
int
L
ua
G
et
M
etatable
(
LuaState
luaState
,
int
objIndex
)
{
{
return
LuaCore
.
LuaGetMetatable
(
luaState
,
objIndex
);
return
LuaCore
.
LuaGetMetatable
(
luaState
,
objIndex
);
}
}
public
static
int
l
ua
_e
qual
(
LuaState
luaState
,
int
index1
,
int
index2
)
public
static
int
L
ua
E
qual
(
LuaState
luaState
,
int
index1
,
int
index2
)
{
{
return
LuaCore
.
LuaNetEqual
(
luaState
,
index1
,
index2
);
return
LuaCore
.
LuaNetEqual
(
luaState
,
index1
,
index2
);
}
}
public
static
void
l
ua
_p
ush
v
alue
(
LuaState
luaState
,
int
index
)
public
static
void
L
ua
P
ush
V
alue
(
LuaState
luaState
,
int
index
)
{
{
LuaCore
.
LuaPushValue
(
luaState
,
index
);
LuaCore
.
LuaPushValue
(
luaState
,
index
);
}
}
public
static
void
l
ua
_r
eplace
(
LuaState
luaState
,
int
index
)
public
static
void
L
ua
R
eplace
(
LuaState
luaState
,
int
index
)
{
{
LuaCore
.
LuaReplace
(
luaState
,
index
);
LuaCore
.
LuaReplace
(
luaState
,
index
);
}
}
public
static
int
l
ua
_g
et
t
op
(
LuaState
luaState
)
public
static
int
L
ua
G
et
T
op
(
LuaState
luaState
)
{
{
return
LuaCore
.
LuaGetTop
(
luaState
);
return
LuaCore
.
LuaGetTop
(
luaState
);
}
}
public
static
LuaTypes
l
ua
_t
ype
(
LuaState
luaState
,
int
index
)
public
static
LuaTypes
L
ua
T
ype
(
LuaState
luaState
,
int
index
)
{
{
return
(
LuaTypes
)
LuaCore
.
LuaType
(
luaState
,
index
);
return
(
LuaTypes
)
LuaCore
.
LuaType
(
luaState
,
index
);
}
}
public
static
bool
l
ua
_isn
il
(
LuaState
luaState
,
int
index
)
public
static
bool
L
ua
IsN
il
(
LuaState
luaState
,
int
index
)
{
{
return
l
ua
_t
ype
(
luaState
,
index
)
==
LuaTypes
.
Nil
;
return
L
ua
T
ype
(
luaState
,
index
)
==
LuaTypes
.
Nil
;
}
}
public
static
bool
l
ua
_isn
umber
(
LuaState
luaState
,
int
index
)
public
static
bool
L
ua
IsN
umber
(
LuaState
luaState
,
int
index
)
{
{
return
l
ua
_t
ype
(
luaState
,
index
)
==
LuaTypes
.
Number
;
return
L
ua
T
ype
(
luaState
,
index
)
==
LuaTypes
.
Number
;
}
}
public
static
bool
l
ua
_isb
oolean
(
LuaState
luaState
,
int
index
)
public
static
bool
L
ua
IsB
oolean
(
LuaState
luaState
,
int
index
)
{
{
return
l
ua
_t
ype
(
luaState
,
index
)
==
LuaTypes
.
Boolean
;
return
L
ua
T
ype
(
luaState
,
index
)
==
LuaTypes
.
Boolean
;
}
}
public
static
int
l
uaL
_r
ef
(
LuaState
luaState
,
int
registryIndex
)
public
static
int
L
uaL
R
ef
(
LuaState
luaState
,
int
registryIndex
)
{
{
return
LuaCore
.
LuaLRef
(
luaState
,
registryIndex
);
return
LuaCore
.
LuaLRef
(
luaState
,
registryIndex
);
}
}
public
static
int
l
ua
_r
ef
(
LuaState
luaState
,
int
lockRef
)
public
static
int
L
ua
R
ef
(
LuaState
luaState
,
int
lockRef
)
{
{
return
lockRef
!=
0
?
l
uaL
_r
ef
(
luaState
,
(
int
)
LuaIndexes
.
Registry
)
:
0
;
return
lockRef
!=
0
?
L
uaL
R
ef
(
luaState
,
(
int
)
LuaIndexes
.
Registry
)
:
0
;
}
}
public
static
void
l
ua
_r
aw
g
et
i
(
LuaState
luaState
,
int
tableIndex
,
int
index
)
public
static
void
L
ua
R
aw
G
et
I
(
LuaState
luaState
,
int
tableIndex
,
int
index
)
{
{
LuaCore
.
LuaRawGetI
(
luaState
,
tableIndex
,
index
);
LuaCore
.
LuaRawGetI
(
luaState
,
tableIndex
,
index
);
}
}
public
static
void
l
ua
_r
aw
s
et
i
(
LuaState
luaState
,
int
tableIndex
,
int
index
)
public
static
void
L
ua
R
aw
S
et
I
(
LuaState
luaState
,
int
tableIndex
,
int
index
)
{
{
LuaCore
.
LuaRawSetI
(
luaState
,
tableIndex
,
index
);
LuaCore
.
LuaRawSetI
(
luaState
,
tableIndex
,
index
);
}
}
public
static
object
l
ua
_n
ew
u
ser
d
ata
(
LuaState
luaState
,
int
size
)
public
static
object
L
ua
N
ew
U
ser
D
ata
(
LuaState
luaState
,
int
size
)
{
{
return
LuaCore
.
LuaNewUserData
(
luaState
,
(
uint
)
size
);
return
LuaCore
.
LuaNewUserData
(
luaState
,
(
uint
)
size
);
}
}
public
static
object
l
ua
_tou
ser
d
ata
(
LuaState
luaState
,
int
index
)
public
static
object
L
ua
ToU
ser
D
ata
(
LuaState
luaState
,
int
index
)
{
{
return
LuaCore
.
LuaToUserData
(
luaState
,
index
);
return
LuaCore
.
LuaToUserData
(
luaState
,
index
);
}
}
public
static
void
l
ua
_g
et
r
ef
(
LuaState
luaState
,
int
reference
)
public
static
void
L
ua
G
et
R
ef
(
LuaState
luaState
,
int
reference
)
{
{
l
ua
_r
aw
g
et
i
(
luaState
,
(
int
)
LuaIndexes
.
Registry
,
reference
);
L
ua
R
aw
G
et
I
(
luaState
,
(
int
)
LuaIndexes
.
Registry
,
reference
);
}
}
public
static
void
l
ua
_u
nref
(
LuaState
luaState
,
int
reference
)
public
static
void
L
ua
U
nref
(
LuaState
luaState
,
int
reference
)
{
{
LuaCore
.
LuaLUnref
(
luaState
,
(
int
)
LuaIndexes
.
Registry
,
reference
);
LuaCore
.
LuaLUnref
(
luaState
,
(
int
)
LuaIndexes
.
Registry
,
reference
);
}
}
public
static
bool
l
ua
_iss
tring
(
LuaState
luaState
,
int
index
)
public
static
bool
L
ua
IsS
tring
(
LuaState
luaState
,
int
index
)
{
{
return
LuaCore
.
LuaIsString
(
luaState
,
index
)
!=
0
;
return
LuaCore
.
LuaIsString
(
luaState
,
index
)
!=
0
;
}
}
public
static
bool
l
ua
_iscf
unction
(
LuaState
luaState
,
int
index
)
public
static
bool
L
ua
IsCF
unction
(
LuaState
luaState
,
int
index
)
{
{
return
LuaCore
.
LuaIsCFunction
(
luaState
,
index
);
return
LuaCore
.
LuaIsCFunction
(
luaState
,
index
);
}
}
public
static
void
l
ua
_p
ush
n
il
(
LuaState
luaState
)
public
static
void
L
ua
P
ush
N
il
(
LuaState
luaState
)
{
{
LuaCore
.
LuaPushNil
(
luaState
);
LuaCore
.
LuaPushNil
(
luaState
);
}
}
public
static
void
l
ua
_c
all
(
LuaState
luaState
,
int
nArgs
,
int
nResults
)
public
static
void
L
ua
C
all
(
LuaState
luaState
,
int
nArgs
,
int
nResults
)
{
{
LuaCore
.
LuaCall
(
luaState
,
nArgs
,
nResults
);
LuaCore
.
LuaCall
(
luaState
,
nArgs
,
nResults
);
}
}
public
static
void
l
ua
_p
ush
s
td
c
all
cf
unction
(
LuaState
luaState
,
LuaCore
.
LuaNativeFunction
function
)
public
static
void
L
ua
P
ush
S
td
C
all
CF
unction
(
LuaState
luaState
,
LuaCore
.
LuaNativeFunction
function
)
{
{
LuaCore
.
LuaPushStdCallCFunction
(
luaState
,
function
);
LuaCore
.
LuaPushStdCallCFunction
(
luaState
,
function
);
}
}
public
static
int
l
ua
_pc
all
(
LuaState
luaState
,
int
nArgs
,
int
nResults
,
int
errfunc
)
public
static
int
L
ua
PC
all
(
LuaState
luaState
,
int
nArgs
,
int
nResults
,
int
errfunc
)
{
{
return
LuaCore
.
LuaNetPCall
(
luaState
,
nArgs
,
nResults
,
errfunc
);
return
LuaCore
.
LuaNetPCall
(
luaState
,
nArgs
,
nResults
,
errfunc
);
}
}
public
static
LuaCore
.
LuaNativeFunction
l
ua
_tocf
unction
(
LuaState
luaState
,
int
index
)
public
static
LuaCore
.
LuaNativeFunction
L
ua
ToCF
unction
(
LuaState
luaState
,
int
index
)
{
{
return
LuaCore
.
LuaToCFunction
(
luaState
,
index
);
return
LuaCore
.
LuaToCFunction
(
luaState
,
index
);
}
}
public
static
double
l
ua
_ton
umber
(
LuaState
luaState
,
int
index
)
public
static
double
L
ua
ToN
umber
(
LuaState
luaState
,
int
index
)
{
{
return
LuaCore
.
LuaNetToNumber
(
luaState
,
index
);
return
LuaCore
.
LuaNetToNumber
(
luaState
,
index
);
}
}
public
static
bool
l
ua
_tob
oolean
(
LuaState
luaState
,
int
index
)
public
static
bool
L
ua
ToB
oolean
(
LuaState
luaState
,
int
index
)
{
{
return
LuaCore
.
LuaToBoolean
(
luaState
,
index
)
!=
0
;
return
LuaCore
.
LuaToBoolean
(
luaState
,
index
)
!=
0
;
}
}
public
static
string
l
ua
_tos
tring
(
LuaState
luaState
,
int
index
)
public
static
string
L
ua
ToS
tring
(
LuaState
luaState
,
int
index
)
{
{
#if true
// FIXME use the same format string as lua i.e. LUA_NUMBER_FMT
// FIXME use the same format string as lua i.e. LUA_NUMBER_FMT
var
t
=
l
ua
_t
ype
(
luaState
,
index
);
var
t
=
L
ua
T
ype
(
luaState
,
index
);
if
(
t
==
LuaTypes
.
Number
)
if
(
t
==
LuaTypes
.
Number
)
return
string
.
Format
(
"{0}"
,
l
ua
_ton
umber
(
luaState
,
index
));
return
string
.
Format
(
"{0}"
,
L
ua
ToN
umber
(
luaState
,
index
));
else
if
(
t
==
LuaTypes
.
String
)
{
else
if
(
t
==
LuaTypes
.
String
)
{
uint
strlen
;
uint
strlen
;
// Changed 2013-05-18 by Dirk Weltz
// Changed 2013-05-18 by Dirk Weltz
...
@@ -345,145 +329,132 @@ namespace NLua
...
@@ -345,145 +329,132 @@ namespace NLua
return
null
;
// treat lua nulls to as C# nulls
return
null
;
// treat lua nulls to as C# nulls
else
else
return
"0"
;
// Because luaV_tostring does this
return
"0"
;
// Because luaV_tostring does this
#else
size_t
strlen
;
// Note! This method will _change_ the representation of the object on the stack to a string.
// We do not want this behavior so we do the conversion ourselves
const
char
*
str
=
LuaCore
.
lua_tolstring
(
luaState
,
index
,
&
strlen
);
if
(
str
)
return
Marshal
::
PtrToStringAnsi
(
IntPtr
((
char
*)
str
),
strlen
);
else
return
nullptr
;
// treat lua nulls to as C# nulls
#endif
}
}
public
static
void
l
ua
_atp
anic
(
LuaState
luaState
,
LuaCore
.
LuaNativeFunction
panicf
)
public
static
void
L
ua
AtP
anic
(
LuaState
luaState
,
LuaCore
.
LuaNativeFunction
panicf
)
{
{
LuaCore
.
LuaAtPanic
(
luaState
,
(
LuaCore
.
LuaNativeFunction
)
panicf
);
LuaCore
.
LuaAtPanic
(
luaState
,
(
LuaCore
.
LuaNativeFunction
)
panicf
);
}
}
public
static
void
l
ua
_p
ush
n
umber
(
LuaState
luaState
,
double
number
)
public
static
void
L
ua
P
ush
N
umber
(
LuaState
luaState
,
double
number
)
{
{
LuaCore
.
LuaPushNumber
(
luaState
,
number
);
LuaCore
.
LuaPushNumber
(
luaState
,
number
);
}
}
public
static
void
l
ua
_p
ush
b
oolean
(
LuaState
luaState
,
bool
value
)
public
static
void
L
ua
P
ush
B
oolean
(
LuaState
luaState
,
bool
value
)
{
{
LuaCore
.
LuaPushBoolean
(
luaState
,
value
?
1
:
0
);
LuaCore
.
LuaPushBoolean
(
luaState
,
value
?
1
:
0
);
}
}
public
static
void
l
ua
_p
ush
s
tring
(
LuaState
luaState
,
string
str
)
public
static
void
L
ua
P
ush
S
tring
(
LuaState
luaState
,
string
str
)
{
{
LuaCore
.
LuaPushString
(
luaState
,
str
);
LuaCore
.
LuaPushString
(
luaState
,
str
);
}
}
public
static
int
l
uaL
_n
ew
m
etatable
(
LuaState
luaState
,
string
meta
)
public
static
int
L
uaL
N
ew
M
etatable
(
LuaState
luaState
,
string
meta
)
{
{
return
LuaCore
.
LuaLNewMetatable
(
luaState
,
meta
);
return
LuaCore
.
LuaLNewMetatable
(
luaState
,
meta
);
}
}
// steffenj: BEGIN Lua 5.1.1 API change (luaL_getmetatable is now a macro using lua_getfield)
public
static
void
LuaGetField
(
LuaState
luaState
,
int
stackPos
,
string
meta
)
public
static
void
lua_getfield
(
LuaState
luaState
,
int
stackPos
,
string
meta
)
{
{
LuaCore
.
LuaGetField
(
luaState
,
stackPos
,
meta
);
LuaCore
.
LuaGetField
(
luaState
,
stackPos
,
meta
);
}
}
public
static
void
l
uaL
_g
et
m
etatable
(
LuaState
luaState
,
string
meta
)
public
static
void
L
uaL
G
et
M
etatable
(
LuaState
luaState
,
string
meta
)
{
{
l
ua
_g
et
f
ield
(
luaState
,
(
int
)
LuaIndexes
.
Registry
,
meta
);
L
ua
G
et
F
ield
(
luaState
,
(
int
)
LuaIndexes
.
Registry
,
meta
);
}
}
public
static
object
l
uaL
_c
heck
ud
ata
(
LuaState
luaState
,
int
stackPos
,
string
meta
)
public
static
object
L
uaL
C
heck
UD
ata
(
LuaState
luaState
,
int
stackPos
,
string
meta
)
{
{
return
LuaCore
.
LuaLCheckUData
(
luaState
,
stackPos
,
meta
);
return
LuaCore
.
LuaLCheckUData
(
luaState
,
stackPos
,
meta
);
}
}
public
static
bool
l
uaL
_g
et
m
etafield
(
LuaState
luaState
,
int
stackPos
,
string
field
)
public
static
bool
L
uaL
G
et
M
etafield
(
LuaState
luaState
,
int
stackPos
,
string
field
)
{
{
return
LuaCore
.
LuaLGetMetafield
(
luaState
,
stackPos
,
field
)
!=
0
;
return
LuaCore
.
LuaLGetMetafield
(
luaState
,
stackPos
,
field
)
!=
0
;
}
}
public
static
int
l
uaL
_l
oad
b
uffer
(
LuaState
luaState
,
string
buff
,
string
name
)
public
static
int
L
uaL
L
oad
B
uffer
(
LuaState
luaState
,
string
buff
,
string
name
)
{
{
return
LuaCore
.
LuaNetLoadBuffer
(
luaState
,
buff
,
(
uint
)
buff
.
Length
,
name
);
return
LuaCore
.
LuaNetLoadBuffer
(
luaState
,
buff
,
(
uint
)
buff
.
Length
,
name
);
}
}
public
static
int
l
uaL
_l
oad
b
uffer
(
LuaState
luaState
,
byte
[]
buff
,
string
name
)
public
static
int
L
uaL
L
oad
B
uffer
(
LuaState
luaState
,
byte
[]
buff
,
string
name
)
{
{
return
LuaCore
.
LuaNetLoadBuffer
(
luaState
,
buff
,
(
uint
)
buff
.
Length
,
name
);
return
LuaCore
.
LuaNetLoadBuffer
(
luaState
,
buff
,
(
uint
)
buff
.
Length
,
name
);
}
}
public
static
int
l
uaL
_l
oad
f
ile
(
LuaState
luaState
,
string
filename
)
public
static
int
L
uaL
L
oad
F
ile
(
LuaState
luaState
,
string
filename
)
{
{
return
LuaCore
.
LuaNetLoadFile
(
luaState
,
filename
);
return
LuaCore
.
LuaNetLoadFile
(
luaState
,
filename
);
}
}
public
static
bool
l
uaL
_c
heck
m
etatable
(
LuaState
luaState
,
int
index
)
public
static
bool
L
uaL
C
heck
M
etatable
(
LuaState
luaState
,
int
index
)
{
{
return
LuaCore
.
LuaLCheckMetatable
(
luaState
,
index
);
return
LuaCore
.
LuaLCheckMetatable
(
luaState
,
index
);
}
}
public
static
int
l
ua
n
et
_r
egistry
i
ndex
()
public
static
int
L
ua
N
et
R
egistry
I
ndex
()
{
{
return
LuaCore
.
LuaNetRegistryIndex
();
return
LuaCore
.
LuaNetRegistryIndex
();
}
}
public
static
int
l
ua
n
et
_ton
et
o
bject
(
LuaState
luaState
,
int
index
)
public
static
int
L
ua
N
et
ToN
et
O
bject
(
LuaState
luaState
,
int
index
)
{
{
return
LuaCore
.
LuaNetToNetObject
(
luaState
,
index
);
return
LuaCore
.
LuaNetToNetObject
(
luaState
,
index
);
}
}
public
static
void
l
ua
n
et
_newud
ata
(
LuaState
luaState
,
int
val
)
public
static
void
L
ua
N
et
NewUD
ata
(
LuaState
luaState
,
int
val
)
{
{
LuaCore
.
LuaNetNewUData
(
luaState
,
val
);
LuaCore
.
LuaNetNewUData
(
luaState
,
val
);
}
}
public
static
int
l
ua
n
et
_r
aw
n
et
o
bj
(
LuaState
luaState
,
int
obj
)
public
static
int
L
ua
N
et
R
aw
N
et
O
bj
(
LuaState
luaState
,
int
obj
)
{
{
return
LuaCore
.
LuaNetRawNetObj
(
luaState
,
obj
);
return
LuaCore
.
LuaNetRawNetObj
(
luaState
,
obj
);
}
}
public
static
int
l
ua
n
et
_c
heck
ud
ata
(
LuaState
luaState
,
int
ud
,
string
tname
)
public
static
int
L
ua
N
et
C
heck
UD
ata
(
LuaState
luaState
,
int
ud
,
string
tname
)
{
{
return
LuaCore
.
LuaNetCheckUData
(
luaState
,
ud
,
tname
);
return
LuaCore
.
LuaNetCheckUData
(
luaState
,
ud
,
tname
);
}
}
public
static
void
l
ua
_e
rror
(
LuaState
luaState
)
public
static
void
L
ua
E
rror
(
LuaState
luaState
)
{
{
LuaCore
.
LuaError
(
luaState
);
LuaCore
.
LuaError
(
luaState
);
}
}
public
static
bool
l
ua
_c
heck
s
tack
(
LuaState
luaState
,
int
extra
)
public
static
bool
L
ua
C
heck
S
tack
(
LuaState
luaState
,
int
extra
)
{
{
return
LuaCore
.
LuaCheckStack
(
luaState
,
extra
)
!=
0
;
return
LuaCore
.
LuaCheckStack
(
luaState
,
extra
)
!=
0
;
}
}
public
static
int
l
ua
_n
ext
(
LuaState
luaState
,
int
index
)
public
static
int
L
ua
N
ext
(
LuaState
luaState
,
int
index
)
{
{
return
LuaCore
.
LuaNext
(
luaState
,
index
);
return
LuaCore
.
LuaNext
(
luaState
,
index
);
}
}
public
static
void
l
ua
_p
ush
l
ight
u
ser
d
ata
(
LuaState
luaState
,
LuaTag
udata
)
public
static
void
L
ua
P
ush
L
ight
U
ser
D
ata
(
LuaState
luaState
,
LuaTag
udata
)
{
{
LuaCore
.
LuaPushLightUserData
(
luaState
,
udata
.
Tag
);
LuaCore
.
LuaPushLightUserData
(
luaState
,
udata
.
Tag
);
}
}
public
static
LuaTag
l
ua
n
et
_g
et
t
ag
()
public
static
LuaTag
L
ua
N
et
G
et
T
ag
()
{
{
return
LuaCore
.
LuaNetGetTag
();
return
LuaCore
.
LuaNetGetTag
();
}
}
public
static
void
l
ua
n
et
_p
ush
g
lobal
t
able
(
LuaState
luaState
)
public
static
void
L
ua
N
et
P
ush
G
lobal
T
able
(
LuaState
luaState
)
{
{
LuaCore
.
LuaNetPushGlobalTable
(
luaState
);
LuaCore
.
LuaNetPushGlobalTable
(
luaState
);
}
}
public
static
void
l
ua
n
et
_p
op
g
lobal
t
able
(
LuaState
luaState
)
public
static
void
L
ua
N
et
P
op
G
lobal
T
able
(
LuaState
luaState
)
{
{
LuaCore
.
LuaNetPopGlobalTable
(
luaState
);
LuaCore
.
LuaNetPopGlobalTable
(
luaState
);
}
}
}
}
}
}
\ No newline at end of file
Core/NLua/LuaTable.cs
View file @
2e501577
...
@@ -57,10 +57,10 @@ namespace NLua
...
@@ -57,10 +57,10 @@ namespace NLua
*/
*/
public
object
this
[
string
field
]
{
public
object
this
[
string
field
]
{
get
{
get
{
return
_Interpreter
.
g
etObject
(
_Reference
,
field
);
return
_Interpreter
.
G
etObject
(
_Reference
,
field
);
}
}
set
{
set
{
_Interpreter
.
s
etObject
(
_Reference
,
field
,
value
);
_Interpreter
.
S
etObject
(
_Reference
,
field
,
value
);
}
}
}
}
...
@@ -69,10 +69,10 @@ namespace NLua
...
@@ -69,10 +69,10 @@ namespace NLua
*/
*/
public
object
this
[
object
field
]
{
public
object
this
[
object
field
]
{
get
{
get
{
return
_Interpreter
.
g
etObject
(
_Reference
,
field
);
return
_Interpreter
.
G
etObject
(
_Reference
,
field
);
}
}
set
{
set
{
_Interpreter
.
s
etObject
(
_Reference
,
field
,
value
);
_Interpreter
.
S
etObject
(
_Reference
,
field
,
value
);
}
}
}
}
...
@@ -93,14 +93,14 @@ namespace NLua
...
@@ -93,14 +93,14 @@ namespace NLua
* Gets an string fields of a table ignoring its metatable,
* Gets an string fields of a table ignoring its metatable,
* if it exists
* if it exists
*/
*/
internal
object
r
aw
g
et
(
string
field
)
internal
object
R
aw
G
et
(
string
field
)
{
{
return
_Interpreter
.
r
awGetObject
(
_Reference
,
field
);
return
_Interpreter
.
R
awGetObject
(
_Reference
,
field
);
}
}
internal
object
r
aw
g
etFunction
(
string
field
)
internal
object
R
aw
G
etFunction
(
string
field
)
{
{
object
obj
=
_Interpreter
.
r
awGetObject
(
_Reference
,
field
);
object
obj
=
_Interpreter
.
R
awGetObject
(
_Reference
,
field
);
if
(
obj
is
LuaCore
.
LuaNativeFunction
)
if
(
obj
is
LuaCore
.
LuaNativeFunction
)
return
new
LuaFunction
((
LuaCore
.
LuaNativeFunction
)
obj
,
_Interpreter
);
return
new
LuaFunction
((
LuaCore
.
LuaNativeFunction
)
obj
,
_Interpreter
);
...
@@ -111,9 +111,9 @@ namespace NLua
...
@@ -111,9 +111,9 @@ namespace NLua
/*
/*
* Pushes this table into the Lua stack
* Pushes this table into the Lua stack
*/
*/
internal
void
p
ush
(
LuaState
luaState
)
internal
void
P
ush
(
LuaState
luaState
)
{
{
LuaLib
.
l
ua
_g
et
r
ef
(
luaState
,
_Reference
);
LuaLib
.
L
ua
G
et
R
ef
(
luaState
,
_Reference
);
}
}
public
override
string
ToString
()
public
override
string
ToString
()
...
...
Core/NLua/LuaUserData.cs
View file @
2e501577
...
@@ -50,10 +50,10 @@ namespace NLua
...
@@ -50,10 +50,10 @@ namespace NLua
*/
*/
public
object
this
[
string
field
]
{
public
object
this
[
string
field
]
{
get
{
get
{
return
_Interpreter
.
g
etObject
(
_Reference
,
field
);
return
_Interpreter
.
G
etObject
(
_Reference
,
field
);
}
}
set
{
set
{
_Interpreter
.
s
etObject
(
_Reference
,
field
,
value
);
_Interpreter
.
S
etObject
(
_Reference
,
field
,
value
);
}
}
}
}
...
@@ -62,10 +62,10 @@ namespace NLua
...
@@ -62,10 +62,10 @@ namespace NLua
*/
*/
public
object
this
[
object
field
]
{
public
object
this
[
object
field
]
{
get
{
get
{
return
_Interpreter
.
g
etObject
(
_Reference
,
field
);
return
_Interpreter
.
G
etObject
(
_Reference
,
field
);
}
}
set
{
set
{
_Interpreter
.
s
etObject
(
_Reference
,
field
,
value
);
_Interpreter
.
S
etObject
(
_Reference
,
field
,
value
);
}
}
}
}
...
@@ -75,15 +75,15 @@ namespace NLua
...
@@ -75,15 +75,15 @@ namespace NLua
*/
*/
public
object
[]
Call
(
params
object
[]
args
)
public
object
[]
Call
(
params
object
[]
args
)
{
{
return
_Interpreter
.
c
allFunction
(
this
,
args
);
return
_Interpreter
.
C
allFunction
(
this
,
args
);
}
}
/*
/*
* Pushes the userdata into the Lua stack
* Pushes the userdata into the Lua stack
*/
*/
internal
void
p
ush
(
LuaState
luaState
)
internal
void
P
ush
(
LuaState
luaState
)
{
{
LuaLib
.
l
ua
_g
et
r
ef
(
luaState
,
_Reference
);
LuaLib
.
L
ua
G
et
R
ef
(
luaState
,
_Reference
);
}
}
public
override
string
ToString
()
public
override
string
ToString
()
...
...
Core/NLua/Metatables.cs
View file @
2e501577
This diff is collapsed.
Click to expand it.
Core/NLua/Method/LuaClassHelper.cs
View file @
2e501577
...
@@ -38,9 +38,9 @@ namespace NLua.Method
...
@@ -38,9 +38,9 @@ namespace NLua.Method
* Gets the function called name from the provided table,
* Gets the function called name from the provided table,
* returning null if it does not exist
* returning null if it does not exist
*/
*/
public
static
LuaFunction
g
etTableFunction
(
LuaTable
luaTable
,
string
name
)
public
static
LuaFunction
G
etTableFunction
(
LuaTable
luaTable
,
string
name
)
{
{
object
funcObj
=
luaTable
.
r
aw
g
et
(
name
);
object
funcObj
=
luaTable
.
R
aw
G
et
(
name
);
if
(
funcObj
is
LuaFunction
)
if
(
funcObj
is
LuaFunction
)
return
(
LuaFunction
)
funcObj
;
return
(
LuaFunction
)
funcObj
;
...
@@ -51,14 +51,14 @@ namespace NLua.Method
...
@@ -51,14 +51,14 @@ namespace NLua.Method
/*
/*
* Calls the provided function with the provided parameters
* Calls the provided function with the provided parameters
*/
*/
public
static
object
c
allFunction
(
LuaFunction
function
,
object
[]
args
,
Type
[]
returnTypes
,
object
[]
inArgs
,
int
[]
outArgs
)
public
static
object
C
allFunction
(
LuaFunction
function
,
object
[]
args
,
Type
[]
returnTypes
,
object
[]
inArgs
,
int
[]
outArgs
)
{
{
// args is the return array of arguments, inArgs is the actual array
// args is the return array of arguments, inArgs is the actual array
// of arguments passed to the function (with in parameters only), outArgs
// of arguments passed to the function (with in parameters only), outArgs
// has the positions of out parameters
// has the positions of out parameters
object
returnValue
;
object
returnValue
;
int
iRefArgs
;
int
iRefArgs
;
object
[]
returnValues
=
function
.
c
all
(
inArgs
,
returnTypes
);
object
[]
returnValues
=
function
.
C
all
(
inArgs
,
returnTypes
);
if
(
returnTypes
[
0
]
==
typeof
(
void
))
{
if
(
returnTypes
[
0
]
==
typeof
(
void
))
{
returnValue
=
null
;
returnValue
=
null
;
...
...
Core/NLua/Method/LuaDelegate.cs
View file @
2e501577
...
@@ -45,14 +45,14 @@ namespace NLua.Method
...
@@ -45,14 +45,14 @@ namespace NLua.Method
returnTypes
=
null
;
returnTypes
=
null
;
}
}
public
object
c
allFunction
(
object
[]
args
,
object
[]
inArgs
,
int
[]
outArgs
)
public
object
C
allFunction
(
object
[]
args
,
object
[]
inArgs
,
int
[]
outArgs
)
{
{
// args is the return array of arguments, inArgs is the actual array
// args is the return array of arguments, inArgs is the actual array
// of arguments passed to the function (with in parameters only), outArgs
// of arguments passed to the function (with in parameters only), outArgs
// has the positions of out parameters
// has the positions of out parameters
object
returnValue
;
object
returnValue
;
int
iRefArgs
;
int
iRefArgs
;
object
[]
returnValues
=
function
.
c
all
(
inArgs
,
returnTypes
);
object
[]
returnValues
=
function
.
C
all
(
inArgs
,
returnTypes
);
if
(
returnTypes
[
0
]
==
typeof
(
void
))
{
if
(
returnTypes
[
0
]
==
typeof
(
void
))
{
returnValue
=
null
;
returnValue
=
null
;
...
...
Core/NLua/Method/LuaEventHandler.cs
View file @
2e501577
...
@@ -40,7 +40,7 @@ namespace NLua.Method
...
@@ -40,7 +40,7 @@ namespace NLua.Method
// CP: Fix provided by Ben Bryant for delegates with one param
// CP: Fix provided by Ben Bryant for delegates with one param
// link: http://luaforge.net/forum/message.php?msg_id=9318
// link: http://luaforge.net/forum/message.php?msg_id=9318
public
void
h
andleEvent
(
object
[]
args
)
public
void
H
andleEvent
(
object
[]
args
)
{
{
handler
.
Call
(
args
);
handler
.
Call
(
args
);
}
}
...
...
Core/NLua/Method/LuaMethodWrapper.cs
View file @
2e501577
...
@@ -66,12 +66,12 @@ namespace NLua.Method
...
@@ -66,12 +66,12 @@ namespace NLua.Method
*/
*/
public
LuaMethodWrapper
(
ObjectTranslator
translator
,
object
target
,
IReflect
targetType
,
MethodBase
method
)
public
LuaMethodWrapper
(
ObjectTranslator
translator
,
object
target
,
IReflect
targetType
,
MethodBase
method
)
{
{
invokeFunction
=
new
LuaCore
.
LuaNativeFunction
(
this
.
c
all
);
invokeFunction
=
new
LuaCore
.
LuaNativeFunction
(
this
.
C
all
);
_Translator
=
translator
;
_Translator
=
translator
;
_Target
=
target
;
_Target
=
target
;
if
(!
targetType
.
IsNull
())
if
(!
targetType
.
IsNull
())
_ExtractTarget
=
translator
.
typeChecker
.
g
etExtractor
(
targetType
);
_ExtractTarget
=
translator
.
typeChecker
.
G
etExtractor
(
targetType
);
_Method
=
method
;
_Method
=
method
;
_MethodName
=
method
.
Name
;
_MethodName
=
method
.
Name
;
...
@@ -87,13 +87,13 @@ namespace NLua.Method
...
@@ -87,13 +87,13 @@ namespace NLua.Method
*/
*/
public
LuaMethodWrapper
(
ObjectTranslator
translator
,
IReflect
targetType
,
string
methodName
,
BindingFlags
bindingType
)
public
LuaMethodWrapper
(
ObjectTranslator
translator
,
IReflect
targetType
,
string
methodName
,
BindingFlags
bindingType
)
{
{
invokeFunction
=
new
LuaCore
.
LuaNativeFunction
(
this
.
c
all
);
invokeFunction
=
new
LuaCore
.
LuaNativeFunction
(
this
.
C
all
);
_Translator
=
translator
;
_Translator
=
translator
;
_MethodName
=
methodName
;
_MethodName
=
methodName
;
if
(!
targetType
.
IsNull
())
if
(!
targetType
.
IsNull
())
_ExtractTarget
=
translator
.
typeChecker
.
g
etExtractor
(
targetType
);
_ExtractTarget
=
translator
.
typeChecker
.
G
etExtractor
(
targetType
);
_BindingType
=
bindingType
;
_BindingType
=
bindingType
;
//CP: Removed NonPublic binding search and added IgnoreCase
//CP: Removed NonPublic binding search and added IgnoreCase
...
@@ -114,14 +114,14 @@ namespace NLua.Method
...
@@ -114,14 +114,14 @@ namespace NLua.Method
* Calls the method. Receives the arguments from the Lua stack
* Calls the method. Receives the arguments from the Lua stack
* and returns values in it.
* and returns values in it.
*/
*/
int
c
all
(
LuaState
luaState
)
int
C
all
(
LuaState
luaState
)
{
{
var
methodToCall
=
_Method
;
var
methodToCall
=
_Method
;
object
targetObject
=
_Target
;
object
targetObject
=
_Target
;
bool
failedCall
=
true
;
bool
failedCall
=
true
;
int
nReturnValues
=
0
;
int
nReturnValues
=
0
;
if
(!
LuaLib
.
l
ua
_c
heck
s
tack
(
luaState
,
5
))
if
(!
LuaLib
.
L
ua
C
heck
S
tack
(
luaState
,
5
))
throw
new
LuaException
(
"Lua stack overflow"
);
throw
new
LuaException
(
"Lua stack overflow"
);
bool
isStatic
=
(
_BindingType
&
BindingFlags
.
Static
)
==
BindingFlags
.
Static
;
bool
isStatic
=
(
_BindingType
&
BindingFlags
.
Static
)
==
BindingFlags
.
Static
;
...
@@ -136,11 +136,11 @@ namespace NLua.Method
...
@@ -136,11 +136,11 @@ namespace NLua.Method
//LuaLib.lua_remove(luaState,1); // Pops the receiver
//LuaLib.lua_remove(luaState,1); // Pops the receiver
if
(!
_LastCalledMethod
.
cachedMethod
.
IsNull
())
{
// Cached?
if
(!
_LastCalledMethod
.
cachedMethod
.
IsNull
())
{
// 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
.
l
ua
_g
et
t
op
(
luaState
)
-
numStackToSkip
;
int
numArgsPassed
=
LuaLib
.
L
ua
G
et
T
op
(
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
.
l
ua
_c
heck
s
tack
(
luaState
,
_LastCalledMethod
.
outList
.
Length
+
6
))
if
(!
LuaLib
.
L
ua
C
heck
S
tack
(
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
;
...
@@ -152,24 +152,24 @@ namespace NLua.Method
...
@@ -152,24 +152,24 @@ namespace NLua.Method
object
luaParamValue
=
type
.
extractValue
(
luaState
,
i
+
1
+
numStackToSkip
);
object
luaParamValue
=
type
.
extractValue
(
luaState
,
i
+
1
+
numStackToSkip
);
if
(
_LastCalledMethod
.
argTypes
[
i
].
isParamsArray
)
{
if
(
_LastCalledMethod
.
argTypes
[
i
].
isParamsArray
)
{
Array
paramArray
=
_Translator
.
t
ableToArray
(
luaParamValue
,
type
.
paramsArrayType
);
Array
paramArray
=
_Translator
.
T
ableToArray
(
luaParamValue
,
type
.
paramsArrayType
);
args
[
_LastCalledMethod
.
argTypes
[
i
].
index
]
=
paramArray
;
args
[
_LastCalledMethod
.
argTypes
[
i
].
index
]
=
paramArray
;
}
else
{
}
else
{
args
[
type
.
index
]
=
luaParamValue
;
args
[
type
.
index
]
=
luaParamValue
;
}
}
if
(
_LastCalledMethod
.
args
[
_LastCalledMethod
.
argTypes
[
i
].
index
]
==
null
&&
if
(
_LastCalledMethod
.
args
[
_LastCalledMethod
.
argTypes
[
i
].
index
]
==
null
&&
!
LuaLib
.
l
ua
_isn
il
(
luaState
,
i
+
1
+
numStackToSkip
))
!
LuaLib
.
L
ua
IsN
il
(
luaState
,
i
+
1
+
numStackToSkip
))
throw
new
LuaException
(
"argument number "
+
(
i
+
1
)
+
" is invalid"
);
throw
new
LuaException
(
"argument number "
+
(
i
+
1
)
+
" is invalid"
);
}
}
if
((
_BindingType
&
BindingFlags
.
Static
)
==
BindingFlags
.
Static
)
if
((
_BindingType
&
BindingFlags
.
Static
)
==
BindingFlags
.
Static
)
_Translator
.
p
ush
(
luaState
,
method
.
Invoke
(
null
,
_LastCalledMethod
.
args
));
_Translator
.
P
ush
(
luaState
,
method
.
Invoke
(
null
,
_LastCalledMethod
.
args
));
else
{
else
{
if
(
method
.
IsConstructor
)
if
(
method
.
IsConstructor
)
_Translator
.
p
ush
(
luaState
,
((
ConstructorInfo
)
method
).
Invoke
(
_LastCalledMethod
.
args
));
_Translator
.
P
ush
(
luaState
,
((
ConstructorInfo
)
method
).
Invoke
(
_LastCalledMethod
.
args
));
else
else
_Translator
.
p
ush
(
luaState
,
method
.
Invoke
(
targetObject
,
_LastCalledMethod
.
args
));
_Translator
.
P
ush
(
luaState
,
method
.
Invoke
(
targetObject
,
_LastCalledMethod
.
args
));
}
}
failedCall
=
false
;
failedCall
=
false
;
...
@@ -190,12 +190,12 @@ namespace NLua.Method
...
@@ -190,12 +190,12 @@ namespace NLua.Method
// If we are running an instance variable, we can now pop the targetObject from the stack
// If we are running an instance variable, we can now pop the targetObject from the stack
if
(!
isStatic
)
{
if
(!
isStatic
)
{
if
(
targetObject
.
IsNull
())
{
if
(
targetObject
.
IsNull
())
{
_Translator
.
t
hrowError
(
luaState
,
String
.
Format
(
"instance method '{0}' requires a non null target object"
,
_MethodName
));
_Translator
.
T
hrowError
(
luaState
,
String
.
Format
(
"instance method '{0}' requires a non null target object"
,
_MethodName
));
LuaLib
.
l
ua
_p
ush
n
il
(
luaState
);
LuaLib
.
L
ua
P
ush
N
il
(
luaState
);
return
1
;
return
1
;
}
}
LuaLib
.
l
ua
_r
emove
(
luaState
,
1
);
// Pops the receiver
LuaLib
.
L
ua
R
emove
(
luaState
,
1
);
// Pops the receiver
}
}
bool
hasMatch
=
false
;
bool
hasMatch
=
false
;
...
@@ -204,7 +204,7 @@ namespace NLua.Method
...
@@ -204,7 +204,7 @@ namespace NLua.Method
foreach
(
var
member
in
_Members
)
{
foreach
(
var
member
in
_Members
)
{
candidateName
=
member
.
ReflectedType
.
Name
+
"."
+
member
.
Name
;
candidateName
=
member
.
ReflectedType
.
Name
+
"."
+
member
.
Name
;
var
m
=
(
MethodInfo
)
member
;
var
m
=
(
MethodInfo
)
member
;
bool
isMethod
=
_Translator
.
m
atchParameters
(
luaState
,
m
,
ref
_LastCalledMethod
);
bool
isMethod
=
_Translator
.
M
atchParameters
(
luaState
,
m
,
ref
_LastCalledMethod
);
if
(
isMethod
)
{
if
(
isMethod
)
{
hasMatch
=
true
;
hasMatch
=
true
;
...
@@ -214,15 +214,15 @@ namespace NLua.Method
...
@@ -214,15 +214,15 @@ namespace NLua.Method
if
(!
hasMatch
)
{
if
(!
hasMatch
)
{
string
msg
=
(
candidateName
==
null
)
?
"invalid arguments to method call"
:
(
"invalid arguments to method: "
+
candidateName
);
string
msg
=
(
candidateName
==
null
)
?
"invalid arguments to method call"
:
(
"invalid arguments to method: "
+
candidateName
);
_Translator
.
t
hrowError
(
luaState
,
msg
);
_Translator
.
T
hrowError
(
luaState
,
msg
);
LuaLib
.
l
ua
_p
ush
n
il
(
luaState
);
LuaLib
.
L
ua
P
ush
N
il
(
luaState
);
return
1
;
return
1
;
}
}
}
}
}
else
{
// Method from MethodBase instance
}
else
{
// Method from MethodBase instance
if
(
methodToCall
.
ContainsGenericParameters
)
{
if
(
methodToCall
.
ContainsGenericParameters
)
{
_Translator
.
m
atchParameters
(
luaState
,
methodToCall
,
ref
_LastCalledMethod
);
_Translator
.
M
atchParameters
(
luaState
,
methodToCall
,
ref
_LastCalledMethod
);
if
(
methodToCall
.
IsGenericMethodDefinition
)
{
if
(
methodToCall
.
IsGenericMethodDefinition
)
{
//need to make a concrete type of the generic method definition
//need to make a concrete type of the generic method definition
...
@@ -232,39 +232,39 @@ namespace NLua.Method
...
@@ -232,39 +232,39 @@ namespace NLua.Method
typeArgs
.
Add
(
arg
.
GetType
());
typeArgs
.
Add
(
arg
.
GetType
());
var
concreteMethod
=
(
methodToCall
as
MethodInfo
).
MakeGenericMethod
(
typeArgs
.
ToArray
());
var
concreteMethod
=
(
methodToCall
as
MethodInfo
).
MakeGenericMethod
(
typeArgs
.
ToArray
());
_Translator
.
p
ush
(
luaState
,
concreteMethod
.
Invoke
(
targetObject
,
_LastCalledMethod
.
args
));
_Translator
.
P
ush
(
luaState
,
concreteMethod
.
Invoke
(
targetObject
,
_LastCalledMethod
.
args
));
failedCall
=
false
;
failedCall
=
false
;
}
else
if
(
methodToCall
.
ContainsGenericParameters
)
{
}
else
if
(
methodToCall
.
ContainsGenericParameters
)
{
_Translator
.
t
hrowError
(
luaState
,
"unable to invoke method on generic class as the current method is an open generic method"
);
_Translator
.
T
hrowError
(
luaState
,
"unable to invoke method on generic class as the current method is an open generic method"
);
LuaLib
.
l
ua
_p
ush
n
il
(
luaState
);
LuaLib
.
L
ua
P
ush
N
il
(
luaState
);
return
1
;
return
1
;
}
}
}
else
{
}
else
{
if
(!
methodToCall
.
IsStatic
&&
!
methodToCall
.
IsConstructor
&&
targetObject
==
null
)
{
if
(!
methodToCall
.
IsStatic
&&
!
methodToCall
.
IsConstructor
&&
targetObject
==
null
)
{
targetObject
=
_ExtractTarget
(
luaState
,
1
);
targetObject
=
_ExtractTarget
(
luaState
,
1
);
LuaLib
.
l
ua
_r
emove
(
luaState
,
1
);
// Pops the receiver
LuaLib
.
L
ua
R
emove
(
luaState
,
1
);
// Pops the receiver
}
}
if
(!
_Translator
.
m
atchParameters
(
luaState
,
methodToCall
,
ref
_LastCalledMethod
))
{
if
(!
_Translator
.
M
atchParameters
(
luaState
,
methodToCall
,
ref
_LastCalledMethod
))
{
_Translator
.
t
hrowError
(
luaState
,
"invalid arguments to method call"
);
_Translator
.
T
hrowError
(
luaState
,
"invalid arguments to method call"
);
LuaLib
.
l
ua
_p
ush
n
il
(
luaState
);
LuaLib
.
L
ua
P
ush
N
il
(
luaState
);
return
1
;
return
1
;
}
}
}
}
}
}
if
(
failedCall
)
{
if
(
failedCall
)
{
if
(!
LuaLib
.
l
ua
_c
heck
s
tack
(
luaState
,
_LastCalledMethod
.
outList
.
Length
+
6
))
if
(!
LuaLib
.
L
ua
C
heck
S
tack
(
luaState
,
_LastCalledMethod
.
outList
.
Length
+
6
))
throw
new
LuaException
(
"Lua stack overflow"
);
throw
new
LuaException
(
"Lua stack overflow"
);
try
{
try
{
if
(
isStatic
)
if
(
isStatic
)
_Translator
.
p
ush
(
luaState
,
_LastCalledMethod
.
cachedMethod
.
Invoke
(
null
,
_LastCalledMethod
.
args
));
_Translator
.
P
ush
(
luaState
,
_LastCalledMethod
.
cachedMethod
.
Invoke
(
null
,
_LastCalledMethod
.
args
));
else
{
else
{
if
(
_LastCalledMethod
.
cachedMethod
.
IsConstructor
)
if
(
_LastCalledMethod
.
cachedMethod
.
IsConstructor
)
_Translator
.
p
ush
(
luaState
,
((
ConstructorInfo
)
_LastCalledMethod
.
cachedMethod
).
Invoke
(
_LastCalledMethod
.
args
));
_Translator
.
P
ush
(
luaState
,
((
ConstructorInfo
)
_LastCalledMethod
.
cachedMethod
).
Invoke
(
_LastCalledMethod
.
args
));
else
else
_Translator
.
p
ush
(
luaState
,
_LastCalledMethod
.
cachedMethod
.
Invoke
(
targetObject
,
_LastCalledMethod
.
args
));
_Translator
.
P
ush
(
luaState
,
_LastCalledMethod
.
cachedMethod
.
Invoke
(
targetObject
,
_LastCalledMethod
.
args
));
}
}
}
catch
(
TargetInvocationException
e
)
{
}
catch
(
TargetInvocationException
e
)
{
return
SetPendingException
(
e
.
GetBaseException
());
return
SetPendingException
(
e
.
GetBaseException
());
...
@@ -276,7 +276,7 @@ namespace NLua.Method
...
@@ -276,7 +276,7 @@ namespace NLua.Method
// Pushes out and ref return values
// Pushes out and ref return values
for
(
int
index
=
0
;
index
<
_LastCalledMethod
.
outList
.
Length
;
index
++)
{
for
(
int
index
=
0
;
index
<
_LastCalledMethod
.
outList
.
Length
;
index
++)
{
nReturnValues
++;
nReturnValues
++;
_Translator
.
p
ush
(
luaState
,
_LastCalledMethod
.
args
[
_LastCalledMethod
.
outList
[
index
]]);
_Translator
.
P
ush
(
luaState
,
_LastCalledMethod
.
args
[
_LastCalledMethod
.
outList
[
index
]]);
}
}
//by isSingle 2010-09-10 11:26:31
//by isSingle 2010-09-10 11:26:31
...
...
Core/NLua/Method/RegisterEventHandler.cs
View file @
2e501577
...
@@ -59,13 +59,6 @@ namespace NLua.Method
...
@@ -59,13 +59,6 @@ namespace NLua.Method
pendingEvents
.
Add
(
handlerDelegate
,
this
);
pendingEvents
.
Add
(
handlerDelegate
,
this
);
return
handlerDelegate
;
return
handlerDelegate
;
//MethodInfo mi = eventInfo.EventHandlerType.GetMethod("Invoke");
//ParameterInfo[] pi = mi.GetParameters();
//LuaEventHandler handler=CodeGeneration.Instance.GetEvent(pi[1].ParameterType,function);
//Delegate handlerDelegate=Delegate.CreateDelegate(eventInfo.EventHandlerType,handler,"HandleEvent");
//eventInfo.AddEventHandler(target,handlerDelegate);
//pendingEvents.Add(handlerDelegate, this);
//return handlerDelegate;
}
}
/*
/*
...
...
Core/NLua/ObjectTranslator.cs
View file @
2e501577
This diff is collapsed.
Click to expand it.
tests/LuaTests.cs
View file @
2e501577
...
@@ -285,7 +285,7 @@ namespace NLuaTest
...
@@ -285,7 +285,7 @@ namespace NLuaTest
object
[]
args
=
new
object
[]
{
sender
,
eventArgs
};
object
[]
args
=
new
object
[]
{
sender
,
eventArgs
};
object
[]
inArgs
=
new
object
[]
{
sender
,
eventArgs
};
object
[]
inArgs
=
new
object
[]
{
sender
,
eventArgs
};
int
[]
outArgs
=
new
int
[]
{
};
int
[]
outArgs
=
new
int
[]
{
};
base
.
c
allFunction
(
args
,
inArgs
,
outArgs
);
base
.
C
allFunction
(
args
,
inArgs
,
outArgs
);
}
}
}
}
...
@@ -1436,8 +1436,8 @@ namespace NLuaTest
...
@@ -1436,8 +1436,8 @@ namespace NLuaTest
};
};
int
[]
outArgs
=
new
int
[]
{
};
int
[]
outArgs
=
new
int
[]
{
};
Type
[]
returnTypes
=
__luaInterface_returnTypes
[
0
];
Type
[]
returnTypes
=
__luaInterface_returnTypes
[
0
];
LuaFunction
function
=
NLua
.
Method
.
LuaClassHelper
.
g
etTableFunction
(
__luaInterface_luaTable
,
"overridableMethod"
);
LuaFunction
function
=
NLua
.
Method
.
LuaClassHelper
.
G
etTableFunction
(
__luaInterface_luaTable
,
"overridableMethod"
);
object
ret
=
NLua
.
Method
.
LuaClassHelper
.
c
allFunction
(
function
,
args
,
returnTypes
,
inArgs
,
outArgs
);
object
ret
=
NLua
.
Method
.
LuaClassHelper
.
C
allFunction
(
function
,
args
,
returnTypes
,
inArgs
,
outArgs
);
return
(
int
)
ret
;
return
(
int
)
ret
;
}
}
}
}
...
@@ -1464,8 +1464,8 @@ namespace NLuaTest
...
@@ -1464,8 +1464,8 @@ namespace NLuaTest
object
[]
inArgs
=
new
object
[]
{
__luaInterface_luaTable
};
object
[]
inArgs
=
new
object
[]
{
__luaInterface_luaTable
};
int
[]
outArgs
=
new
int
[]
{
};
int
[]
outArgs
=
new
int
[]
{
};
Type
[]
returnTypes
=
__luaInterface_returnTypes
[
0
];
Type
[]
returnTypes
=
__luaInterface_returnTypes
[
0
];
LuaFunction
function
=
NLua
.
Method
.
LuaClassHelper
.
g
etTableFunction
(
__luaInterface_luaTable
,
"get_intProp"
);
LuaFunction
function
=
NLua
.
Method
.
LuaClassHelper
.
G
etTableFunction
(
__luaInterface_luaTable
,
"get_intProp"
);
object
ret
=
NLua
.
Method
.
LuaClassHelper
.
c
allFunction
(
function
,
args
,
returnTypes
,
inArgs
,
outArgs
);
object
ret
=
NLua
.
Method
.
LuaClassHelper
.
C
allFunction
(
function
,
args
,
returnTypes
,
inArgs
,
outArgs
);
return
(
int
)
ret
;
return
(
int
)
ret
;
}
}
set
{
set
{
...
@@ -1480,8 +1480,8 @@ namespace NLuaTest
...
@@ -1480,8 +1480,8 @@ namespace NLuaTest
};
};
int
[]
outArgs
=
new
int
[]
{
};
int
[]
outArgs
=
new
int
[]
{
};
Type
[]
returnTypes
=
__luaInterface_returnTypes
[
1
];
Type
[]
returnTypes
=
__luaInterface_returnTypes
[
1
];
LuaFunction
function
=
NLua
.
Method
.
LuaClassHelper
.
g
etTableFunction
(
__luaInterface_luaTable
,
"set_intProp"
);
LuaFunction
function
=
NLua
.
Method
.
LuaClassHelper
.
G
etTableFunction
(
__luaInterface_luaTable
,
"set_intProp"
);
NLua
.
Method
.
LuaClassHelper
.
c
allFunction
(
function
,
args
,
returnTypes
,
inArgs
,
outArgs
);
NLua
.
Method
.
LuaClassHelper
.
C
allFunction
(
function
,
args
,
returnTypes
,
inArgs
,
outArgs
);
}
}
}
}
...
@@ -1491,8 +1491,8 @@ namespace NLuaTest
...
@@ -1491,8 +1491,8 @@ namespace NLuaTest
object
[]
inArgs
=
new
object
[]
{
__luaInterface_luaTable
};
object
[]
inArgs
=
new
object
[]
{
__luaInterface_luaTable
};
int
[]
outArgs
=
new
int
[]
{
};
int
[]
outArgs
=
new
int
[]
{
};
Type
[]
returnTypes
=
__luaInterface_returnTypes
[
2
];
Type
[]
returnTypes
=
__luaInterface_returnTypes
[
2
];
LuaFunction
function
=
NLua
.
Method
.
LuaClassHelper
.
g
etTableFunction
(
__luaInterface_luaTable
,
"get_refProp"
);
LuaFunction
function
=
NLua
.
Method
.
LuaClassHelper
.
G
etTableFunction
(
__luaInterface_luaTable
,
"get_refProp"
);
object
ret
=
NLua
.
Method
.
LuaClassHelper
.
c
allFunction
(
function
,
args
,
returnTypes
,
inArgs
,
outArgs
);
object
ret
=
NLua
.
Method
.
LuaClassHelper
.
C
allFunction
(
function
,
args
,
returnTypes
,
inArgs
,
outArgs
);
return
(
TestClass
)
ret
;
return
(
TestClass
)
ret
;
}
}
set
{
set
{
...
@@ -1507,8 +1507,8 @@ namespace NLuaTest
...
@@ -1507,8 +1507,8 @@ namespace NLuaTest
};
};
int
[]
outArgs
=
new
int
[]
{
};
int
[]
outArgs
=
new
int
[]
{
};
Type
[]
returnTypes
=
__luaInterface_returnTypes
[
3
];
Type
[]
returnTypes
=
__luaInterface_returnTypes
[
3
];
LuaFunction
function
=
NLua
.
Method
.
LuaClassHelper
.
g
etTableFunction
(
__luaInterface_luaTable
,
"set_refProp"
);
LuaFunction
function
=
NLua
.
Method
.
LuaClassHelper
.
G
etTableFunction
(
__luaInterface_luaTable
,
"set_refProp"
);
NLua
.
Method
.
LuaClassHelper
.
c
allFunction
(
function
,
args
,
returnTypes
,
inArgs
,
outArgs
);
NLua
.
Method
.
LuaClassHelper
.
C
allFunction
(
function
,
args
,
returnTypes
,
inArgs
,
outArgs
);
}
}
}
}
...
@@ -1526,8 +1526,8 @@ namespace NLuaTest
...
@@ -1526,8 +1526,8 @@ namespace NLuaTest
};
};
int
[]
outArgs
=
new
int
[]
{
};
int
[]
outArgs
=
new
int
[]
{
};
Type
[]
returnTypes
=
__luaInterface_returnTypes
[
4
];
Type
[]
returnTypes
=
__luaInterface_returnTypes
[
4
];
LuaFunction
function
=
NLua
.
Method
.
LuaClassHelper
.
g
etTableFunction
(
__luaInterface_luaTable
,
"test1"
);
LuaFunction
function
=
NLua
.
Method
.
LuaClassHelper
.
G
etTableFunction
(
__luaInterface_luaTable
,
"test1"
);
object
ret
=
NLua
.
Method
.
LuaClassHelper
.
c
allFunction
(
function
,
args
,
returnTypes
,
inArgs
,
outArgs
);
object
ret
=
NLua
.
Method
.
LuaClassHelper
.
C
allFunction
(
function
,
args
,
returnTypes
,
inArgs
,
outArgs
);
return
(
int
)
ret
;
return
(
int
)
ret
;
}
}
...
@@ -1544,8 +1544,8 @@ namespace NLuaTest
...
@@ -1544,8 +1544,8 @@ namespace NLuaTest
};
};
int
[]
outArgs
=
new
int
[]
{
1
};
int
[]
outArgs
=
new
int
[]
{
1
};
Type
[]
returnTypes
=
__luaInterface_returnTypes
[
5
];
Type
[]
returnTypes
=
__luaInterface_returnTypes
[
5
];
LuaFunction
function
=
NLua
.
Method
.
LuaClassHelper
.
g
etTableFunction
(
__luaInterface_luaTable
,
"test2"
);
LuaFunction
function
=
NLua
.
Method
.
LuaClassHelper
.
G
etTableFunction
(
__luaInterface_luaTable
,
"test2"
);
object
ret
=
NLua
.
Method
.
LuaClassHelper
.
c
allFunction
(
function
,
args
,
returnTypes
,
inArgs
,
outArgs
);
object
ret
=
NLua
.
Method
.
LuaClassHelper
.
C
allFunction
(
function
,
args
,
returnTypes
,
inArgs
,
outArgs
);
b
=
(
int
)
args
[
1
];
b
=
(
int
)
args
[
1
];
return
(
int
)
ret
;
return
(
int
)
ret
;
}
}
...
@@ -1564,8 +1564,8 @@ namespace NLuaTest
...
@@ -1564,8 +1564,8 @@ namespace NLuaTest
};
};
int
[]
outArgs
=
new
int
[]
{
1
};
int
[]
outArgs
=
new
int
[]
{
1
};
Type
[]
returnTypes
=
__luaInterface_returnTypes
[
6
];
Type
[]
returnTypes
=
__luaInterface_returnTypes
[
6
];
LuaFunction
function
=
NLua
.
Method
.
LuaClassHelper
.
g
etTableFunction
(
__luaInterface_luaTable
,
"test3"
);
LuaFunction
function
=
NLua
.
Method
.
LuaClassHelper
.
G
etTableFunction
(
__luaInterface_luaTable
,
"test3"
);
NLua
.
Method
.
LuaClassHelper
.
c
allFunction
(
function
,
args
,
returnTypes
,
inArgs
,
outArgs
);
NLua
.
Method
.
LuaClassHelper
.
C
allFunction
(
function
,
args
,
returnTypes
,
inArgs
,
outArgs
);
b
=
(
int
)
args
[
1
];
b
=
(
int
)
args
[
1
];
}
}
...
@@ -1583,8 +1583,8 @@ namespace NLuaTest
...
@@ -1583,8 +1583,8 @@ namespace NLuaTest
};
};
int
[]
outArgs
=
new
int
[]
{
};
int
[]
outArgs
=
new
int
[]
{
};
Type
[]
returnTypes
=
__luaInterface_returnTypes
[
7
];
Type
[]
returnTypes
=
__luaInterface_returnTypes
[
7
];
LuaFunction
function
=
NLua
.
Method
.
LuaClassHelper
.
g
etTableFunction
(
__luaInterface_luaTable
,
"test4"
);
LuaFunction
function
=
NLua
.
Method
.
LuaClassHelper
.
G
etTableFunction
(
__luaInterface_luaTable
,
"test4"
);
object
ret
=
NLua
.
Method
.
LuaClassHelper
.
c
allFunction
(
function
,
args
,
returnTypes
,
inArgs
,
outArgs
);
object
ret
=
NLua
.
Method
.
LuaClassHelper
.
C
allFunction
(
function
,
args
,
returnTypes
,
inArgs
,
outArgs
);
return
(
TestClass
)
ret
;
return
(
TestClass
)
ret
;
}
}
...
@@ -1602,8 +1602,8 @@ namespace NLuaTest
...
@@ -1602,8 +1602,8 @@ namespace NLuaTest
};
};
int
[]
outArgs
=
new
int
[]
{
};
int
[]
outArgs
=
new
int
[]
{
};
Type
[]
returnTypes
=
__luaInterface_returnTypes
[
8
];
Type
[]
returnTypes
=
__luaInterface_returnTypes
[
8
];
LuaFunction
function
=
NLua
.
Method
.
LuaClassHelper
.
g
etTableFunction
(
__luaInterface_luaTable
,
"test5"
);
LuaFunction
function
=
NLua
.
Method
.
LuaClassHelper
.
G
etTableFunction
(
__luaInterface_luaTable
,
"test5"
);
object
ret
=
NLua
.
Method
.
LuaClassHelper
.
c
allFunction
(
function
,
args
,
returnTypes
,
inArgs
,
outArgs
);
object
ret
=
NLua
.
Method
.
LuaClassHelper
.
C
allFunction
(
function
,
args
,
returnTypes
,
inArgs
,
outArgs
);
return
(
int
)
ret
;
return
(
int
)
ret
;
}
}
...
@@ -1620,8 +1620,8 @@ namespace NLuaTest
...
@@ -1620,8 +1620,8 @@ namespace NLuaTest
};
};
int
[]
outArgs
=
new
int
[]
{
1
};
int
[]
outArgs
=
new
int
[]
{
1
};
Type
[]
returnTypes
=
__luaInterface_returnTypes
[
9
];
Type
[]
returnTypes
=
__luaInterface_returnTypes
[
9
];
LuaFunction
function
=
NLua
.
Method
.
LuaClassHelper
.
g
etTableFunction
(
__luaInterface_luaTable
,
"test6"
);
LuaFunction
function
=
NLua
.
Method
.
LuaClassHelper
.
G
etTableFunction
(
__luaInterface_luaTable
,
"test6"
);
object
ret
=
NLua
.
Method
.
LuaClassHelper
.
c
allFunction
(
function
,
args
,
returnTypes
,
inArgs
,
outArgs
);
object
ret
=
NLua
.
Method
.
LuaClassHelper
.
C
allFunction
(
function
,
args
,
returnTypes
,
inArgs
,
outArgs
);
b
=
(
TestClass
)
args
[
1
];
b
=
(
TestClass
)
args
[
1
];
return
(
int
)
ret
;
return
(
int
)
ret
;
...
@@ -1641,8 +1641,8 @@ namespace NLuaTest
...
@@ -1641,8 +1641,8 @@ namespace NLuaTest
};
};
int
[]
outArgs
=
new
int
[]
{
1
};
int
[]
outArgs
=
new
int
[]
{
1
};
Type
[]
returnTypes
=
__luaInterface_returnTypes
[
10
];
Type
[]
returnTypes
=
__luaInterface_returnTypes
[
10
];
LuaFunction
function
=
NLua
.
Method
.
LuaClassHelper
.
g
etTableFunction
(
__luaInterface_luaTable
,
"test7"
);
LuaFunction
function
=
NLua
.
Method
.
LuaClassHelper
.
G
etTableFunction
(
__luaInterface_luaTable
,
"test7"
);
NLua
.
Method
.
LuaClassHelper
.
c
allFunction
(
function
,
args
,
returnTypes
,
inArgs
,
outArgs
);
NLua
.
Method
.
LuaClassHelper
.
C
allFunction
(
function
,
args
,
returnTypes
,
inArgs
,
outArgs
);
b
=
(
TestClass
)
args
[
1
];
b
=
(
TestClass
)
args
[
1
];
}
}
}
}
...
...
tests/TestLua.cs
View file @
2e501577
...
@@ -35,7 +35,7 @@ namespace NLuaTest.Mock
...
@@ -35,7 +35,7 @@ namespace NLuaTest.Mock
object
[]
inArgs
=
new
object
[]
{
a
,
b
};
object
[]
inArgs
=
new
object
[]
{
a
,
b
};
int
[]
outArgs
=
new
int
[]
{
};
int
[]
outArgs
=
new
int
[]
{
};
object
ret
=
base
.
c
allFunction
(
args
,
inArgs
,
outArgs
);
object
ret
=
base
.
C
allFunction
(
args
,
inArgs
,
outArgs
);
return
(
int
)
ret
;
return
(
int
)
ret
;
}
}
...
@@ -49,7 +49,7 @@ namespace NLuaTest.Mock
...
@@ -49,7 +49,7 @@ namespace NLuaTest.Mock
object
[]
inArgs
=
new
object
[]
{
a
};
object
[]
inArgs
=
new
object
[]
{
a
};
int
[]
outArgs
=
new
int
[]
{
1
};
int
[]
outArgs
=
new
int
[]
{
1
};
object
ret
=
base
.
c
allFunction
(
args
,
inArgs
,
outArgs
);
object
ret
=
base
.
C
allFunction
(
args
,
inArgs
,
outArgs
);
b
=
(
int
)
args
[
1
];
b
=
(
int
)
args
[
1
];
return
(
int
)
ret
;
return
(
int
)
ret
;
...
@@ -64,7 +64,7 @@ namespace NLuaTest.Mock
...
@@ -64,7 +64,7 @@ namespace NLuaTest.Mock
object
[]
inArgs
=
new
object
[]
{
a
,
b
};
object
[]
inArgs
=
new
object
[]
{
a
,
b
};
int
[]
outArgs
=
new
int
[]
{
1
};
int
[]
outArgs
=
new
int
[]
{
1
};
base
.
c
allFunction
(
args
,
inArgs
,
outArgs
);
base
.
C
allFunction
(
args
,
inArgs
,
outArgs
);
b
=
(
int
)
args
[
1
];
b
=
(
int
)
args
[
1
];
}
}
...
@@ -78,7 +78,7 @@ namespace NLuaTest.Mock
...
@@ -78,7 +78,7 @@ namespace NLuaTest.Mock
object
[]
inArgs
=
new
object
[]
{
a
,
b
};
object
[]
inArgs
=
new
object
[]
{
a
,
b
};
int
[]
outArgs
=
new
int
[]
{
};
int
[]
outArgs
=
new
int
[]
{
};
object
ret
=
base
.
c
allFunction
(
args
,
inArgs
,
outArgs
);
object
ret
=
base
.
C
allFunction
(
args
,
inArgs
,
outArgs
);
return
(
TestClass
)
ret
;
return
(
TestClass
)
ret
;
}
}
...
@@ -92,7 +92,7 @@ namespace NLuaTest.Mock
...
@@ -92,7 +92,7 @@ namespace NLuaTest.Mock
object
[]
inArgs
=
new
object
[]
{
a
,
b
};
object
[]
inArgs
=
new
object
[]
{
a
,
b
};
int
[]
outArgs
=
new
int
[]
{
};
int
[]
outArgs
=
new
int
[]
{
};
object
ret
=
base
.
c
allFunction
(
args
,
inArgs
,
outArgs
);
object
ret
=
base
.
C
allFunction
(
args
,
inArgs
,
outArgs
);
return
(
int
)
ret
;
return
(
int
)
ret
;
}
}
...
@@ -106,7 +106,7 @@ namespace NLuaTest.Mock
...
@@ -106,7 +106,7 @@ namespace NLuaTest.Mock
object
[]
inArgs
=
new
object
[]
{
a
};
object
[]
inArgs
=
new
object
[]
{
a
};
int
[]
outArgs
=
new
int
[]
{
1
};
int
[]
outArgs
=
new
int
[]
{
1
};
object
ret
=
base
.
c
allFunction
(
args
,
inArgs
,
outArgs
);
object
ret
=
base
.
C
allFunction
(
args
,
inArgs
,
outArgs
);
b
=
(
TestClass
)
args
[
1
];
b
=
(
TestClass
)
args
[
1
];
return
(
int
)
ret
;
return
(
int
)
ret
;
...
@@ -121,7 +121,7 @@ namespace NLuaTest.Mock
...
@@ -121,7 +121,7 @@ namespace NLuaTest.Mock
object
[]
inArgs
=
new
object
[]
{
a
,
b
};
object
[]
inArgs
=
new
object
[]
{
a
,
b
};
int
[]
outArgs
=
new
int
[]
{
1
};
int
[]
outArgs
=
new
int
[]
{
1
};
base
.
c
allFunction
(
args
,
inArgs
,
outArgs
);
base
.
C
allFunction
(
args
,
inArgs
,
outArgs
);
b
=
(
TestClass
)
args
[
1
];
b
=
(
TestClass
)
args
[
1
];
}
}
...
...
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