Skip to content

Basic Usage

Rohan Singh edited this page Jan 30, 2025 · 4 revisions

In order to run Mond scripts you need to create a new state.

var state = new MondState();

Scripts can then be run by using state.Run.

var result = state.Run("return 1 + 1;");

All values can be converted to a string using its Serialize function.

Console.WriteLine(result.Serialize());

Globals can be accessed with the state's indexer.

state["a"] = 10;

state.Run("global.b = global.a * global.a;");

Console.WriteLine(state["b"].Serialize());

Caching scripts

If you are expecting to run the same script source code multiple times then it is best to compile the script before you run it in MondState instance(s). This can significantly improve performance by skipping parsing and compiling for subsequent runs.

var program = MondProgram.Compile("return 1 + 1;");

The MondProgram instance can then be loaded into any MondState as many times as you need to run it.

var result = state.Load(program);

The MondProgram instances can also be saved to disk if you plan on distributing scripts and want to improve load times and/or not distribute your script source code.