Commit 375499a3 authored by Vinicius Jarina's avatar Vinicius Jarina
Browse files

[KeraLua] Fixed Debug Hook callback (usingn a cdecl) trampoline #56

parent 4d4b65a5
...@@ -4,29 +4,54 @@ using System.Linq; ...@@ -4,29 +4,54 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using NLua; using NLua;
using NLuaTest.Mock;
namespace ConsoleTest namespace ConsoleTest
{ {
class Program struct Sub2 {
int someval;
}
struct Sub {
public Sub2 z;
}
struct Top {
public Sub y;
}
public class Program
{ {
public static void func()
{
Console.WriteLine ("Casa");
}
static void DebugHook (object sender, NLua.Event.DebugHookEventArgs args)
{
}
static void Main (string [] args) static void Main (string [] args)
{ {
using (Lua lua = new Lua ()) { using (Lua lua = new Lua())
lua.DoString ("luanet.load_assembly('mscorlib')"); {
lua.DoString ("luanet.load_assembly('ConsoleTest')"); lua.DebugHook += DebugHook;
lua.DoString ("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')"); lua.SetDebugHook (NLua.Event.EventMasks.LUA_MASKLINE, 0);
lua.DoString ("test=TestClass()");
lua.DoString (@"function testing_hooks() return 10 end
try { val = testing_hooks()
lua.DoString ("test:exceptionMethod()"); val = val + 1
//failed ");
//Assert.True (false); double res = (double)lua ["val"];
} catch (Exception) { Console.WriteLine ("{0}", res);
//passed }
//Assert.True (true);
}
}
} }
} }
......
Subproject commit b0376e18f8fb50447aec2370533b394e79bbba18 Subproject commit 60b2f79a5e9602c7288809d48fbd44b801f03d9d
...@@ -1007,12 +1007,17 @@ end ...@@ -1007,12 +1007,17 @@ end
[MonoTouch.MonoPInvokeCallback (typeof (LuaHook))] [MonoTouch.MonoPInvokeCallback (typeof (LuaHook))]
#endif #endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls] [System.Runtime.InteropServices.AllowReversePInvokeCalls]
private static void DebugHookCallback (LuaState luaState, LuaDebug luaDebug) #if USE_KOPILUA
static void DebugHookCallback (LuaState luaState, LuaDebug debug)
{ {
var translator = ObjectTranslatorPool.Instance.Find (luaState); #else
var lua = translator.Interpreter; static void DebugHookCallback (LuaState luaState, IntPtr luaDebug)
{
lua.DebugHookCallbackInternal (luaState, luaDebug); LuaDebug debug = (LuaDebug)System.Runtime.InteropServices.Marshal.PtrToStructure (luaDebug, typeof (LuaDebug));
#endif
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find (luaState);
Lua lua = translator.Interpreter;
lua.DebugHookCallbackInternal (luaState, debug);
} }
private void DebugHookCallbackInternal (LuaState luaState, LuaDebug luaDebug) private void DebugHookCallbackInternal (LuaState luaState, LuaDebug luaDebug)
......
...@@ -1894,5 +1894,24 @@ namespace NLuaTest ...@@ -1894,5 +1894,24 @@ namespace NLuaTest
} }
} }
[Test]
public void TestDebugHook ()
{
int [] lines = { 1, 2, 1, 3 };
int line = 0;
using (Lua lua = new Lua ()) {
lua.DebugHook += (sender,args) => {
Assert.AreEqual (args.LuaDebug.currentline,lines [line]);
line ++;
};
lua.SetDebugHook (NLua.Event.EventMasks.LUA_MASKLINE, 0);
lua.DoString (@"function testing_hooks() return 10 end
val = testing_hooks()
val = val + 1");
}
}
} }
} }
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