Commit 60d4ee03 authored by Vinicius Jarina's avatar Vinicius Jarina
Browse files

Fixed Debug functions GetInfo/GetStack + Unit tests.

parent 96329dcb
...@@ -78,6 +78,10 @@ ...@@ -78,6 +78,10 @@
</Target> </Target>
--> -->
<ItemGroup> <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"> <ProjectReference Include="..\Core\NLua\NLua.Net45.csproj">
<Project>{F55CABBB-4108-4A39-94E1-581FD46DC021}</Project> <Project>{F55CABBB-4108-4A39-94E1-581FD46DC021}</Project>
<Name>NLua.Net45</Name> <Name>NLua.Net45</Name>
......
...@@ -14,33 +14,51 @@ namespace ConsoleTest ...@@ -14,33 +14,51 @@ namespace ConsoleTest
{ {
public static void func() public static void func()
{ {
Console.WriteLine ("Casa"); KopiLua.LuaDebug info = new KopiLua.LuaDebug ();
} int level = 0;
StringBuilder sb = new StringBuilder ();
static void DebugHook (object sender, NLua.Event.DebugHookEventArgs args) 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) static void Main (string [] args)
{ {
using (Lua lua = new Lua ()) { using (Lua lua = new Lua ()) {
lua.LoadCLRPackage (); lua.LoadCLRPackage ();
m_lua = lua;
lua.DoString (@"
import ('ConsoleTest')
function f1 ()
f2 ()
end
function f2()
f3()
end
lua.DoString (@" import ('NLuaTest') function f3()
v = Vector() Program.func()
v.x = 10 end
v.y = 3
v = v*2 "); f1 ()
");
var v = (Vector)lua ["v"];
double len = v.Lenght ();
lua.DoString (" v:Lenght() ");
lua.DoString (@" len2 = v:Lenght()");
double len2 = (double)lua ["len2"];
} }
} }
......
Subproject commit fd0014e22b79664a4dd3e70fe15f9ca5ab40162f Subproject commit 6e29cfa2d13f62a5f2e2aca728fe1def62035f97
Subproject commit 4a98db974cc76dcf080e20bdb5ae9ce1ab8e1134 Subproject commit 9ca352bd9b1bfe64576cda42bff059a3495b04dd
...@@ -865,7 +865,6 @@ end ...@@ -865,7 +865,6 @@ end
/// <param name = "mask">Mask</param> /// <param name = "mask">Mask</param>
/// <param name = "count">Count</param> /// <param name = "count">Count</param>
/// <returns>see lua docs. -1 if hook is already set</returns> /// <returns>see lua docs. -1 if hook is already set</returns>
/// <author>Reinhard Ostermeier</author>
public int SetDebugHook (EventMasks mask, int count) public int SetDebugHook (EventMasks mask, int count)
{ {
if (hookCallback == null) { if (hookCallback == null) {
...@@ -880,7 +879,6 @@ end ...@@ -880,7 +879,6 @@ end
/// Removes the debug hook /// Removes the debug hook
/// </summary> /// </summary>
/// <returns>see lua docs</returns> /// <returns>see lua docs</returns>
/// <author>Reinhard Ostermeier</author>
public int RemoveDebugHook () public int RemoveDebugHook ()
{ {
hookCallback = null; hookCallback = null;
...@@ -891,7 +889,6 @@ end ...@@ -891,7 +889,6 @@ end
/// Gets the hook mask. /// Gets the hook mask.
/// </summary> /// </summary>
/// <returns>hook mask</returns> /// <returns>hook mask</returns>
/// <author>Reinhard Ostermeier</author>
public EventMasks GetHookMask () public EventMasks GetHookMask ()
{ {
return (EventMasks)LuaCore.LuaGetHookMask (luaState); return (EventMasks)LuaCore.LuaGetHookMask (luaState);
...@@ -901,7 +898,6 @@ end ...@@ -901,7 +898,6 @@ end
/// Gets the hook count /// Gets the hook count
/// </summary> /// </summary>
/// <returns>see lua docs</returns> /// <returns>see lua docs</returns>
/// <author>Reinhard Ostermeier</author>
public int GetHookCount () public int GetHookCount ()
{ {
return LuaCore.LuaGetHookCount (luaState); return LuaCore.LuaGetHookCount (luaState);
...@@ -913,7 +909,6 @@ end ...@@ -913,7 +909,6 @@ end
/// <param name = "level">level</param> /// <param name = "level">level</param>
/// <param name = "luaDebug">lua debug structure</param> /// <param name = "luaDebug">lua debug structure</param>
/// <returns>Returns true if level was allowed, false if level was invalid.</returns> /// <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) /*public bool GetStack(int level, out LuaCore.lua_Debug luaDebug)
{ {
luaDebug = new LuaDebug(); luaDebug = new LuaDebug();
...@@ -958,7 +953,6 @@ end ...@@ -958,7 +953,6 @@ end
/// <param name = "luaDebug">lua debug structure</param> /// <param name = "luaDebug">lua debug structure</param>
/// <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>
public string GetLocal (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 ();
...@@ -970,19 +964,27 @@ end ...@@ -970,19 +964,27 @@ end
/// <param name = "luaDebug">lua debug structure</param> /// <param name = "luaDebug">lua debug structure</param>
/// <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>
public string SetLocal (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 ();
} }
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> /// <summary>
/// Gets up value (see lua docs) /// Gets up value (see lua docs)
/// </summary> /// </summary>
/// <param name = "funcindex">see lua docs</param> /// <param name = "funcindex">see lua docs</param>
/// <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>
public string GetUpValue (int funcindex, int n) public string GetUpValue (int funcindex, int n)
{ {
return LuaCore.LuaGetUpValue (luaState, funcindex, n).ToString (); return LuaCore.LuaGetUpValue (luaState, funcindex, n).ToString ();
...@@ -994,7 +996,6 @@ end ...@@ -994,7 +996,6 @@ end
/// <param name = "funcindex">see lua docs</param> /// <param name = "funcindex">see lua docs</param>
/// <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>
public string SetUpValue (int funcindex, int n) public string SetUpValue (int funcindex, int n)
{ {
return LuaCore.LuaSetUpValue (luaState, funcindex, n).ToString (); return LuaCore.LuaSetUpValue (luaState, funcindex, n).ToString ();
...@@ -1005,7 +1006,6 @@ end ...@@ -1005,7 +1006,6 @@ end
/// </summary> /// </summary>
/// <param name = "luaState">lua state</param> /// <param name = "luaState">lua state</param>
/// <param name = "luaDebug">Pointer to LuaDebug (lua_debug) structure</param> /// <param name = "luaDebug">Pointer to LuaDebug (lua_debug) structure</param>
/// <author>Reinhard Ostermeier</author>
/// ///
#if MONOTOUCH #if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaHook))] [MonoTouch.MonoPInvokeCallback (typeof (LuaHook))]
...@@ -1058,7 +1058,6 @@ end ...@@ -1058,7 +1058,6 @@ end
/// Pushes a value onto the lua stack. /// Pushes a value onto the lua stack.
/// </summary> /// </summary>
/// <param name = "value">Value to push.</param> /// <param name = "value">Value to push.</param>
/// <author>Reinhard Ostermeier</author>
public void Push (object value) public void Push (object value)
{ {
translator.Push (luaState, value); translator.Push (luaState, value);
...@@ -1101,7 +1100,6 @@ end ...@@ -1101,7 +1100,6 @@ end
/* /*
* Gets a numeric field of the table or userdata corresponding the the provided reference * Gets a numeric field of the table or userdata corresponding the the provided reference
*/ */
internal object GetObject (int reference, object field) internal object GetObject (int reference, object field)
{ {
int oldTop = LuaLib.LuaGetTop (luaState); int oldTop = LuaLib.LuaGetTop (luaState);
...@@ -1116,8 +1114,7 @@ end ...@@ -1116,8 +1114,7 @@ end
/* /*
* Sets a field of the table or userdata corresponding the the provided reference * Sets a field of the table or userdata corresponding the the provided reference
* to the provided value * 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); int oldTop = LuaLib.LuaGetTop (luaState);
LuaLib.LuaGetRef (luaState, reference); LuaLib.LuaGetRef (luaState, reference);
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'DebugKopiLua|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'DebugKopiLua|AnyCPU'">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<OutputPath>bin\DebugKopiLua\</OutputPath> <OutputPath>bin\DebugKopiLua\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>TRACE;DEBUG;USE_KOPILUA</DefineConstants>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<Prefer32Bit>false</Prefer32Bit> <Prefer32Bit>false</Prefer32Bit>
<DefineConstants>USE_KOPILUA</DefineConstants>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
......
...@@ -2131,7 +2131,60 @@ namespace NLuaTest ...@@ -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;
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment