PaxScripter demo application written in C# which illustrates debug capabilities.

demo_debug.jpg
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using PaxScript.Net;

namespace DebugApp
{
	public partial class WinForm : System.Windows.Forms.Form
	{
		private PaxScript.Net.PaxScripter paxScripter1;

		public WinForm()
		{
                	paxScripter1.DebugMode = true;
	                this.paxScripter1.State = PaxScript.Net.ScripterState.Init;
            		this.paxScripter1.OnChangeState += new PaxScript.Net.ChangeStateHandler(this.paxScripter1_OnChangeState);
                        this.paxScripter1.OnPrint += DoPrint;

		}

       		private void DoPrint(PaxScripter sender, string s)
        	{
            		tbState.Text += "\r\n" + "Output :" + s;
        	}

		static void Main()
		{
			Application.Run(new WinForm());
		}

		private void btnReset_Click(object sender, System.EventArgs e)
		{
			paxScripter1.Reset();
		}

		private void btnRun_Click(object sender, System.EventArgs e)
		{
			paxScripter1.Run(RunMode.Run);
		}

		private void btnTraceInto_Click(object sender, System.EventArgs e)
		{
			paxScripter1.Run(RunMode.TraceInto);
		}

		private void btnStepOver_Click(object sender, System.EventArgs e)
		{
			paxScripter1.Run(RunMode.StepOver);
		}

		private void btnAddBreakpoint_Click(object sender, System.EventArgs e)
		{
			paxScripter1.AddBreakpoint("1", 5);
			ShowInfo(paxScripter1, paxScripter1.State);
		}

		private void btnRemoveBreakpoint_Click(object sender, System.EventArgs e)
		{
			paxScripter1.RemoveAllBreakpoints();
			ShowInfo(paxScripter1, paxScripter1.State);
		}

		private void ShowInfo(PaxScript.Net.PaxScripter sender, ScripterState new_state)
		{
			rtbState.Text = "State: " + new_state.ToString();
			rtbState.Text += "\nModule: " + sender.CurrentModule;
			rtbState.Text += "\nLine " + sender.CurrentLineNumber.ToString() +
					" : " + sender.CurrentLine;

			object v = null;
			if (new_state == ScripterState.Paused)
			{
				v = sender.Eval("number");
				sender.DiscardError();
			}

			if (v == null)
				rtbState.Text += "\nnumber = null";
			else
				rtbState.Text += "\nnumber = " + v.ToString();

			rtbState.Text += "\nCall stack:";
			foreach (CallStackRec csr in sender.Call_Stack)
			{
				rtbState.Text += "\n" + csr.CallView + " at line " + csr.LineNumber;
			}

			rtbState.Text += "\nBreakpoints:";
			foreach (Breakpoint bp in sender.Breakpoint_List)
			{
				rtbState.Text += "\nBreakpoint at line " + bp.LineNumber +
					", Activated = " + bp.Activated;
			}
		}

		private void paxScripter1_OnChangeState(PaxScript.Net.PaxScripter sender, PaxScript.Net.ChangeStateEventArgs e)
		{
			if (!sender.HasErrors)
				ShowInfo(sender, e.NewState);

			if (e.NewState == ScripterState.Error)
			{
				MessageBox.Show("Error: " + sender.Error_List[0].Message);
			}
			else if (e.OldState == ScripterState.Init)
			{
				sender.AddModule("1");
				sender.AddCode("1", rtbScript.Text);
			}
		}
	}
}


Copyright © 2005-2024 Alexander Baranovsky. All rights reserved.