void HandleDebugHook(object sender, NLua.Event.DebugHookEventArgs e) { Console.Out.WriteLine("LUA EXCEPTION:"); Console.Out.Write(String.Format("FT {0} ", e.LuaDebug.eventCode.ToString())); Console.Out.WriteLine(e.LuaDebug.currentline); KeraLua.LuaDebug luaDebug = e.LuaDebug; if (luaDebug.source.Length > 0 && luaDebug.source[0] == '@') { Console.Out.WriteLine(String.Format(" n:{0} nw:{1} s:{2} ss:{3} ld:{4} lld:{5} cl:{6}", luaDebug.name, luaDebug.namewhat, luaDebug.source, luaDebug.shortsrc, luaDebug.linedefined, luaDebug.lastlinedefined, luaDebug.currentline)); } }
static string DumpTrace(Lua st, int upto) { string ret = ""; for (int i = upto; i >= 0; i--) { KeraLua.LuaDebug d = new KeraLua.LuaDebug(); if (st.GetStack(i, ref d) == 1) { ret += (d.source + ":" + d.currentline); } } return(ret); }
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.True (!string.IsNullOrEmpty(x)); }