Skip to content

Cross language Calls

Rohan Singh edited this page Feb 17, 2024 · 4 revisions

Mond calling C#

In most cases it is preferable to use automatic binding to expose C# code to Mond but it can be done manually as well. Functions matching the MondFunction delegate can implicitly cast to MondValue for use in Mond scripts.

var state = new MondState();
state["add"] = MondValue.Function((_, args) => args[0] + args[1]);

var result = state.Run("return global.add(1, 1);");

C# calling Mond

Mond functions can be called from C# with MondState.Call.

var state = new MondState();
state.Run("global.add = fun (a, b) -> a + b;");

var result = state.Call(state["add"], 1, 1);