public void Attach(Script S, string scriptName, bool freeRunAfterAttach = false) { lock (m_Lock) { DebugServer d = new DebugServer(scriptName, S, m_RpcPortMax, m_Options.NetworkOptions, freeRunAfterAttach); S.AttachDebugger(d); m_DebugServers.Add(d); } }
/// <summary> /// Attaches the specified script to the debugger /// </summary> /// <param name="script">The script.</param> /// <param name="name">The name of the script.</param> /// <param name="sourceFinder">A function which gets in input a source code and returns the path to /// source file to use. It can return null and in that case (or if the file cannot be found) /// a temporary file will be generated on the fly.</param> /// <exception cref="ArgumentException">If the script has already been attached to this debugger.</exception> public void AttachToScript(Script script, string name, Func<SourceCode, string> sourceFinder = null) { lock (m_Lock) { if (m_DebuggerList.Any(d => d.Script == script)) throw new ArgumentException("Script already attached to this debugger."); var debugger = new AsyncDebugger(script, sourceFinder ?? (s => s.Name), name); script.AttachDebugger(debugger); m_DebuggerList.Add(debugger); if (m_Current == null) m_Current = debugger; } }
private void DebugScript(string filename) { m_Script = new Script(CoreModules.Preset_HardSandbox); m_Script.Options.UseLuaErrorLocations = true; m_Script.Options.DebugPrint = s => { Console_WriteLine("{0}", s); }; ((ScriptLoaderBase)m_Script.Options.ScriptLoader).ModulePaths = ScriptLoaderBase.UnpackStringPaths("Modules/?;Modules/?.lua"); try { m_Script.LoadFile(filename, null, filename.Replace(':', '|')); } catch (Exception ex) { txtOutput.Text = ""; Console_WriteLine("{0}", ex.Message); return; } m_Script.AttachDebugger(this); Thread m_Debugger = new Thread(DebugMain); m_Debugger.Name = "MoonSharp Execution Thread"; m_Debugger.IsBackground = true; m_Debugger.Start(); }
static void BreakAfterManyInstructions() { Script script = new Script(); try { script.AttachDebugger(new BreakAfterManyInstructionsDebugger()); script.DoString(@" x = 0; while true do x = x + 1; end; "); } catch (MyException) { Console.WriteLine("Done. x = {0}", script.Globals["x"]); } }