Skip to main content
Version: Stable (v0.95.5)

Extend FScript with Host APIs

Extend FScript when a script needs an operation the language and standard library do not provide: a database query, a numerical library, an application service, or a graphics resource. The script calls a typed function; trusted host code implements it. This boundary is often called FFI (foreign-function interface).

You do not need a provider to write functions, records, unions, or multi-file FScript programs. Those are language features. An extension adds operations and types to an execution environment.

Choose the integration boundary​

EnvironmentHow to extend it
Interpreted CLI scriptsConfigure a .NET assembly provider or NuGet provider in fscript.toml; grant Native for loading and calls.
Compiled .NET programsSelect .NET providers during compilation; typed CLR mappings support direct calls and compatible AOT publishing.
Embedded .NET applicationRegister typed functions and host-managed values directly, or inspect and load configured providers under the host's explicit grants.
JavaScript applicationSupply typed JavaScript externs through the npm host API; the .NET provider catalog is not included.

Add functions before resources​

Start with a small operation over ordinary script values: records, strings, numbers, or lists. Its declared type gives FScript enough information to check calls and gives the editor completion and hover information.

  1. Follow Register Extern Functions for .NET function contracts, assembly providers, and typed CLR bindings.
  2. Use Create Async Libraries when a library exposes asynchronous I/O. Script-side task coordination is a separate concern.
  3. Use Host-Provided Types for values that carry opaque resources or private application state. The host owns their lifetime and synchronization.
  4. Set up Extension Environments in VS Code so editor diagnostics use the same configured APIs.

For JavaScript externs, follow Fable and JavaScript Hosts. For compiler-specific integration, follow Compile to .NET.

Treat providers as trusted code​

Native is trust in executable code with host/OS access. Interpreter filesystem checks do not confine arbitrary provider code. Declare a narrow script-facing API, inspect configuration before loading providers, and use Permissions and Safety to understand each mode's boundary.

Host-controlled source loading is a separate extension point. Use Resolver and Includes when source comes from memory, a database, or another application-owned location.

Try it: the FFI graphics walkthrough combines ordinary script records, opaque resources, and typed .NET calls in a complete application.