Replies: 1 comment
-
Hi @nextfool, The problem with your approach is that a module's context is only accessible within the module, so an empty module can serve no purpose. It needs to export something in order to be useful. The context, accessible in ES6 modules as Here's an example that sets up a minimal "@system/console" module. Note that you can use the system document feature instead of a custom document loader for this purpose: const string consoleCode = @"
export function log() {
import.meta.Console.WriteLine(...arguments);
}
";
engine.DocumentSettings.AddSystemDocument(
"@system/console",
ModuleCategory.Standard,
consoleCode,
_ => new Dictionary<string, object> {
{ "Console", typeof(Console).ToHostType() }
}
); With this setup, you can do this: engine.Execute(new DocumentInfo { Category = ModuleCategory.Standard }, @"
import * as console from '@system/console';
console.log('Hello, world! {0} is the current time.', new Date().toLocaleTimeString());
"); Please let us know if you have additional questions. Thanks! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi @ClearScriptLib ,
I don't know if I am on the right path, but here is what I intend to do:
I want to expose some api/objects(implemented with c# of course) with the "import syntax"
import {SomeApi} form "@systemApi/SomeApi",
so I created a custom document loader, whenever the "specifier" matches my system api uri format, I pass a "DocumentContextCallback" which create a "context" (with corresponding javascript api exposed) to the default loader's "LoadDocumentAsync".
The problem is that, I don't have any "runnable" javascript code for the "module", so I am thinking of returning an empty document.
Please see the screenshot bellow.
Can you please tell me whether it is the correct way or you have any other advice?
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions