Script libraries

Nov 26, 2013 at 2:48 PM
I would like to be able to build and use a lib of helper scripts preferably residing separately (in separate files or storage records).
How can I load or include such scripts in addition to or perhaps from within a main script being executed.
What would be your recommendations.

Yours faithfully,
MW
Coordinator
Nov 26, 2013 at 6:25 PM
Hello MW!

You can execute any number of library scripts to prepare the environment for your main script. There really are no limitations. You can do something simple:
using (var engine = new V8ScriptEngine()) {
    engine.Execute(File.ReadAllText(@"C:\path\to\lib1.js"));
    engine.Execute(File.ReadAllText(@"C:\path\to\lib2.js"));
    // and so on
}
Or you can use a module manager such as RequireJS for a bit more structure; see here for a simple RequireJS implementation on ClearScript.

And because ClearScript executes scripts from in-memory strings, you can use whatever storage is convenient - files, resources, database records, etc. You can also construct scripts on the fly in memory.

Cheers!