Kephas.Scripting 11.1.0

Prefix Reserved
dotnet add package Kephas.Scripting --version 11.1.0
                    
NuGet\Install-Package Kephas.Scripting -Version 11.1.0
                    
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.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Kephas.Scripting" Version="11.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Kephas.Scripting" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Kephas.Scripting --version 11.1.0
                    
#r "nuget: Kephas.Scripting, 11.1.0"
                    
#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.
#addin nuget:?package=Kephas.Scripting&version=11.1.0
                    
Install Kephas.Scripting as a Cake Addin
#tool nuget:?package=Kephas.Scripting&version=11.1.0
                    
Install Kephas.Scripting as a Cake Tool

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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.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,520 4/13/2022
11.1.0-dev.4 172 4/6/2022
11.1.0-dev.3 155 3/30/2022
11.1.0-dev.2 163 3/23/2022
11.1.0-dev.1 148 3/23/2022
11.0.0 1,287 3/11/2022
11.0.0-dev.7 153 3/7/2022
11.0.0-dev.6 163 2/28/2022
11.0.0-dev.5 156 2/26/2022
11.0.0-dev.4 159 2/24/2022
11.0.0-dev.3 154 2/23/2022
11.0.0-dev.2 153 2/18/2022
11.0.0-dev.1 161 2/7/2022
10.3.0 1,317 1/18/2022
10.2.0 1,311 12/3/2021
10.1.0 5,383 11/23/2021
10.1.0-dev.7 235 11/17/2021
10.1.0-dev.6 200 11/16/2021
10.1.0-dev.5 196 11/10/2021
10.1.0-dev.4 195 11/8/2021
10.1.0-dev.3 171 11/8/2021
10.1.0-dev.2 185 11/4/2021
10.1.0-dev.1 189 11/3/2021
10.0.1 975 10/16/2021
10.0.0 937 10/13/2021
10.0.0-dev.4 181 10/13/2021
10.0.0-dev.3 190 10/11/2021
10.0.0-dev.2 243 10/8/2021
9.3.4 965 8/25/2021
9.3.3 907 8/25/2021
9.3.2 892 8/24/2021
9.3.1 914 8/12/2021
9.3.0 962 8/12/2021
9.2.0 971 6/17/2021
9.1.0 919 6/17/2021
9.1.0-dev.9 222 5/26/2021
9.1.0-dev.8 216 5/26/2021
9.1.0-dev.7 229 5/17/2021
9.1.0-dev.6 210 4/28/2021
9.1.0-dev.5 232 4/23/2021
9.1.0-dev.4 220 4/21/2021
9.1.0-dev.3 219 4/17/2021
9.1.0-dev.2 210 4/12/2021
9.1.0-dev.1 219 4/9/2021
9.0.5 915 3/31/2021
9.0.4 948 3/23/2021
9.0.3 977 3/20/2021
9.0.1 923 3/18/2021
9.0.0 972 3/17/2021
9.0.0-dev.4 217 3/4/2021
9.0.0-dev.3 224 3/1/2021
9.0.0-dev.2 257 2/22/2021
8.4.0 1,073 11/11/2020
8.3.0 1,058 10/28/2020
8.2.0 1,125 10/16/2020
8.1.0 1,156 9/23/2020
8.0.0 1,071 7/1/2020
8.0.0-dev.44 326 6/25/2020
8.0.0-dev.43 315 6/23/2020
8.0.0-dev.42 362 6/22/2020
8.0.0-dev.41 355 6/18/2020
8.0.0-dev.40 308 6/18/2020
8.0.0-dev.39 324 6/15/2020
8.0.0-dev.38 439 6/14/2020
8.0.0-dev.37 295 6/13/2020
8.0.0-dev.36 339 6/13/2020
8.0.0-dev.35 280 6/12/2020
8.0.0-dev.34 335 6/12/2020
8.0.0-dev.33 383 6/10/2020
8.0.0-dev.32 304 6/1/2020
8.0.0-dev.31 327 6/1/2020
8.0.0-dev.30 401 5/30/2020
8.0.0-dev.28 340 5/28/2020
8.0.0-dev.27 323 5/15/2020
8.0.0-dev.26 308 5/14/2020
8.0.0-dev.25 319 5/14/2020
8.0.0-dev.24 315 5/13/2020
8.0.0-dev.23 306 5/13/2020
8.0.0-dev.22 311 5/13/2020
8.0.0-dev.21 316 5/12/2020
8.0.0-dev.20 321 5/12/2020
8.0.0-dev.19 324 5/7/2020
8.0.0-dev.18 310 5/7/2020
8.0.0-dev.17 300 5/6/2020
8.0.0-dev.16 311 5/6/2020
8.0.0-dev.15 311 5/5/2020
8.0.0-dev.14 307 5/5/2020
8.0.0-dev.13 345 5/4/2020
7.6.0-dev.13 331 5/1/2020
7.6.0-dev.12 350 4/30/2020
7.6.0-dev.11 318 4/28/2020
7.6.0-dev.10 319 4/27/2020
7.6.0-dev.9 314 4/24/2020
7.6.0-dev.8 315 4/22/2020
7.6.0-dev.7 305 4/15/2020
7.6.0-dev.6 299 4/15/2020
7.6.0-dev.5 298 4/15/2020
7.6.0-dev.4 428 4/11/2020
7.6.0-dev.3 302 4/10/2020
7.6.0-dev.2 303 4/10/2020
7.6.0-dev.1 380 4/8/2020
7.5.2 1,200 3/20/2020
7.5.1 1,130 3/12/2020
7.5.0 1,183 3/10/2020
7.5.0-dev.18 327 3/5/2020
7.5.0-dev.17 328 3/5/2020
7.5.0-dev.16 355 3/4/2020
7.5.0-dev.15 296 3/3/2020
7.5.0-dev.14 302 3/3/2020
7.5.0-dev.13 289 2/29/2020
7.5.0-dev.12 410 2/29/2020
7.5.0-dev.10 282 2/25/2020
7.5.0-dev.9 338 2/20/2020
7.5.0-dev.8 373 2/18/2020
7.5.0-dev.7 300 2/18/2020
7.5.0-dev.6 312 2/14/2020
7.5.0-dev.5 327 2/12/2020
7.5.0-dev.4 309 2/11/2020
7.5.0-dev.3 286 2/11/2020
7.5.0-dev.2 420 2/8/2020
7.5.0-dev.1 312 2/7/2020
7.4.2 1,115 2/5/2020
7.4.1 1,212 2/3/2020
7.4.0 1,239 1/31/2020
7.4.0-dev.4 364 1/31/2020
7.4.0-dev.3 350 1/29/2020
7.4.0-dev.2 298 1/28/2020
7.4.0-dev.1 305 1/23/2020
7.3.1 1,146 1/21/2020
7.3.1-preview.7 304 1/21/2020
7.3.1-preview.1 335 1/20/2020
7.3.0 1,109 1/19/2020
7.2.6 1,221 1/18/2020
7.2.5 1,151 12/19/2019
7.2.4 1,134 12/19/2019
7.2.3 1,195 12/16/2019
7.2.2 1,150 12/9/2019
7.2.1 1,172 12/4/2019
7.2.0 1,137 11/26/2019
7.2.0-preview.10 307 11/20/2019
7.2.0-preview.9 305 11/19/2019
7.2.0-preview.8 305 11/18/2019
7.2.0-preview.6 310 11/14/2019
7.2.0-preview.5 301 11/14/2019
7.2.0-preview.4 314 11/14/2019
7.2.0-preview.2 318 11/11/2019
7.2.0-preview.1 318 11/9/2019
7.1.0 1,204 11/6/2019
7.1.0-preview.8 315 11/5/2019
7.1.0-preview.7 305 11/4/2019
7.1.0-preview.6 309 11/1/2019
7.1.0-preview.5 342 10/31/2019
7.1.0-preview.4.1 328 10/31/2019
7.1.0-preview.4 335 10/30/2019
7.1.0-preview.3 310 10/26/2019
7.1.0-preview.2 323 10/25/2019
7.1.0-preview.1 317 10/24/2019
7.0.0 1,025 10/16/2019
7.0.0-rc.41 332 10/15/2019
7.0.0-rc.40 329 10/15/2019
7.0.0-rc.39 321 10/12/2019
7.0.0-rc.38 314 10/11/2019
7.0.0-rc.37 319 10/10/2019
7.0.0-rc.36 319 10/9/2019
7.0.0-rc.35 312 10/8/2019
7.0.0-rc.34 321 10/8/2019
7.0.0-rc.33 312 10/7/2019
7.0.0-rc.32 321 10/5/2019
7.0.0-rc.31 321 10/3/2019
7.0.0-rc.30 312 10/1/2019
7.0.0-rc.28 321 10/1/2019
7.0.0-rc.27 317 9/30/2019
7.0.0-rc.26 326 9/30/2019
7.0.0-rc.25 313 9/27/2019
7.0.0-rc.24 311 9/27/2019
7.0.0-rc.23 306 9/26/2019
7.0.0-rc.22 310 9/25/2019
7.0.0-rc.21 317 9/24/2019
7.0.0-rc.20 314 9/23/2019
7.0.0-rc.19 324 9/20/2019
7.0.0-rc.18.1 314 9/20/2019
7.0.0-rc.18 326 9/20/2019
6.5.0-rc.17 333 9/19/2019
6.5.0-rc.16 341 9/18/2019
6.5.0-rc.15 335 9/18/2019
6.5.0-rc.14.1 334 9/18/2019
6.5.0-rc.14 337 9/17/2019
6.5.0-rc.13 327 9/16/2019
6.5.0-rc.12.2 325 9/13/2019
6.5.0-rc.12.1 329 9/12/2019
6.5.0-rc.12 334 9/12/2019
6.5.0-rc.11 322 9/11/2019
6.5.0-rc.10 318 9/10/2019
6.5.0-rc.9 328 9/9/2019
6.5.0-rc.8 312 9/6/2019
6.5.0-rc.7 336 9/6/2019
6.5.0-rc.6 328 9/6/2019
6.5.0-rc.5 318 9/2/2019
6.5.0-rc.4 338 9/2/2019
6.5.0-rc.3 320 8/30/2019
6.5.0-rc.2 344 8/29/2019
6.5.0-rc.1 342 8/28/2019
6.5.0-beta.5 340 8/28/2019
6.5.0-beta.4 333 8/27/2019
6.0.0 876 8/6/2019
6.0.0-rc.7 331 7/19/2019
6.0.0-rc.6 327 6/28/2019
6.0.0-rc.5 315 6/28/2019
6.0.0-rc.4 324 6/25/2019
6.0.0-rc.3 332 6/20/2019
6.0.0-rc.2 323 5/29/2019
6.0.0-rc.1 332 5/28/2019
6.0.0-beta.3 345 4/17/2019
5.3.0-beta.2 342 3/21/2019
5.3.0-beta.1 342 3/20/2019
5.2.0 851 3/19/2019
5.1.0 1,200 1/25/2019
5.0.0 1,214 12/21/2018
5.0.0-rc11 897 12/14/2018
5.0.0-rc10 716 11/16/2018
5.0.0-rc09 725 11/1/2018
5.0.0-rc08 698 10/31/2018
5.0.0-rc07 703 10/31/2018
5.0.0-rc06 732 10/30/2018
5.0.0-rc05 728 10/29/2018
5.0.0-rc04 769 10/29/2018
5.0.0-rc03 747 10/26/2018
5.0.0-rc02 729 10/25/2018
5.0.0-rc01 757 10/12/2018
5.0.0-beta03 800 9/21/2018
5.0.0-beta02 799 9/10/2018
5.0.0-beta01 792 9/7/2018
4.5.1 948 8/7/2018
4.5.0 1,350 8/7/2018
4.5.0-rc01 975 6/7/2018
4.5.0-beta09 830 6/7/2018
4.5.0-beta08 977 5/16/2018
4.5.0-beta07 894 5/9/2018
4.5.0-beta06 950 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.