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
60d4ee03
Commit
60d4ee03
authored
Sep 07, 2014
by
Vinicius Jarina
Browse files
Fixed Debug functions GetInfo/GetStack + Unit tests.
parent
96329dcb
Changes
7
Show whitespace changes
Inline
Side-by-side
ConsoleTest/ConsoleTest.csproj
View file @
60d4ee03
...
...
@@ -78,6 +78,10 @@
</Target>
-->
<ItemGroup>
<ProjectReference
Include=
"..\Core\KopiLua\KopiLua\KopiLua.Net45.csproj"
>
<Project>
{e8ddbc21-ef74-4aba-9c49-bfc702be25d8}
</Project>
<Name>
KopiLua.Net45
</Name>
</ProjectReference>
<ProjectReference
Include=
"..\Core\NLua\NLua.Net45.csproj"
>
<Project>
{F55CABBB-4108-4A39-94E1-581FD46DC021}
</Project>
<Name>
NLua.Net45
</Name>
...
...
ConsoleTest/Program.cs
View file @
60d4ee03
...
...
@@ -14,33 +14,51 @@ namespace ConsoleTest
{
public
static
void
func
()
{
Console
.
WriteLine
(
"Casa"
);
}
static
void
DebugHook
(
object
sender
,
NLua
.
Event
.
DebugHookEventArgs
args
)
{
KopiLua
.
LuaDebug
info
=
new
KopiLua
.
LuaDebug
();
int
level
=
0
;
StringBuilder
sb
=
new
StringBuilder
();
while
(
m_lua
.
GetStack
(
level
,
ref
info
)
!=
0
)
{
m_lua
.
GetInfo
(
"nSl"
,
ref
info
);
string
name
=
"<unknow>"
;
if
(
info
.
name
!=
null
&&
!
string
.
IsNullOrEmpty
(
info
.
name
.
ToString
()))
name
=
info
.
name
.
ToString
();
sb
.
AppendFormat
(
"[{0}] {1}:{2} -- {3} [{4}]\n"
,
level
,
info
.
shortsrc
,
info
.
currentline
,
name
,
info
.
namewhat
);
++
level
;
}
string
expected
=
"[0] [C]:-1 -- func [field]\n[1] [string \"chunk\"]:12 -- f3 [global]\n[2] [string \"chunk\"]:8 -- f2 [global]\n[3] [string \"chunk\"]:4 -- f1 [global]\n[4] [string \"chunk\"]:15 -- <unknow> []\n"
;
string
x
=
sb
.
ToString
();
if
(
x
==
expected
)
Console
.
WriteLine
(
"OK"
);
Console
.
Write
(
x
);
}
static
Lua
m_lua
;
static
void
Main
(
string
[]
args
)
{
using
(
Lua
lua
=
new
Lua
())
{
lua
.
LoadCLRPackage
();
m_lua
=
lua
;
lua
.
DoString
(
@"
import ('ConsoleTest')
function f1 ()
f2 ()
end
lua
.
DoString
(
@" import ('NLuaTest')
v = Vector()
v.x = 10
v.y = 3
v = v*2 "
);
var
v
=
(
Vector
)
lua
[
"v"
];
function f2()
f3()
end
double
len
=
v
.
Lenght
();
lua
.
DoString
(
" v:Lenght() "
);
lua
.
DoString
(
@" len2 = v:Lenght()"
);
double
len2
=
(
double
)
lua
[
"len2"
];
function f3()
Program.func()
end
f1 ()
"
);
}
}
...
...
KeraLua
@
6e29cfa2
Compare
fd0014e2
...
6e29cfa2
Subproject commit
fd0014e22b79664a4dd3e70fe15f9ca5ab40162f
Subproject commit
6e29cfa2d13f62a5f2e2aca728fe1def62035f97
KopiLua
@
9ca352bd
Compare
4a98db97
...
9ca352bd
Subproject commit
4a98db974cc76dcf080e20bdb5ae9ce1ab8e1134
Subproject commit
9ca352bd9b1bfe64576cda42bff059a3495b04dd
Core/NLua/Lua.cs
View file @
60d4ee03
...
...
@@ -865,7 +865,6 @@ end
/// <param name = "mask">Mask</param>
/// <param name = "count">Count</param>
/// <returns>see lua docs. -1 if hook is already set</returns>
/// <author>Reinhard Ostermeier</author>
public
int
SetDebugHook
(
EventMasks
mask
,
int
count
)
{
if
(
hookCallback
==
null
)
{
...
...
@@ -880,7 +879,6 @@ end
/// Removes the debug hook
/// </summary>
/// <returns>see lua docs</returns>
/// <author>Reinhard Ostermeier</author>
public
int
RemoveDebugHook
()
{
hookCallback
=
null
;
...
...
@@ -891,7 +889,6 @@ end
/// Gets the hook mask.
/// </summary>
/// <returns>hook mask</returns>
/// <author>Reinhard Ostermeier</author>
public
EventMasks
GetHookMask
()
{
return
(
EventMasks
)
LuaCore
.
LuaGetHookMask
(
luaState
);
...
...
@@ -901,7 +898,6 @@ end
/// Gets the hook count
/// </summary>
/// <returns>see lua docs</returns>
/// <author>Reinhard Ostermeier</author>
public
int
GetHookCount
()
{
return
LuaCore
.
LuaGetHookCount
(
luaState
);
...
...
@@ -913,7 +909,6 @@ end
/// <param name = "level">level</param>
/// <param name = "luaDebug">lua debug structure</param>
/// <returns>Returns true if level was allowed, false if level was invalid.</returns>
/// <author>Reinhard Ostermeier</author>
/*public bool GetStack(int level, out LuaCore.lua_Debug luaDebug)
{
luaDebug = new LuaDebug();
...
...
@@ -958,7 +953,6 @@ end
/// <param name = "luaDebug">lua debug structure</param>
/// <param name = "n">see lua docs</param>
/// <returns>see lua docs</returns>
/// <author>Reinhard Ostermeier</author>
public
string
GetLocal
(
LuaDebug
luaDebug
,
int
n
)
{
return
LuaCore
.
LuaGetLocal
(
luaState
,
luaDebug
,
n
).
ToString
();
...
...
@@ -970,19 +964,27 @@ end
/// <param name = "luaDebug">lua debug structure</param>
/// <param name = "n">see lua docs</param>
/// <returns>see lua docs</returns>
/// <author>Reinhard Ostermeier</author>
public
string
SetLocal
(
LuaDebug
luaDebug
,
int
n
)
{
return
LuaCore
.
LuaSetLocal
(
luaState
,
luaDebug
,
n
).
ToString
();
}
public
int
GetStack
(
int
level
,
ref
LuaDebug
ar
)
{
return
LuaCore
.
LuaGetStack
(
luaState
,
level
,
ref
ar
);
}
public
int
GetInfo
(
string
what
,
ref
LuaDebug
ar
)
{
return
LuaCore
.
LuaGetInfo
(
luaState
,
what
,
ref
ar
);
}
/// <summary>
/// Gets up value (see lua docs)
/// </summary>
/// <param name = "funcindex">see lua docs</param>
/// <param name = "n">see lua docs</param>
/// <returns>see lua docs</returns>
/// <author>Reinhard Ostermeier</author>
public
string
GetUpValue
(
int
funcindex
,
int
n
)
{
return
LuaCore
.
LuaGetUpValue
(
luaState
,
funcindex
,
n
).
ToString
();
...
...
@@ -994,7 +996,6 @@ end
/// <param name = "funcindex">see lua docs</param>
/// <param name = "n">see lua docs</param>
/// <returns>see lua docs</returns>
/// <author>Reinhard Ostermeier</author>
public
string
SetUpValue
(
int
funcindex
,
int
n
)
{
return
LuaCore
.
LuaSetUpValue
(
luaState
,
funcindex
,
n
).
ToString
();
...
...
@@ -1005,7 +1006,6 @@ end
/// </summary>
/// <param name = "luaState">lua state</param>
/// <param name = "luaDebug">Pointer to LuaDebug (lua_debug) structure</param>
/// <author>Reinhard Ostermeier</author>
///
#if MONOTOUCH
[
MonoTouch
.
MonoPInvokeCallback
(
typeof
(
LuaHook
))]
...
...
@@ -1058,7 +1058,6 @@ end
/// Pushes a value onto the lua stack.
/// </summary>
/// <param name = "value">Value to push.</param>
/// <author>Reinhard Ostermeier</author>
public
void
Push
(
object
value
)
{
translator
.
Push
(
luaState
,
value
);
...
...
@@ -1101,7 +1100,6 @@ end
/*
* Gets a numeric field of the table or userdata corresponding the the provided reference
*/
internal
object
GetObject
(
int
reference
,
object
field
)
{
int
oldTop
=
LuaLib
.
LuaGetTop
(
luaState
);
...
...
@@ -1116,8 +1114,7 @@ end
/*
* Sets a field of the table or userdata corresponding the the provided reference
* to the provided value
*/
internal
void
SetObject
(
int
reference
,
string
field
,
object
val
)
*/
internal
void
SetObject
(
int
reference
,
string
field
,
object
val
)
{
int
oldTop
=
LuaLib
.
LuaGetTop
(
luaState
);
LuaLib
.
LuaGetRef
(
luaState
,
reference
);
...
...
NLuaTest/NLuaTest.csproj
View file @
60d4ee03
...
...
@@ -36,7 +36,7 @@
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)' == 'DebugKopiLua|AnyCPU'"
>
<DebugSymbols>
true
</DebugSymbols>
<OutputPath>
bin\DebugKopiLua\
</OutputPath>
<DefineConstants>
DEBUG;TRACE
</DefineConstants>
<DefineConstants>
TRACE;DEBUG;USE_KOPILUA
</DefineConstants>
<DebugType>
full
</DebugType>
<PlatformTarget>
AnyCPU
</PlatformTarget>
<ErrorReport>
prompt
</ErrorReport>
...
...
@@ -50,6 +50,7 @@
<WarningLevel>
4
</WarningLevel>
<Optimize>
true
</Optimize>
<Prefer32Bit>
false
</Prefer32Bit>
<DefineConstants>
USE_KOPILUA
</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Reference
Include=
"System"
/>
...
...
tests/LuaTests.cs
View file @
60d4ee03
...
...
@@ -2131,7 +2131,60 @@ namespace NLuaTest
}
}
[
Test
]
public
void
TestGetStack
()
{
using
(
Lua
lua
=
new
Lua
())
{
lua
.
LoadCLRPackage
();
m_lua
=
lua
;
lua
.
DoString
(
@"
import ('ConsoleTest')
function f1 ()
f2 ()
end
function f2()
f3()
end
function f3()
Program.func()
end
f1 ()
"
);
}
m_lua
=
null
;
}
public
static
void
func
()
{
#if USE_KOPILUA
string
expected
=
"[0] [C]:-1 -- func [field]\n[1] [string \"chunk\"]:12 -- f3 [global]\n[2] [string \"chunk\"]:8 -- f2 [global]\n[3] [string \"chunk\"]:4 -- f1 [global]\n[4] [string \"chunk\"]:15 -- <unknow> []\n"
;
KopiLua
.
LuaDebug
info
=
new
KopiLua
.
LuaDebug
();
#else
string
expected
=
"[0] func:-1 -- <unknown> [func]\n[1] f3:12 -- <unknown> [f3]\n[2] f2:8 -- <unknown> [f2]\n[3] f1:4 -- <unknown> [f1]\n[4] :15 -- []\n"
;
KeraLua
.
LuaDebug
info
=
new
KeraLua
.
LuaDebug
();
#endif
int
level
=
0
;
StringBuilder
sb
=
new
StringBuilder
();
while
(
m_lua
.
GetStack
(
level
,
ref
info
)
!=
0
)
{
m_lua
.
GetInfo
(
"nSl"
,
ref
info
);
string
name
=
"<unknow>"
;
if
(
info
.
name
!=
null
&&
!
string
.
IsNullOrEmpty
(
info
.
name
.
ToString
()))
name
=
info
.
name
.
ToString
();
sb
.
AppendFormat
(
"[{0}] {1}:{2} -- {3} [{4}]\n"
,
level
,
info
.
shortsrc
,
info
.
currentline
,
name
,
info
.
namewhat
);
++
level
;
}
string
x
=
sb
.
ToString
();
Assert
.
AreEqual
(
expected
,
x
);
}
static
Lua
m_lua
;
}
}
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