protected unsafe void DebugHook(UIntPtr L, IntPtr ptr) //unsafe for speed { LuaStackRecord *sr = (LuaStackRecord *)ptr; BBLua.lua_getstack(L, 0, ptr); if (sr->debugEvent == LuaEvent.Call) { this.callStack++; } else if (sr->debugEvent == LuaEvent.Return || sr->debugEvent == LuaEvent.TailReturn) { this.callStack--; if ((this.callStack == 0) && //stepping into engine code is not possible -> resume (this.CurrentRequest == DebugRequest.StepIn || this.CurrentRequest == DebugRequest.StepToLevel)) { this.CurrentRequest = DebugRequest.Resume; this.CurrentState = DebugState.Running; FireStateChangedEvent(); } } // event == line else if (this.CurrentRequest == DebugRequest.Pause || this.CurrentRequest == DebugRequest.StepIn) { NormalBreak(); } else if (this.CurrentRequest == DebugRequest.StepToLevel && (this.callStack <= this.targetCallStackLevel)) { NormalBreak(); } // request == resume else { List <Breakpoint> bpsAtLine; if (!this.lineToBP.TryGetValue(sr->currentline, out bpsAtLine)) { return; //no breakpoints on this line } BBLua.lua_getinfo(L, "S", ptr); LuaDebugSourceRecord dr = (LuaDebugSourceRecord)Marshal.PtrToStructure(ptr, typeof(LuaDebugSourceRecord)); foreach (Breakpoint bp in bpsAtLine) { if (bp.File.Filename == dr.source) { NormalBreak(); break; } } } }
public static LuaFunctionInfo ReadFunctionInfo(LuaState ls, int level) { IntPtr memBlock = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(LuaDebugRecord))); if (BBLua.lua_getstack(ls.L, level, memBlock) == 0) { return(null); } BBLua.lua_getinfo(ls.L, "nSlu", memBlock); LuaDebugRecord ldr = (LuaDebugRecord)Marshal.PtrToStructure(memBlock, typeof(LuaDebugRecord)); LuaFunctionInfo lfi = new LuaFunctionInfo(memBlock, ls, ldr.nups); if (ldr.source.Length > 1 && ldr.source[0] != '=') { lfi.Source = ldr.source; lfi.Line = ldr.currentline; } else { lfi.Source = "unavailable"; lfi.Line = 0; } if (ldr.what == "C") { lfi.FunctionName = "Game Engine (direct call)"; } else if (ldr.what == "main") { lfi.FunctionName = "Game Engine (code outside function)"; } else if (ldr.name != "" && ldr.namewhat != "") { lfi.FunctionName = ldr.namewhat + " " + ldr.name + "()"; } else if (ldr.what == "Lua" || ldr.what == "tail") { lfi.FunctionName = "Lua Code"; } if (ls.LoadedFiles.ContainsKey(lfi.Source)) { lfi.CanFakeEnvironment = true; } return(lfi); }