{ "version":"0.2.0", "configurations":[ { "name":"MoonSharp Attach", "type":"moonsharp-debug", "request":"attach", "debugServer":41912, "HELP":"Please set 'debugServer':41912 (or whatever port you ar connecting to) right after the 'version' field in this json." } ] }
bool attached = AwaitDebuggerAttach(server); if (!attached) { Console.WriteLine("VS Code debugger did not attach. Running the script."); }
script.Call(...); }
privatestaticboolAwaitDebuggerAttach(MoonSharpVsCodeDebugServer server) { // as soon as a client has attached, 'm_Client__' field of 'm_Current' isn't null anymore // // we wait for ~60 seconds for a client to attach
BindingFlags bindFlags = BindingFlags.Instance | BindingFlags.NonPublic; FieldInfo field = server.GetType().GetField("m_Current", bindFlags); object current = field.GetValue(server);
privatevoidActivateRemoteDebugger(Script script) { if (remoteDebugger == null) { remoteDebugger = new RemoteDebuggerService(); // the last boolean is to specify if the script is free to run // after attachment, defaults to false remoteDebugger.Attach(script, "Description of the script", false); } // start the web-browser at the correct url. Replace this or just // pass the url to the user in some way. Process.Start(remoteDebugger.HttpUrlStringLocalHost); }
publicstaticvoidDebuggerDemo() { Script script = new Script();
ActivateRemoteDebugger(script);
script.DoString(@" function accum(n, f) if (n == 0) then return 1; else return n * f(n); end end local sum = 0; for i = 1, 5 do -- let's use a lambda to spice things up sum = sum + accum(i, | x | x * 2); end "); Console.WriteLine("The script has ended.."); Console.ReadKey(); }