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
ea33713d
Commit
ea33713d
authored
Jun 23, 2013
by
Vinicius Jarina
Browse files
Removing Gendarme Warnings.
parent
769c8950
Changes
16
Show whitespace changes
Inline
Side-by-side
KeraLua
@
df2cee88
Compare
a64268ad
...
df2cee88
Subproject commit
a64268ad3f8513dca48d2eabd4c8c5db7fa90798
Subproject commit
df2cee885786733e6397a4f8db0a05f9aa176111
KopiLua
@
3bf5dade
Compare
fd01e109
...
3bf5dade
Subproject commit
fd01e1094246498dbe22180f3f60019540e18f76
Subproject commit
3bf5dade6bdf3f86e5d6d0157bcf7cbee63c8d24
Core/NLua/CheckType.cs
View file @
ea33713d
...
...
@@ -95,7 +95,7 @@ namespace NLua
return
extractValues
.
ContainsKey
(
extractKey
)
?
extractValues
[
extractKey
]
:
extractNetObject
;
}
internal
ExtractValue
checkType
(
LuaCore
.
l
ua
_
State
luaState
,
int
stackPos
,
Type
paramType
)
internal
ExtractValue
checkType
(
LuaCore
.
L
uaState
luaState
,
int
stackPos
,
Type
paramType
)
{
var
luatype
=
LuaLib
.
lua_type
(
luaState
,
stackPos
);
...
...
@@ -189,7 +189,7 @@ namespace NLua
* index stackPos as the desired type if it can, or null
* otherwise.
*/
private
object
getAsSbyte
(
LuaCore
.
l
ua
_
State
luaState
,
int
stackPos
)
private
object
getAsSbyte
(
LuaCore
.
L
uaState
luaState
,
int
stackPos
)
{
sbyte
retVal
=
(
sbyte
)
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
...
...
@@ -198,7 +198,7 @@ namespace NLua
return
retVal
;
}
private
object
getAsByte
(
LuaCore
.
l
ua
_
State
luaState
,
int
stackPos
)
private
object
getAsByte
(
LuaCore
.
L
uaState
luaState
,
int
stackPos
)
{
byte
retVal
=
(
byte
)
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
...
...
@@ -207,7 +207,7 @@ namespace NLua
return
retVal
;
}
private
object
getAsShort
(
LuaCore
.
l
ua
_
State
luaState
,
int
stackPos
)
private
object
getAsShort
(
LuaCore
.
L
uaState
luaState
,
int
stackPos
)
{
short
retVal
=
(
short
)
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
...
...
@@ -216,7 +216,7 @@ namespace NLua
return
retVal
;
}
private
object
getAsUshort
(
LuaCore
.
l
ua
_
State
luaState
,
int
stackPos
)
private
object
getAsUshort
(
LuaCore
.
L
uaState
luaState
,
int
stackPos
)
{
ushort
retVal
=
(
ushort
)
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
...
...
@@ -225,7 +225,7 @@ namespace NLua
return
retVal
;
}
private
object
getAsInt
(
LuaCore
.
l
ua
_
State
luaState
,
int
stackPos
)
private
object
getAsInt
(
LuaCore
.
L
uaState
luaState
,
int
stackPos
)
{
int
retVal
=
(
int
)
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
...
...
@@ -234,7 +234,7 @@ namespace NLua
return
retVal
;
}
private
object
getAsUint
(
LuaCore
.
l
ua
_
State
luaState
,
int
stackPos
)
private
object
getAsUint
(
LuaCore
.
L
uaState
luaState
,
int
stackPos
)
{
uint
retVal
=
(
uint
)
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
...
...
@@ -243,7 +243,7 @@ namespace NLua
return
retVal
;
}
private
object
getAsLong
(
LuaCore
.
l
ua
_
State
luaState
,
int
stackPos
)
private
object
getAsLong
(
LuaCore
.
L
uaState
luaState
,
int
stackPos
)
{
long
retVal
=
(
long
)
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
...
...
@@ -252,7 +252,7 @@ namespace NLua
return
retVal
;
}
private
object
getAsUlong
(
LuaCore
.
l
ua
_
State
luaState
,
int
stackPos
)
private
object
getAsUlong
(
LuaCore
.
L
uaState
luaState
,
int
stackPos
)
{
ulong
retVal
=
(
ulong
)
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
...
...
@@ -261,7 +261,7 @@ namespace NLua
return
retVal
;
}
private
object
getAsDouble
(
LuaCore
.
l
ua
_
State
luaState
,
int
stackPos
)
private
object
getAsDouble
(
LuaCore
.
L
uaState
luaState
,
int
stackPos
)
{
double
retVal
=
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
...
...
@@ -270,7 +270,7 @@ namespace NLua
return
retVal
;
}
private
object
getAsChar
(
LuaCore
.
l
ua
_
State
luaState
,
int
stackPos
)
private
object
getAsChar
(
LuaCore
.
L
uaState
luaState
,
int
stackPos
)
{
char
retVal
=
(
char
)
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
...
...
@@ -279,7 +279,7 @@ namespace NLua
return
retVal
;
}
private
object
getAsFloat
(
LuaCore
.
l
ua
_
State
luaState
,
int
stackPos
)
private
object
getAsFloat
(
LuaCore
.
L
uaState
luaState
,
int
stackPos
)
{
float
retVal
=
(
float
)
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
...
...
@@ -288,7 +288,7 @@ namespace NLua
return
retVal
;
}
private
object
getAsDecimal
(
LuaCore
.
l
ua
_
State
luaState
,
int
stackPos
)
private
object
getAsDecimal
(
LuaCore
.
L
uaState
luaState
,
int
stackPos
)
{
decimal
retVal
=
(
decimal
)
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
...
...
@@ -297,12 +297,12 @@ namespace NLua
return
retVal
;
}
private
object
getAsBoolean
(
LuaCore
.
l
ua
_
State
luaState
,
int
stackPos
)
private
object
getAsBoolean
(
LuaCore
.
L
uaState
luaState
,
int
stackPos
)
{
return
LuaLib
.
lua_toboolean
(
luaState
,
stackPos
);
}
private
object
getAsString
(
LuaCore
.
l
ua
_
State
luaState
,
int
stackPos
)
private
object
getAsString
(
LuaCore
.
L
uaState
luaState
,
int
stackPos
)
{
string
retVal
=
LuaLib
.
lua_tostring
(
luaState
,
stackPos
).
ToString
();
if
(
retVal
==
string
.
Empty
&&
!
LuaLib
.
lua_isstring
(
luaState
,
stackPos
))
...
...
@@ -311,22 +311,22 @@ namespace NLua
return
retVal
;
}
private
object
getAsTable
(
LuaCore
.
l
ua
_
State
luaState
,
int
stackPos
)
private
object
getAsTable
(
LuaCore
.
L
uaState
luaState
,
int
stackPos
)
{
return
translator
.
getTable
(
luaState
,
stackPos
);
}
private
object
getAsFunction
(
LuaCore
.
l
ua
_
State
luaState
,
int
stackPos
)
private
object
getAsFunction
(
LuaCore
.
L
uaState
luaState
,
int
stackPos
)
{
return
translator
.
getFunction
(
luaState
,
stackPos
);
}
private
object
getAsUserdata
(
LuaCore
.
l
ua
_
State
luaState
,
int
stackPos
)
private
object
getAsUserdata
(
LuaCore
.
L
uaState
luaState
,
int
stackPos
)
{
return
translator
.
getUserData
(
luaState
,
stackPos
);
}
public
object
getAsObject
(
LuaCore
.
l
ua
_
State
luaState
,
int
stackPos
)
public
object
getAsObject
(
LuaCore
.
L
uaState
luaState
,
int
stackPos
)
{
if
(
LuaLib
.
lua_type
(
luaState
,
stackPos
)
==
LuaTypes
.
Table
)
{
if
(
LuaLib
.
luaL_getmetafield
(
luaState
,
stackPos
,
"__index"
))
{
...
...
@@ -342,7 +342,7 @@ namespace NLua
return
obj
;
}
public
object
getAsNetObject
(
LuaCore
.
l
ua
_
State
luaState
,
int
stackPos
)
public
object
getAsNetObject
(
LuaCore
.
L
uaState
luaState
,
int
stackPos
)
{
object
obj
=
translator
.
getNetObject
(
luaState
,
stackPos
);
...
...
Core/NLua/Event/DebugHookEventArgs.cs
View file @
ea33713d
...
...
@@ -39,14 +39,14 @@ namespace NLua.Event
/// <author>Reinhard Ostermeier</author>
public
class
DebugHookEventArgs
:
EventArgs
{
private
readonly
LuaCore
.
l
ua
_
Debug
luaDebug
;
private
readonly
LuaCore
.
L
uaDebug
luaDebug
;
public
DebugHookEventArgs
(
LuaCore
.
l
ua
_
Debug
luaDebug
)
public
DebugHookEventArgs
(
LuaCore
.
L
uaDebug
luaDebug
)
{
this
.
luaDebug
=
luaDebug
;
}
public
LuaCore
.
l
ua
_
Debug
LuaDebug
{
public
LuaCore
.
L
uaDebug
LuaDebug
{
get
{
return
luaDebug
;
}
}
}
...
...
Core/NLua/GenerateEventAssembly/ClassGenerator.cs
View file @
ea33713d
...
...
@@ -50,7 +50,7 @@ namespace NLua
this
.
klass
=
klass
;
}
public
object
extractGenerated
(
LuaCore
.
l
ua
_
State
luaState
,
int
stackPos
)
public
object
extractGenerated
(
LuaCore
.
L
uaState
luaState
,
int
stackPos
)
{
return
CodeGeneration
.
Instance
.
GetClassInstance
(
klass
,
translator
.
getTable
(
luaState
,
stackPos
));
}
...
...
Core/NLua/GenerateEventAssembly/DelegateGenerator.cs
View file @
ea33713d
...
...
@@ -51,7 +51,7 @@ namespace NLua
this
.
delegateType
=
delegateType
;
}
public
object
extractGenerated
(
LuaCore
.
l
ua
_
State
luaState
,
int
stackPos
)
public
object
extractGenerated
(
LuaCore
.
L
uaState
luaState
,
int
stackPos
)
{
return
CodeGeneration
.
Instance
.
GetDelegate
(
delegateType
,
translator
.
getFunction
(
luaState
,
stackPos
));
}
...
...
Core/NLua/Lua.cs
View file @
ea33713d
...
...
@@ -75,19 +75,19 @@ namespace NLua
/// lua hook calback delegate
/// </summary>
/// <author>Reinhard Ostermeier</author>
private
LuaCore
.
l
ua
_
Hook
hookCallback
=
null
;
private
LuaCore
.
L
uaHook
hookCallback
=
null
;
#
endregion
#
region
Globals
auto
-
complete
private
readonly
List
<
string
>
globals
=
new
List
<
string
>
();
private
bool
globalsSorted
;
#
endregion
private
/*readonly */
LuaCore
.
l
ua
_
State
luaState
;
private
/*readonly */
LuaCore
.
L
uaState
luaState
;
/// <summary>
/// True while a script is being executed
/// </summary>
public
bool
IsExecuting
{
get
{
return
executing
;
}
}
private
LuaCore
.
l
ua
_C
Function
panicCallback
;
private
LuaCore
.
L
ua
Native
Function
panicCallback
;
private
ObjectTranslator
translator
;
/// <summary>
/// Used to ensure multiple .net threads all get serialized by this single lock for access to the lua stack/objects
...
...
@@ -267,14 +267,14 @@ end
LuaLib
.
luaL_openlibs
(
luaState
);
// steffenj: Lua 5.1.1 API change (luaopen_base is gone, just open all libs right here)
Init
(
luaState
);
// We need to keep this in a managed reference so the delegate doesn't get garbage collected
panicCallback
=
new
LuaCore
.
l
ua
_C
Function
(
PanicCallback
);
panicCallback
=
new
LuaCore
.
L
ua
Native
Function
(
PanicCallback
);
LuaLib
.
lua_atpanic
(
luaState
,
panicCallback
);
}
/*
* CAUTION: NLua.Lua instances can't share the same lua state!
*/
public
Lua
(
LuaCore
.
l
ua
_
State
lState
)
public
Lua
(
LuaCore
.
L
uaState
lState
)
{
LuaLib
.
lua_pushstring
(
lState
,
"LUAINTERFACE LOADED"
);
LuaLib
.
lua_gettable
(
lState
,
(
int
)
LuaIndexes
.
Registry
);
...
...
@@ -290,7 +290,7 @@ end
}
}
void
Init
(
LuaCore
.
l
ua
_
State
luaState
)
void
Init
(
LuaCore
.
L
uaState
luaState
)
{
LuaLib
.
lua_pushstring
(
luaState
,
"LUAINTERFACE LOADED"
);
LuaLib
.
lua_pushboolean
(
luaState
,
true
);
...
...
@@ -317,17 +317,17 @@ end
return
;
if
(!
luaState
.
IsNull
())
{
LuaCore
.
l
ua
_c
lose
(
luaState
);
LuaCore
.
L
ua
C
lose
(
luaState
);
ObjectTranslatorPool
.
Instance
.
Remove
(
luaState
);
}
//luaState = LuaCore.
l
ua
_
State.Zero; <- suggested by Christopher Cebulski http://luaforge.net/forum/forum.php?thread_id = 44593&forum_id = 146
//luaState = LuaCore.
L
uaState.Zero; <- suggested by Christopher Cebulski http://luaforge.net/forum/forum.php?thread_id = 44593&forum_id = 146
}
#if MONOTOUCH
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
static
int
PanicCallback
(
LuaCore
.
l
ua
_
State
luaState
)
static
int
PanicCallback
(
LuaCore
.
L
uaState
luaState
)
{
string
reason
=
string
.
Format
(
"unprotected error in call to Lua API ({0})"
,
LuaLib
.
lua_tostring
(
luaState
,
-
1
));
throw
new
LuaException
(
reason
);
...
...
@@ -582,7 +582,7 @@ end
private
void
registerGlobal
(
string
path
,
Type
type
,
int
recursionCounter
)
{
// If the type is a global method, list it directly
if
(
type
==
typeof
(
LuaCore
.
l
ua
_C
Function
))
{
if
(
type
==
typeof
(
LuaCore
.
L
ua
Native
Function
))
{
// Format for easy method invocation
globals
.
Add
(
path
+
"("
);
}
...
...
@@ -704,7 +704,7 @@ end
public
LuaFunction
GetFunction
(
string
fullPath
)
{
object
obj
=
this
[
fullPath
];
return
(
obj
is
LuaCore
.
l
ua
_C
Function
?
new
LuaFunction
((
LuaCore
.
l
ua
_C
Function
)
obj
,
this
)
:
(
LuaFunction
)
obj
);
return
(
obj
is
LuaCore
.
L
ua
Native
Function
?
new
LuaFunction
((
LuaCore
.
L
ua
Native
Function
)
obj
,
this
)
:
(
LuaFunction
)
obj
);
}
/*
...
...
@@ -852,8 +852,8 @@ end
public
int
SetDebugHook
(
EventMasks
mask
,
int
count
)
{
if
(
hookCallback
.
IsNull
())
{
hookCallback
=
new
LuaCore
.
l
ua
_
Hook
(
Lua
.
DebugHookCallback
);
return
LuaCore
.
l
ua
_s
et
h
ook
(
luaState
,
hookCallback
,
(
int
)
mask
,
count
);
hookCallback
=
new
LuaCore
.
L
uaHook
(
Lua
.
DebugHookCallback
);
return
LuaCore
.
L
ua
S
et
H
ook
(
luaState
,
hookCallback
,
(
int
)
mask
,
count
);
}
return
-
1
;
...
...
@@ -867,7 +867,7 @@ end
public
int
RemoveDebugHook
()
{
hookCallback
=
null
;
return
LuaCore
.
l
ua
_s
et
h
ook
(
luaState
,
null
,
0
,
0
);
return
LuaCore
.
L
ua
S
et
H
ook
(
luaState
,
null
,
0
,
0
);
}
/// <summary>
...
...
@@ -877,7 +877,7 @@ end
/// <author>Reinhard Ostermeier</author>
public
EventMasks
GetHookMask
()
{
return
(
EventMasks
)
LuaCore
.
l
ua
_g
et
h
ook
m
ask
(
luaState
);
return
(
EventMasks
)
LuaCore
.
L
ua
G
et
H
ook
M
ask
(
luaState
);
}
/// <summary>
...
...
@@ -887,7 +887,7 @@ end
/// <author>Reinhard Ostermeier</author>
public
int
GetHookCount
()
{
return
LuaCore
.
l
ua
_g
et
h
ook
c
ount
(
luaState
);
return
LuaCore
.
L
ua
G
et
H
ook
C
ount
(
luaState
);
}
/// <summary>
...
...
@@ -900,7 +900,7 @@ end
/*public bool GetStack(int level, out LuaCore.lua_Debug luaDebug)
{
luaDebug = new LuaDebug();
LuaCore.
l
ua
_
State ld = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(luaDebug));
LuaCore.
L
uaState ld = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(luaDebug));
System.Runtime.InteropServices.Marshal.StructureToPtr(luaDebug, ld, false);
try
{
...
...
@@ -922,7 +922,7 @@ end
/// <author>Reinhard Ostermeier</author>
/*public int GetInfo(String what, ref LuaCore.lua_Debug luaDebug)
{
LuaCore.
l
ua
_
State ld = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(luaDebug));
LuaCore.
L
uaState ld = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(luaDebug));
System.Runtime.InteropServices.Marshal.StructureToPtr(luaDebug, ld, false);
try
{
...
...
@@ -942,9 +942,9 @@ end
/// <param name = "n">see lua docs</param>
/// <returns>see lua docs</returns>
/// <author>Reinhard Ostermeier</author>
public
string
GetLocal
(
LuaCore
.
l
ua
_
Debug
luaDebug
,
int
n
)
public
string
GetLocal
(
LuaCore
.
L
uaDebug
luaDebug
,
int
n
)
{
return
LuaCore
.
l
ua
_g
et
l
ocal
(
luaState
,
luaDebug
,
n
).
ToString
();
return
LuaCore
.
L
ua
G
et
L
ocal
(
luaState
,
luaDebug
,
n
).
ToString
();
}
/// <summary>
...
...
@@ -954,9 +954,9 @@ end
/// <param name = "n">see lua docs</param>
/// <returns>see lua docs</returns>
/// <author>Reinhard Ostermeier</author>
public
string
SetLocal
(
LuaCore
.
l
ua
_
Debug
luaDebug
,
int
n
)
public
string
SetLocal
(
LuaCore
.
L
uaDebug
luaDebug
,
int
n
)
{
return
LuaCore
.
l
ua
_s
et
l
ocal
(
luaState
,
luaDebug
,
n
).
ToString
();
return
LuaCore
.
L
ua
S
et
L
ocal
(
luaState
,
luaDebug
,
n
).
ToString
();
}
/// <summary>
...
...
@@ -968,7 +968,7 @@ end
/// <author>Reinhard Ostermeier</author>
public
string
GetUpValue
(
int
funcindex
,
int
n
)
{
return
LuaCore
.
l
ua
_getupv
alue
(
luaState
,
funcindex
,
n
).
ToString
();
return
LuaCore
.
L
ua
GetUpV
alue
(
luaState
,
funcindex
,
n
).
ToString
();
}
/// <summary>
...
...
@@ -980,7 +980,7 @@ end
/// <author>Reinhard Ostermeier</author>
public
string
SetUpValue
(
int
funcindex
,
int
n
)
{
return
LuaCore
.
l
ua
_setupv
alue
(
luaState
,
funcindex
,
n
).
ToString
();
return
LuaCore
.
L
ua
SetUpV
alue
(
luaState
,
funcindex
,
n
).
ToString
();
}
/// <summary>
...
...
@@ -994,7 +994,7 @@ end
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_Hook
))]
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
private
static
void
DebugHookCallback
(
LuaCore
.
l
ua
_
State
luaState
,
LuaCore
.
l
ua
_
Debug
luaDebug
)
private
static
void
DebugHookCallback
(
LuaCore
.
L
uaState
luaState
,
LuaCore
.
L
uaDebug
luaDebug
)
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
lua
=
translator
.
Interpreter
;
...
...
@@ -1002,7 +1002,7 @@ end
lua
.
DebugHookCallbackInternal
(
luaState
,
luaDebug
);
}
private
void
DebugHookCallbackInternal
(
LuaCore
.
l
ua
_
State
luaState
,
LuaCore
.
l
ua
_
Debug
luaDebug
)
private
void
DebugHookCallbackInternal
(
LuaCore
.
L
uaState
luaState
,
LuaCore
.
L
uaDebug
luaDebug
)
{
try
{
var
temp
=
DebugHook
;
...
...
@@ -1131,7 +1131,7 @@ end
// We leave nothing on the stack when we are done
int
oldTop
=
LuaLib
.
lua_gettop
(
luaState
);
var
wrapper
=
new
LuaMethodWrapper
(
translator
,
target
,
function
.
DeclaringType
,
function
);
translator
.
push
(
luaState
,
new
LuaCore
.
l
ua
_C
Function
(
wrapper
.
invokeFunction
));
translator
.
push
(
luaState
,
new
LuaCore
.
L
ua
Native
Function
(
wrapper
.
invokeFunction
));
this
[
path
]
=
translator
.
getObject
(
luaState
,
-
1
);
var
f
=
GetFunction
(
path
);
LuaLib
.
lua_settop
(
luaState
,
oldTop
);
...
...
@@ -1151,7 +1151,7 @@ end
return
(
equal
!=
0
);
}
internal
void
pushCSFunction
(
LuaCore
.
l
ua
_C
Function
function
)
internal
void
pushCSFunction
(
LuaCore
.
L
ua
Native
Function
function
)
{
translator
.
pushFunction
(
luaState
,
function
);
}
...
...
Core/NLua/LuaFunction.cs
View file @
ea33713d
...
...
@@ -37,7 +37,7 @@ namespace NLua
public
class
LuaFunction
:
LuaBase
{
internal
LuaCore
.
l
ua
_C
Function
function
;
internal
LuaCore
.
L
ua
Native
Function
function
;
public
LuaFunction
(
int
reference
,
Lua
interpreter
)
{
...
...
@@ -46,7 +46,7 @@ namespace NLua
_Interpreter
=
interpreter
;
}
public
LuaFunction
(
LuaCore
.
l
ua
_C
Function
function
,
Lua
interpreter
)
public
LuaFunction
(
LuaCore
.
L
ua
Native
Function
function
,
Lua
interpreter
)
{
_Reference
=
0
;
this
.
function
=
function
;
...
...
@@ -74,7 +74,7 @@ namespace NLua
/*
* Pushes the function into the Lua stack
*/
internal
void
push
(
LuaCore
.
l
ua
_
State
luaState
)
internal
void
push
(
LuaCore
.
L
uaState
luaState
)
{
if
(
_Reference
!=
0
)
LuaLib
.
lua_getref
(
luaState
,
_Reference
);
...
...
Core/NLua/LuaLib/LuaIndexes.cs
View file @
ea33713d
...
...
@@ -41,7 +41,7 @@ namespace NLua
{
if
(
registryIndex
!=
0
)
return
registryIndex
;
registryIndex
=
LuaCore
.
l
ua
n
et
_r
egistry
i
ndex
();
registryIndex
=
LuaCore
.
L
ua
N
et
R
egistry
I
ndex
();
return
registryIndex
;
}
}
...
...
Core/NLua/LuaLib/LuaLib.cs
View file @
ea33713d
...
...
@@ -39,56 +39,56 @@ namespace NLua
public
class
LuaLib
{
// steffenj: BEGIN additional Lua API functions new in Lua 5.1
public
static
int
lua_gc
(
LuaCore
.
l
ua
_
State
luaState
,
GCOptions
what
,
int
data
)
public
static
int
lua_gc
(
LuaCore
.
L
uaState
luaState
,
GCOptions
what
,
int
data
)
{
return
LuaCore
.
l
ua
_gc
(
luaState
,
(
int
)
what
,
data
);
return
LuaCore
.
L
ua
GC
(
luaState
,
(
int
)
what
,
data
);
}
public
static
string
lua_typename
(
LuaCore
.
l
ua
_
State
luaState
,
LuaTypes
type
)
public
static
string
lua_typename
(
LuaCore
.
L
uaState
luaState
,
LuaTypes
type
)
{
return
LuaCore
.
l
ua
_t
ype
n
ame
(
luaState
,
(
int
)
type
).
ToString
();
return
LuaCore
.
L
ua
T
ype
N
ame
(
luaState
,
(
int
)
type
).
ToString
();
}
public
static
string
luaL_typename
(
LuaCore
.
l
ua
_
State
luaState
,
int
stackPos
)
public
static
string
luaL_typename
(
LuaCore
.
L
uaState
luaState
,
int
stackPos
)
{
return
lua_typename
(
luaState
,
lua_type
(
luaState
,
stackPos
));
}
public
static
void
luaL_error
(
LuaCore
.
l
ua
_
State
luaState
,
string
message
)
public
static
void
luaL_error
(
LuaCore
.
L
uaState
luaState
,
string
message
)
{
LuaCore
.
l
uaL
_e
rror
(
luaState
,
message
);
LuaCore
.
L
uaL
E
rror
(
luaState
,
message
);
}
public
static
void
luaL_where
(
LuaCore
.
l
ua
_
State
luaState
,
int
level
)
public
static
void
luaL_where
(
LuaCore
.
L
uaState
luaState
,
int
level
)
{
LuaCore
.
l
uaL
_w
here
(
luaState
,
level
);
LuaCore
.
L
uaL
W
here
(
luaState
,
level
);
}
// steffenj: BEGIN Lua 5.1.1 API change (lua_open replaced by luaL_newstate)
public
static
LuaCore
.
l
ua
_
State
luaL_newstate
()
public
static
LuaCore
.
L
uaState
luaL_newstate
()
{
return
LuaCore
.
l
uaL
_n
ew
s
tate
();
return
LuaCore
.
L
uaL
N
ew
S
tate
();
}
// steffenj: BEGIN Lua 5.1.1 API change (new function luaL_openlibs)
public
static
void
luaL_openlibs
(
LuaCore
.
l
ua
_
State
luaState
)
public
static
void
luaL_openlibs
(
LuaCore
.
L
uaState
luaState
)
{
LuaCore
.
l
uaL
_o
pen
l
ibs
(
luaState
);
LuaCore
.
L
uaL
O
pen
L
ibs
(
luaState
);
}
// steffenj: END Lua 5.1.1 API change (lua_strlen is now lua_objlen)
// steffenj: BEGIN Lua 5.1.1 API change (lua_dostring is now a macro luaL_dostring)
public
static
int
luaL_loadstring
(
LuaCore
.
l
ua
_
State
luaState
,
string
chunk
)
public
static
int
luaL_loadstring
(
LuaCore
.
L
uaState
luaState
,
string
chunk
)
{
return
LuaCore
.
l
uaL
_l
oad
s
tring
(
luaState
,
chunk
);
return
LuaCore
.
L
uaL
L
oad
S
tring
(
luaState
,
chunk
);
}
public
static
int
luaL_loadstring
(
LuaCore
.
l
ua
_
State
luaState
,
byte
[]
chunk
)
public
static
int
luaL_loadstring
(
LuaCore
.
L
uaState
luaState
,
byte
[]
chunk
)
{
return
LuaCore
.
l
uaL
_l
oad
s
tring
(
luaState
,
chunk
);
return
LuaCore
.
L
uaL
L
oad
S
tring
(
luaState
,
chunk
);
}
public
static
int
luaL_dostring
(
LuaCore
.
l
ua
_
State
luaState
,
string
chunk
)
public
static
int
luaL_dostring
(
LuaCore
.
L
uaState
luaState
,
string
chunk
)
{
int
result
=
luaL_loadstring
(
luaState
,
chunk
);
if
(
result
!=
0
)
...
...
@@ -97,7 +97,7 @@ namespace NLua
return
lua_pcall
(
luaState
,
0
,
-
1
,
0
);
}
public
static
int
luaL_dostring
(
LuaCore
.
l
ua
_
State
luaState
,
byte
[]
chunk
)
public
static
int
luaL_dostring
(
LuaCore
.
L
uaState
luaState
,
byte
[]
chunk
)
{
int
result
=
luaL_loadstring
(
luaState
,
chunk
);
if
(
result
!=
0
)
...
...
@@ -106,221 +106,221 @@ namespace NLua
return
lua_pcall
(
luaState
,
0
,
-
1
,
0
);
}
/// <summary>DEPRECATED - use luaL_dostring(LuaCore.
l
ua
_
State luaState, string chunk) instead!</summary>
public
static
int
lua_dostring
(
LuaCore
.
l
ua
_
State
luaState
,
string
chunk
)
/// <summary>DEPRECATED - use luaL_dostring(LuaCore.
L
uaState luaState, string chunk) instead!</summary>
public
static
int
lua_dostring
(
LuaCore
.
L
uaState
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
(
LuaCore
.
l
ua
_
State
luaState
,
int
narr
,
int
nrec
)
public
static
void
lua_createtable
(
LuaCore
.
L
uaState
luaState
,
int
narr
,
int
nrec
)
{
LuaCore
.
l
ua
_c
reate
t
able
(
luaState
,
narr
,
nrec
);
LuaCore
.
L
ua
C
reate
T
able
(
luaState
,
narr
,
nrec
);
}
public
static
void
lua_newtable
(
LuaCore
.
l
ua
_
State
luaState
)
public
static
void
lua_newtable
(
LuaCore
.
L
uaState
luaState
)
{
lua_createtable
(
luaState
,
0
,
0
);
}
// steffenj: END Lua 5.1.1 API change (lua_newtable is gone, lua_createtable is new)
// steffenj: BEGIN Lua 5.1.1 API change (lua_dofile now in LuaLib as luaL_dofile macro)
public
static
int
luaL_dofile
(
LuaCore
.
l
ua
_
State
luaState
,
string
fileName
)
public
static
int
luaL_dofile
(
LuaCore
.
L
uaState
luaState
,
string
fileName
)
{
int
result
=
LuaCore
.
l
ua
n
et
_l
oad
f
ile
(
luaState
,
fileName
);
int
result
=
LuaCore
.
L
ua
N
et
L
oad
F
ile
(
luaState
,
fileName
);
if
(
result
!=
0
)
return
result
;
return
LuaCore
.
l
ua
n
et
_pc
all
(
luaState
,
0
,
-
1
,
0
);
return
LuaCore
.
L
ua
N
et
PC
all
(
luaState
,
0
,
-
1
,
0
);
}
public
static
void
lua_getglobal
(
LuaCore
.
l
ua
_
State
luaState
,
string
name
)
public
static
void
lua_getglobal
(
LuaCore
.
L
uaState
luaState
,
string
name
)
{
LuaCore
.
l
ua
n
et
_g
et
g
lobal
(
luaState
,
name
);
LuaCore
.
L
ua
N
et
G
et
G
lobal
(
luaState
,
name
);
}
public
static
void
lua_setglobal
(
LuaCore
.
l
ua
_
State
luaState
,
string
name
)
public
static
void
lua_setglobal
(
LuaCore
.
L
uaState
luaState
,
string
name
)
{
LuaCore
.
l
ua
n
et
_s
et
g
lobal
(
luaState
,
name
);
LuaCore
.
L
ua
N
et
S
et
G
lobal
(
luaState
,
name
);
}
public
static
void
lua_settop
(
LuaCore
.
l
ua
_
State
luaState
,
int
newTop
)
public
static
void
lua_settop
(
LuaCore
.
L
uaState
luaState
,
int
newTop
)
{
LuaCore
.
l
ua
_s
et
t
op
(
luaState
,
newTop
);
LuaCore
.
L
ua
S
et
T
op
(
luaState
,
newTop
);
}
public
static
void
lua_pop
(
LuaCore
.
l
ua
_
State
luaState
,
int
amount
)
public
static
void
lua_pop
(
LuaCore
.
L
uaState
luaState
,
int
amount
)
{
lua_settop
(
luaState
,
-(
amount
)
-
1
);
}
public
static
void
lua_insert
(
LuaCore
.
l
ua
_
State
luaState
,
int
newTop
)
public
static
void
lua_insert
(
LuaCore
.
L
uaState
luaState
,
int
newTop
)
{
LuaCore
.
l
ua
_i
nsert
(
luaState
,
newTop
);
LuaCore
.
L
ua
I
nsert
(
luaState
,
newTop
);
}
public
static
void
lua_remove
(
LuaCore
.
l
ua
_
State
luaState
,
int
index
)
public
static
void
lua_remove
(
LuaCore
.
L
uaState
luaState
,
int
index
)
{
LuaCore
.
l
ua
_r
emove
(
luaState
,
index
);
LuaCore
.
L
ua
R
emove
(
luaState
,
index
);
}
public
static
void
lua_gettable
(
LuaCore
.
l
ua
_
State
luaState
,
int
index
)
public
static
void
lua_gettable
(
LuaCore
.
L
uaState
luaState
,
int
index
)
{
LuaCore
.
l
ua
_g
et
t
able
(
luaState
,
index
);
LuaCore
.
L
ua
G
et
T
able
(
luaState
,
index
);
}
public
static
void
lua_rawget
(
LuaCore
.
l
ua
_
State
luaState
,
int
index
)
public
static
void
lua_rawget
(
LuaCore
.
L
uaState
luaState
,
int
index
)
{
LuaCore
.
l
ua
_r
aw
g
et
(
luaState
,
index
);
LuaCore
.
L
ua
R
aw
G
et
(
luaState
,
index
);
}
public
static
void
lua_settable
(
LuaCore
.
l
ua
_
State
luaState
,
int
index
)
public
static
void
lua_settable
(
LuaCore
.
L
uaState
luaState
,
int
index
)
{
LuaCore
.
l
ua
_s
et
t
able
(
luaState
,
index
);
LuaCore
.
L
ua
S
et
T
able
(
luaState
,
index
);
}
public
static
void
lua_rawset
(
LuaCore
.
l
ua
_
State
luaState
,
int
index
)
public
static
void
lua_rawset
(
LuaCore
.
L
uaState
luaState
,
int
index
)
{
LuaCore
.
l
ua
_r
aw
s
et
(
luaState
,
index
);
LuaCore
.
L
ua
R
aw
S
et
(
luaState
,
index
);
}
public
static
void
lua_setmetatable
(
LuaCore
.
l
ua
_
State
luaState
,
int
objIndex
)
public
static
void
lua_setmetatable
(
LuaCore
.
L
uaState
luaState
,
int
objIndex
)
{
LuaCore
.
l
ua
_s
et
m
etatable
(
luaState
,
objIndex
);
LuaCore
.
L
ua
S
et
M
etatable
(
luaState
,
objIndex
);
}
public
static
int
lua_getmetatable
(
LuaCore
.
l
ua
_
State
luaState
,
int
objIndex
)
public
static
int
lua_getmetatable
(
LuaCore
.
L
uaState
luaState
,
int
objIndex
)
{
return
LuaCore
.
l
ua
_g
et
m
etatable
(
luaState
,
objIndex
);
return
LuaCore
.
L
ua
G
et
M
etatable
(
luaState
,
objIndex
);
}
public
static
int
lua_equal
(
LuaCore
.
l
ua
_
State
luaState
,
int
index1
,
int
index2
)
public
static
int
lua_equal
(
LuaCore
.
L
uaState
luaState
,
int
index1
,
int
index2
)
{
return
LuaCore
.
l
ua
_e
qual
(
luaState
,
index1
,
index2
);
return
LuaCore
.
L
ua
NetE
qual
(
luaState
,
index1
,
index2
);
}
public
static
void
lua_pushvalue
(
LuaCore
.
l
ua
_
State
luaState
,
int
index
)
public
static
void
lua_pushvalue
(
LuaCore
.
L
uaState
luaState
,
int
index
)
{
LuaCore
.
l
ua
_p
ush
v
alue
(
luaState
,
index
);
LuaCore
.
L
ua
P
ush
V
alue
(
luaState
,
index
);
}
public
static
void
lua_replace
(
LuaCore
.
l
ua
_
State
luaState
,
int
index
)
public
static
void
lua_replace
(
LuaCore
.
L
uaState
luaState
,
int
index
)
{
LuaCore
.
l
ua
_r
eplace
(
luaState
,
index
);
LuaCore
.
L
ua
R
eplace
(
luaState
,
index
);
}
public
static
int
lua_gettop
(
LuaCore
.
l
ua
_
State
luaState
)
public
static
int
lua_gettop
(
LuaCore
.
L
uaState
luaState
)
{
return
LuaCore
.
l
ua
_g
et
t
op
(
luaState
);
return
LuaCore
.
L
ua
G
et
T
op
(
luaState
);
}
public
static
LuaTypes
lua_type
(
LuaCore
.
l
ua
_
State
luaState
,
int
index
)
public
static
LuaTypes
lua_type
(
LuaCore
.
L
uaState
luaState
,
int
index
)
{
return
(
LuaTypes
)
LuaCore
.
l
ua
_t
ype
(
luaState
,
index
);
return
(
LuaTypes
)
LuaCore
.
L
ua
T
ype
(
luaState
,
index
);
}
public
static
bool
lua_isnil
(
LuaCore
.
l
ua
_
State
luaState
,
int
index
)
public
static
bool
lua_isnil
(
LuaCore
.
L
uaState
luaState
,
int
index
)
{
return
lua_type
(
luaState
,
index
)
==
LuaTypes
.
Nil
;
}
public
static
bool
lua_isnumber
(
LuaCore
.
l
ua
_
State
luaState
,
int
index
)
public
static
bool
lua_isnumber
(
LuaCore
.
L
uaState
luaState
,
int
index
)
{
return
lua_type
(
luaState
,
index
)
==
LuaTypes
.
Number
;
}
public
static
bool
lua_isboolean
(
LuaCore
.
l
ua
_
State
luaState
,
int
index
)
public
static
bool
lua_isboolean
(
LuaCore
.
L
uaState
luaState
,
int
index
)
{
return
lua_type
(
luaState
,
index
)
==
LuaTypes
.
Boolean
;
}
public
static
int
luaL_ref
(
LuaCore
.
l
ua
_
State
luaState
,
int
registryIndex
)
public
static
int
luaL_ref
(
LuaCore
.
L
uaState
luaState
,
int
registryIndex
)
{
return
LuaCore
.
l
uaL
_r
ef
(
luaState
,
registryIndex
);
return
LuaCore
.
L
uaL
R
ef
(
luaState
,
registryIndex
);
}
public
static
int
lua_ref
(
LuaCore
.
l
ua
_
State
luaState
,
int
lockRef
)
public
static
int
lua_ref
(
LuaCore
.
L
uaState
luaState
,
int
lockRef
)
{
return
lockRef
!=
0
?
luaL_ref
(
luaState
,
(
int
)
LuaIndexes
.
Registry
)
:
0
;
}
public
static
void
lua_rawgeti
(
LuaCore
.
l
ua
_
State
luaState
,
int
tableIndex
,
int
index
)
public
static
void
lua_rawgeti
(
LuaCore
.
L
uaState
luaState
,
int
tableIndex
,
int
index
)
{
LuaCore
.
l
ua
_r
aw
g
et
i
(
luaState
,
tableIndex
,
index
);
LuaCore
.
L
ua
R
aw
G
et
I
(
luaState
,
tableIndex
,
index
);
}
public
static
void
lua_rawseti
(
LuaCore
.
l
ua
_
State
luaState
,
int
tableIndex
,
int
index
)
public
static
void
lua_rawseti
(
LuaCore
.
L
uaState
luaState
,
int
tableIndex
,
int
index
)
{
LuaCore
.
l
ua
_r
aw
s
et
i
(
luaState
,
tableIndex
,
index
);
LuaCore
.
L
ua
R
aw
S
et
I
(
luaState
,
tableIndex
,
index
);
}
public
static
object
lua_newuserdata
(
LuaCore
.
l
ua
_
State
luaState
,
int
size
)
public
static
object
lua_newuserdata
(
LuaCore
.
L
uaState
luaState
,
int
size
)
{
return
LuaCore
.
l
ua
_n
ew
u
ser
d
ata
(
luaState
,
(
uint
)
size
);
return
LuaCore
.
L
ua
N
ew
U
ser
D
ata
(
luaState
,
(
uint
)
size
);
}
public
static
object
lua_touserdata
(
LuaCore
.
l
ua
_
State
luaState
,
int
index
)
public
static
object
lua_touserdata
(
LuaCore
.
L
uaState
luaState
,
int
index
)
{
return
LuaCore
.
l
ua
_tou
ser
d
ata
(
luaState
,
index
);
return
LuaCore
.
L
ua
ToU
ser
D
ata
(
luaState
,
index
);
}
public
static
void
lua_getref
(
LuaCore
.
l
ua
_
State
luaState
,
int
reference
)
public
static
void
lua_getref
(
LuaCore
.
L
uaState
luaState
,
int
reference
)
{
lua_rawgeti
(
luaState
,
(
int
)
LuaIndexes
.
Registry
,
reference
);
}
public
static
void
lua_unref
(
LuaCore
.
l
ua
_
State
luaState
,
int
reference
)
public
static
void
lua_unref
(
LuaCore
.
L
uaState
luaState
,
int
reference
)
{
LuaCore
.
l
uaL
_u
nref
(
luaState
,
(
int
)
LuaIndexes
.
Registry
,
reference
);
LuaCore
.
L
uaL
U
nref
(
luaState
,
(
int
)
LuaIndexes
.
Registry
,
reference
);
}
public
static
bool
lua_isstring
(
LuaCore
.
l
ua
_
State
luaState
,
int
index
)
public
static
bool
lua_isstring
(
LuaCore
.
L
uaState
luaState
,
int
index
)
{
return
LuaCore
.
l
ua
_iss
tring
(
luaState
,
index
)
!=
0
;
return
LuaCore
.
L
ua
IsS
tring
(
luaState
,
index
)
!=
0
;
}
public
static
bool
lua_iscfunction
(
LuaCore
.
l
ua
_
State
luaState
,
int
index
)
public
static
bool
lua_iscfunction
(
LuaCore
.
L
uaState
luaState
,
int
index
)
{
return
LuaCore
.
l
ua
_iscf
unction
(
luaState
,
index
);
return
LuaCore
.
L
ua
IsCF
unction
(
luaState
,
index
);
}
public
static
void
lua_pushnil
(
LuaCore
.
l
ua
_
State
luaState
)
public
static
void
lua_pushnil
(
LuaCore
.
L
uaState
luaState
)
{
LuaCore
.
l
ua
_p
ush
n
il
(
luaState
);
LuaCore
.
L
ua
P
ush
N
il
(
luaState
);
}
public
static
void
lua_call
(
LuaCore
.
l
ua
_
State
luaState
,
int
nArgs
,
int
nResults
)
public
static
void
lua_call
(
LuaCore
.
L
uaState
luaState
,
int
nArgs
,
int
nResults
)
{
LuaCore
.
l
ua
_c
all
(
luaState
,
nArgs
,
nResults
);
LuaCore
.
L
ua
C
all
(
luaState
,
nArgs
,
nResults
);
}
public
static
void
lua_pushstdcallcfunction
(
LuaCore
.
l
ua
_
State
luaState
,
LuaCore
.
l
ua
_C
Function
function
)
public
static
void
lua_pushstdcallcfunction
(
LuaCore
.
L
uaState
luaState
,
LuaCore
.
L
ua
Native
Function
function
)
{
LuaCore
.
l
ua
_p
ush
cf
unction
(
luaState
,
function
);
LuaCore
.
L
ua
P
ush
StdCallCF
unction
(
luaState
,
function
);
}
public
static
int
lua_pcall
(
LuaCore
.
l
ua
_
State
luaState
,
int
nArgs
,
int
nResults
,
int
errfunc
)
public
static
int
lua_pcall
(
LuaCore
.
L
uaState
luaState
,
int
nArgs
,
int
nResults
,
int
errfunc
)
{
return
LuaCore
.
l
ua
n
et
_pc
all
(
luaState
,
nArgs
,
nResults
,
errfunc
);
return
LuaCore
.
L
ua
N
et
PC
all
(
luaState
,
nArgs
,
nResults
,
errfunc
);
}
public
static
LuaCore
.
l
ua
_C
Function
lua_tocfunction
(
LuaCore
.
l
ua
_
State
luaState
,
int
index
)
public
static
LuaCore
.
L
ua
Native
Function
lua_tocfunction
(
LuaCore
.
L
uaState
luaState
,
int
index
)
{
return
LuaCore
.
l
ua
_tocf
unction
(
luaState
,
index
);
return
LuaCore
.
L
ua
ToCF
unction
(
luaState
,
index
);
}
public
static
double
lua_tonumber
(
LuaCore
.
l
ua
_
State
luaState
,
int
index
)
public
static
double
lua_tonumber
(
LuaCore
.
L
uaState
luaState
,
int
index
)
{
return
LuaCore
.
l
ua
n
et
_ton
umber
(
luaState
,
index
);
return
LuaCore
.
L
ua
N
et
ToN
umber
(
luaState
,
index
);
}
public
static
bool
lua_toboolean
(
LuaCore
.
l
ua
_
State
luaState
,
int
index
)
public
static
bool
lua_toboolean
(
LuaCore
.
L
uaState
luaState
,
int
index
)
{
return
LuaCore
.
l
ua
_tob
oolean
(
luaState
,
index
)
!=
0
;
return
LuaCore
.
L
ua
ToB
oolean
(
luaState
,
index
)
!=
0
;
}
public
static
string
lua_tostring
(
LuaCore
.
l
ua
_
State
luaState
,
int
index
)
public
static
string
lua_tostring
(
LuaCore
.
L
uaState
luaState
,
int
index
)
{
#if true
// FIXME use the same format string as lua i.e. LUA_NUMBER_FMT
...
...
@@ -336,7 +336,7 @@ namespace NLua
// So we use the ToString method with string length, so it could be checked,
// if string is a binary chunk and if, could transfered to string without
// encoding.
return
LuaCore
.
l
ua
_tols
tring
(
luaState
,
index
,
out
strlen
).
ToString
((
int
)
strlen
);
return
LuaCore
.
L
ua
ToLS
tring
(
luaState
,
index
,
out
strlen
).
ToString
((
int
)
strlen
);
}
else
if
(
t
==
LuaTypes
.
Nil
)
return
null
;
// treat lua nulls to as C# nulls
else
...
...
@@ -354,131 +354,131 @@ namespace NLua
#endif
}
public
static
void
lua_atpanic
(
LuaCore
.
l
ua
_
State
luaState
,
LuaCore
.
l
ua
_C
Function
panicf
)
public
static
void
lua_atpanic
(
LuaCore
.
L
uaState
luaState
,
LuaCore
.
L
ua
Native
Function
panicf
)
{
LuaCore
.
l
ua
_atp
anic
(
luaState
,
(
LuaCore
.
l
ua
_C
Function
)
panicf
);
LuaCore
.
L
ua
AtP
anic
(
luaState
,
(
LuaCore
.
L
ua
Native
Function
)
panicf
);
}
public
static
void
lua_pushnumber
(
LuaCore
.
l
ua
_
State
luaState
,
double
number
)
public
static
void
lua_pushnumber
(
LuaCore
.
L
uaState
luaState
,
double
number
)
{
LuaCore
.
l
ua
_p
ush
n
umber
(
luaState
,
number
);
LuaCore
.
L
ua
P
ush
N
umber
(
luaState
,
number
);
}
public
static
void
lua_pushboolean
(
LuaCore
.
l
ua
_
State
luaState
,
bool
value
)
public
static
void
lua_pushboolean
(
LuaCore
.
L
uaState
luaState
,
bool
value
)
{
LuaCore
.
l
ua
_p
ush
b
oolean
(
luaState
,
value
?
1
:
0
);
LuaCore
.
L
ua
P
ush
B
oolean
(
luaState
,
value
?
1
:
0
);
}
public
static
void
lua_pushstring
(
LuaCore
.
l
ua
_
State
luaState
,
string
str
)
public
static
void
lua_pushstring
(
LuaCore
.
L
uaState
luaState
,
string
str
)
{
LuaCore
.
l
ua
_p
ush
s
tring
(
luaState
,
str
);
LuaCore
.
L
ua
P
ush
S
tring
(
luaState
,
str
);
}
public
static
int
luaL_newmetatable
(
LuaCore
.
l
ua
_
State
luaState
,
string
meta
)
public
static
int
luaL_newmetatable
(
LuaCore
.
L
uaState
luaState
,
string
meta
)
{
return
LuaCore
.
l
uaL
_n
ew
m
etatable
(
luaState
,
meta
);
return
LuaCore
.
L
uaL
N
ew
M
etatable
(
luaState
,
meta
);
}
// steffenj: BEGIN Lua 5.1.1 API change (luaL_getmetatable is now a macro using lua_getfield)
public
static
void
lua_getfield
(
LuaCore
.
l
ua
_
State
luaState
,
int
stackPos
,
string
meta
)
public
static
void
lua_getfield
(
LuaCore
.
L
uaState
luaState
,
int
stackPos
,
string
meta
)
{
LuaCore
.
l
ua
_g
et
f
ield
(
luaState
,
stackPos
,
meta
);
LuaCore
.
L
ua
G
et
F
ield
(
luaState
,
stackPos
,
meta
);
}
public
static
void
luaL_getmetatable
(
LuaCore
.
l
ua
_
State
luaState
,
string
meta
)
public
static
void
luaL_getmetatable
(
LuaCore
.
L
uaState
luaState
,
string
meta
)
{
lua_getfield
(
luaState
,
(
int
)
LuaIndexes
.
Registry
,
meta
);
}
public
static
object
luaL_checkudata
(
LuaCore
.
l
ua
_
State
luaState
,
int
stackPos
,
string
meta
)
public
static
object
luaL_checkudata
(
LuaCore
.
L
uaState
luaState
,
int
stackPos
,
string
meta
)
{
return
LuaCore
.
l
uaL
_c
heck
ud
ata
(
luaState
,
stackPos
,
meta
);
return
LuaCore
.
L
uaL
C
heck
UD
ata
(
luaState
,
stackPos
,
meta
);
}
public
static
bool
luaL_getmetafield
(
LuaCore
.
l
ua
_
State
luaState
,
int
stackPos
,
string
field
)
public
static
bool
luaL_getmetafield
(
LuaCore
.
L
uaState
luaState
,
int
stackPos
,
string
field
)
{
return
LuaCore
.
l
uaL
_g
et
m
etafield
(
luaState
,
stackPos
,
field
)
!=
0
;
return
LuaCore
.
L
uaL
G
et
M
etafield
(
luaState
,
stackPos
,
field
)
!=
0
;
}
public
static
int
luaL_loadbuffer
(
LuaCore
.
l
ua
_
State
luaState
,
string
buff
,
string
name
)
public
static
int
luaL_loadbuffer
(
LuaCore
.
L
uaState
luaState
,
string
buff
,
string
name
)
{
return
LuaCore
.
l
ua
n
et
_l
oad
b
uffer
(
luaState
,
buff
,
(
uint
)
buff
.
Length
,
name
);
return
LuaCore
.
L
ua
N
et
L
oad
B
uffer
(
luaState
,
buff
,
(
uint
)
buff
.
Length
,
name
);
}
public
static
int
luaL_loadbuffer
(
LuaCore
.
l
ua
_
State
luaState
,
byte
[]
buff
,
string
name
)
public
static
int
luaL_loadbuffer
(
LuaCore
.
L
uaState
luaState
,
byte
[]
buff
,
string
name
)
{
return
LuaCore
.
l
ua
n
et
_l
oad
b
uffer
(
luaState
,
buff
,
(
uint
)
buff
.
Length
,
name
);
return
LuaCore
.
L
ua
N
et
L
oad
B
uffer
(
luaState
,
buff
,
(
uint
)
buff
.
Length
,
name
);
}
public
static
int
luaL_loadfile
(
LuaCore
.
l
ua
_
State
luaState
,
string
filename
)
public
static
int
luaL_loadfile
(
LuaCore
.
L
uaState
luaState
,
string
filename
)
{
return
LuaCore
.
l
ua
n
et
_l
oad
f
ile
(
luaState
,
filename
);
return
LuaCore
.
L
ua
N
et
L
oad
F
ile
(
luaState
,
filename
);
}
public
static
bool
luaL_checkmetatable
(
LuaCore
.
l
ua
_
State
luaState
,
int
index
)
public
static
bool
luaL_checkmetatable
(
LuaCore
.
L
uaState
luaState
,
int
index
)
{
return
LuaCore
.
l
uaL
_c
heck
m
etatable
(
luaState
,
index
);
return
LuaCore
.
L
uaL
C
heck
M
etatable
(
luaState
,
index
);
}
public
static
int
luanet_registryindex
()
{
return
LuaCore
.
l
ua
n
et
_r
egistry
i
ndex
();
return
LuaCore
.
L
ua
N
et
R
egistry
I
ndex
();
}
public
static
int
luanet_tonetobject
(
LuaCore
.
l
ua
_
State
luaState
,
int
index
)
public
static
int
luanet_tonetobject
(
LuaCore
.
L
uaState
luaState
,
int
index
)
{
return
LuaCore
.
l
ua
n
et
_ton
et
o
bject
(
luaState
,
index
);
return
LuaCore
.
L
ua
N
et
ToN
et
O
bject
(
luaState
,
index
);
}
public
static
void
luanet_newudata
(
LuaCore
.
l
ua
_
State
luaState
,
int
val
)
public
static
void
luanet_newudata
(
LuaCore
.
L
uaState
luaState
,
int
val
)
{
LuaCore
.
l
ua
n
et
_newud
ata
(
luaState
,
val
);
LuaCore
.
L
ua
N
et
NewUD
ata
(
luaState
,
val
);
}
public
static
int
luanet_rawnetobj
(
LuaCore
.
l
ua
_
State
luaState
,
int
obj
)
public
static
int
luanet_rawnetobj
(
LuaCore
.
L
uaState
luaState
,
int
obj
)
{
return
LuaCore
.
l
ua
n
et
_r
aw
n
et
o
bj
(
luaState
,
obj
);
return
LuaCore
.
L
ua
N
et
R
aw
N
et
O
bj
(
luaState
,
obj
);
}
public
static
int
luanet_checkudata
(
LuaCore
.
l
ua
_
State
luaState
,
int
ud
,
string
tname
)
public
static
int
luanet_checkudata
(
LuaCore
.
L
uaState
luaState
,
int
ud
,
string
tname
)
{
return
LuaCore
.
l
ua
n
et
_c
heck
ud
ata
(
luaState
,
ud
,
tname
);
return
LuaCore
.
L
ua
N
et
C
heck
UD
ata
(
luaState
,
ud
,
tname
);
}
public
static
void
lua_error
(
LuaCore
.
l
ua
_
State
luaState
)
public
static
void
lua_error
(
LuaCore
.
L
uaState
luaState
)
{
LuaCore
.
l
ua
_e
rror
(
luaState
);
LuaCore
.
L
ua
E
rror
(
luaState
);
}
public
static
bool
lua_checkstack
(
LuaCore
.
l
ua
_
State
luaState
,
int
extra
)
public
static
bool
lua_checkstack
(
LuaCore
.
L
uaState
luaState
,
int
extra
)
{
return
LuaCore
.
l
ua
_c
heck
s
tack
(
luaState
,
extra
)
!=
0
;
return
LuaCore
.
L
ua
C
heck
S
tack
(
luaState
,
extra
)
!=
0
;
}
public
static
int
lua_next
(
LuaCore
.
l
ua
_
State
luaState
,
int
index
)
public
static
int
lua_next
(
LuaCore
.
L
uaState
luaState
,
int
index
)
{
return
LuaCore
.
l
ua
_n
ext
(
luaState
,
index
);
return
LuaCore
.
L
ua
N
ext
(
luaState
,
index
);
}
public
static
void
lua_pushlightuserdata
(
LuaCore
.
l
ua
_
State
luaState
,
LuaCore
.
LuaTag
udata
)
public
static
void
lua_pushlightuserdata
(
LuaCore
.
L
uaState
luaState
,
LuaCore
.
LuaTag
udata
)
{
LuaCore
.
l
ua
_p
ush
l
ight
u
ser
d
ata
(
luaState
,
udata
.
Tag
);
LuaCore
.
L
ua
P
ush
L
ight
U
ser
D
ata
(
luaState
,
udata
.
Tag
);
}
public
static
LuaCore
.
LuaTag
luanet_gettag
()
{
return
LuaCore
.
l
ua
n
et
_g
et
t
ag
();
return
LuaCore
.
L
ua
N
et
G
et
T
ag
();
}
public
static
void
luanet_pushglobaltable
(
LuaCore
.
l
ua
_
State
luaState
)
public
static
void
luanet_pushglobaltable
(
LuaCore
.
L
uaState
luaState
)
{
LuaCore
.
l
ua
n
et
_p
ush
g
lobal
t
able
(
luaState
);
LuaCore
.
L
ua
N
et
P
ush
G
lobal
T
able
(
luaState
);
}
public
static
void
luanet_popglobaltable
(
LuaCore
.
l
ua
_
State
luaState
)
public
static
void
luanet_popglobaltable
(
LuaCore
.
L
uaState
luaState
)
{
LuaCore
.
l
ua
n
et
_p
op
g
lobal
t
able
(
luaState
);
LuaCore
.
L
ua
N
et
P
op
G
lobal
T
able
(
luaState
);
}
}
...
...
Core/NLua/LuaTable.cs
View file @
ea33713d
...
...
@@ -100,8 +100,8 @@ namespace NLua
{
object
obj
=
_Interpreter
.
rawGetObject
(
_Reference
,
field
);
if
(
obj
is
LuaCore
.
l
ua
_C
Function
)
return
new
LuaFunction
((
LuaCore
.
l
ua
_C
Function
)
obj
,
_Interpreter
);
if
(
obj
is
LuaCore
.
L
ua
Native
Function
)
return
new
LuaFunction
((
LuaCore
.
L
ua
Native
Function
)
obj
,
_Interpreter
);
else
return
obj
;
}
...
...
@@ -109,7 +109,7 @@ namespace NLua
/*
* Pushes this table into the Lua stack
*/
internal
void
push
(
LuaCore
.
l
ua
_
State
luaState
)
internal
void
push
(
LuaCore
.
L
uaState
luaState
)
{
LuaLib
.
lua_getref
(
luaState
,
_Reference
);
}
...
...
Core/NLua/LuaUserData.cs
View file @
ea33713d
...
...
@@ -79,7 +79,7 @@ namespace NLua
/*
* Pushes the userdata into the Lua stack
*/
internal
void
push
(
LuaCore
.
l
ua
_
State
luaState
)
internal
void
push
(
LuaCore
.
L
uaState
luaState
)
{
LuaLib
.
lua_getref
(
luaState
,
_Reference
);
}
...
...
Core/NLua/Metatables.cs
View file @
ea33713d
...
...
@@ -49,7 +49,7 @@ namespace NLua
*/
public
class
MetaFunctions
{
internal
LuaCore
.
l
ua
_C
Function
gcFunction
,
indexFunction
,
newindexFunction
,
baseIndexFunction
,
internal
LuaCore
.
L
ua
Native
Function
gcFunction
,
indexFunction
,
newindexFunction
,
baseIndexFunction
,
classIndexFunction
,
classNewindexFunction
,
execDelegateFunction
,
callConstructorFunction
,
toStringFunction
;
private
Dictionary
<
object
,
object
>
memberCache
=
new
Dictionary
<
object
,
object
>
();
private
ObjectTranslator
translator
;
...
...
@@ -77,15 +77,15 @@ namespace NLua
public
MetaFunctions
(
ObjectTranslator
translator
)
{
this
.
translator
=
translator
;
gcFunction
=
new
LuaCore
.
l
ua
_C
Function
(
MetaFunctions
.
collectObject
);
toStringFunction
=
new
LuaCore
.
l
ua
_C
Function
(
MetaFunctions
.
toString
);
indexFunction
=
new
LuaCore
.
l
ua
_C
Function
(
MetaFunctions
.
getMethod
);
newindexFunction
=
new
LuaCore
.
l
ua
_C
Function
(
MetaFunctions
.
setFieldOrProperty
);
baseIndexFunction
=
new
LuaCore
.
l
ua
_C
Function
(
MetaFunctions
.
getBaseMethod
);
callConstructorFunction
=
new
LuaCore
.
l
ua
_C
Function
(
MetaFunctions
.
callConstructor
);
classIndexFunction
=
new
LuaCore
.
l
ua
_C
Function
(
MetaFunctions
.
getClassMethod
);
classNewindexFunction
=
new
LuaCore
.
l
ua
_C
Function
(
MetaFunctions
.
setClassFieldOrProperty
);
execDelegateFunction
=
new
LuaCore
.
l
ua
_C
Function
(
MetaFunctions
.
runFunctionDelegate
);
gcFunction
=
new
LuaCore
.
L
ua
Native
Function
(
MetaFunctions
.
collectObject
);
toStringFunction
=
new
LuaCore
.
L
ua
Native
Function
(
MetaFunctions
.
toString
);
indexFunction
=
new
LuaCore
.
L
ua
Native
Function
(
MetaFunctions
.
getMethod
);
newindexFunction
=
new
LuaCore
.
L
ua
Native
Function
(
MetaFunctions
.
setFieldOrProperty
);
baseIndexFunction
=
new
LuaCore
.
L
ua
Native
Function
(
MetaFunctions
.
getBaseMethod
);
callConstructorFunction
=
new
LuaCore
.
L
ua
Native
Function
(
MetaFunctions
.
callConstructor
);
classIndexFunction
=
new
LuaCore
.
L
ua
Native
Function
(
MetaFunctions
.
getClassMethod
);
classNewindexFunction
=
new
LuaCore
.
L
ua
Native
Function
(
MetaFunctions
.
setClassFieldOrProperty
);
execDelegateFunction
=
new
LuaCore
.
L
ua
Native
Function
(
MetaFunctions
.
runFunctionDelegate
);
}
/*
...
...
@@ -95,15 +95,15 @@ namespace NLua
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
private
static
int
runFunctionDelegate
(
LuaCore
.
l
ua
_
State
luaState
)
private
static
int
runFunctionDelegate
(
LuaCore
.
L
uaState
luaState
)
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
return
runFunctionDelegate
(
luaState
,
translator
);
}
private
static
int
runFunctionDelegate
(
LuaCore
.
l
ua
_
State
luaState
,
ObjectTranslator
translator
)
private
static
int
runFunctionDelegate
(
LuaCore
.
L
uaState
luaState
,
ObjectTranslator
translator
)
{
LuaCore
.
l
ua
_C
Function
func
=
(
LuaCore
.
l
ua
_C
Function
)
translator
.
getRawNetObject
(
luaState
,
1
);
LuaCore
.
L
ua
Native
Function
func
=
(
LuaCore
.
L
ua
Native
Function
)
translator
.
getRawNetObject
(
luaState
,
1
);
LuaLib
.
lua_remove
(
luaState
,
1
);
return
func
(
luaState
);
}
...
...
@@ -115,13 +115,13 @@ namespace NLua
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
private
static
int
collectObject
(
LuaCore
.
l
ua
_
State
luaState
)
private
static
int
collectObject
(
LuaCore
.
L
uaState
luaState
)
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
return
collectObject
(
luaState
,
translator
);
}
private
static
int
collectObject
(
LuaCore
.
l
ua
_
State
luaState
,
ObjectTranslator
translator
)
private
static
int
collectObject
(
LuaCore
.
L
uaState
luaState
,
ObjectTranslator
translator
)
{
int
udata
=
LuaLib
.
luanet_rawnetobj
(
luaState
,
1
);
...
...
@@ -138,13 +138,13 @@ namespace NLua
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
private
static
int
toString
(
LuaCore
.
l
ua
_
State
luaState
)
private
static
int
toString
(
LuaCore
.
L
uaState
luaState
)
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
return
toString
(
luaState
,
translator
);
}
private
static
int
toString
(
LuaCore
.
l
ua
_
State
luaState
,
ObjectTranslator
translator
)
private
static
int
toString
(
LuaCore
.
L
uaState
luaState
,
ObjectTranslator
translator
)
{
object
obj
=
translator
.
getRawNetObject
(
luaState
,
1
);
...
...
@@ -161,7 +161,7 @@ namespace NLua
/// Debug tool to dump the lua stack
/// </summary>
/// FIXME, move somewhere else
public
static
void
dumpStack
(
ObjectTranslator
translator
,
LuaCore
.
l
ua
_
State
luaState
)
public
static
void
dumpStack
(
ObjectTranslator
translator
,
LuaCore
.
L
uaState
luaState
)
{
int
depth
=
LuaLib
.
lua_gettop
(
luaState
);
Debug
.
WriteLine
(
"lua stack depth: "
+
depth
);
...
...
@@ -196,14 +196,14 @@ namespace NLua
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
private
static
int
getMethod
(
LuaCore
.
l
ua
_
State
luaState
)
private
static
int
getMethod
(
LuaCore
.
L
uaState
luaState
)
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
instance
=
translator
.
MetaFunctionsInstance
;
return
instance
.
getMethodInternal
(
luaState
);
}
private
int
getMethodInternal
(
LuaCore
.
l
ua
_
State
luaState
)
private
int
getMethodInternal
(
LuaCore
.
L
uaState
luaState
)
{
object
obj
=
translator
.
getRawNetObject
(
luaState
,
1
);
...
...
@@ -297,14 +297,14 @@ namespace NLua
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
private
static
int
getBaseMethod
(
LuaCore
.
l
ua
_
State
luaState
)
private
static
int
getBaseMethod
(
LuaCore
.
L
uaState
luaState
)
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
instance
=
translator
.
MetaFunctionsInstance
;
return
instance
.
getBaseMethodInternal
(
luaState
);
}
private
int
getBaseMethodInternal
(
LuaCore
.
l
ua
_
State
luaState
)
private
int
getBaseMethodInternal
(
LuaCore
.
L
uaState
luaState
)
{
object
obj
=
translator
.
getRawNetObject
(
luaState
,
1
);
...
...
@@ -359,15 +359,15 @@ namespace NLua
* Uses reflection to find members, and stores the reflected MemberInfo object in
* a cache (indexed by the type of the object and the name of the member).
*/
private
int
getMember
(
LuaCore
.
l
ua
_
State
luaState
,
IReflect
objType
,
object
obj
,
string
methodName
,
BindingFlags
bindingType
)
private
int
getMember
(
LuaCore
.
L
uaState
luaState
,
IReflect
objType
,
object
obj
,
string
methodName
,
BindingFlags
bindingType
)
{
bool
implicitStatic
=
false
;
MemberInfo
member
=
null
;
object
cachedMember
=
checkMemberCache
(
memberCache
,
objType
,
methodName
);
//object cachedMember=null;
if
(
cachedMember
is
LuaCore
.
l
ua
_C
Function
)
{
translator
.
pushFunction
(
luaState
,
(
LuaCore
.
l
ua
_C
Function
)
cachedMember
);
if
(
cachedMember
is
LuaCore
.
L
ua
Native
Function
)
{
translator
.
pushFunction
(
luaState
,
(
LuaCore
.
L
ua
Native
Function
)
cachedMember
);
translator
.
push
(
luaState
,
true
);
return
2
;
}
else
if
(!
cachedMember
.
IsNull
())
...
...
@@ -445,7 +445,7 @@ namespace NLua
translator
.
pushType
(
luaState
,
nestedType
);
}
else
{
// Member type must be 'method'
var
wrapper
=
new
LuaCore
.
l
ua
_C
Function
((
new
LuaMethodWrapper
(
translator
,
objType
,
methodName
,
bindingType
)).
invokeFunction
);
var
wrapper
=
new
LuaCore
.
L
ua
Native
Function
((
new
LuaMethodWrapper
(
translator
,
objType
,
methodName
,
bindingType
)).
invokeFunction
);
if
(
cachedMember
.
IsNull
())
setMemberCache
(
memberCache
,
objType
,
methodName
,
wrapper
);
...
...
@@ -519,14 +519,14 @@ namespace NLua
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
private
static
int
setFieldOrProperty
(
LuaCore
.
l
ua
_
State
luaState
)
private
static
int
setFieldOrProperty
(
LuaCore
.
L
uaState
luaState
)
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
instance
=
translator
.
MetaFunctionsInstance
;
return
instance
.
setFieldOrPropertyInternal
(
luaState
);
}
private
int
setFieldOrPropertyInternal
(
LuaCore
.
l
ua
_
State
luaState
)
private
int
setFieldOrPropertyInternal
(
LuaCore
.
L
uaState
luaState
)
{
object
target
=
translator
.
getRawNetObject
(
luaState
,
1
);
...
...
@@ -592,7 +592,7 @@ namespace NLua
/// <param name="target"></param>
/// <param name="bindingType"></param>
/// <returns>false if unable to find the named member, true for success</returns>
private
bool
trySetMember
(
LuaCore
.
l
ua
_
State
luaState
,
IReflect
targetType
,
object
target
,
BindingFlags
bindingType
,
out
string
detailMessage
)
private
bool
trySetMember
(
LuaCore
.
L
uaState
luaState
,
IReflect
targetType
,
object
target
,
BindingFlags
bindingType
,
out
string
detailMessage
)
{
detailMessage
=
null
;
// No error yet
...
...
@@ -661,7 +661,7 @@ namespace NLua
* Writes to fields or properties, either static or instance. Throws an error
* if the operation is invalid.
*/
private
int
setMember
(
LuaCore
.
l
ua
_
State
luaState
,
IReflect
targetType
,
object
target
,
BindingFlags
bindingType
)
private
int
setMember
(
LuaCore
.
L
uaState
luaState
,
IReflect
targetType
,
object
target
,
BindingFlags
bindingType
)
{
string
detail
;
bool
success
=
trySetMember
(
luaState
,
targetType
,
target
,
bindingType
,
out
detail
);
...
...
@@ -677,7 +677,7 @@ namespace NLua
/// </summary>
/// <param name="e"></param>
/// We try to look into the exception to give the most meaningful description
void
ThrowError
(
LuaCore
.
l
ua
_
State
luaState
,
Exception
e
)
void
ThrowError
(
LuaCore
.
L
uaState
luaState
,
Exception
e
)
{
// If we got inside a reflection show what really happened
var
te
=
e
as
TargetInvocationException
;
...
...
@@ -695,14 +695,14 @@ namespace NLua
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
private
static
int
getClassMethod
(
LuaCore
.
l
ua
_
State
luaState
)
private
static
int
getClassMethod
(
LuaCore
.
L
uaState
luaState
)
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
instance
=
translator
.
MetaFunctionsInstance
;
return
instance
.
getClassMethodInternal
(
luaState
);
}
private
int
getClassMethodInternal
(
LuaCore
.
l
ua
_
State
luaState
)
private
int
getClassMethodInternal
(
LuaCore
.
L
uaState
luaState
)
{
IReflect
klass
;
object
obj
=
translator
.
getRawNetObject
(
luaState
,
1
);
...
...
@@ -737,14 +737,14 @@ namespace NLua
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
private
static
int
setClassFieldOrProperty
(
LuaCore
.
l
ua
_
State
luaState
)
private
static
int
setClassFieldOrProperty
(
LuaCore
.
L
uaState
luaState
)
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
instance
=
translator
.
MetaFunctionsInstance
;
return
instance
.
setClassFieldOrPropertyInternal
(
luaState
);
}
private
int
setClassFieldOrPropertyInternal
(
LuaCore
.
l
ua
_
State
luaState
)
private
int
setClassFieldOrPropertyInternal
(
LuaCore
.
L
uaState
luaState
)
{
IReflect
target
;
object
obj
=
translator
.
getRawNetObject
(
luaState
,
1
);
...
...
@@ -768,14 +768,14 @@ namespace NLua
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
private
static
int
callConstructor
(
LuaCore
.
l
ua
_
State
luaState
)
private
static
int
callConstructor
(
LuaCore
.
L
uaState
luaState
)
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
instance
=
translator
.
MetaFunctionsInstance
;
return
instance
.
callConstructorInternal
(
luaState
);
}
private
int
callConstructorInternal
(
LuaCore
.
l
ua
_
State
luaState
)
private
int
callConstructorInternal
(
LuaCore
.
L
uaState
luaState
)
{
var
validConstructor
=
new
MethodCache
();
IReflect
klass
;
...
...
@@ -860,7 +860,7 @@ namespace NLua
* if the match was succesful. It it was also returns the information
* necessary to invoke the method.
*/
internal
bool
matchParameters
(
LuaCore
.
l
ua
_
State
luaState
,
MethodBase
method
,
ref
MethodCache
methodCache
)
internal
bool
matchParameters
(
LuaCore
.
L
uaState
luaState
,
MethodBase
method
,
ref
MethodCache
methodCache
)
{
ExtractValue
extractValue
;
bool
isMethod
=
true
;
...
...
@@ -945,7 +945,7 @@ namespace NLua
/// <param name="currentNetParam"></param>
/// <param name="extractValue"></param>
/// <returns></returns>
private
bool
_IsTypeCorrect
(
LuaCore
.
l
ua
_
State
luaState
,
int
currentLuaParam
,
ParameterInfo
currentNetParam
,
out
ExtractValue
extractValue
)
private
bool
_IsTypeCorrect
(
LuaCore
.
L
uaState
luaState
,
int
currentLuaParam
,
ParameterInfo
currentNetParam
,
out
ExtractValue
extractValue
)
{
try
{
return
(
extractValue
=
translator
.
typeChecker
.
checkType
(
luaState
,
currentLuaParam
,
currentNetParam
.
ParameterType
))
!=
null
;
...
...
@@ -956,7 +956,7 @@ namespace NLua
}
}
private
bool
_IsParamsArray
(
LuaCore
.
l
ua
_
State
luaState
,
int
currentLuaParam
,
ParameterInfo
currentNetParam
,
out
ExtractValue
extractValue
)
private
bool
_IsParamsArray
(
LuaCore
.
L
uaState
luaState
,
int
currentLuaParam
,
ParameterInfo
currentNetParam
,
out
ExtractValue
extractValue
)
{
extractValue
=
null
;
...
...
Core/NLua/Method/LuaMethodWrapper.cs
View file @
ea33713d
...
...
@@ -39,7 +39,7 @@ namespace NLua.Method
/*
* Argument extraction with type-conversion function
*/
delegate
object
ExtractValue
(
LuaCore
.
l
ua
_
State
luaState
,
int
stackPos
);
delegate
object
ExtractValue
(
LuaCore
.
L
uaState
luaState
,
int
stackPos
);
/*
* Wrapper class for methods/constructors accessed from Lua.
...
...
@@ -49,7 +49,7 @@ namespace NLua.Method
*/
class
LuaMethodWrapper
{
internal
LuaCore
.
l
ua
_C
Function
invokeFunction
;
internal
LuaCore
.
L
ua
Native
Function
invokeFunction
;
private
ObjectTranslator
_Translator
;
private
MethodBase
_Method
;
private
MethodCache
_LastCalledMethod
=
new
MethodCache
();
...
...
@@ -64,7 +64,7 @@ namespace NLua.Method
*/
public
LuaMethodWrapper
(
ObjectTranslator
translator
,
object
target
,
IReflect
targetType
,
MethodBase
method
)
{
invokeFunction
=
new
LuaCore
.
l
ua
_C
Function
(
this
.
call
);
invokeFunction
=
new
LuaCore
.
L
ua
Native
Function
(
this
.
call
);
_Translator
=
translator
;
_Target
=
target
;
...
...
@@ -85,7 +85,7 @@ namespace NLua.Method
*/
public
LuaMethodWrapper
(
ObjectTranslator
translator
,
IReflect
targetType
,
string
methodName
,
BindingFlags
bindingType
)
{
invokeFunction
=
new
LuaCore
.
l
ua
_C
Function
(
this
.
call
);
invokeFunction
=
new
LuaCore
.
L
ua
Native
Function
(
this
.
call
);
_Translator
=
translator
;
_MethodName
=
methodName
;
...
...
@@ -112,7 +112,7 @@ namespace NLua.Method
* Calls the method. Receives the arguments from the Lua stack
* and returns values in it.
*/
int
call
(
LuaCore
.
l
ua
_
State
luaState
)
int
call
(
LuaCore
.
L
uaState
luaState
)
{
var
methodToCall
=
_Method
;
object
targetObject
=
_Target
;
...
...
Core/NLua/ObjectTranslator.cs
View file @
ea33713d
...
...
@@ -49,7 +49,7 @@ namespace NLua
*/
public
class
ObjectTranslator
{
private
LuaCore
.
l
ua
_C
Function
registerTableFunction
,
unregisterTableFunction
,
getMethodSigFunction
,
private
LuaCore
.
L
ua
Native
Function
registerTableFunction
,
unregisterTableFunction
,
getMethodSigFunction
,
getConstructorSigFunction
,
importTypeFunction
,
loadAssemblyFunction
;
// object to object #
public
readonly
Dictionary
<
object
,
int
>
objectsBackMap
=
new
Dictionary
<
object
,
int
>
();
...
...
@@ -77,19 +77,19 @@ namespace NLua
}
}
public
ObjectTranslator
(
Lua
interpreter
,
LuaCore
.
l
ua
_
State
luaState
)
public
ObjectTranslator
(
Lua
interpreter
,
LuaCore
.
L
uaState
luaState
)
{
this
.
interpreter
=
interpreter
;
typeChecker
=
new
CheckType
(
this
);
metaFunctions
=
new
MetaFunctions
(
this
);
assemblies
=
new
List
<
Assembly
>
();
importTypeFunction
=
new
LuaCore
.
l
ua
_C
Function
(
ObjectTranslator
.
importType
);
loadAssemblyFunction
=
new
LuaCore
.
l
ua
_C
Function
(
ObjectTranslator
.
loadAssembly
);
registerTableFunction
=
new
LuaCore
.
l
ua
_C
Function
(
ObjectTranslator
.
registerTable
);
unregisterTableFunction
=
new
LuaCore
.
l
ua
_C
Function
(
ObjectTranslator
.
unregisterTable
);
getMethodSigFunction
=
new
LuaCore
.
l
ua
_C
Function
(
ObjectTranslator
.
getMethodSignature
);
getConstructorSigFunction
=
new
LuaCore
.
l
ua
_C
Function
(
ObjectTranslator
.
getConstructorSignature
);
importTypeFunction
=
new
LuaCore
.
L
ua
Native
Function
(
ObjectTranslator
.
importType
);
loadAssemblyFunction
=
new
LuaCore
.
L
ua
Native
Function
(
ObjectTranslator
.
loadAssembly
);
registerTableFunction
=
new
LuaCore
.
L
ua
Native
Function
(
ObjectTranslator
.
registerTable
);
unregisterTableFunction
=
new
LuaCore
.
L
ua
Native
Function
(
ObjectTranslator
.
unregisterTable
);
getMethodSigFunction
=
new
LuaCore
.
L
ua
Native
Function
(
ObjectTranslator
.
getMethodSignature
);
getConstructorSigFunction
=
new
LuaCore
.
L
ua
Native
Function
(
ObjectTranslator
.
getConstructorSignature
);
createLuaObjectList
(
luaState
);
createIndexingMetaFunction
(
luaState
);
...
...
@@ -102,7 +102,7 @@ namespace NLua
/*
* Sets up the list of objects in the Lua side
*/
private
void
createLuaObjectList
(
LuaCore
.
l
ua
_
State
luaState
)
private
void
createLuaObjectList
(
LuaCore
.
L
uaState
luaState
)
{
LuaLib
.
lua_pushstring
(
luaState
,
"luaNet_objects"
);
LuaLib
.
lua_newtable
(
luaState
);
...
...
@@ -118,7 +118,7 @@ namespace NLua
* Registers the indexing function of CLR objects
* passed to Lua
*/
private
void
createIndexingMetaFunction
(
LuaCore
.
l
ua
_
State
luaState
)
private
void
createIndexingMetaFunction
(
LuaCore
.
L
uaState
luaState
)
{
LuaLib
.
lua_pushstring
(
luaState
,
"luaNet_indexfunction"
);
LuaLib
.
luaL_dostring
(
luaState
,
MetaFunctions
.
luaIndexFunction
);
// steffenj: lua_dostring renamed to luaL_dostring
...
...
@@ -129,7 +129,7 @@ namespace NLua
* Creates the metatable for superclasses (the base
* field of registered tables)
*/
private
void
createBaseClassMetatable
(
LuaCore
.
l
ua
_
State
luaState
)
private
void
createBaseClassMetatable
(
LuaCore
.
L
uaState
luaState
)
{
LuaLib
.
luaL_newmetatable
(
luaState
,
"luaNet_searchbase"
);
LuaLib
.
lua_pushstring
(
luaState
,
"__gc"
);
...
...
@@ -150,7 +150,7 @@ namespace NLua
/*
* Creates the metatable for type references
*/
private
void
createClassMetatable
(
LuaCore
.
l
ua
_
State
luaState
)
private
void
createClassMetatable
(
LuaCore
.
L
uaState
luaState
)
{
LuaLib
.
luaL_newmetatable
(
luaState
,
"luaNet_class"
);
LuaLib
.
lua_pushstring
(
luaState
,
"__gc"
);
...
...
@@ -174,7 +174,7 @@ namespace NLua
/*
* Registers the global functions used by NLua
*/
private
void
setGlobalFunctions
(
LuaCore
.
l
ua
_
State
luaState
)
private
void
setGlobalFunctions
(
LuaCore
.
L
uaState
luaState
)
{
LuaLib
.
lua_pushstdcallcfunction
(
luaState
,
metaFunctions
.
indexFunction
);
LuaLib
.
lua_setglobal
(
luaState
,
"get_object_member"
);
...
...
@@ -195,7 +195,7 @@ namespace NLua
/*
* Creates the metatable for delegates
*/
private
void
createFunctionMetatable
(
LuaCore
.
l
ua
_
State
luaState
)
private
void
createFunctionMetatable
(
LuaCore
.
L
uaState
luaState
)
{
LuaLib
.
luaL_newmetatable
(
luaState
,
"luaNet_function"
);
LuaLib
.
lua_pushstring
(
luaState
,
"__gc"
);
...
...
@@ -210,7 +210,7 @@ namespace NLua
/*
* Passes errors (argument e) to the Lua interpreter
*/
internal
void
throwError
(
LuaCore
.
l
ua
_
State
luaState
,
object
e
)
internal
void
throwError
(
LuaCore
.
L
uaState
luaState
,
object
e
)
{
// We use this to remove anything pushed by luaL_where
int
oldTop
=
LuaLib
.
lua_gettop
(
luaState
);
...
...
@@ -252,13 +252,13 @@ namespace NLua
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
private
static
int
loadAssembly
(
LuaCore
.
l
ua
_
State
luaState
)
private
static
int
loadAssembly
(
LuaCore
.
L
uaState
luaState
)
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
return
translator
.
loadAssemblyInternal
(
luaState
);
}
private
int
loadAssemblyInternal
(
LuaCore
.
l
ua
_
State
luaState
)
private
int
loadAssemblyInternal
(
LuaCore
.
L
uaState
luaState
)
{
try
{
string
assemblyName
=
LuaLib
.
lua_tostring
(
luaState
,
1
).
ToString
();
...
...
@@ -303,13 +303,13 @@ namespace NLua
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
private
static
int
importType
(
LuaCore
.
l
ua
_
State
luaState
)
private
static
int
importType
(
LuaCore
.
L
uaState
luaState
)
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
return
translator
.
importTypeInternal
(
luaState
);
}
private
int
importTypeInternal
(
LuaCore
.
l
ua
_
State
luaState
)
private
int
importTypeInternal
(
LuaCore
.
L
uaState
luaState
)
{
string
className
=
LuaLib
.
lua_tostring
(
luaState
,
1
).
ToString
();
var
klass
=
FindType
(
className
);
...
...
@@ -331,13 +331,13 @@ namespace NLua
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
private
static
int
registerTable
(
LuaCore
.
l
ua
_
State
luaState
)
private
static
int
registerTable
(
LuaCore
.
L
uaState
luaState
)
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
return
translator
.
registerTableInternal
(
luaState
);
}
private
int
registerTableInternal
(
LuaCore
.
l
ua
_
State
luaState
)
private
int
registerTableInternal
(
LuaCore
.
L
uaState
luaState
)
{
if
(
LuaLib
.
lua_type
(
luaState
,
1
)
==
LuaTypes
.
Table
)
{
var
luaTable
=
getTable
(
luaState
,
1
);
...
...
@@ -383,13 +383,13 @@ namespace NLua
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
private
static
int
unregisterTable
(
LuaCore
.
l
ua
_
State
luaState
)
private
static
int
unregisterTable
(
LuaCore
.
L
uaState
luaState
)
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
return
translator
.
unregisterTableInternal
(
luaState
);
}
private
int
unregisterTableInternal
(
LuaCore
.
l
ua
_
State
luaState
)
private
int
unregisterTableInternal
(
LuaCore
.
L
uaState
luaState
)
{
try
{
if
(
LuaLib
.
lua_getmetatable
(
luaState
,
1
)
!=
0
)
{
...
...
@@ -428,13 +428,13 @@ namespace NLua
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
private
static
int
getMethodSignature
(
LuaCore
.
l
ua
_
State
luaState
)
private
static
int
getMethodSignature
(
LuaCore
.
L
uaState
luaState
)
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
return
translator
.
getMethodSignatureInternal
(
luaState
);
}
private
int
getMethodSignatureInternal
(
LuaCore
.
l
ua
_
State
luaState
)
private
int
getMethodSignatureInternal
(
LuaCore
.
L
uaState
luaState
)
{
IReflect
klass
;
object
target
;
...
...
@@ -465,7 +465,7 @@ namespace NLua
//CP: Added ignore case
var
method
=
klass
.
GetMethod
(
methodName
,
BindingFlags
.
Public
|
BindingFlags
.
Static
|
BindingFlags
.
Instance
|
BindingFlags
.
FlattenHierarchy
|
BindingFlags
.
IgnoreCase
,
null
,
signature
,
null
);
pushFunction
(
luaState
,
new
LuaCore
.
l
ua
_C
Function
((
new
LuaMethodWrapper
(
this
,
target
,
klass
,
method
)).
invokeFunction
));
pushFunction
(
luaState
,
new
LuaCore
.
L
ua
Native
Function
((
new
LuaMethodWrapper
(
this
,
target
,
klass
,
method
)).
invokeFunction
));
}
catch
(
Exception
e
)
{
throwError
(
luaState
,
e
);
LuaLib
.
lua_pushnil
(
luaState
);
...
...
@@ -482,13 +482,13 @@ namespace NLua
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
private
static
int
getConstructorSignature
(
LuaCore
.
l
ua
_
State
luaState
)
private
static
int
getConstructorSignature
(
LuaCore
.
L
uaState
luaState
)
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
return
translator
.
getConstructorSignatureInternal
(
luaState
);
}
private
int
getConstructorSignatureInternal
(
LuaCore
.
l
ua
_
State
luaState
)
private
int
getConstructorSignatureInternal
(
LuaCore
.
L
uaState
luaState
)
{
IReflect
klass
=
null
;
int
udata
=
LuaLib
.
luanet_checkudata
(
luaState
,
1
,
"luaNet_class"
);
...
...
@@ -506,7 +506,7 @@ namespace NLua
try
{
ConstructorInfo
constructor
=
klass
.
UnderlyingSystemType
.
GetConstructor
(
signature
);
pushFunction
(
luaState
,
new
LuaCore
.
l
ua
_C
Function
((
new
LuaMethodWrapper
(
this
,
null
,
klass
,
constructor
)).
invokeFunction
));
pushFunction
(
luaState
,
new
LuaCore
.
L
ua
Native
Function
((
new
LuaMethodWrapper
(
this
,
null
,
klass
,
constructor
)).
invokeFunction
));
}
catch
(
Exception
e
)
{
throwError
(
luaState
,
e
);
LuaLib
.
lua_pushnil
(
luaState
);
...
...
@@ -518,7 +518,7 @@ namespace NLua
/*
* Pushes a type reference into the stack
*/
internal
void
pushType
(
LuaCore
.
l
ua
_
State
luaState
,
Type
t
)
internal
void
pushType
(
LuaCore
.
L
uaState
luaState
,
Type
t
)
{
pushObject
(
luaState
,
new
ProxyType
(
t
),
"luaNet_class"
);
}
...
...
@@ -526,7 +526,7 @@ namespace NLua
/*
* Pushes a delegate into the stack
*/
internal
void
pushFunction
(
LuaCore
.
l
ua
_
State
luaState
,
LuaCore
.
l
ua
_C
Function
func
)
internal
void
pushFunction
(
LuaCore
.
L
uaState
luaState
,
LuaCore
.
L
ua
Native
Function
func
)
{
pushObject
(
luaState
,
func
,
"luaNet_function"
);
}
...
...
@@ -535,7 +535,7 @@ namespace NLua
* Pushes a CLR object into the Lua stack as an userdata
* with the provided metatable
*/
internal
void
pushObject
(
LuaCore
.
l
ua
_
State
luaState
,
object
o
,
string
metatable
)
internal
void
pushObject
(
LuaCore
.
L
uaState
luaState
,
object
o
,
string
metatable
)
{
int
index
=
-
1
;
...
...
@@ -577,7 +577,7 @@ namespace NLua
* Pushes a new object into the Lua stack with the provided
* metatable
*/
private
void
pushNewObject
(
LuaCore
.
l
ua
_
State
luaState
,
object
o
,
int
index
,
string
metatable
)
private
void
pushNewObject
(
LuaCore
.
L
uaState
luaState
,
object
o
,
int
index
,
string
metatable
)
{
if
(
metatable
==
"luaNet_metatable"
)
{
// Gets or creates the metatable for the object's type
...
...
@@ -625,7 +625,7 @@ namespace NLua
* Gets an object from the Lua stack with the desired type, if it matches, otherwise
* returns null.
*/
internal
object
getAsType
(
LuaCore
.
l
ua
_
State
luaState
,
int
stackPos
,
Type
paramType
)
internal
object
getAsType
(
LuaCore
.
L
uaState
luaState
,
int
stackPos
,
Type
paramType
)
{
var
extractor
=
typeChecker
.
checkType
(
luaState
,
stackPos
,
paramType
);
return
!
extractor
.
IsNull
()
?
extractor
(
luaState
,
stackPos
)
:
null
;
...
...
@@ -671,7 +671,7 @@ namespace NLua
/*
* Gets an object from the Lua stack according to its Lua type.
*/
internal
object
getObject
(
LuaCore
.
l
ua
_
State
luaState
,
int
index
)
internal
object
getObject
(
LuaCore
.
L
uaState
luaState
,
int
index
)
{
var
type
=
LuaLib
.
lua_type
(
luaState
,
index
);
...
...
@@ -709,7 +709,7 @@ namespace NLua
/*
* Gets the table in the index positon of the Lua stack.
*/
internal
LuaTable
getTable
(
LuaCore
.
l
ua
_
State
luaState
,
int
index
)
internal
LuaTable
getTable
(
LuaCore
.
L
uaState
luaState
,
int
index
)
{
LuaLib
.
lua_pushvalue
(
luaState
,
index
);
return
new
LuaTable
(
LuaLib
.
lua_ref
(
luaState
,
1
),
interpreter
);
...
...
@@ -718,7 +718,7 @@ namespace NLua
/*
* Gets the userdata in the index positon of the Lua stack.
*/
internal
LuaUserData
getUserData
(
LuaCore
.
l
ua
_
State
luaState
,
int
index
)
internal
LuaUserData
getUserData
(
LuaCore
.
L
uaState
luaState
,
int
index
)
{
LuaLib
.
lua_pushvalue
(
luaState
,
index
);
return
new
LuaUserData
(
LuaLib
.
lua_ref
(
luaState
,
1
),
interpreter
);
...
...
@@ -727,7 +727,7 @@ namespace NLua
/*
* Gets the function in the index positon of the Lua stack.
*/
internal
LuaFunction
getFunction
(
LuaCore
.
l
ua
_
State
luaState
,
int
index
)
internal
LuaFunction
getFunction
(
LuaCore
.
L
uaState
luaState
,
int
index
)
{
LuaLib
.
lua_pushvalue
(
luaState
,
index
);
return
new
LuaFunction
(
LuaLib
.
lua_ref
(
luaState
,
1
),
interpreter
);
...
...
@@ -737,7 +737,7 @@ namespace NLua
* Gets the CLR object in the index positon of the Lua stack. Returns
* delegates as Lua functions.
*/
internal
object
getNetObject
(
LuaCore
.
l
ua
_
State
luaState
,
int
index
)
internal
object
getNetObject
(
LuaCore
.
L
uaState
luaState
,
int
index
)
{
int
idx
=
LuaLib
.
luanet_tonetobject
(
luaState
,
index
);
return
idx
!=
-
1
?
objects
[
idx
]
:
null
;
...
...
@@ -747,7 +747,7 @@ namespace NLua
* Gets the CLR object in the index position of the Lua stack. Returns
* delegates as is.
*/
internal
object
getRawNetObject
(
LuaCore
.
l
ua
_
State
luaState
,
int
index
)
internal
object
getRawNetObject
(
LuaCore
.
L
uaState
luaState
,
int
index
)
{
int
udata
=
LuaLib
.
luanet_rawnetobj
(
luaState
,
index
);
return
udata
!=
-
1
?
objects
[
udata
]
:
null
;
...
...
@@ -757,7 +757,7 @@ namespace NLua
* Pushes the entire array into the Lua stack and returns the number
* of elements pushed.
*/
internal
int
returnValues
(
LuaCore
.
l
ua
_
State
luaState
,
object
[]
returnValues
)
internal
int
returnValues
(
LuaCore
.
L
uaState
luaState
,
object
[]
returnValues
)
{
if
(
LuaLib
.
lua_checkstack
(
luaState
,
returnValues
.
Length
+
5
))
{
for
(
int
i
=
0
;
i
<
returnValues
.
Length
;
i
++)
...
...
@@ -772,7 +772,7 @@ namespace NLua
* Gets the values from the provided index to
* the top of the stack and returns them in an array.
*/
internal
object
[]
popValues
(
LuaCore
.
l
ua
_
State
luaState
,
int
oldTop
)
internal
object
[]
popValues
(
LuaCore
.
L
uaState
luaState
,
int
oldTop
)
{
int
newTop
=
LuaLib
.
lua_gettop
(
luaState
);
...
...
@@ -793,7 +793,7 @@ namespace NLua
* the top of the stack and returns them in an array, casting
* them to the provided types.
*/
internal
object
[]
popValues
(
LuaCore
.
l
ua
_
State
luaState
,
int
oldTop
,
Type
[]
popTypes
)
internal
object
[]
popValues
(
LuaCore
.
L
uaState
luaState
,
int
oldTop
,
Type
[]
popTypes
)
{
int
newTop
=
LuaLib
.
lua_gettop
(
luaState
);
...
...
@@ -837,7 +837,7 @@ namespace NLua
/*
* Pushes the object into the Lua stack according to its type.
*/
internal
void
push
(
LuaCore
.
l
ua
_
State
luaState
,
object
o
)
internal
void
push
(
LuaCore
.
L
uaState
luaState
,
object
o
)
{
if
(
o
.
IsNull
())
LuaLib
.
lua_pushnil
(
luaState
);
...
...
@@ -859,8 +859,8 @@ namespace NLua
(((
ILuaGeneratedType
)
o
).
LuaInterfaceGetLuaTable
()).
push
(
luaState
);
else
if
(
o
is
LuaTable
)
((
LuaTable
)
o
).
push
(
luaState
);
else
if
(
o
is
LuaCore
.
l
ua
_C
Function
)
pushFunction
(
luaState
,
(
LuaCore
.
l
ua
_C
Function
)
o
);
else
if
(
o
is
LuaCore
.
L
ua
Native
Function
)
pushFunction
(
luaState
,
(
LuaCore
.
L
ua
Native
Function
)
o
);
else
if
(
o
is
LuaFunction
)
((
LuaFunction
)
o
).
push
(
luaState
);
else
...
...
@@ -871,7 +871,7 @@ namespace NLua
* Checks if the method matches the arguments in the Lua stack, getting
* the arguments if it does.
*/
internal
bool
matchParameters
(
LuaCore
.
l
ua
_
State
luaState
,
MethodBase
method
,
ref
MethodCache
methodCache
)
internal
bool
matchParameters
(
LuaCore
.
L
uaState
luaState
,
MethodBase
method
,
ref
MethodCache
methodCache
)
{
return
metaFunctions
.
matchParameters
(
luaState
,
method
,
ref
methodCache
);
}
...
...
Core/NLua/ObjectTranslatorPool.cs
View file @
ea33713d
...
...
@@ -36,7 +36,7 @@ namespace NLua
internal
class
ObjectTranslatorPool
{
private
static
volatile
ObjectTranslatorPool
instance
=
new
ObjectTranslatorPool
();
private
Dictionary
<
LuaCore
.
l
ua
_
State
,
ObjectTranslator
>
translators
=
new
Dictionary
<
LuaCore
.
l
ua
_
State
,
ObjectTranslator
>();
private
Dictionary
<
LuaCore
.
L
uaState
,
ObjectTranslator
>
translators
=
new
Dictionary
<
LuaCore
.
L
uaState
,
ObjectTranslator
>();
public
static
ObjectTranslatorPool
Instance
{
...
...
@@ -50,12 +50,12 @@ namespace NLua
{
}
public
void
Add
(
LuaCore
.
l
ua
_
State
luaState
,
ObjectTranslator
translator
)
public
void
Add
(
LuaCore
.
L
uaState
luaState
,
ObjectTranslator
translator
)
{
translators
.
Add
(
luaState
,
translator
);
}
public
ObjectTranslator
Find
(
LuaCore
.
l
ua
_
State
luaState
)
public
ObjectTranslator
Find
(
LuaCore
.
L
uaState
luaState
)
{
if
(!
translators
.
ContainsKey
(
luaState
))
return
null
;
...
...
@@ -63,7 +63,7 @@ namespace NLua
return
translators
[
luaState
];
}
public
void
Remove
(
LuaCore
.
l
ua
_
State
luaState
)
public
void
Remove
(
LuaCore
.
L
uaState
luaState
)
{
if
(!
translators
.
ContainsKey
(
luaState
))
return
;
...
...
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