Our new scripting language: PlatformScript Released

PlatformScript is an extensible scripting language built in C# .NET Core 3. It's a basic scripting language that can be extremely useful for the use of simple processes, in particular user-customisable macros and automations.

PlatformScript is open source under the MIT License and can be accessed from our Github Repo. Contributions are welcome!

Variables

Variables only need to be initialised before use. Variables can either be a Number, String or an internal type.

Numbers are stored in C# as a double and can be used in mathematical expressions.

Control Flow

PlatformScript supports the basic control flow operations expected from all languages

if elseif else

i = 10;

if(i == 5)
{
  print("i equals 5");
}
elseif(i == 6)
{
  print("i equals 5");
}
elseif(i % 2 == 0)
{
  print("i is even");
}

 while

a = 0;

while(a < 10)
{
  print(a);
  a++;
}

for

for(a = 0; a < 10; a++)
{
  print(a);
}

Extensions

PlatformScript is an extensible scripting language.

To add an extension function in C#, create a class that extends CustomFeature:

class MyExtensionFunction : CustomFeature
{
    public override Variable Execute(List<Variable.Variable> args = null)
    {
        return new Variable();
    }
}

Returning an empty Variable or String means that the new function cannot be used in calculations. Returning a number means it can be used in mathematical calculations, e.g.:

a = myFunc(10) + 1; // myFunc(10) returns a number

a = anotherFunc(10) + 1; // error: anotherFunc does not return a number

You will now need to register this function with the interpreter:

ScriptSandbox sandbox = new ScriptSandbox();
sandbox.Interpreter.Functions.Add("myExtension", new MyExtensionFunction());
sandbox.ScriptFromFile("myScript.platscript");
sandbox.Prepare();
Variable.Variable = sandbox.Process();

Now in PlatformScript you can call the myExtension() function globally:

myExtension();

There is no built-in argument validation - this needs to be added yourself.

Take a look

Head over to our Github Repo to browse the code and grab a copy.

Written by Kieran on 2019-11-28
This website uses Cookies to enhance your experience. Close Manage