Loads a script file (or series of script files).
Syntax
.incscript "source" [, "source" [, ...]]
Remarks
Script files can be written in any .NET-compatible language, such as C# or Visual Basic.
Script files should contain at least one public class containing public static (Shared in Visual Basic) methods.
The following argument and return value types are valid:
Arguments and Return | String.
Double, Float, Int32, UInt32, Int16, UInt16, Byte, SByte. Bool. |
---|---|
Arguments Only | Brass3.Compiler, Brass3.Label. |
Return Only | void (Sub in Visual Basic). |
Brass itself only understands double-precision floats and strings, so data types are converted before your function is called and converted again when returned.
The Brass3.Compiler argument is a special case. If you specify it, do not pass a value for it from your assembly source file. It will be populated with the instance of the compiler object building the current file so that your script file can control the compiler directly if need be.
Examples
C# script.
/* File: Script.cs public class ScriptSample { public static double Multiply(double a, double b) { return a * b; } } */ .incscript "Script.cs" .echoln Multiply(4, 5) ; Outputs 20.
Passing a Label to a directive.
/* File: Script.cs using Brass3; public class ScriptSample { public static void IncrementLabel(Label label) { ++label.NumericValue; } } */ .incscript "Script.cs" x = 10 ; Initialise to 10. .echoln x ; Outputs 10. #incrementlabel x ; Increments X. .echoln x ; Outputs 11.
Using Windows Forms.
/* File: WinForms.cs using Brass3; using System.Windows.Forms; using System.Collections.Generic; public class ConfirmBox { #region Private Fields private readonly Compiler Compiler; private QueueResults; #endregion #region Constructor public ConfirmBox(Compiler compiler) { this.Compiler = compiler; this.Results = new Queue .scriptreference "System.Windows.Forms.dll" .incscript "WinForms.cs" ClickCount = 0 .while Confirm("Would you like to increment " + ClickCount + "?")) ++ClickCount .loop .Alert "Final value: " + ClickCount + "."(); } #endregion #region Public Methods public void Alert(string prompt) { if (this.Compiler.CurrentPass == AssemblyPass.CreatingLabels) { MessageBox.Show( prompt, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information ); } } public bool Confirm(string prompt) { if (this.Compiler.CurrentPass == AssemblyPass.CreatingLabels) { bool Result = MessageBox.Show( prompt, "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question ) == DialogResult.Yes; Results.Enqueue(Result); return Result; } else { return Results.Dequeue(); } } #endregion } */
Visual Basic script.
/* File: Script.vb Public Class ScriptSample Public Shared Function RepeatString( _ ByVal str As String, _ ByVal amount As Integer) As String RepeatString = String.Empty For i As Integer = 1 to amount RepeatString &= str Next i End Function End Class */ .incscript "Script.vb" .echoln "Pot" + RepeatString("o", 8)