Skip to content
Glenn Block edited this page Mar 30, 2016 · 4 revisions

You can host scriptcs within your own custom applications / and components whether they are running on .NET or Mono.

Hosting sample

You can download a simple example illustrating how to host scriptcs within a console app here.

Creating a custom Script Host

Within scriptcs your scripts can access ambient members like Env which are surfaced via the ScriptHost object. You can also create a custom script host which exposes additional members to scripts running in your custom hosted environment. For example you may want to add additional properties or members.

Here are the steps to create and register a custom host:

  • Create a custom host class which derives from ScriptHost. Add whatever properties or methods you'd like to this object. They will project into the scripting environment as ambient members similar to Env.
  • Create a custom ScriptHostFactory which returns your host.
  • Register this factory using the ScriptCsServicesBuilder.ScriptHostFactory<T>() method where T is your factory. Do this before calling Build on the builder.

That should be it. Within your scripts / the REPL (if you are hosting the REPL) you should be able to access the new members.

Projects

There are several projects which leverage scriptcs hosting in the box.