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
c84425fd
Commit
c84425fd
authored
Jun 23, 2013
by
Vinicius Jarina
Browse files
Un-nest public classes.
parent
83bd7e63
Changes
16
Show whitespace changes
Inline
Side-by-side
KeraLua
@
48ed8696
Compare
df2cee88
...
48ed8696
Subproject commit
df2cee885786733e6397a4f8db0a05f9aa176111
Subproject commit
48ed86961855816ef88d6a7486c3248e389f4317
KopiLua
@
922e92fa
Compare
3bf5dade
...
922e92fa
Subproject commit
3bf5dade6bdf3f86e5d6d0157bcf7cbee63c8d24
Subproject commit
922e92fa41c960e02023c258874ea81810884c6c
Core/NLua/CheckType.cs
View file @
c84425fd
...
@@ -33,8 +33,10 @@ namespace NLua
...
@@ -33,8 +33,10 @@ namespace NLua
{
{
#
if
USE_KOPILUA
#
if
USE_KOPILUA
using
LuaCore
=
KopiLua
.
Lua
;
using
LuaCore
=
KopiLua
.
Lua
;
using
LuaState
=
KopiLua
.
LuaState
;
#
else
#
else
using
LuaCore
=
KeraLua
.
Lua
;
using
LuaCore
=
KeraLua
.
Lua
;
using
LuaState
=
KeraLua
.
LuaState
;
#
endif
#
endif
/*
/*
...
@@ -95,7 +97,7 @@ namespace NLua
...
@@ -95,7 +97,7 @@ namespace NLua
return
extractValues
.
ContainsKey
(
extractKey
)
?
extractValues
[
extractKey
]
:
extractNetObject
;
return
extractValues
.
ContainsKey
(
extractKey
)
?
extractValues
[
extractKey
]
:
extractNetObject
;
}
}
internal
ExtractValue
checkType
(
LuaCore
.
LuaState
luaState
,
int
stackPos
,
Type
paramType
)
internal
ExtractValue
checkType
(
LuaState
luaState
,
int
stackPos
,
Type
paramType
)
{
{
var
luatype
=
LuaLib
.
lua_type
(
luaState
,
stackPos
);
var
luatype
=
LuaLib
.
lua_type
(
luaState
,
stackPos
);
...
@@ -189,7 +191,7 @@ namespace NLua
...
@@ -189,7 +191,7 @@ 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
getAsSbyte
(
LuaCore
.
LuaState
luaState
,
int
stackPos
)
private
object
getAsSbyte
(
LuaState
luaState
,
int
stackPos
)
{
{
sbyte
retVal
=
(
sbyte
)
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
sbyte
retVal
=
(
sbyte
)
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
...
@@ -198,7 +200,7 @@ namespace NLua
...
@@ -198,7 +200,7 @@ namespace NLua
return
retVal
;
return
retVal
;
}
}
private
object
getAsByte
(
LuaCore
.
LuaState
luaState
,
int
stackPos
)
private
object
getAsByte
(
LuaState
luaState
,
int
stackPos
)
{
{
byte
retVal
=
(
byte
)
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
byte
retVal
=
(
byte
)
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
...
@@ -207,7 +209,7 @@ namespace NLua
...
@@ -207,7 +209,7 @@ namespace NLua
return
retVal
;
return
retVal
;
}
}
private
object
getAsShort
(
LuaCore
.
LuaState
luaState
,
int
stackPos
)
private
object
getAsShort
(
LuaState
luaState
,
int
stackPos
)
{
{
short
retVal
=
(
short
)
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
short
retVal
=
(
short
)
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
...
@@ -216,7 +218,7 @@ namespace NLua
...
@@ -216,7 +218,7 @@ namespace NLua
return
retVal
;
return
retVal
;
}
}
private
object
getAsUshort
(
LuaCore
.
LuaState
luaState
,
int
stackPos
)
private
object
getAsUshort
(
LuaState
luaState
,
int
stackPos
)
{
{
ushort
retVal
=
(
ushort
)
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
ushort
retVal
=
(
ushort
)
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
...
@@ -225,7 +227,7 @@ namespace NLua
...
@@ -225,7 +227,7 @@ namespace NLua
return
retVal
;
return
retVal
;
}
}
private
object
getAsInt
(
LuaCore
.
LuaState
luaState
,
int
stackPos
)
private
object
getAsInt
(
LuaState
luaState
,
int
stackPos
)
{
{
int
retVal
=
(
int
)
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
int
retVal
=
(
int
)
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
...
@@ -234,7 +236,7 @@ namespace NLua
...
@@ -234,7 +236,7 @@ namespace NLua
return
retVal
;
return
retVal
;
}
}
private
object
getAsUint
(
LuaCore
.
LuaState
luaState
,
int
stackPos
)
private
object
getAsUint
(
LuaState
luaState
,
int
stackPos
)
{
{
uint
retVal
=
(
uint
)
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
uint
retVal
=
(
uint
)
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
...
@@ -243,7 +245,7 @@ namespace NLua
...
@@ -243,7 +245,7 @@ namespace NLua
return
retVal
;
return
retVal
;
}
}
private
object
getAsLong
(
LuaCore
.
LuaState
luaState
,
int
stackPos
)
private
object
getAsLong
(
LuaState
luaState
,
int
stackPos
)
{
{
long
retVal
=
(
long
)
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
long
retVal
=
(
long
)
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
...
@@ -252,7 +254,7 @@ namespace NLua
...
@@ -252,7 +254,7 @@ namespace NLua
return
retVal
;
return
retVal
;
}
}
private
object
getAsUlong
(
LuaCore
.
LuaState
luaState
,
int
stackPos
)
private
object
getAsUlong
(
LuaState
luaState
,
int
stackPos
)
{
{
ulong
retVal
=
(
ulong
)
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
ulong
retVal
=
(
ulong
)
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
...
@@ -261,7 +263,7 @@ namespace NLua
...
@@ -261,7 +263,7 @@ namespace NLua
return
retVal
;
return
retVal
;
}
}
private
object
getAsDouble
(
LuaCore
.
LuaState
luaState
,
int
stackPos
)
private
object
getAsDouble
(
LuaState
luaState
,
int
stackPos
)
{
{
double
retVal
=
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
double
retVal
=
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
...
@@ -270,7 +272,7 @@ namespace NLua
...
@@ -270,7 +272,7 @@ namespace NLua
return
retVal
;
return
retVal
;
}
}
private
object
getAsChar
(
LuaCore
.
LuaState
luaState
,
int
stackPos
)
private
object
getAsChar
(
LuaState
luaState
,
int
stackPos
)
{
{
char
retVal
=
(
char
)
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
char
retVal
=
(
char
)
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
...
@@ -279,7 +281,7 @@ namespace NLua
...
@@ -279,7 +281,7 @@ namespace NLua
return
retVal
;
return
retVal
;
}
}
private
object
getAsFloat
(
LuaCore
.
LuaState
luaState
,
int
stackPos
)
private
object
getAsFloat
(
LuaState
luaState
,
int
stackPos
)
{
{
float
retVal
=
(
float
)
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
float
retVal
=
(
float
)
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
...
@@ -288,7 +290,7 @@ namespace NLua
...
@@ -288,7 +290,7 @@ namespace NLua
return
retVal
;
return
retVal
;
}
}
private
object
getAsDecimal
(
LuaCore
.
LuaState
luaState
,
int
stackPos
)
private
object
getAsDecimal
(
LuaState
luaState
,
int
stackPos
)
{
{
decimal
retVal
=
(
decimal
)
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
decimal
retVal
=
(
decimal
)
LuaLib
.
lua_tonumber
(
luaState
,
stackPos
);
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
if
(
retVal
==
0
&&
!
LuaLib
.
lua_isnumber
(
luaState
,
stackPos
))
...
@@ -297,12 +299,12 @@ namespace NLua
...
@@ -297,12 +299,12 @@ namespace NLua
return
retVal
;
return
retVal
;
}
}
private
object
getAsBoolean
(
LuaCore
.
LuaState
luaState
,
int
stackPos
)
private
object
getAsBoolean
(
LuaState
luaState
,
int
stackPos
)
{
{
return
LuaLib
.
lua_toboolean
(
luaState
,
stackPos
);
return
LuaLib
.
lua_toboolean
(
luaState
,
stackPos
);
}
}
private
object
getAsString
(
LuaCore
.
LuaState
luaState
,
int
stackPos
)
private
object
getAsString
(
LuaState
luaState
,
int
stackPos
)
{
{
string
retVal
=
LuaLib
.
lua_tostring
(
luaState
,
stackPos
).
ToString
();
string
retVal
=
LuaLib
.
lua_tostring
(
luaState
,
stackPos
).
ToString
();
if
(
retVal
==
string
.
Empty
&&
!
LuaLib
.
lua_isstring
(
luaState
,
stackPos
))
if
(
retVal
==
string
.
Empty
&&
!
LuaLib
.
lua_isstring
(
luaState
,
stackPos
))
...
@@ -311,22 +313,22 @@ namespace NLua
...
@@ -311,22 +313,22 @@ namespace NLua
return
retVal
;
return
retVal
;
}
}
private
object
getAsTable
(
LuaCore
.
LuaState
luaState
,
int
stackPos
)
private
object
getAsTable
(
LuaState
luaState
,
int
stackPos
)
{
{
return
translator
.
getTable
(
luaState
,
stackPos
);
return
translator
.
getTable
(
luaState
,
stackPos
);
}
}
private
object
getAsFunction
(
LuaCore
.
LuaState
luaState
,
int
stackPos
)
private
object
getAsFunction
(
LuaState
luaState
,
int
stackPos
)
{
{
return
translator
.
getFunction
(
luaState
,
stackPos
);
return
translator
.
getFunction
(
luaState
,
stackPos
);
}
}
private
object
getAsUserdata
(
LuaCore
.
LuaState
luaState
,
int
stackPos
)
private
object
getAsUserdata
(
LuaState
luaState
,
int
stackPos
)
{
{
return
translator
.
getUserData
(
luaState
,
stackPos
);
return
translator
.
getUserData
(
luaState
,
stackPos
);
}
}
public
object
getAsObject
(
LuaCore
.
LuaState
luaState
,
int
stackPos
)
public
object
getAsObject
(
LuaState
luaState
,
int
stackPos
)
{
{
if
(
LuaLib
.
lua_type
(
luaState
,
stackPos
)
==
LuaTypes
.
Table
)
{
if
(
LuaLib
.
lua_type
(
luaState
,
stackPos
)
==
LuaTypes
.
Table
)
{
if
(
LuaLib
.
luaL_getmetafield
(
luaState
,
stackPos
,
"__index"
))
{
if
(
LuaLib
.
luaL_getmetafield
(
luaState
,
stackPos
,
"__index"
))
{
...
@@ -342,7 +344,7 @@ namespace NLua
...
@@ -342,7 +344,7 @@ namespace NLua
return
obj
;
return
obj
;
}
}
public
object
getAsNetObject
(
LuaCore
.
LuaState
luaState
,
int
stackPos
)
public
object
getAsNetObject
(
LuaState
luaState
,
int
stackPos
)
{
{
object
obj
=
translator
.
getNetObject
(
luaState
,
stackPos
);
object
obj
=
translator
.
getNetObject
(
luaState
,
stackPos
);
...
...
Core/NLua/Event/DebugHookEventArgs.cs
View file @
c84425fd
...
@@ -27,11 +27,15 @@ using System;
...
@@ -27,11 +27,15 @@ using System;
namespace
NLua.Event
namespace
NLua.Event
{
{
#if USE_KOPILUA
#
if
USE_KOPILUA
using
LuaCore
=
KopiLua
.
Lua
;
using
LuaCore
=
KopiLua
.
Lua
;
#else
using
LuaState
=
KopiLua
.
LuaState
;
using
LuaDebug
=
KopiLua
.
LuaDebug
;
#
else
using
LuaCore
=
KeraLua
.
Lua
;
using
LuaCore
=
KeraLua
.
Lua
;
#endif
using
LuaState
=
KeraLua
.
LuaState
;
using
LuaDebug
=
KeraLua
.
LuaDebug
;
#
endif
/// <summary>
/// <summary>
/// Event args for hook callback event
/// Event args for hook callback event
...
@@ -39,14 +43,14 @@ namespace NLua.Event
...
@@ -39,14 +43,14 @@ namespace NLua.Event
/// <author>Reinhard Ostermeier</author>
/// <author>Reinhard Ostermeier</author>
public
class
DebugHookEventArgs
:
EventArgs
public
class
DebugHookEventArgs
:
EventArgs
{
{
private
readonly
LuaCore
.
LuaDebug
luaDebug
;
private
readonly
LuaDebug
luaDebug
;
public
DebugHookEventArgs
(
LuaCore
.
LuaDebug
luaDebug
)
public
DebugHookEventArgs
(
LuaDebug
luaDebug
)
{
{
this
.
luaDebug
=
luaDebug
;
this
.
luaDebug
=
luaDebug
;
}
}
public
LuaCore
.
LuaDebug
LuaDebug
{
public
LuaDebug
LuaDebug
{
get
{
return
luaDebug
;
}
get
{
return
luaDebug
;
}
}
}
}
}
...
...
Core/NLua/GenerateEventAssembly/ClassGenerator.cs
View file @
c84425fd
...
@@ -29,8 +29,10 @@ namespace NLua
...
@@ -29,8 +29,10 @@ namespace NLua
{
{
#
if
USE_KOPILUA
#
if
USE_KOPILUA
using
LuaCore
=
KopiLua
.
Lua
;
using
LuaCore
=
KopiLua
.
Lua
;
using
LuaState
=
KopiLua
.
LuaState
;
#
else
#
else
using
LuaCore
=
KeraLua
.
Lua
;
using
LuaCore
=
KeraLua
.
Lua
;
using
LuaState
=
KeraLua
.
LuaState
;
#
endif
#
endif
/*
/*
* Class used for generating delegates that get a table from the Lua
* Class used for generating delegates that get a table from the Lua
...
@@ -50,7 +52,7 @@ namespace NLua
...
@@ -50,7 +52,7 @@ namespace NLua
this
.
klass
=
klass
;
this
.
klass
=
klass
;
}
}
public
object
extractGenerated
(
LuaCore
.
LuaState
luaState
,
int
stackPos
)
public
object
extractGenerated
(
LuaState
luaState
,
int
stackPos
)
{
{
return
CodeGeneration
.
Instance
.
GetClassInstance
(
klass
,
translator
.
getTable
(
luaState
,
stackPos
));
return
CodeGeneration
.
Instance
.
GetClassInstance
(
klass
,
translator
.
getTable
(
luaState
,
stackPos
));
}
}
...
...
Core/NLua/GenerateEventAssembly/DelegateGenerator.cs
View file @
c84425fd
...
@@ -29,8 +29,10 @@ namespace NLua
...
@@ -29,8 +29,10 @@ namespace NLua
{
{
#
if
USE_KOPILUA
#
if
USE_KOPILUA
using
LuaCore
=
KopiLua
.
Lua
;
using
LuaCore
=
KopiLua
.
Lua
;
using
LuaState
=
KopiLua
.
LuaState
;
#
else
#
else
using
LuaCore
=
KeraLua
.
Lua
;
using
LuaCore
=
KeraLua
.
Lua
;
using
LuaState
=
KeraLua
.
LuaState
;
#
endif
#
endif
/*
/*
* Class used for generating delegates that get a function from the Lua
* Class used for generating delegates that get a function from the Lua
...
@@ -51,7 +53,7 @@ namespace NLua
...
@@ -51,7 +53,7 @@ namespace NLua
this
.
delegateType
=
delegateType
;
this
.
delegateType
=
delegateType
;
}
}
public
object
extractGenerated
(
LuaCore
.
LuaState
luaState
,
int
stackPos
)
public
object
extractGenerated
(
LuaState
luaState
,
int
stackPos
)
{
{
return
CodeGeneration
.
Instance
.
GetDelegate
(
delegateType
,
translator
.
getFunction
(
luaState
,
stackPos
));
return
CodeGeneration
.
Instance
.
GetDelegate
(
delegateType
,
translator
.
getFunction
(
luaState
,
stackPos
));
}
}
...
...
Core/NLua/Lua.cs
View file @
c84425fd
...
@@ -39,8 +39,14 @@ namespace NLua
...
@@ -39,8 +39,14 @@ namespace NLua
{
{
#
if
USE_KOPILUA
#
if
USE_KOPILUA
using
LuaCore
=
KopiLua
.
Lua
;
using
LuaCore
=
KopiLua
.
Lua
;
using
LuaState
=
KopiLua
.
LuaState
;
using
LuaHook
=
KopiLua
.
LuaHook
;
using
LuaDebug
=
KopiLua
.
LuaDebug
;
#
else
#
else
using
LuaCore
=
KeraLua
.
Lua
;
using
LuaCore
=
KeraLua
.
Lua
;
using
LuaState
=
KeraLua
.
LuaState
;
using
LuaHook
=
KeraLua
.
LuaHook
;
using
LuaDebug
=
KeraLua
.
LuaDebug
;
#
endif
#
endif
/*
/*
...
@@ -75,13 +81,13 @@ namespace NLua
...
@@ -75,13 +81,13 @@ namespace NLua
/// lua hook calback delegate
/// lua hook calback delegate
/// </summary>
/// </summary>
/// <author>Reinhard Ostermeier</author>
/// <author>Reinhard Ostermeier</author>
private
LuaCore
.
LuaHook
hookCallback
=
null
;
private
LuaHook
hookCallback
=
null
;
#
endregion
#
endregion
#
region
Globals
auto
-
complete
#
region
Globals
auto
-
complete
private
readonly
List
<
string
>
globals
=
new
List
<
string
>
();
private
readonly
List
<
string
>
globals
=
new
List
<
string
>
();
private
bool
globalsSorted
;
private
bool
globalsSorted
;
#
endregion
#
endregion
private
/*readonly */
LuaCore
.
LuaState
luaState
;
private
/*readonly */
LuaState
luaState
;
/// <summary>
/// <summary>
/// True while a script is being executed
/// True while a script is being executed
/// </summary>
/// </summary>
...
@@ -274,7 +280,7 @@ end
...
@@ -274,7 +280,7 @@ end
/*
/*
* CAUTION: NLua.Lua instances can't share the same lua state!
* CAUTION: NLua.Lua instances can't share the same lua state!
*/
*/
public
Lua
(
LuaCore
.
LuaState
lState
)
public
Lua
(
LuaState
lState
)
{
{
LuaLib
.
lua_pushstring
(
lState
,
"LUAINTERFACE LOADED"
);
LuaLib
.
lua_pushstring
(
lState
,
"LUAINTERFACE LOADED"
);
LuaLib
.
lua_gettable
(
lState
,
(
int
)
LuaIndexes
.
Registry
);
LuaLib
.
lua_gettable
(
lState
,
(
int
)
LuaIndexes
.
Registry
);
...
@@ -290,7 +296,7 @@ end
...
@@ -290,7 +296,7 @@ end
}
}
}
}
void
Init
(
LuaCore
.
LuaState
luaState
)
void
Init
(
LuaState
luaState
)
{
{
LuaLib
.
lua_pushstring
(
luaState
,
"LUAINTERFACE LOADED"
);
LuaLib
.
lua_pushstring
(
luaState
,
"LUAINTERFACE LOADED"
);
LuaLib
.
lua_pushboolean
(
luaState
,
true
);
LuaLib
.
lua_pushboolean
(
luaState
,
true
);
...
@@ -320,14 +326,14 @@ end
...
@@ -320,14 +326,14 @@ end
LuaCore
.
LuaClose
(
luaState
);
LuaCore
.
LuaClose
(
luaState
);
ObjectTranslatorPool
.
Instance
.
Remove
(
luaState
);
ObjectTranslatorPool
.
Instance
.
Remove
(
luaState
);
}
}
//luaState =
LuaCore.
LuaState.Zero; <- suggested by Christopher Cebulski http://luaforge.net/forum/forum.php?thread_id = 44593&forum_id = 146
//luaState = LuaState.Zero; <- suggested by Christopher Cebulski http://luaforge.net/forum/forum.php?thread_id = 44593&forum_id = 146
}
}
#if MONOTOUCH
#if MONOTOUCH
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
#endif
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
static
int
PanicCallback
(
LuaCore
.
LuaState
luaState
)
static
int
PanicCallback
(
LuaState
luaState
)
{
{
string
reason
=
string
.
Format
(
"unprotected error in call to Lua API ({0})"
,
LuaLib
.
lua_tostring
(
luaState
,
-
1
));
string
reason
=
string
.
Format
(
"unprotected error in call to Lua API ({0})"
,
LuaLib
.
lua_tostring
(
luaState
,
-
1
));
throw
new
LuaException
(
reason
);
throw
new
LuaException
(
reason
);
...
@@ -852,7 +858,7 @@ end
...
@@ -852,7 +858,7 @@ end
public
int
SetDebugHook
(
EventMasks
mask
,
int
count
)
public
int
SetDebugHook
(
EventMasks
mask
,
int
count
)
{
{
if
(
hookCallback
.
IsNull
())
{
if
(
hookCallback
.
IsNull
())
{
hookCallback
=
new
LuaCore
.
LuaHook
(
Lua
.
DebugHookCallback
);
hookCallback
=
new
LuaHook
(
Lua
.
DebugHookCallback
);
return
LuaCore
.
LuaSetHook
(
luaState
,
hookCallback
,
(
int
)
mask
,
count
);
return
LuaCore
.
LuaSetHook
(
luaState
,
hookCallback
,
(
int
)
mask
,
count
);
}
}
...
@@ -900,7 +906,7 @@ end
...
@@ -900,7 +906,7 @@ end
/*public bool GetStack(int level, out LuaCore.lua_Debug luaDebug)
/*public bool GetStack(int level, out LuaCore.lua_Debug luaDebug)
{
{
luaDebug = new LuaDebug();
luaDebug = new LuaDebug();
LuaCore.
LuaState ld = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(luaDebug));
LuaState ld = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(luaDebug));
System.Runtime.InteropServices.Marshal.StructureToPtr(luaDebug, ld, false);
System.Runtime.InteropServices.Marshal.StructureToPtr(luaDebug, ld, false);
try
try
{
{
...
@@ -922,7 +928,7 @@ end
...
@@ -922,7 +928,7 @@ end
/// <author>Reinhard Ostermeier</author>
/// <author>Reinhard Ostermeier</author>
/*public int GetInfo(String what, ref LuaCore.lua_Debug luaDebug)
/*public int GetInfo(String what, ref LuaCore.lua_Debug luaDebug)
{
{
LuaCore.
LuaState ld = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(luaDebug));
LuaState ld = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(luaDebug));
System.Runtime.InteropServices.Marshal.StructureToPtr(luaDebug, ld, false);
System.Runtime.InteropServices.Marshal.StructureToPtr(luaDebug, ld, false);
try
try
{
{
...
@@ -942,7 +948,7 @@ end
...
@@ -942,7 +948,7 @@ end
/// <param name = "n">see lua docs</param>
/// <param name = "n">see lua docs</param>
/// <returns>see lua docs</returns>
/// <returns>see lua docs</returns>
/// <author>Reinhard Ostermeier</author>
/// <author>Reinhard Ostermeier</author>
public
string
GetLocal
(
LuaCore
.
LuaDebug
luaDebug
,
int
n
)
public
string
GetLocal
(
LuaDebug
luaDebug
,
int
n
)
{
{
return
LuaCore
.
LuaGetLocal
(
luaState
,
luaDebug
,
n
).
ToString
();
return
LuaCore
.
LuaGetLocal
(
luaState
,
luaDebug
,
n
).
ToString
();
}
}
...
@@ -954,7 +960,7 @@ end
...
@@ -954,7 +960,7 @@ end
/// <param name = "n">see lua docs</param>
/// <param name = "n">see lua docs</param>
/// <returns>see lua docs</returns>
/// <returns>see lua docs</returns>
/// <author>Reinhard Ostermeier</author>
/// <author>Reinhard Ostermeier</author>
public
string
SetLocal
(
LuaCore
.
LuaDebug
luaDebug
,
int
n
)
public
string
SetLocal
(
LuaDebug
luaDebug
,
int
n
)
{
{
return
LuaCore
.
LuaSetLocal
(
luaState
,
luaDebug
,
n
).
ToString
();
return
LuaCore
.
LuaSetLocal
(
luaState
,
luaDebug
,
n
).
ToString
();
}
}
...
@@ -994,7 +1000,7 @@ end
...
@@ -994,7 +1000,7 @@ end
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_Hook
))]
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_Hook
))]
#endif
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
private
static
void
DebugHookCallback
(
LuaCore
.
LuaState
luaState
,
LuaCore
.
LuaDebug
luaDebug
)
private
static
void
DebugHookCallback
(
LuaState
luaState
,
LuaDebug
luaDebug
)
{
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
lua
=
translator
.
Interpreter
;
var
lua
=
translator
.
Interpreter
;
...
@@ -1002,7 +1008,7 @@ end
...
@@ -1002,7 +1008,7 @@ end
lua
.
DebugHookCallbackInternal
(
luaState
,
luaDebug
);
lua
.
DebugHookCallbackInternal
(
luaState
,
luaDebug
);
}
}
private
void
DebugHookCallbackInternal
(
LuaCore
.
LuaState
luaState
,
LuaCore
.
LuaDebug
luaDebug
)
private
void
DebugHookCallbackInternal
(
LuaState
luaState
,
LuaDebug
luaDebug
)
{
{
try
{
try
{
var
temp
=
DebugHook
;
var
temp
=
DebugHook
;
...
...
Core/NLua/LuaFunction.cs
View file @
c84425fd
...
@@ -31,8 +31,10 @@ namespace NLua
...
@@ -31,8 +31,10 @@ namespace NLua
{
{
#
if
USE_KOPILUA
#
if
USE_KOPILUA
using
LuaCore
=
KopiLua
.
Lua
;
using
LuaCore
=
KopiLua
.
Lua
;
using
LuaState
=
KopiLua
.
LuaState
;
#
else
#
else
using
LuaCore
=
KeraLua
.
Lua
;
using
LuaCore
=
KeraLua
.
Lua
;
using
LuaState
=
KeraLua
.
LuaState
;
#
endif
#
endif
public
class
LuaFunction
:
LuaBase
public
class
LuaFunction
:
LuaBase
...
@@ -74,7 +76,7 @@ namespace NLua
...
@@ -74,7 +76,7 @@ namespace NLua
/*
/*
* Pushes the function into the Lua stack
* Pushes the function into the Lua stack
*/
*/
internal
void
push
(
LuaCore
.
LuaState
luaState
)
internal
void
push
(
LuaState
luaState
)
{
{
if
(
_Reference
!=
0
)
if
(
_Reference
!=
0
)
LuaLib
.
lua_getref
(
luaState
,
_Reference
);
LuaLib
.
lua_getref
(
luaState
,
_Reference
);
...
...
Core/NLua/LuaLib/LuaIndexes.cs
View file @
c84425fd
...
@@ -28,11 +28,14 @@ using System;
...
@@ -28,11 +28,14 @@ using System;
namespace
NLua
namespace
NLua
{
{
#if USE_KOPILUA
#
if
USE_KOPILUA
using
LuaCore
=
KopiLua
.
Lua
;
using
LuaCore
=
KopiLua
.
Lua
;
#else
using
LuaState
=
KopiLua
.
LuaState
;
#
else
using
LuaCore
=
KeraLua
.
Lua
;
using
LuaCore
=
KeraLua
.
Lua
;
#endif
using
LuaState
=
KeraLua
.
LuaState
;
#
endif
public
class
LuaIndexes
public
class
LuaIndexes
{
{
static
int
registryIndex
=
0
;
static
int
registryIndex
=
0
;
...
...
Core/NLua/LuaLib/LuaLib.cs
View file @
c84425fd
...
@@ -32,63 +32,67 @@ namespace NLua
...
@@ -32,63 +32,67 @@ namespace NLua
{
{
#
if
USE_KOPILUA
#
if
USE_KOPILUA
using
LuaCore
=
KopiLua
.
Lua
;
using
LuaCore
=
KopiLua
.
Lua
;
using
LuaState
=
KopiLua
.
LuaState
;
using
LuaTag
=
KopiLua
.
LuaTag
;
#
else
#
else
using
LuaCore
=
KeraLua
.
Lua
;
using
LuaCore
=
KeraLua
.
Lua
;
using
LuaState
=
KeraLua
.
LuaState
;
using
LuaTag
=
KeraLua
.
LuaTag
;
#
endif
#
endif
public
class
LuaLib
public
class
LuaLib
{
{
// steffenj: BEGIN additional Lua API functions new in Lua 5.1
// steffenj: BEGIN additional Lua API functions new in Lua 5.1
public
static
int
lua_gc
(
LuaCore
.
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
lua_typename
(
LuaCore
.
LuaState
luaState
,
LuaTypes
type
)
public
static
string
lua_typename
(
LuaState
luaState
,
LuaTypes
type
)
{
{
return
LuaCore
.
LuaTypeName
(
luaState
,
(
int
)
type
).
ToString
();
return
LuaCore
.
LuaTypeName
(
luaState
,
(
int
)
type
).
ToString
();
}
}
public
static
string
luaL_typename
(
LuaCore
.
LuaState
luaState
,
int
stackPos
)
public
static
string
luaL_typename
(
LuaState
luaState
,
int
stackPos
)
{
{
return
lua_typename
(
luaState
,
lua_type
(
luaState
,
stackPos
));
return
lua_typename
(
luaState
,
lua_type
(
luaState
,
stackPos
));
}
}
public
static
void
luaL_error
(
LuaCore
.
LuaState
luaState
,
string
message
)
public
static
void
luaL_error
(
LuaState
luaState
,
string
message
)
{
{
LuaCore
.
LuaLError
(
luaState
,
message
);
LuaCore
.
LuaLError
(
luaState
,
message
);
}
}
public
static
void
luaL_where
(
LuaCore
.
LuaState
luaState
,
int
level
)
public
static
void
luaL_where
(
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)
// steffenj: BEGIN Lua 5.1.1 API change (lua_open replaced by luaL_newstate)
public
static
LuaCore
.
LuaState
luaL_newstate
()
public
static
LuaState
luaL_newstate
()
{
{
return
LuaCore
.
LuaLNewState
();
return
LuaCore
.
LuaLNewState
();
}
}
// steffenj: BEGIN Lua 5.1.1 API change (new function luaL_openlibs)
// steffenj: BEGIN Lua 5.1.1 API change (new function luaL_openlibs)
public
static
void
luaL_openlibs
(
LuaCore
.
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)
// 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)
// steffenj: BEGIN Lua 5.1.1 API change (lua_dostring is now a macro luaL_dostring)
public
static
int
luaL_loadstring
(
LuaCore
.
LuaState
luaState
,
string
chunk
)
public
static
int
luaL_loadstring
(
LuaState
luaState
,
string
chunk
)
{
{
return
LuaCore
.
LuaLLoadString
(
luaState
,
chunk
);
return
LuaCore
.
LuaLLoadString
(
luaState
,
chunk
);
}
}
public
static
int
luaL_loadstring
(
LuaCore
.
LuaState
luaState
,
byte
[]
chunk
)
public
static
int
luaL_loadstring
(
LuaState
luaState
,
byte
[]
chunk
)
{
{
return
LuaCore
.
LuaLLoadString
(
luaState
,
chunk
);
return
LuaCore
.
LuaLLoadString
(
luaState
,
chunk
);
}
}
public
static
int
luaL_dostring
(
LuaCore
.
LuaState
luaState
,
string
chunk
)
public
static
int
luaL_dostring
(
LuaState
luaState
,
string
chunk
)
{
{
int
result
=
luaL_loadstring
(
luaState
,
chunk
);
int
result
=
luaL_loadstring
(
luaState
,
chunk
);
if
(
result
!=
0
)
if
(
result
!=
0
)
...
@@ -97,7 +101,7 @@ namespace NLua
...
@@ -97,7 +101,7 @@ namespace NLua
return
lua_pcall
(
luaState
,
0
,
-
1
,
0
);
return
lua_pcall
(
luaState
,
0
,
-
1
,
0
);
}
}
public
static
int
luaL_dostring
(
LuaCore
.
LuaState
luaState
,
byte
[]
chunk
)
public
static
int
luaL_dostring
(
LuaState
luaState
,
byte
[]
chunk
)
{
{
int
result
=
luaL_loadstring
(
luaState
,
chunk
);
int
result
=
luaL_loadstring
(
luaState
,
chunk
);
if
(
result
!=
0
)
if
(
result
!=
0
)
...
@@ -106,27 +110,27 @@ namespace NLua
...
@@ -106,27 +110,27 @@ namespace NLua
return
lua_pcall
(
luaState
,
0
,
-
1
,
0
);
return
lua_pcall
(
luaState
,
0
,
-
1
,
0
);
}
}
/// <summary>DEPRECATED - use luaL_dostring(
LuaCore.
LuaState luaState, string chunk) instead!</summary>
/// <summary>DEPRECATED - use luaL_dostring(LuaState luaState, string chunk) instead!</summary>
public
static
int
lua_dostring
(
LuaCore
.
LuaState
luaState
,
string
chunk
)
public
static
int
lua_dostring
(
LuaState
luaState
,
string
chunk
)
{
{
return
luaL_dostring
(
luaState
,
chunk
);
return
luaL_dostring
(
luaState
,
chunk
);
}
}
// steffenj: END Lua 5.1.1 API change (lua_dostring is now a macro luaL_dostring)
// 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)
// steffenj: BEGIN Lua 5.1.1 API change (lua_newtable is gone, lua_createtable is new)
public
static
void
lua_createtable
(
LuaCore
.
LuaState
luaState
,
int
narr
,
int
nrec
)
public
static
void
lua_createtable
(
LuaState
luaState
,
int
narr
,
int
nrec
)
{
{
LuaCore
.
LuaCreateTable
(
luaState
,
narr
,
nrec
);
LuaCore
.
LuaCreateTable
(
luaState
,
narr
,
nrec
);
}
}
public
static
void
lua_newtable
(
LuaCore
.
LuaState
luaState
)
public
static
void
lua_newtable
(
LuaState
luaState
)
{
{
lua_createtable
(
luaState
,
0
,
0
);
lua_createtable
(
luaState
,
0
,
0
);
}
}
// steffenj: END Lua 5.1.1 API change (lua_newtable is gone, lua_createtable is new)
// 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)
// steffenj: BEGIN Lua 5.1.1 API change (lua_dofile now in LuaLib as luaL_dofile macro)
public
static
int
luaL_dofile
(
LuaCore
.
LuaState
luaState
,
string
fileName
)
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
)
...
@@ -135,192 +139,192 @@ namespace NLua
...
@@ -135,192 +139,192 @@ namespace NLua
return
LuaCore
.
LuaNetPCall
(
luaState
,
0
,
-
1
,
0
);
return
LuaCore
.
LuaNetPCall
(
luaState
,
0
,
-
1
,
0
);
}
}
public
static
void
lua_getglobal
(
LuaCore
.
LuaState
luaState
,
string
name
)
public
static
void
lua_getglobal
(
LuaState
luaState
,
string
name
)
{
{
LuaCore
.
LuaNetGetGlobal
(
luaState
,
name
);
LuaCore
.
LuaNetGetGlobal
(
luaState
,
name
);
}
}
public
static
void
lua_setglobal
(
LuaCore
.
LuaState
luaState
,
string
name
)
public
static
void
lua_setglobal
(
LuaState
luaState
,
string
name
)
{
{
LuaCore
.
LuaNetSetGlobal
(
luaState
,
name
);
LuaCore
.
LuaNetSetGlobal
(
luaState
,
name
);
}
}
public
static
void
lua_settop
(
LuaCore
.
LuaState
luaState
,
int
newTop
)
public
static
void
lua_settop
(
LuaState
luaState
,
int
newTop
)
{
{
LuaCore
.
LuaSetTop
(
luaState
,
newTop
);
LuaCore
.
LuaSetTop
(
luaState
,
newTop
);
}
}
public
static
void
lua_pop
(
LuaCore
.
LuaState
luaState
,
int
amount
)
public
static
void
lua_pop
(
LuaState
luaState
,
int
amount
)
{
{
lua_settop
(
luaState
,
-(
amount
)
-
1
);
lua_settop
(
luaState
,
-(
amount
)
-
1
);
}
}
public
static
void
lua_insert
(
LuaCore
.
LuaState
luaState
,
int
newTop
)
public
static
void
lua_insert
(
LuaState
luaState
,
int
newTop
)
{
{
LuaCore
.
LuaInsert
(
luaState
,
newTop
);
LuaCore
.
LuaInsert
(
luaState
,
newTop
);
}
}
public
static
void
lua_remove
(
LuaCore
.
LuaState
luaState
,
int
index
)
public
static
void
lua_remove
(
LuaState
luaState
,
int
index
)
{
{
LuaCore
.
LuaRemove
(
luaState
,
index
);
LuaCore
.
LuaRemove
(
luaState
,
index
);
}
}
public
static
void
lua_gettable
(
LuaCore
.
LuaState
luaState
,
int
index
)
public
static
void
lua_gettable
(
LuaState
luaState
,
int
index
)
{
{
LuaCore
.
LuaGetTable
(
luaState
,
index
);
LuaCore
.
LuaGetTable
(
luaState
,
index
);
}
}
public
static
void
lua_rawget
(
LuaCore
.
LuaState
luaState
,
int
index
)
public
static
void
lua_rawget
(
LuaState
luaState
,
int
index
)
{
{
LuaCore
.
LuaRawGet
(
luaState
,
index
);
LuaCore
.
LuaRawGet
(
luaState
,
index
);
}
}
public
static
void
lua_settable
(
LuaCore
.
LuaState
luaState
,
int
index
)
public
static
void
lua_settable
(
LuaState
luaState
,
int
index
)
{
{
LuaCore
.
LuaSetTable
(
luaState
,
index
);
LuaCore
.
LuaSetTable
(
luaState
,
index
);
}
}
public
static
void
lua_rawset
(
LuaCore
.
LuaState
luaState
,
int
index
)
public
static
void
lua_rawset
(
LuaState
luaState
,
int
index
)
{
{
LuaCore
.
LuaRawSet
(
luaState
,
index
);
LuaCore
.
LuaRawSet
(
luaState
,
index
);
}
}
public
static
void
lua_setmetatable
(
LuaCore
.
LuaState
luaState
,
int
objIndex
)
public
static
void
lua_setmetatable
(
LuaState
luaState
,
int
objIndex
)
{
{
LuaCore
.
LuaSetMetatable
(
luaState
,
objIndex
);
LuaCore
.
LuaSetMetatable
(
luaState
,
objIndex
);
}
}
public
static
int
lua_getmetatable
(
LuaCore
.
LuaState
luaState
,
int
objIndex
)
public
static
int
lua_getmetatable
(
LuaState
luaState
,
int
objIndex
)
{
{
return
LuaCore
.
LuaGetMetatable
(
luaState
,
objIndex
);
return
LuaCore
.
LuaGetMetatable
(
luaState
,
objIndex
);
}
}
public
static
int
lua_equal
(
LuaCore
.
LuaState
luaState
,
int
index1
,
int
index2
)
public
static
int
lua_equal
(
LuaState
luaState
,
int
index1
,
int
index2
)
{
{
return
LuaCore
.
LuaNetEqual
(
luaState
,
index1
,
index2
);
return
LuaCore
.
LuaNetEqual
(
luaState
,
index1
,
index2
);
}
}
public
static
void
lua_pushvalue
(
LuaCore
.
LuaState
luaState
,
int
index
)
public
static
void
lua_pushvalue
(
LuaState
luaState
,
int
index
)
{
{
LuaCore
.
LuaPushValue
(
luaState
,
index
);
LuaCore
.
LuaPushValue
(
luaState
,
index
);
}
}
public
static
void
lua_replace
(
LuaCore
.
LuaState
luaState
,
int
index
)
public
static
void
lua_replace
(
LuaState
luaState
,
int
index
)
{
{
LuaCore
.
LuaReplace
(
luaState
,
index
);
LuaCore
.
LuaReplace
(
luaState
,
index
);
}
}
public
static
int
lua_gettop
(
LuaCore
.
LuaState
luaState
)
public
static
int
lua_gettop
(
LuaState
luaState
)
{
{
return
LuaCore
.
LuaGetTop
(
luaState
);
return
LuaCore
.
LuaGetTop
(
luaState
);
}
}
public
static
LuaTypes
lua_type
(
LuaCore
.
LuaState
luaState
,
int
index
)
public
static
LuaTypes
lua_type
(
LuaState
luaState
,
int
index
)
{
{
return
(
LuaTypes
)
LuaCore
.
LuaType
(
luaState
,
index
);
return
(
LuaTypes
)
LuaCore
.
LuaType
(
luaState
,
index
);
}
}
public
static
bool
lua_isnil
(
LuaCore
.
LuaState
luaState
,
int
index
)
public
static
bool
lua_isnil
(
LuaState
luaState
,
int
index
)
{
{
return
lua_type
(
luaState
,
index
)
==
LuaTypes
.
Nil
;
return
lua_type
(
luaState
,
index
)
==
LuaTypes
.
Nil
;
}
}
public
static
bool
lua_isnumber
(
LuaCore
.
LuaState
luaState
,
int
index
)
public
static
bool
lua_isnumber
(
LuaState
luaState
,
int
index
)
{
{
return
lua_type
(
luaState
,
index
)
==
LuaTypes
.
Number
;
return
lua_type
(
luaState
,
index
)
==
LuaTypes
.
Number
;
}
}
public
static
bool
lua_isboolean
(
LuaCore
.
LuaState
luaState
,
int
index
)
public
static
bool
lua_isboolean
(
LuaState
luaState
,
int
index
)
{
{
return
lua_type
(
luaState
,
index
)
==
LuaTypes
.
Boolean
;
return
lua_type
(
luaState
,
index
)
==
LuaTypes
.
Boolean
;
}
}
public
static
int
luaL_ref
(
LuaCore
.
LuaState
luaState
,
int
registryIndex
)
public
static
int
luaL_ref
(
LuaState
luaState
,
int
registryIndex
)
{
{
return
LuaCore
.
LuaLRef
(
luaState
,
registryIndex
);
return
LuaCore
.
LuaLRef
(
luaState
,
registryIndex
);
}
}
public
static
int
lua_ref
(
LuaCore
.
LuaState
luaState
,
int
lockRef
)
public
static
int
lua_ref
(
LuaState
luaState
,
int
lockRef
)
{
{
return
lockRef
!=
0
?
luaL_ref
(
luaState
,
(
int
)
LuaIndexes
.
Registry
)
:
0
;
return
lockRef
!=
0
?
luaL_ref
(
luaState
,
(
int
)
LuaIndexes
.
Registry
)
:
0
;
}
}
public
static
void
lua_rawgeti
(
LuaCore
.
LuaState
luaState
,
int
tableIndex
,
int
index
)
public
static
void
lua_rawgeti
(
LuaState
luaState
,
int
tableIndex
,
int
index
)
{
{
LuaCore
.
LuaRawGetI
(
luaState
,
tableIndex
,
index
);
LuaCore
.
LuaRawGetI
(
luaState
,
tableIndex
,
index
);
}
}
public
static
void
lua_rawseti
(
LuaCore
.
LuaState
luaState
,
int
tableIndex
,
int
index
)
public
static
void
lua_rawseti
(
LuaState
luaState
,
int
tableIndex
,
int
index
)
{
{
LuaCore
.
LuaRawSetI
(
luaState
,
tableIndex
,
index
);
LuaCore
.
LuaRawSetI
(
luaState
,
tableIndex
,
index
);
}
}
public
static
object
lua_newuserdata
(
LuaCore
.
LuaState
luaState
,
int
size
)
public
static
object
lua_newuserdata
(
LuaState
luaState
,
int
size
)
{
{
return
LuaCore
.
LuaNewUserData
(
luaState
,
(
uint
)
size
);
return
LuaCore
.
LuaNewUserData
(
luaState
,
(
uint
)
size
);
}
}
public
static
object
lua_touserdata
(
LuaCore
.
LuaState
luaState
,
int
index
)
public
static
object
lua_touserdata
(
LuaState
luaState
,
int
index
)
{
{
return
LuaCore
.
LuaToUserData
(
luaState
,
index
);
return
LuaCore
.
LuaToUserData
(
luaState
,
index
);
}
}
public
static
void
lua_getref
(
LuaCore
.
LuaState
luaState
,
int
reference
)
public
static
void
lua_getref
(
LuaState
luaState
,
int
reference
)
{
{
lua_rawgeti
(
luaState
,
(
int
)
LuaIndexes
.
Registry
,
reference
);
lua_rawgeti
(
luaState
,
(
int
)
LuaIndexes
.
Registry
,
reference
);
}
}
public
static
void
lua_unref
(
LuaCore
.
LuaState
luaState
,
int
reference
)
public
static
void
lua_unref
(
LuaState
luaState
,
int
reference
)
{
{
LuaCore
.
LuaLUnref
(
luaState
,
(
int
)
LuaIndexes
.
Registry
,
reference
);
LuaCore
.
LuaLUnref
(
luaState
,
(
int
)
LuaIndexes
.
Registry
,
reference
);
}
}
public
static
bool
lua_isstring
(
LuaCore
.
LuaState
luaState
,
int
index
)
public
static
bool
lua_isstring
(
LuaState
luaState
,
int
index
)
{
{
return
LuaCore
.
LuaIsString
(
luaState
,
index
)
!=
0
;
return
LuaCore
.
LuaIsString
(
luaState
,
index
)
!=
0
;
}
}
public
static
bool
lua_iscfunction
(
LuaCore
.
LuaState
luaState
,
int
index
)
public
static
bool
lua_iscfunction
(
LuaState
luaState
,
int
index
)
{
{
return
LuaCore
.
LuaIsCFunction
(
luaState
,
index
);
return
LuaCore
.
LuaIsCFunction
(
luaState
,
index
);
}
}
public
static
void
lua_pushnil
(
LuaCore
.
LuaState
luaState
)
public
static
void
lua_pushnil
(
LuaState
luaState
)
{
{
LuaCore
.
LuaPushNil
(
luaState
);
LuaCore
.
LuaPushNil
(
luaState
);
}
}
public
static
void
lua_call
(
LuaCore
.
LuaState
luaState
,
int
nArgs
,
int
nResults
)
public
static
void
lua_call
(
LuaState
luaState
,
int
nArgs
,
int
nResults
)
{
{
LuaCore
.
LuaCall
(
luaState
,
nArgs
,
nResults
);
LuaCore
.
LuaCall
(
luaState
,
nArgs
,
nResults
);
}
}
public
static
void
lua_pushstdcallcfunction
(
LuaCore
.
LuaState
luaState
,
LuaCore
.
LuaNativeFunction
function
)
public
static
void
lua_pushstdcallcfunction
(
LuaState
luaState
,
LuaCore
.
LuaNativeFunction
function
)
{
{
LuaCore
.
LuaPushStdCallCFunction
(
luaState
,
function
);
LuaCore
.
LuaPushStdCallCFunction
(
luaState
,
function
);
}
}
public
static
int
lua_pcall
(
LuaCore
.
LuaState
luaState
,
int
nArgs
,
int
nResults
,
int
errfunc
)
public
static
int
lua_pcall
(
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
lua_tocfunction
(
LuaCore
.
LuaState
luaState
,
int
index
)
public
static
LuaCore
.
LuaNativeFunction
lua_tocfunction
(
LuaState
luaState
,
int
index
)
{
{
return
LuaCore
.
LuaToCFunction
(
luaState
,
index
);
return
LuaCore
.
LuaToCFunction
(
luaState
,
index
);
}
}
public
static
double
lua_tonumber
(
LuaCore
.
LuaState
luaState
,
int
index
)
public
static
double
lua_tonumber
(
LuaState
luaState
,
int
index
)
{
{
return
LuaCore
.
LuaNetToNumber
(
luaState
,
index
);
return
LuaCore
.
LuaNetToNumber
(
luaState
,
index
);
}
}
public
static
bool
lua_toboolean
(
LuaCore
.
LuaState
luaState
,
int
index
)
public
static
bool
lua_toboolean
(
LuaState
luaState
,
int
index
)
{
{
return
LuaCore
.
LuaToBoolean
(
luaState
,
index
)
!=
0
;
return
LuaCore
.
LuaToBoolean
(
luaState
,
index
)
!=
0
;
}
}
public
static
string
lua_tostring
(
LuaCore
.
LuaState
luaState
,
int
index
)
public
static
string
lua_tostring
(
LuaState
luaState
,
int
index
)
{
{
#if true
#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
...
@@ -354,69 +358,69 @@ namespace NLua
...
@@ -354,69 +358,69 @@ namespace NLua
#endif
#endif
}
}
public
static
void
lua_atpanic
(
LuaCore
.
LuaState
luaState
,
LuaCore
.
LuaNativeFunction
panicf
)
public
static
void
lua_atpanic
(
LuaState
luaState
,
LuaCore
.
LuaNativeFunction
panicf
)
{
{
LuaCore
.
LuaAtPanic
(
luaState
,
(
LuaCore
.
LuaNativeFunction
)
panicf
);
LuaCore
.
LuaAtPanic
(
luaState
,
(
LuaCore
.
LuaNativeFunction
)
panicf
);
}
}
public
static
void
lua_pushnumber
(
LuaCore
.
LuaState
luaState
,
double
number
)
public
static
void
lua_pushnumber
(
LuaState
luaState
,
double
number
)
{
{
LuaCore
.
LuaPushNumber
(
luaState
,
number
);
LuaCore
.
LuaPushNumber
(
luaState
,
number
);
}
}
public
static
void
lua_pushboolean
(
LuaCore
.
LuaState
luaState
,
bool
value
)
public
static
void
lua_pushboolean
(
LuaState
luaState
,
bool
value
)
{
{
LuaCore
.
LuaPushBoolean
(
luaState
,
value
?
1
:
0
);
LuaCore
.
LuaPushBoolean
(
luaState
,
value
?
1
:
0
);
}
}
public
static
void
lua_pushstring
(
LuaCore
.
LuaState
luaState
,
string
str
)
public
static
void
lua_pushstring
(
LuaState
luaState
,
string
str
)
{
{
LuaCore
.
LuaPushString
(
luaState
,
str
);
LuaCore
.
LuaPushString
(
luaState
,
str
);
}
}
public
static
int
luaL_newmetatable
(
LuaCore
.
LuaState
luaState
,
string
meta
)
public
static
int
luaL_newmetatable
(
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)
// steffenj: BEGIN Lua 5.1.1 API change (luaL_getmetatable is now a macro using lua_getfield)
public
static
void
lua_getfield
(
LuaCore
.
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
luaL_getmetatable
(
LuaCore
.
LuaState
luaState
,
string
meta
)
public
static
void
luaL_getmetatable
(
LuaState
luaState
,
string
meta
)
{
{
lua_getfield
(
luaState
,
(
int
)
LuaIndexes
.
Registry
,
meta
);
lua_getfield
(
luaState
,
(
int
)
LuaIndexes
.
Registry
,
meta
);
}
}
public
static
object
luaL_checkudata
(
LuaCore
.
LuaState
luaState
,
int
stackPos
,
string
meta
)
public
static
object
luaL_checkudata
(
LuaState
luaState
,
int
stackPos
,
string
meta
)
{
{
return
LuaCore
.
LuaLCheckUData
(
luaState
,
stackPos
,
meta
);
return
LuaCore
.
LuaLCheckUData
(
luaState
,
stackPos
,
meta
);
}
}
public
static
bool
luaL_getmetafield
(
LuaCore
.
LuaState
luaState
,
int
stackPos
,
string
field
)
public
static
bool
luaL_getmetafield
(
LuaState
luaState
,
int
stackPos
,
string
field
)
{
{
return
LuaCore
.
LuaLGetMetafield
(
luaState
,
stackPos
,
field
)
!=
0
;
return
LuaCore
.
LuaLGetMetafield
(
luaState
,
stackPos
,
field
)
!=
0
;
}
}
public
static
int
luaL_loadbuffer
(
LuaCore
.
LuaState
luaState
,
string
buff
,
string
name
)
public
static
int
luaL_loadbuffer
(
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
luaL_loadbuffer
(
LuaCore
.
LuaState
luaState
,
byte
[]
buff
,
string
name
)
public
static
int
luaL_loadbuffer
(
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
luaL_loadfile
(
LuaCore
.
LuaState
luaState
,
string
filename
)
public
static
int
luaL_loadfile
(
LuaState
luaState
,
string
filename
)
{
{
return
LuaCore
.
LuaNetLoadFile
(
luaState
,
filename
);
return
LuaCore
.
LuaNetLoadFile
(
luaState
,
filename
);
}
}
public
static
bool
luaL_checkmetatable
(
LuaCore
.
LuaState
luaState
,
int
index
)
public
static
bool
luaL_checkmetatable
(
LuaState
luaState
,
int
index
)
{
{
return
LuaCore
.
LuaLCheckMetatable
(
luaState
,
index
);
return
LuaCore
.
LuaLCheckMetatable
(
luaState
,
index
);
}
}
...
@@ -426,57 +430,57 @@ namespace NLua
...
@@ -426,57 +430,57 @@ namespace NLua
return
LuaCore
.
LuaNetRegistryIndex
();
return
LuaCore
.
LuaNetRegistryIndex
();
}
}
public
static
int
luanet_tonetobject
(
LuaCore
.
LuaState
luaState
,
int
index
)
public
static
int
luanet_tonetobject
(
LuaState
luaState
,
int
index
)
{
{
return
LuaCore
.
LuaNetToNetObject
(
luaState
,
index
);
return
LuaCore
.
LuaNetToNetObject
(
luaState
,
index
);
}
}
public
static
void
luanet_newudata
(
LuaCore
.
LuaState
luaState
,
int
val
)
public
static
void
luanet_newudata
(
LuaState
luaState
,
int
val
)
{
{
LuaCore
.
LuaNetNewUData
(
luaState
,
val
);
LuaCore
.
LuaNetNewUData
(
luaState
,
val
);
}
}
public
static
int
luanet_rawnetobj
(
LuaCore
.
LuaState
luaState
,
int
obj
)
public
static
int
luanet_rawnetobj
(
LuaState
luaState
,
int
obj
)
{
{
return
LuaCore
.
LuaNetRawNetObj
(
luaState
,
obj
);
return
LuaCore
.
LuaNetRawNetObj
(
luaState
,
obj
);
}
}
public
static
int
luanet_checkudata
(
LuaCore
.
LuaState
luaState
,
int
ud
,
string
tname
)
public
static
int
luanet_checkudata
(
LuaState
luaState
,
int
ud
,
string
tname
)
{
{
return
LuaCore
.
LuaNetCheckUData
(
luaState
,
ud
,
tname
);
return
LuaCore
.
LuaNetCheckUData
(
luaState
,
ud
,
tname
);
}
}
public
static
void
lua_error
(
LuaCore
.
LuaState
luaState
)
public
static
void
lua_error
(
LuaState
luaState
)
{
{
LuaCore
.
LuaError
(
luaState
);
LuaCore
.
LuaError
(
luaState
);
}
}
public
static
bool
lua_checkstack
(
LuaCore
.
LuaState
luaState
,
int
extra
)
public
static
bool
lua_checkstack
(
LuaState
luaState
,
int
extra
)
{
{
return
LuaCore
.
LuaCheckStack
(
luaState
,
extra
)
!=
0
;
return
LuaCore
.
LuaCheckStack
(
luaState
,
extra
)
!=
0
;
}
}
public
static
int
lua_next
(
LuaCore
.
LuaState
luaState
,
int
index
)
public
static
int
lua_next
(
LuaState
luaState
,
int
index
)
{
{
return
LuaCore
.
LuaNext
(
luaState
,
index
);
return
LuaCore
.
LuaNext
(
luaState
,
index
);
}
}
public
static
void
lua_pushlightuserdata
(
LuaCore
.
LuaState
luaState
,
LuaCore
.
LuaTag
udata
)
public
static
void
lua_pushlightuserdata
(
LuaState
luaState
,
LuaTag
udata
)
{
{
LuaCore
.
LuaPushLightUserData
(
luaState
,
udata
.
Tag
);
LuaCore
.
LuaPushLightUserData
(
luaState
,
udata
.
Tag
);
}
}
public
static
LuaCore
.
LuaTag
luanet_gettag
()
public
static
LuaTag
luanet_gettag
()
{
{
return
LuaCore
.
LuaNetGetTag
();
return
LuaCore
.
LuaNetGetTag
();
}
}
public
static
void
luanet_pushglobaltable
(
LuaCore
.
LuaState
luaState
)
public
static
void
luanet_pushglobaltable
(
LuaState
luaState
)
{
{
LuaCore
.
LuaNetPushGlobalTable
(
luaState
);
LuaCore
.
LuaNetPushGlobalTable
(
luaState
);
}
}
public
static
void
luanet_popglobaltable
(
LuaCore
.
LuaState
luaState
)
public
static
void
luanet_popglobaltable
(
LuaState
luaState
)
{
{
LuaCore
.
LuaNetPopGlobalTable
(
luaState
);
LuaCore
.
LuaNetPopGlobalTable
(
luaState
);
}
}
...
...
Core/NLua/LuaTable.cs
View file @
c84425fd
...
@@ -32,8 +32,10 @@ namespace NLua
...
@@ -32,8 +32,10 @@ namespace NLua
{
{
#
if
USE_KOPILUA
#
if
USE_KOPILUA
using
LuaCore
=
KopiLua
.
Lua
;
using
LuaCore
=
KopiLua
.
Lua
;
using
LuaState
=
KopiLua
.
LuaState
;
#
else
#
else
using
LuaCore
=
KeraLua
.
Lua
;
using
LuaCore
=
KeraLua
.
Lua
;
using
LuaState
=
KeraLua
.
LuaState
;
#
endif
#
endif
/*
/*
...
@@ -109,7 +111,7 @@ namespace NLua
...
@@ -109,7 +111,7 @@ namespace NLua
/*
/*
* Pushes this table into the Lua stack
* Pushes this table into the Lua stack
*/
*/
internal
void
push
(
LuaCore
.
LuaState
luaState
)
internal
void
push
(
LuaState
luaState
)
{
{
LuaLib
.
lua_getref
(
luaState
,
_Reference
);
LuaLib
.
lua_getref
(
luaState
,
_Reference
);
}
}
...
...
Core/NLua/LuaUserData.cs
View file @
c84425fd
...
@@ -31,8 +31,10 @@ namespace NLua
...
@@ -31,8 +31,10 @@ namespace NLua
{
{
#
if
USE_KOPILUA
#
if
USE_KOPILUA
using
LuaCore
=
KopiLua
.
Lua
;
using
LuaCore
=
KopiLua
.
Lua
;
using
LuaState
=
KopiLua
.
LuaState
;
#
else
#
else
using
LuaCore
=
KeraLua
.
Lua
;
using
LuaCore
=
KeraLua
.
Lua
;
using
LuaState
=
KeraLua
.
LuaState
;
#
endif
#
endif
public
class
LuaUserData
:
LuaBase
public
class
LuaUserData
:
LuaBase
...
@@ -79,7 +81,7 @@ namespace NLua
...
@@ -79,7 +81,7 @@ namespace NLua
/*
/*
* Pushes the userdata into the Lua stack
* Pushes the userdata into the Lua stack
*/
*/
internal
void
push
(
LuaCore
.
LuaState
luaState
)
internal
void
push
(
LuaState
luaState
)
{
{
LuaLib
.
lua_getref
(
luaState
,
_Reference
);
LuaLib
.
lua_getref
(
luaState
,
_Reference
);
}
}
...
...
Core/NLua/Metatables.cs
View file @
c84425fd
...
@@ -36,8 +36,10 @@ namespace NLua
...
@@ -36,8 +36,10 @@ namespace NLua
{
{
#
if
USE_KOPILUA
#
if
USE_KOPILUA
using
LuaCore
=
KopiLua
.
Lua
;
using
LuaCore
=
KopiLua
.
Lua
;
using
LuaState
=
KopiLua
.
LuaState
;
#
else
#
else
using
LuaCore
=
KeraLua
.
Lua
;
using
LuaCore
=
KeraLua
.
Lua
;
using
LuaState
=
KeraLua
.
LuaState
;
#
endif
#
endif
/*
/*
...
@@ -95,13 +97,13 @@ namespace NLua
...
@@ -95,13 +97,13 @@ namespace NLua
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
#endif
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
private
static
int
runFunctionDelegate
(
LuaCore
.
LuaState
luaState
)
private
static
int
runFunctionDelegate
(
LuaState
luaState
)
{
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
return
runFunctionDelegate
(
luaState
,
translator
);
return
runFunctionDelegate
(
luaState
,
translator
);
}
}
private
static
int
runFunctionDelegate
(
LuaCore
.
LuaState
luaState
,
ObjectTranslator
translator
)
private
static
int
runFunctionDelegate
(
LuaState
luaState
,
ObjectTranslator
translator
)
{
{
LuaCore
.
LuaNativeFunction
func
=
(
LuaCore
.
LuaNativeFunction
)
translator
.
getRawNetObject
(
luaState
,
1
);
LuaCore
.
LuaNativeFunction
func
=
(
LuaCore
.
LuaNativeFunction
)
translator
.
getRawNetObject
(
luaState
,
1
);
LuaLib
.
lua_remove
(
luaState
,
1
);
LuaLib
.
lua_remove
(
luaState
,
1
);
...
@@ -115,13 +117,13 @@ namespace NLua
...
@@ -115,13 +117,13 @@ namespace NLua
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
#endif
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
private
static
int
collectObject
(
LuaCore
.
LuaState
luaState
)
private
static
int
collectObject
(
LuaState
luaState
)
{
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
return
collectObject
(
luaState
,
translator
);
return
collectObject
(
luaState
,
translator
);
}
}
private
static
int
collectObject
(
LuaCore
.
LuaState
luaState
,
ObjectTranslator
translator
)
private
static
int
collectObject
(
LuaState
luaState
,
ObjectTranslator
translator
)
{
{
int
udata
=
LuaLib
.
luanet_rawnetobj
(
luaState
,
1
);
int
udata
=
LuaLib
.
luanet_rawnetobj
(
luaState
,
1
);
...
@@ -138,13 +140,13 @@ namespace NLua
...
@@ -138,13 +140,13 @@ namespace NLua
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
#endif
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
private
static
int
toString
(
LuaCore
.
LuaState
luaState
)
private
static
int
toString
(
LuaState
luaState
)
{
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
return
toString
(
luaState
,
translator
);
return
toString
(
luaState
,
translator
);
}
}
private
static
int
toString
(
LuaCore
.
LuaState
luaState
,
ObjectTranslator
translator
)
private
static
int
toString
(
LuaState
luaState
,
ObjectTranslator
translator
)
{
{
object
obj
=
translator
.
getRawNetObject
(
luaState
,
1
);
object
obj
=
translator
.
getRawNetObject
(
luaState
,
1
);
...
@@ -161,7 +163,7 @@ namespace NLua
...
@@ -161,7 +163,7 @@ namespace NLua
/// Debug tool to dump the lua stack
/// Debug tool to dump the lua stack
/// </summary>
/// </summary>
/// FIXME, move somewhere else
/// FIXME, move somewhere else
public
static
void
dumpStack
(
ObjectTranslator
translator
,
LuaCore
.
LuaState
luaState
)
public
static
void
dumpStack
(
ObjectTranslator
translator
,
LuaState
luaState
)
{
{
int
depth
=
LuaLib
.
lua_gettop
(
luaState
);
int
depth
=
LuaLib
.
lua_gettop
(
luaState
);
Debug
.
WriteLine
(
"lua stack depth: "
+
depth
);
Debug
.
WriteLine
(
"lua stack depth: "
+
depth
);
...
@@ -196,14 +198,14 @@ namespace NLua
...
@@ -196,14 +198,14 @@ namespace NLua
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
#endif
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
private
static
int
getMethod
(
LuaCore
.
LuaState
luaState
)
private
static
int
getMethod
(
LuaState
luaState
)
{
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
instance
=
translator
.
MetaFunctionsInstance
;
var
instance
=
translator
.
MetaFunctionsInstance
;
return
instance
.
getMethodInternal
(
luaState
);
return
instance
.
getMethodInternal
(
luaState
);
}
}
private
int
getMethodInternal
(
LuaCore
.
LuaState
luaState
)
private
int
getMethodInternal
(
LuaState
luaState
)
{
{
object
obj
=
translator
.
getRawNetObject
(
luaState
,
1
);
object
obj
=
translator
.
getRawNetObject
(
luaState
,
1
);
...
@@ -297,14 +299,14 @@ namespace NLua
...
@@ -297,14 +299,14 @@ namespace NLua
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
#endif
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
private
static
int
getBaseMethod
(
LuaCore
.
LuaState
luaState
)
private
static
int
getBaseMethod
(
LuaState
luaState
)
{
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
instance
=
translator
.
MetaFunctionsInstance
;
var
instance
=
translator
.
MetaFunctionsInstance
;
return
instance
.
getBaseMethodInternal
(
luaState
);
return
instance
.
getBaseMethodInternal
(
luaState
);
}
}
private
int
getBaseMethodInternal
(
LuaCore
.
LuaState
luaState
)
private
int
getBaseMethodInternal
(
LuaState
luaState
)
{
{
object
obj
=
translator
.
getRawNetObject
(
luaState
,
1
);
object
obj
=
translator
.
getRawNetObject
(
luaState
,
1
);
...
@@ -359,7 +361,7 @@ namespace NLua
...
@@ -359,7 +361,7 @@ namespace NLua
* Uses reflection to find members, and stores the reflected MemberInfo object in
* 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).
* a cache (indexed by the type of the object and the name of the member).
*/
*/
private
int
getMember
(
LuaCore
.
LuaState
luaState
,
IReflect
objType
,
object
obj
,
string
methodName
,
BindingFlags
bindingType
)
private
int
getMember
(
LuaState
luaState
,
IReflect
objType
,
object
obj
,
string
methodName
,
BindingFlags
bindingType
)
{
{
bool
implicitStatic
=
false
;
bool
implicitStatic
=
false
;
MemberInfo
member
=
null
;
MemberInfo
member
=
null
;
...
@@ -519,14 +521,14 @@ namespace NLua
...
@@ -519,14 +521,14 @@ namespace NLua
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
#endif
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
private
static
int
setFieldOrProperty
(
LuaCore
.
LuaState
luaState
)
private
static
int
setFieldOrProperty
(
LuaState
luaState
)
{
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
instance
=
translator
.
MetaFunctionsInstance
;
var
instance
=
translator
.
MetaFunctionsInstance
;
return
instance
.
setFieldOrPropertyInternal
(
luaState
);
return
instance
.
setFieldOrPropertyInternal
(
luaState
);
}
}
private
int
setFieldOrPropertyInternal
(
LuaCore
.
LuaState
luaState
)
private
int
setFieldOrPropertyInternal
(
LuaState
luaState
)
{
{
object
target
=
translator
.
getRawNetObject
(
luaState
,
1
);
object
target
=
translator
.
getRawNetObject
(
luaState
,
1
);
...
@@ -592,7 +594,7 @@ namespace NLua
...
@@ -592,7 +594,7 @@ namespace NLua
/// <param name="target"></param>
/// <param name="target"></param>
/// <param name="bindingType"></param>
/// <param name="bindingType"></param>
/// <returns>false if unable to find the named member, true for success</returns>
/// <returns>false if unable to find the named member, true for success</returns>
private
bool
trySetMember
(
LuaCore
.
LuaState
luaState
,
IReflect
targetType
,
object
target
,
BindingFlags
bindingType
,
out
string
detailMessage
)
private
bool
trySetMember
(
LuaState
luaState
,
IReflect
targetType
,
object
target
,
BindingFlags
bindingType
,
out
string
detailMessage
)
{
{
detailMessage
=
null
;
// No error yet
detailMessage
=
null
;
// No error yet
...
@@ -661,7 +663,7 @@ namespace NLua
...
@@ -661,7 +663,7 @@ namespace NLua
* Writes to fields or properties, either static or instance. Throws an error
* Writes to fields or properties, either static or instance. Throws an error
* if the operation is invalid.
* if the operation is invalid.
*/
*/
private
int
setMember
(
LuaCore
.
LuaState
luaState
,
IReflect
targetType
,
object
target
,
BindingFlags
bindingType
)
private
int
setMember
(
LuaState
luaState
,
IReflect
targetType
,
object
target
,
BindingFlags
bindingType
)
{
{
string
detail
;
string
detail
;
bool
success
=
trySetMember
(
luaState
,
targetType
,
target
,
bindingType
,
out
detail
);
bool
success
=
trySetMember
(
luaState
,
targetType
,
target
,
bindingType
,
out
detail
);
...
@@ -677,7 +679,7 @@ namespace NLua
...
@@ -677,7 +679,7 @@ namespace NLua
/// </summary>
/// </summary>
/// <param name="e"></param>
/// <param name="e"></param>
/// We try to look into the exception to give the most meaningful description
/// We try to look into the exception to give the most meaningful description
void
ThrowError
(
LuaCore
.
LuaState
luaState
,
Exception
e
)
void
ThrowError
(
LuaState
luaState
,
Exception
e
)
{
{
// If we got inside a reflection show what really happened
// If we got inside a reflection show what really happened
var
te
=
e
as
TargetInvocationException
;
var
te
=
e
as
TargetInvocationException
;
...
@@ -695,14 +697,14 @@ namespace NLua
...
@@ -695,14 +697,14 @@ namespace NLua
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
#endif
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
private
static
int
getClassMethod
(
LuaCore
.
LuaState
luaState
)
private
static
int
getClassMethod
(
LuaState
luaState
)
{
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
instance
=
translator
.
MetaFunctionsInstance
;
var
instance
=
translator
.
MetaFunctionsInstance
;
return
instance
.
getClassMethodInternal
(
luaState
);
return
instance
.
getClassMethodInternal
(
luaState
);
}
}
private
int
getClassMethodInternal
(
LuaCore
.
LuaState
luaState
)
private
int
getClassMethodInternal
(
LuaState
luaState
)
{
{
IReflect
klass
;
IReflect
klass
;
object
obj
=
translator
.
getRawNetObject
(
luaState
,
1
);
object
obj
=
translator
.
getRawNetObject
(
luaState
,
1
);
...
@@ -737,14 +739,14 @@ namespace NLua
...
@@ -737,14 +739,14 @@ namespace NLua
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
#endif
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
private
static
int
setClassFieldOrProperty
(
LuaCore
.
LuaState
luaState
)
private
static
int
setClassFieldOrProperty
(
LuaState
luaState
)
{
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
instance
=
translator
.
MetaFunctionsInstance
;
var
instance
=
translator
.
MetaFunctionsInstance
;
return
instance
.
setClassFieldOrPropertyInternal
(
luaState
);
return
instance
.
setClassFieldOrPropertyInternal
(
luaState
);
}
}
private
int
setClassFieldOrPropertyInternal
(
LuaCore
.
LuaState
luaState
)
private
int
setClassFieldOrPropertyInternal
(
LuaState
luaState
)
{
{
IReflect
target
;
IReflect
target
;
object
obj
=
translator
.
getRawNetObject
(
luaState
,
1
);
object
obj
=
translator
.
getRawNetObject
(
luaState
,
1
);
...
@@ -768,14 +770,14 @@ namespace NLua
...
@@ -768,14 +770,14 @@ namespace NLua
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
#endif
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
private
static
int
callConstructor
(
LuaCore
.
LuaState
luaState
)
private
static
int
callConstructor
(
LuaState
luaState
)
{
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
instance
=
translator
.
MetaFunctionsInstance
;
var
instance
=
translator
.
MetaFunctionsInstance
;
return
instance
.
callConstructorInternal
(
luaState
);
return
instance
.
callConstructorInternal
(
luaState
);
}
}
private
int
callConstructorInternal
(
LuaCore
.
LuaState
luaState
)
private
int
callConstructorInternal
(
LuaState
luaState
)
{
{
var
validConstructor
=
new
MethodCache
();
var
validConstructor
=
new
MethodCache
();
IReflect
klass
;
IReflect
klass
;
...
@@ -860,7 +862,7 @@ namespace NLua
...
@@ -860,7 +862,7 @@ namespace NLua
* if the match was succesful. It it was also returns the information
* if the match was succesful. It it was also returns the information
* necessary to invoke the method.
* necessary to invoke the method.
*/
*/
internal
bool
matchParameters
(
LuaCore
.
LuaState
luaState
,
MethodBase
method
,
ref
MethodCache
methodCache
)
internal
bool
matchParameters
(
LuaState
luaState
,
MethodBase
method
,
ref
MethodCache
methodCache
)
{
{
ExtractValue
extractValue
;
ExtractValue
extractValue
;
bool
isMethod
=
true
;
bool
isMethod
=
true
;
...
@@ -945,7 +947,7 @@ namespace NLua
...
@@ -945,7 +947,7 @@ namespace NLua
/// <param name="currentNetParam"></param>
/// <param name="currentNetParam"></param>
/// <param name="extractValue"></param>
/// <param name="extractValue"></param>
/// <returns></returns>
/// <returns></returns>
private
bool
_IsTypeCorrect
(
LuaCore
.
LuaState
luaState
,
int
currentLuaParam
,
ParameterInfo
currentNetParam
,
out
ExtractValue
extractValue
)
private
bool
_IsTypeCorrect
(
LuaState
luaState
,
int
currentLuaParam
,
ParameterInfo
currentNetParam
,
out
ExtractValue
extractValue
)
{
{
try
{
try
{
return
(
extractValue
=
translator
.
typeChecker
.
checkType
(
luaState
,
currentLuaParam
,
currentNetParam
.
ParameterType
))
!=
null
;
return
(
extractValue
=
translator
.
typeChecker
.
checkType
(
luaState
,
currentLuaParam
,
currentNetParam
.
ParameterType
))
!=
null
;
...
@@ -956,7 +958,7 @@ namespace NLua
...
@@ -956,7 +958,7 @@ namespace NLua
}
}
}
}
private
bool
_IsParamsArray
(
LuaCore
.
LuaState
luaState
,
int
currentLuaParam
,
ParameterInfo
currentNetParam
,
out
ExtractValue
extractValue
)
private
bool
_IsParamsArray
(
LuaState
luaState
,
int
currentLuaParam
,
ParameterInfo
currentNetParam
,
out
ExtractValue
extractValue
)
{
{
extractValue
=
null
;
extractValue
=
null
;
...
...
Core/NLua/Method/LuaMethodWrapper.cs
View file @
c84425fd
...
@@ -32,14 +32,16 @@ namespace NLua.Method
...
@@ -32,14 +32,16 @@ namespace NLua.Method
{
{
#
if
USE_KOPILUA
#
if
USE_KOPILUA
using
LuaCore
=
KopiLua
.
Lua
;
using
LuaCore
=
KopiLua
.
Lua
;
using
LuaState
=
KopiLua
.
LuaState
;
#
else
#
else
using
LuaCore
=
KeraLua
.
Lua
;
using
LuaCore
=
KeraLua
.
Lua
;
using
LuaState
=
KeraLua
.
LuaState
;
#
endif
#
endif
/*
/*
* Argument extraction with type-conversion function
* Argument extraction with type-conversion function
*/
*/
delegate
object
ExtractValue
(
LuaCore
.
LuaState
luaState
,
int
stackPos
);
delegate
object
ExtractValue
(
LuaState
luaState
,
int
stackPos
);
/*
/*
* Wrapper class for methods/constructors accessed from Lua.
* Wrapper class for methods/constructors accessed from Lua.
...
@@ -112,7 +114,7 @@ namespace NLua.Method
...
@@ -112,7 +114,7 @@ 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
call
(
LuaCore
.
LuaState
luaState
)
int
call
(
LuaState
luaState
)
{
{
var
methodToCall
=
_Method
;
var
methodToCall
=
_Method
;
object
targetObject
=
_Target
;
object
targetObject
=
_Target
;
...
...
Core/NLua/ObjectTranslator.cs
View file @
c84425fd
...
@@ -37,8 +37,10 @@ namespace NLua
...
@@ -37,8 +37,10 @@ namespace NLua
{
{
#
if
USE_KOPILUA
#
if
USE_KOPILUA
using
LuaCore
=
KopiLua
.
Lua
;
using
LuaCore
=
KopiLua
.
Lua
;
using
LuaState
=
KopiLua
.
LuaState
;
#
else
#
else
using
LuaCore
=
KeraLua
.
Lua
;
using
LuaCore
=
KeraLua
.
Lua
;
using
LuaState
=
KeraLua
.
LuaState
;
#
endif
#
endif
/*
/*
...
@@ -77,7 +79,7 @@ namespace NLua
...
@@ -77,7 +79,7 @@ namespace NLua
}
}
}
}
public
ObjectTranslator
(
Lua
interpreter
,
LuaCore
.
LuaState
luaState
)
public
ObjectTranslator
(
Lua
interpreter
,
LuaState
luaState
)
{
{
this
.
interpreter
=
interpreter
;
this
.
interpreter
=
interpreter
;
typeChecker
=
new
CheckType
(
this
);
typeChecker
=
new
CheckType
(
this
);
...
@@ -102,7 +104,7 @@ namespace NLua
...
@@ -102,7 +104,7 @@ namespace NLua
/*
/*
* Sets up the list of objects in the Lua side
* Sets up the list of objects in the Lua side
*/
*/
private
void
createLuaObjectList
(
LuaCore
.
LuaState
luaState
)
private
void
createLuaObjectList
(
LuaState
luaState
)
{
{
LuaLib
.
lua_pushstring
(
luaState
,
"luaNet_objects"
);
LuaLib
.
lua_pushstring
(
luaState
,
"luaNet_objects"
);
LuaLib
.
lua_newtable
(
luaState
);
LuaLib
.
lua_newtable
(
luaState
);
...
@@ -118,7 +120,7 @@ namespace NLua
...
@@ -118,7 +120,7 @@ namespace NLua
* Registers the indexing function of CLR objects
* Registers the indexing function of CLR objects
* passed to Lua
* passed to Lua
*/
*/
private
void
createIndexingMetaFunction
(
LuaCore
.
LuaState
luaState
)
private
void
createIndexingMetaFunction
(
LuaState
luaState
)
{
{
LuaLib
.
lua_pushstring
(
luaState
,
"luaNet_indexfunction"
);
LuaLib
.
lua_pushstring
(
luaState
,
"luaNet_indexfunction"
);
LuaLib
.
luaL_dostring
(
luaState
,
MetaFunctions
.
luaIndexFunction
);
// steffenj: lua_dostring renamed to luaL_dostring
LuaLib
.
luaL_dostring
(
luaState
,
MetaFunctions
.
luaIndexFunction
);
// steffenj: lua_dostring renamed to luaL_dostring
...
@@ -129,7 +131,7 @@ namespace NLua
...
@@ -129,7 +131,7 @@ namespace NLua
* Creates the metatable for superclasses (the base
* Creates the metatable for superclasses (the base
* field of registered tables)
* field of registered tables)
*/
*/
private
void
createBaseClassMetatable
(
LuaCore
.
LuaState
luaState
)
private
void
createBaseClassMetatable
(
LuaState
luaState
)
{
{
LuaLib
.
luaL_newmetatable
(
luaState
,
"luaNet_searchbase"
);
LuaLib
.
luaL_newmetatable
(
luaState
,
"luaNet_searchbase"
);
LuaLib
.
lua_pushstring
(
luaState
,
"__gc"
);
LuaLib
.
lua_pushstring
(
luaState
,
"__gc"
);
...
@@ -150,7 +152,7 @@ namespace NLua
...
@@ -150,7 +152,7 @@ namespace NLua
/*
/*
* Creates the metatable for type references
* Creates the metatable for type references
*/
*/
private
void
createClassMetatable
(
LuaCore
.
LuaState
luaState
)
private
void
createClassMetatable
(
LuaState
luaState
)
{
{
LuaLib
.
luaL_newmetatable
(
luaState
,
"luaNet_class"
);
LuaLib
.
luaL_newmetatable
(
luaState
,
"luaNet_class"
);
LuaLib
.
lua_pushstring
(
luaState
,
"__gc"
);
LuaLib
.
lua_pushstring
(
luaState
,
"__gc"
);
...
@@ -174,7 +176,7 @@ namespace NLua
...
@@ -174,7 +176,7 @@ namespace NLua
/*
/*
* Registers the global functions used by NLua
* Registers the global functions used by NLua
*/
*/
private
void
setGlobalFunctions
(
LuaCore
.
LuaState
luaState
)
private
void
setGlobalFunctions
(
LuaState
luaState
)
{
{
LuaLib
.
lua_pushstdcallcfunction
(
luaState
,
metaFunctions
.
indexFunction
);
LuaLib
.
lua_pushstdcallcfunction
(
luaState
,
metaFunctions
.
indexFunction
);
LuaLib
.
lua_setglobal
(
luaState
,
"get_object_member"
);
LuaLib
.
lua_setglobal
(
luaState
,
"get_object_member"
);
...
@@ -195,7 +197,7 @@ namespace NLua
...
@@ -195,7 +197,7 @@ namespace NLua
/*
/*
* Creates the metatable for delegates
* Creates the metatable for delegates
*/
*/
private
void
createFunctionMetatable
(
LuaCore
.
LuaState
luaState
)
private
void
createFunctionMetatable
(
LuaState
luaState
)
{
{
LuaLib
.
luaL_newmetatable
(
luaState
,
"luaNet_function"
);
LuaLib
.
luaL_newmetatable
(
luaState
,
"luaNet_function"
);
LuaLib
.
lua_pushstring
(
luaState
,
"__gc"
);
LuaLib
.
lua_pushstring
(
luaState
,
"__gc"
);
...
@@ -210,7 +212,7 @@ namespace NLua
...
@@ -210,7 +212,7 @@ namespace NLua
/*
/*
* Passes errors (argument e) to the Lua interpreter
* Passes errors (argument e) to the Lua interpreter
*/
*/
internal
void
throwError
(
LuaCore
.
LuaState
luaState
,
object
e
)
internal
void
throwError
(
LuaState
luaState
,
object
e
)
{
{
// We use this to remove anything pushed by luaL_where
// We use this to remove anything pushed by luaL_where
int
oldTop
=
LuaLib
.
lua_gettop
(
luaState
);
int
oldTop
=
LuaLib
.
lua_gettop
(
luaState
);
...
@@ -252,13 +254,13 @@ namespace NLua
...
@@ -252,13 +254,13 @@ namespace NLua
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
#endif
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
private
static
int
loadAssembly
(
LuaCore
.
LuaState
luaState
)
private
static
int
loadAssembly
(
LuaState
luaState
)
{
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
return
translator
.
loadAssemblyInternal
(
luaState
);
return
translator
.
loadAssemblyInternal
(
luaState
);
}
}
private
int
loadAssemblyInternal
(
LuaCore
.
LuaState
luaState
)
private
int
loadAssemblyInternal
(
LuaState
luaState
)
{
{
try
{
try
{
string
assemblyName
=
LuaLib
.
lua_tostring
(
luaState
,
1
).
ToString
();
string
assemblyName
=
LuaLib
.
lua_tostring
(
luaState
,
1
).
ToString
();
...
@@ -303,13 +305,13 @@ namespace NLua
...
@@ -303,13 +305,13 @@ namespace NLua
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
#endif
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
private
static
int
importType
(
LuaCore
.
LuaState
luaState
)
private
static
int
importType
(
LuaState
luaState
)
{
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
return
translator
.
importTypeInternal
(
luaState
);
return
translator
.
importTypeInternal
(
luaState
);
}
}
private
int
importTypeInternal
(
LuaCore
.
LuaState
luaState
)
private
int
importTypeInternal
(
LuaState
luaState
)
{
{
string
className
=
LuaLib
.
lua_tostring
(
luaState
,
1
).
ToString
();
string
className
=
LuaLib
.
lua_tostring
(
luaState
,
1
).
ToString
();
var
klass
=
FindType
(
className
);
var
klass
=
FindType
(
className
);
...
@@ -331,13 +333,13 @@ namespace NLua
...
@@ -331,13 +333,13 @@ namespace NLua
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
#endif
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
private
static
int
registerTable
(
LuaCore
.
LuaState
luaState
)
private
static
int
registerTable
(
LuaState
luaState
)
{
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
return
translator
.
registerTableInternal
(
luaState
);
return
translator
.
registerTableInternal
(
luaState
);
}
}
private
int
registerTableInternal
(
LuaCore
.
LuaState
luaState
)
private
int
registerTableInternal
(
LuaState
luaState
)
{
{
if
(
LuaLib
.
lua_type
(
luaState
,
1
)
==
LuaTypes
.
Table
)
{
if
(
LuaLib
.
lua_type
(
luaState
,
1
)
==
LuaTypes
.
Table
)
{
var
luaTable
=
getTable
(
luaState
,
1
);
var
luaTable
=
getTable
(
luaState
,
1
);
...
@@ -383,13 +385,13 @@ namespace NLua
...
@@ -383,13 +385,13 @@ namespace NLua
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
#endif
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
private
static
int
unregisterTable
(
LuaCore
.
LuaState
luaState
)
private
static
int
unregisterTable
(
LuaState
luaState
)
{
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
return
translator
.
unregisterTableInternal
(
luaState
);
return
translator
.
unregisterTableInternal
(
luaState
);
}
}
private
int
unregisterTableInternal
(
LuaCore
.
LuaState
luaState
)
private
int
unregisterTableInternal
(
LuaState
luaState
)
{
{
try
{
try
{
if
(
LuaLib
.
lua_getmetatable
(
luaState
,
1
)
!=
0
)
{
if
(
LuaLib
.
lua_getmetatable
(
luaState
,
1
)
!=
0
)
{
...
@@ -428,13 +430,13 @@ namespace NLua
...
@@ -428,13 +430,13 @@ namespace NLua
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
#endif
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
private
static
int
getMethodSignature
(
LuaCore
.
LuaState
luaState
)
private
static
int
getMethodSignature
(
LuaState
luaState
)
{
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
return
translator
.
getMethodSignatureInternal
(
luaState
);
return
translator
.
getMethodSignatureInternal
(
luaState
);
}
}
private
int
getMethodSignatureInternal
(
LuaCore
.
LuaState
luaState
)
private
int
getMethodSignatureInternal
(
LuaState
luaState
)
{
{
IReflect
klass
;
IReflect
klass
;
object
target
;
object
target
;
...
@@ -482,13 +484,13 @@ namespace NLua
...
@@ -482,13 +484,13 @@ namespace NLua
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaCore
.
lua_CFunction
))]
#endif
#endif
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
[
System
.
Runtime
.
InteropServices
.
AllowReversePInvokeCalls
]
private
static
int
getConstructorSignature
(
LuaCore
.
LuaState
luaState
)
private
static
int
getConstructorSignature
(
LuaState
luaState
)
{
{
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
return
translator
.
getConstructorSignatureInternal
(
luaState
);
return
translator
.
getConstructorSignatureInternal
(
luaState
);
}
}
private
int
getConstructorSignatureInternal
(
LuaCore
.
LuaState
luaState
)
private
int
getConstructorSignatureInternal
(
LuaState
luaState
)
{
{
IReflect
klass
=
null
;
IReflect
klass
=
null
;
int
udata
=
LuaLib
.
luanet_checkudata
(
luaState
,
1
,
"luaNet_class"
);
int
udata
=
LuaLib
.
luanet_checkudata
(
luaState
,
1
,
"luaNet_class"
);
...
@@ -518,7 +520,7 @@ namespace NLua
...
@@ -518,7 +520,7 @@ namespace NLua
/*
/*
* Pushes a type reference into the stack
* Pushes a type reference into the stack
*/
*/
internal
void
pushType
(
LuaCore
.
LuaState
luaState
,
Type
t
)
internal
void
pushType
(
LuaState
luaState
,
Type
t
)
{
{
pushObject
(
luaState
,
new
ProxyType
(
t
),
"luaNet_class"
);
pushObject
(
luaState
,
new
ProxyType
(
t
),
"luaNet_class"
);
}
}
...
@@ -526,7 +528,7 @@ namespace NLua
...
@@ -526,7 +528,7 @@ namespace NLua
/*
/*
* Pushes a delegate into the stack
* Pushes a delegate into the stack
*/
*/
internal
void
pushFunction
(
LuaCore
.
LuaState
luaState
,
LuaCore
.
LuaNativeFunction
func
)
internal
void
pushFunction
(
LuaState
luaState
,
LuaCore
.
LuaNativeFunction
func
)
{
{
pushObject
(
luaState
,
func
,
"luaNet_function"
);
pushObject
(
luaState
,
func
,
"luaNet_function"
);
}
}
...
@@ -535,7 +537,7 @@ namespace NLua
...
@@ -535,7 +537,7 @@ namespace NLua
* Pushes a CLR object into the Lua stack as an userdata
* Pushes a CLR object into the Lua stack as an userdata
* with the provided metatable
* with the provided metatable
*/
*/
internal
void
pushObject
(
LuaCore
.
LuaState
luaState
,
object
o
,
string
metatable
)
internal
void
pushObject
(
LuaState
luaState
,
object
o
,
string
metatable
)
{
{
int
index
=
-
1
;
int
index
=
-
1
;
...
@@ -577,7 +579,7 @@ namespace NLua
...
@@ -577,7 +579,7 @@ namespace NLua
* Pushes a new object into the Lua stack with the provided
* Pushes a new object into the Lua stack with the provided
* metatable
* metatable
*/
*/
private
void
pushNewObject
(
LuaCore
.
LuaState
luaState
,
object
o
,
int
index
,
string
metatable
)
private
void
pushNewObject
(
LuaState
luaState
,
object
o
,
int
index
,
string
metatable
)
{
{
if
(
metatable
==
"luaNet_metatable"
)
{
if
(
metatable
==
"luaNet_metatable"
)
{
// Gets or creates the metatable for the object's type
// Gets or creates the metatable for the object's type
...
@@ -625,7 +627,7 @@ namespace NLua
...
@@ -625,7 +627,7 @@ namespace NLua
* Gets an object from the Lua stack with the desired type, if it matches, otherwise
* Gets an object from the Lua stack with the desired type, if it matches, otherwise
* returns null.
* returns null.
*/
*/
internal
object
getAsType
(
LuaCore
.
LuaState
luaState
,
int
stackPos
,
Type
paramType
)
internal
object
getAsType
(
LuaState
luaState
,
int
stackPos
,
Type
paramType
)
{
{
var
extractor
=
typeChecker
.
checkType
(
luaState
,
stackPos
,
paramType
);
var
extractor
=
typeChecker
.
checkType
(
luaState
,
stackPos
,
paramType
);
return
!
extractor
.
IsNull
()
?
extractor
(
luaState
,
stackPos
)
:
null
;
return
!
extractor
.
IsNull
()
?
extractor
(
luaState
,
stackPos
)
:
null
;
...
@@ -671,7 +673,7 @@ namespace NLua
...
@@ -671,7 +673,7 @@ namespace NLua
/*
/*
* Gets an object from the Lua stack according to its Lua type.
* Gets an object from the Lua stack according to its Lua type.
*/
*/
internal
object
getObject
(
LuaCore
.
LuaState
luaState
,
int
index
)
internal
object
getObject
(
LuaState
luaState
,
int
index
)
{
{
var
type
=
LuaLib
.
lua_type
(
luaState
,
index
);
var
type
=
LuaLib
.
lua_type
(
luaState
,
index
);
...
@@ -709,7 +711,7 @@ namespace NLua
...
@@ -709,7 +711,7 @@ namespace NLua
/*
/*
* Gets the table in the index positon of the Lua stack.
* Gets the table in the index positon of the Lua stack.
*/
*/
internal
LuaTable
getTable
(
LuaCore
.
LuaState
luaState
,
int
index
)
internal
LuaTable
getTable
(
LuaState
luaState
,
int
index
)
{
{
LuaLib
.
lua_pushvalue
(
luaState
,
index
);
LuaLib
.
lua_pushvalue
(
luaState
,
index
);
return
new
LuaTable
(
LuaLib
.
lua_ref
(
luaState
,
1
),
interpreter
);
return
new
LuaTable
(
LuaLib
.
lua_ref
(
luaState
,
1
),
interpreter
);
...
@@ -718,7 +720,7 @@ namespace NLua
...
@@ -718,7 +720,7 @@ namespace NLua
/*
/*
* Gets the userdata in the index positon of the Lua stack.
* Gets the userdata in the index positon of the Lua stack.
*/
*/
internal
LuaUserData
getUserData
(
LuaCore
.
LuaState
luaState
,
int
index
)
internal
LuaUserData
getUserData
(
LuaState
luaState
,
int
index
)
{
{
LuaLib
.
lua_pushvalue
(
luaState
,
index
);
LuaLib
.
lua_pushvalue
(
luaState
,
index
);
return
new
LuaUserData
(
LuaLib
.
lua_ref
(
luaState
,
1
),
interpreter
);
return
new
LuaUserData
(
LuaLib
.
lua_ref
(
luaState
,
1
),
interpreter
);
...
@@ -727,7 +729,7 @@ namespace NLua
...
@@ -727,7 +729,7 @@ namespace NLua
/*
/*
* Gets the function in the index positon of the Lua stack.
* Gets the function in the index positon of the Lua stack.
*/
*/
internal
LuaFunction
getFunction
(
LuaCore
.
LuaState
luaState
,
int
index
)
internal
LuaFunction
getFunction
(
LuaState
luaState
,
int
index
)
{
{
LuaLib
.
lua_pushvalue
(
luaState
,
index
);
LuaLib
.
lua_pushvalue
(
luaState
,
index
);
return
new
LuaFunction
(
LuaLib
.
lua_ref
(
luaState
,
1
),
interpreter
);
return
new
LuaFunction
(
LuaLib
.
lua_ref
(
luaState
,
1
),
interpreter
);
...
@@ -737,7 +739,7 @@ namespace NLua
...
@@ -737,7 +739,7 @@ namespace NLua
* Gets the CLR object in the index positon of the Lua stack. Returns
* Gets the CLR object in the index positon of the Lua stack. Returns
* delegates as Lua functions.
* delegates as Lua functions.
*/
*/
internal
object
getNetObject
(
LuaCore
.
LuaState
luaState
,
int
index
)
internal
object
getNetObject
(
LuaState
luaState
,
int
index
)
{
{
int
idx
=
LuaLib
.
luanet_tonetobject
(
luaState
,
index
);
int
idx
=
LuaLib
.
luanet_tonetobject
(
luaState
,
index
);
return
idx
!=
-
1
?
objects
[
idx
]
:
null
;
return
idx
!=
-
1
?
objects
[
idx
]
:
null
;
...
@@ -747,7 +749,7 @@ namespace NLua
...
@@ -747,7 +749,7 @@ namespace NLua
* Gets the CLR object in the index position of the Lua stack. Returns
* Gets the CLR object in the index position of the Lua stack. Returns
* delegates as is.
* delegates as is.
*/
*/
internal
object
getRawNetObject
(
LuaCore
.
LuaState
luaState
,
int
index
)
internal
object
getRawNetObject
(
LuaState
luaState
,
int
index
)
{
{
int
udata
=
LuaLib
.
luanet_rawnetobj
(
luaState
,
index
);
int
udata
=
LuaLib
.
luanet_rawnetobj
(
luaState
,
index
);
return
udata
!=
-
1
?
objects
[
udata
]
:
null
;
return
udata
!=
-
1
?
objects
[
udata
]
:
null
;
...
@@ -757,7 +759,7 @@ namespace NLua
...
@@ -757,7 +759,7 @@ namespace NLua
* Pushes the entire array into the Lua stack and returns the number
* Pushes the entire array into the Lua stack and returns the number
* of elements pushed.
* of elements pushed.
*/
*/
internal
int
returnValues
(
LuaCore
.
LuaState
luaState
,
object
[]
returnValues
)
internal
int
returnValues
(
LuaState
luaState
,
object
[]
returnValues
)
{
{
if
(
LuaLib
.
lua_checkstack
(
luaState
,
returnValues
.
Length
+
5
))
{
if
(
LuaLib
.
lua_checkstack
(
luaState
,
returnValues
.
Length
+
5
))
{
for
(
int
i
=
0
;
i
<
returnValues
.
Length
;
i
++)
for
(
int
i
=
0
;
i
<
returnValues
.
Length
;
i
++)
...
@@ -772,7 +774,7 @@ namespace NLua
...
@@ -772,7 +774,7 @@ namespace NLua
* Gets the values from the provided index to
* Gets the values from the provided index to
* the top of the stack and returns them in an array.
* the top of the stack and returns them in an array.
*/
*/
internal
object
[]
popValues
(
LuaCore
.
LuaState
luaState
,
int
oldTop
)
internal
object
[]
popValues
(
LuaState
luaState
,
int
oldTop
)
{
{
int
newTop
=
LuaLib
.
lua_gettop
(
luaState
);
int
newTop
=
LuaLib
.
lua_gettop
(
luaState
);
...
@@ -793,7 +795,7 @@ namespace NLua
...
@@ -793,7 +795,7 @@ namespace NLua
* the top of the stack and returns them in an array, casting
* the top of the stack and returns them in an array, casting
* them to the provided types.
* them to the provided types.
*/
*/
internal
object
[]
popValues
(
LuaCore
.
LuaState
luaState
,
int
oldTop
,
Type
[]
popTypes
)
internal
object
[]
popValues
(
LuaState
luaState
,
int
oldTop
,
Type
[]
popTypes
)
{
{
int
newTop
=
LuaLib
.
lua_gettop
(
luaState
);
int
newTop
=
LuaLib
.
lua_gettop
(
luaState
);
...
@@ -837,7 +839,7 @@ namespace NLua
...
@@ -837,7 +839,7 @@ namespace NLua
/*
/*
* Pushes the object into the Lua stack according to its type.
* Pushes the object into the Lua stack according to its type.
*/
*/
internal
void
push
(
LuaCore
.
LuaState
luaState
,
object
o
)
internal
void
push
(
LuaState
luaState
,
object
o
)
{
{
if
(
o
.
IsNull
())
if
(
o
.
IsNull
())
LuaLib
.
lua_pushnil
(
luaState
);
LuaLib
.
lua_pushnil
(
luaState
);
...
@@ -871,7 +873,7 @@ namespace NLua
...
@@ -871,7 +873,7 @@ namespace NLua
* Checks if the method matches the arguments in the Lua stack, getting
* Checks if the method matches the arguments in the Lua stack, getting
* the arguments if it does.
* the arguments if it does.
*/
*/
internal
bool
matchParameters
(
LuaCore
.
LuaState
luaState
,
MethodBase
method
,
ref
MethodCache
methodCache
)
internal
bool
matchParameters
(
LuaState
luaState
,
MethodBase
method
,
ref
MethodCache
methodCache
)
{
{
return
metaFunctions
.
matchParameters
(
luaState
,
method
,
ref
methodCache
);
return
metaFunctions
.
matchParameters
(
luaState
,
method
,
ref
methodCache
);
}
}
...
...
Core/NLua/ObjectTranslatorPool.cs
View file @
c84425fd
...
@@ -29,14 +29,16 @@ namespace NLua
...
@@ -29,14 +29,16 @@ namespace NLua
{
{
#
if
USE_KOPILUA
#
if
USE_KOPILUA
using
LuaCore
=
KopiLua
.
Lua
;
using
LuaCore
=
KopiLua
.
Lua
;
using
LuaState
=
KopiLua
.
LuaState
;
#
else
#
else
using
LuaCore
=
KeraLua
.
Lua
;
using
LuaCore
=
KeraLua
.
Lua
;
using
LuaState
=
KeraLua
.
LuaState
;
#
endif
#
endif
internal
class
ObjectTranslatorPool
internal
class
ObjectTranslatorPool
{
{
private
static
volatile
ObjectTranslatorPool
instance
=
new
ObjectTranslatorPool
();
private
static
volatile
ObjectTranslatorPool
instance
=
new
ObjectTranslatorPool
();
private
Dictionary
<
LuaCore
.
LuaState
,
ObjectTranslator
>
translators
=
new
Dictionary
<
LuaCore
.
LuaState
,
ObjectTranslator
>();
private
Dictionary
<
LuaState
,
ObjectTranslator
>
translators
=
new
Dictionary
<
LuaState
,
ObjectTranslator
>();
public
static
ObjectTranslatorPool
Instance
public
static
ObjectTranslatorPool
Instance
{
{
...
@@ -50,12 +52,12 @@ namespace NLua
...
@@ -50,12 +52,12 @@ namespace NLua
{
{
}
}
public
void
Add
(
LuaCore
.
LuaState
luaState
,
ObjectTranslator
translator
)
public
void
Add
(
LuaState
luaState
,
ObjectTranslator
translator
)
{
{
translators
.
Add
(
luaState
,
translator
);
translators
.
Add
(
luaState
,
translator
);
}
}
public
ObjectTranslator
Find
(
LuaCore
.
LuaState
luaState
)
public
ObjectTranslator
Find
(
LuaState
luaState
)
{
{
if
(!
translators
.
ContainsKey
(
luaState
))
if
(!
translators
.
ContainsKey
(
luaState
))
return
null
;
return
null
;
...
@@ -63,7 +65,7 @@ namespace NLua
...
@@ -63,7 +65,7 @@ namespace NLua
return
translators
[
luaState
];
return
translators
[
luaState
];
}
}
public
void
Remove
(
LuaCore
.
LuaState
luaState
)
public
void
Remove
(
LuaState
luaState
)
{
{
if
(!
translators
.
ContainsKey
(
luaState
))
if
(!
translators
.
ContainsKey
(
luaState
))
return
;
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