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;
using System.Text;
using System.Threading.Tasks;
using NLua;
using NLuaTest.Mock;
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)
{
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly('mscorlib')");
lua.DoString ("luanet.load_assembly('ConsoleTest')");
lua.DoString ("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')");
lua.DoString ("test=TestClass()");
try {
lua.DoString ("test:exceptionMethod()");
//failed
//Assert.True (false);
} catch (Exception) {
//passed
//Assert.True (true);
}
}
using (Lua lua = new Lua())
{
lua.DebugHook += DebugHook;
lua.SetDebugHook (NLua.Event.EventMasks.LUA_MASKLINE, 0);
lua.DoString (@"function testing_hooks() return 10 end
val = testing_hooks()
val = val + 1
");
double res = (double)lua ["val"];
Console.WriteLine ("{0}", res);
}
}
}
......
Subproject commit b0376e18f8fb50447aec2370533b394e79bbba18
Subproject commit 60b2f79a5e9602c7288809d48fbd44b801f03d9d
......@@ -1007,12 +1007,17 @@ end
[MonoTouch.MonoPInvokeCallback (typeof (LuaHook))]
#endif
[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);
var lua = translator.Interpreter;
lua.DebugHookCallbackInternal (luaState, luaDebug);
#else
static void DebugHookCallback (LuaState luaState, IntPtr 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)
......
......@@ -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