ExportFunction help
#1750
-
I want to export a module and export functions from this module but there is no practical example of how to do it despite the existence of builder.ExportFunction. E.g: public class Example
{
public Example(Engine engine) {
engine.Modules.Add("@example", builder => {
builder.ExportFunction("log", Log)
});
}
public void Log(string message) {
Console.WriteLine(message);
}
}
import { log } from "@example";
log("Hello from script.js"); |
Beta Was this translation helpful? Give feedback.
Answered by
Hadaward
Jan 20, 2024
Replies: 1 comment
-
Sorry, i just figured out how to do this: public class Example
{
public Example(Engine engine) {
engine.Modules.Add("@example", builder => {
builder.ExportFunction("log", new Func<JsValue[], JsValue>(args => Log(args)))
});
}
public JsValue Log(JsValue[] args)
{
string message = string.Join("\t", args.Select(arg => arg.AsString()).ToArray());
Console.WriteLine(message);
return JsValue.Undefined;
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Hadaward
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry, i just figured out how to do this: