Kephas.Scripting 11.0.0-dev.5

Prefix Reserved
This is a prerelease version of Kephas.Scripting.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Kephas.Scripting --version 11.0.0-dev.5                
NuGet\Install-Package Kephas.Scripting -Version 11.0.0-dev.5                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Kephas.Scripting" Version="11.0.0-dev.5" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Kephas.Scripting --version 11.0.0-dev.5                
#r "nuget: Kephas.Scripting, 11.0.0-dev.5"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Kephas.Scripting as a Cake Addin
#addin nuget:?package=Kephas.Scripting&version=11.0.0-dev.5&prerelease

// Install Kephas.Scripting as a Cake Tool
#tool nuget:?package=Kephas.Scripting&version=11.0.0-dev.5&prerelease                

Scripting

Introduction

The scripting area in Kephas handles dynamic code execution. The entry point is the IScriptProcessor singleton service, which returns a result through the ExecuteAsync method, provided with a script, execution arguments, and globals.

Check the following packages for more information:

Packages providing scripting implementations:

Usage

// normally you would get the processor injected into the service constructor.
var processor = injector.Resolve<IScriptProcessor>();

// the next line uses C# scripting, so you will need also to reference Kephas.Scripting.CSharp.
var result = processor.ExecuteAsync(new CSharpStringScript("name[..4] + age.ToString()"), new { name = "Johnny", age = 42 }));
Assert.Equals("John42", result);

// the next line uses Python scripting, so you will need also to reference Kephas.Scripting.Python.
// additionally, instead of using typed arguments, it used an Expando - it could use as well a IDictionary<string, object?>.
var result = processor.ExecuteAsync(new PythonStringScript("name[..4] + str(age)"), new Expando { ["name"] = "Johnny", ["age"] = 42 }));
Assert.Equals("John42", result);

The IScriptProcessor service

This service is the central piece providing the ExecuteAsync method through which a script is executed. The script return value is, in turn, returned by the method.

DefaultScriptProcessor is the default implementation of the IScriptProcessor. Just like the other default implementations provided by the Kephas framework, it declares a low override priority, so that it can be easily overridden. By default, it delegates the template processing to a specific ILanguageService handling the provided script. It identifies the language service based on the script's language, which the service declares using the [Language(...)] attribute.

Passing arguments

The arguments passed to the execution can be referenced in the scripts directly by their name. However, if the DeconstructArgs scripting context options is set to false, the arguments can be accessed through the Args global variable.

Example
var processor = injector.Resolve<IScriptProcessor>();
var script = new CSharpStringScript(
    "int Power(int a) => a * a;" +
    "return Power((int)Args.a);");
var result = await processor.ExecuteAsync(script, new { a = 2 }, ctx => ctx.DeconstructArgs(false)); 

Language services

These services implement the ILanguageService contract and handle specific languages. By default, the framework does not provide any language service in the Kephas.Scripting package due to the heavy overhead it brings. However, there are several language services provided in separate packages:

Controlling the script execution

The scripting context

Additional to the script and the arguments, the processing methods receive also a context which can be used to further control the operations. Just like all the other context instances, it is a dynamic expandable object (IExpando) and it aggregates the provided template and the model. Through the Result and Exception properties, the behaviors (see below) can control the processing output.

The scripting behaviors

The DefaultScriptProcessor uses also IScriptingBehavior services to further control the execution. Just like the ILanguageService services, they declare the language they support, and are invoked before and after the selected language service executes the script. They can cover various purposes: authorization, pre-processing/post-processing, audit, and whatever other functionality may be required.

The scripts

A script implements IScript, basically providing a Language (string), a Name (string), and source code (GetSourceCodeAsync(), GetSourceCode()). By default, the framework supports these script sources:

  • StringScript: constructed using a string.
  • StreamScript: constructed using a Stream.
  • FileScript: constructed using a file path. If not provided, the Language is considered to be the file extension.
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Kephas.Scripting:

Package Downloads
Kephas.Scripting.CSharp

Provides the infrastructure for executing C# scripts. Typically used areas and classes/interfaces/services: - CSharpLanguageService. Kephas Framework ("stone" in aramaic) aims to deliver a solid infrastructure for applications and application ecosystems.

Kephas.Scripting.Python

Provides the infrastructure for executing Python scripts. Typically used areas and classes/interfaces/services: - PythonLanguageService. Kephas Framework ("stone" in aramaic) aims to deliver a solid infrastructure for applications and application ecosystems.

Kephas.Scripting.Lua

Provides the infrastructure for executing LUA scripts. Typically used areas and classes/interfaces/services: - LuaLanguageService. Kephas Framework ("stone" in aramaic) aims to deliver a solid infrastructure for applications and application ecosystems.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
11.1.0 1,353 4/13/2022
11.1.0-dev.4 146 4/6/2022
11.1.0-dev.3 129 3/30/2022
11.1.0-dev.2 137 3/23/2022
11.1.0-dev.1 124 3/23/2022
11.0.0 1,236 3/11/2022
11.0.0-dev.7 128 3/7/2022
11.0.0-dev.6 134 2/28/2022
11.0.0-dev.5 129 2/26/2022
11.0.0-dev.4 133 2/24/2022
11.0.0-dev.3 129 2/23/2022
11.0.0-dev.2 125 2/18/2022
11.0.0-dev.1 135 2/7/2022
10.3.0 1,256 1/18/2022
10.2.0 1,238 12/3/2021
10.1.0 5,303 11/23/2021
10.1.0-dev.7 201 11/17/2021
10.1.0-dev.6 173 11/16/2021
10.1.0-dev.5 168 11/10/2021
10.1.0-dev.4 167 11/8/2021
10.1.0-dev.3 142 11/8/2021
10.1.0-dev.2 155 11/4/2021
10.1.0-dev.1 160 11/3/2021
10.0.1 904 10/16/2021
10.0.0 848 10/13/2021
10.0.0-dev.4 154 10/13/2021
10.0.0-dev.3 163 10/11/2021
10.0.0-dev.2 215 10/8/2021
9.3.4 883 8/25/2021
9.3.3 828 8/25/2021
9.3.2 827 8/24/2021
9.3.1 859 8/12/2021
9.3.0 895 8/12/2021
9.2.0 912 6/17/2021
9.1.0 855 6/17/2021
9.1.0-dev.9 194 5/26/2021
9.1.0-dev.8 190 5/26/2021
9.1.0-dev.7 201 5/17/2021
9.1.0-dev.6 181 4/28/2021
9.1.0-dev.5 203 4/23/2021
9.1.0-dev.4 189 4/21/2021
9.1.0-dev.3 190 4/17/2021
9.1.0-dev.2 179 4/12/2021
9.1.0-dev.1 191 4/9/2021
9.0.5 826 3/31/2021
9.0.4 879 3/23/2021
9.0.3 887 3/20/2021
9.0.1 857 3/18/2021
9.0.0 889 3/17/2021
9.0.0-dev.4 181 3/4/2021
9.0.0-dev.3 188 3/1/2021
9.0.0-dev.2 216 2/22/2021
8.4.0 1,004 11/11/2020
8.3.0 969 10/28/2020
8.2.0 1,037 10/16/2020
8.1.0 1,080 9/23/2020
8.0.0 990 7/1/2020
8.0.0-dev.44 290 6/25/2020
8.0.0-dev.43 279 6/23/2020
8.0.0-dev.42 325 6/22/2020
8.0.0-dev.41 319 6/18/2020
8.0.0-dev.40 267 6/18/2020
8.0.0-dev.39 288 6/15/2020
8.0.0-dev.38 404 6/14/2020
8.0.0-dev.37 257 6/13/2020
8.0.0-dev.36 304 6/13/2020
8.0.0-dev.35 244 6/12/2020
8.0.0-dev.34 293 6/12/2020
8.0.0-dev.33 345 6/10/2020
8.0.0-dev.32 267 6/1/2020
8.0.0-dev.31 291 6/1/2020
8.0.0-dev.30 364 5/30/2020
8.0.0-dev.28 303 5/28/2020
8.0.0-dev.27 286 5/15/2020
8.0.0-dev.26 267 5/14/2020
8.0.0-dev.25 281 5/14/2020
8.0.0-dev.24 277 5/13/2020
8.0.0-dev.23 267 5/13/2020
8.0.0-dev.22 273 5/13/2020
8.0.0-dev.21 278 5/12/2020
8.0.0-dev.20 283 5/12/2020
8.0.0-dev.19 273 5/7/2020
8.0.0-dev.18 271 5/7/2020
8.0.0-dev.17 261 5/6/2020
8.0.0-dev.16 272 5/6/2020
8.0.0-dev.15 271 5/5/2020
8.0.0-dev.14 268 5/5/2020
8.0.0-dev.13 297 5/4/2020
7.6.0-dev.13 293 5/1/2020
7.6.0-dev.12 312 4/30/2020
7.6.0-dev.11 279 4/28/2020
7.6.0-dev.10 268 4/27/2020
7.6.0-dev.9 276 4/24/2020
7.6.0-dev.8 277 4/22/2020
7.6.0-dev.7 267 4/15/2020
7.6.0-dev.6 263 4/15/2020
7.6.0-dev.5 261 4/15/2020
7.6.0-dev.4 389 4/11/2020
7.6.0-dev.3 265 4/10/2020
7.6.0-dev.2 266 4/10/2020
7.6.0-dev.1 343 4/8/2020
7.5.2 1,110 3/20/2020
7.5.1 1,047 3/12/2020
7.5.0 1,098 3/10/2020
7.5.0-dev.18 290 3/5/2020
7.5.0-dev.17 291 3/5/2020
7.5.0-dev.16 318 3/4/2020
7.5.0-dev.15 259 3/3/2020
7.5.0-dev.14 265 3/3/2020
7.5.0-dev.13 252 2/29/2020
7.5.0-dev.12 374 2/29/2020
7.5.0-dev.10 245 2/25/2020
7.5.0-dev.9 300 2/20/2020
7.5.0-dev.8 335 2/18/2020
7.5.0-dev.7 262 2/18/2020
7.5.0-dev.6 275 2/14/2020
7.5.0-dev.5 290 2/12/2020
7.5.0-dev.4 272 2/11/2020
7.5.0-dev.3 249 2/11/2020
7.5.0-dev.2 383 2/8/2020
7.5.0-dev.1 277 2/7/2020
7.4.2 1,028 2/5/2020
7.4.1 1,124 2/3/2020
7.4.0 1,149 1/31/2020
7.4.0-dev.4 326 1/31/2020
7.4.0-dev.3 313 1/29/2020
7.4.0-dev.2 261 1/28/2020
7.4.0-dev.1 267 1/23/2020
7.3.1 1,064 1/21/2020
7.3.1-preview.7 267 1/21/2020
7.3.1-preview.1 299 1/20/2020
7.3.0 1,019 1/19/2020
7.2.6 1,138 1/18/2020
7.2.5 1,078 12/19/2019
7.2.4 1,063 12/19/2019
7.2.3 1,110 12/16/2019
7.2.2 1,062 12/9/2019
7.2.1 1,096 12/4/2019
7.2.0 1,049 11/26/2019
7.2.0-preview.10 270 11/20/2019
7.2.0-preview.9 268 11/19/2019
7.2.0-preview.8 268 11/18/2019
7.2.0-preview.6 273 11/14/2019
7.2.0-preview.5 264 11/14/2019
7.2.0-preview.4 276 11/14/2019
7.2.0-preview.2 276 11/11/2019
7.2.0-preview.1 281 11/9/2019
7.1.0 1,118 11/6/2019
7.1.0-preview.8 278 11/5/2019
7.1.0-preview.7 268 11/4/2019
7.1.0-preview.6 271 11/1/2019
7.1.0-preview.5 304 10/31/2019
7.1.0-preview.4.1 290 10/31/2019
7.1.0-preview.4 297 10/30/2019
7.1.0-preview.3 272 10/26/2019
7.1.0-preview.2 285 10/25/2019
7.1.0-preview.1 277 10/24/2019
7.0.0 933 10/16/2019
7.0.0-rc.41 288 10/15/2019
7.0.0-rc.40 291 10/15/2019
7.0.0-rc.39 283 10/12/2019
7.0.0-rc.38 276 10/11/2019
7.0.0-rc.37 275 10/10/2019
7.0.0-rc.36 280 10/9/2019
7.0.0-rc.35 275 10/8/2019
7.0.0-rc.34 282 10/8/2019
7.0.0-rc.33 275 10/7/2019
7.0.0-rc.32 281 10/5/2019
7.0.0-rc.31 283 10/3/2019
7.0.0-rc.30 275 10/1/2019
7.0.0-rc.28 283 10/1/2019
7.0.0-rc.27 279 9/30/2019
7.0.0-rc.26 287 9/30/2019
7.0.0-rc.25 275 9/27/2019
7.0.0-rc.24 274 9/27/2019
7.0.0-rc.23 268 9/26/2019
7.0.0-rc.22 273 9/25/2019
7.0.0-rc.21 279 9/24/2019
7.0.0-rc.20 276 9/23/2019
7.0.0-rc.19 285 9/20/2019
7.0.0-rc.18.1 275 9/20/2019
7.0.0-rc.18 287 9/20/2019
6.5.0-rc.17 297 9/19/2019
6.5.0-rc.16 300 9/18/2019
6.5.0-rc.15 296 9/18/2019
6.5.0-rc.14.1 295 9/18/2019
6.5.0-rc.14 294 9/17/2019
6.5.0-rc.13 285 9/16/2019
6.5.0-rc.12.2 287 9/13/2019
6.5.0-rc.12.1 293 9/12/2019
6.5.0-rc.12 298 9/12/2019
6.5.0-rc.11 284 9/11/2019
6.5.0-rc.10 282 9/10/2019
6.5.0-rc.9 292 9/9/2019
6.5.0-rc.8 274 9/6/2019
6.5.0-rc.7 299 9/6/2019
6.5.0-rc.6 285 9/6/2019
6.5.0-rc.5 282 9/2/2019
6.5.0-rc.4 300 9/2/2019
6.5.0-rc.3 282 8/30/2019
6.5.0-rc.2 301 8/29/2019
6.5.0-rc.1 303 8/28/2019
6.5.0-beta.5 297 8/28/2019
6.5.0-beta.4 294 8/27/2019
6.0.0 813 8/6/2019
6.0.0-rc.7 296 7/19/2019
6.0.0-rc.6 292 6/28/2019
6.0.0-rc.5 277 6/28/2019
6.0.0-rc.4 287 6/25/2019
6.0.0-rc.3 294 6/20/2019
6.0.0-rc.2 284 5/29/2019
6.0.0-rc.1 296 5/28/2019
6.0.0-beta.3 304 4/17/2019
5.3.0-beta.2 304 3/21/2019
5.3.0-beta.1 302 3/20/2019
5.2.0 806 3/19/2019
5.1.0 1,108 1/25/2019
5.0.0 1,116 12/21/2018
5.0.0-rc11 813 12/14/2018
5.0.0-rc10 635 11/16/2018
5.0.0-rc09 647 11/1/2018
5.0.0-rc08 635 10/31/2018
5.0.0-rc07 642 10/31/2018
5.0.0-rc06 659 10/30/2018
5.0.0-rc05 666 10/29/2018
5.0.0-rc04 692 10/29/2018
5.0.0-rc03 687 10/26/2018
5.0.0-rc02 654 10/25/2018
5.0.0-rc01 680 10/12/2018
5.0.0-beta03 719 9/21/2018
5.0.0-beta02 709 9/10/2018
5.0.0-beta01 710 9/7/2018
4.5.1 864 8/7/2018
4.5.0 1,231 8/7/2018
4.5.0-rc01 831 6/7/2018
4.5.0-beta09 754 6/7/2018
4.5.0-beta08 836 5/16/2018
4.5.0-beta07 770 5/9/2018
4.5.0-beta06 808 4/25/2018

Please check https://github.com/kephas-software/kephas/releases for the change log.
           Also check the documentation and the samples from https://github.com/kephas-software/kephas/wiki and https://github.com/kephas-software/kephas/tree/master/Samples.