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.
#:package Kephas.Scripting@11.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Kephas.Scripting&version=11.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Kephas.Scripting&version=11.1.0
                    
Install 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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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,780 4/13/2022
11.1.0-dev.4 275 4/6/2022
11.1.0-dev.3 266 3/30/2022
11.1.0-dev.2 271 3/23/2022
11.1.0-dev.1 249 3/23/2022
11.0.0 1,470 3/11/2022
11.0.0-dev.7 258 3/7/2022
11.0.0-dev.6 297 2/28/2022
11.0.0-dev.5 266 2/26/2022
11.0.0-dev.4 269 2/24/2022
11.0.0-dev.3 263 2/23/2022
11.0.0-dev.2 268 2/18/2022
11.0.0-dev.1 265 2/7/2022
10.3.0 1,494 1/18/2022
10.2.0 1,490 12/3/2021
10.1.0 5,579 11/23/2021
10.1.0-dev.7 357 11/17/2021
10.1.0-dev.6 306 11/16/2021
10.1.0-dev.5 320 11/10/2021
10.1.0-dev.4 302 11/8/2021
10.1.0-dev.3 283 11/8/2021
10.1.0-dev.2 312 11/4/2021
10.1.0-dev.1 310 11/3/2021
10.0.1 1,175 10/16/2021
10.0.0 1,134 10/13/2021
10.0.0-dev.4 289 10/13/2021
10.0.0-dev.3 301 10/11/2021
10.0.0-dev.2 353 10/8/2021
9.3.4 1,177 8/25/2021
9.3.3 1,099 8/25/2021
9.3.2 1,094 8/24/2021
9.3.1 1,112 8/12/2021
9.3.0 1,163 8/12/2021
9.2.0 1,166 6/17/2021
9.1.0 1,077 6/17/2021
9.1.0-dev.9 328 5/26/2021
9.1.0-dev.8 355 5/26/2021
9.1.0-dev.7 358 5/17/2021
9.1.0-dev.6 318 4/28/2021
9.1.0-dev.5 343 4/23/2021
9.1.0-dev.4 334 4/21/2021
9.1.0-dev.3 345 4/17/2021
9.1.0-dev.2 324 4/12/2021
9.1.0-dev.1 356 4/9/2021
9.0.5 1,088 3/31/2021
9.0.4 1,152 3/23/2021
9.0.3 1,165 3/20/2021
9.0.1 1,135 3/18/2021
9.0.0 1,146 3/17/2021
9.0.0-dev.4 346 3/4/2021
9.0.0-dev.3 341 3/1/2021
9.0.0-dev.2 369 2/22/2021
8.4.0 1,291 11/11/2020
8.3.0 1,248 10/28/2020
8.2.0 1,352 10/16/2020
8.1.0 1,378 9/23/2020
8.0.0 1,281 7/1/2020
8.0.0-dev.44 453 6/25/2020
8.0.0-dev.43 442 6/23/2020
8.0.0-dev.42 485 6/22/2020
8.0.0-dev.41 483 6/18/2020
8.0.0-dev.40 441 6/18/2020
8.0.0-dev.39 442 6/15/2020
8.0.0-dev.38 563 6/14/2020
8.0.0-dev.37 416 6/13/2020
8.0.0-dev.36 467 6/13/2020
8.0.0-dev.35 412 6/12/2020
8.0.0-dev.34 459 6/12/2020
8.0.0-dev.33 531 6/10/2020
8.0.0-dev.32 431 6/1/2020
8.0.0-dev.31 451 6/1/2020
8.0.0-dev.30 529 5/30/2020
8.0.0-dev.28 460 5/28/2020
8.0.0-dev.27 463 5/15/2020
8.0.0-dev.26 462 5/14/2020
8.0.0-dev.25 453 5/14/2020
8.0.0-dev.24 467 5/13/2020
8.0.0-dev.23 433 5/13/2020
8.0.0-dev.22 450 5/13/2020
8.0.0-dev.21 477 5/12/2020
8.0.0-dev.20 461 5/12/2020
8.0.0-dev.19 472 5/7/2020
8.0.0-dev.18 458 5/7/2020
8.0.0-dev.17 432 5/6/2020
8.0.0-dev.16 463 5/6/2020
8.0.0-dev.15 445 5/5/2020
8.0.0-dev.14 438 5/5/2020
8.0.0-dev.13 474 5/4/2020
7.6.0-dev.13 461 5/1/2020
7.6.0-dev.12 475 4/30/2020
7.6.0-dev.11 452 4/28/2020
7.6.0-dev.10 441 4/27/2020
7.6.0-dev.9 461 4/24/2020
7.6.0-dev.8 445 4/22/2020
7.6.0-dev.7 434 4/15/2020
7.6.0-dev.6 431 4/15/2020
7.6.0-dev.5 431 4/15/2020
7.6.0-dev.4 557 4/11/2020
7.6.0-dev.3 431 4/10/2020
7.6.0-dev.2 435 4/10/2020
7.6.0-dev.1 527 4/8/2020
7.5.2 1,398 3/20/2020
7.5.1 1,322 3/12/2020
7.5.0 1,406 3/10/2020
7.5.0-dev.18 458 3/5/2020
7.5.0-dev.17 457 3/5/2020
7.5.0-dev.16 484 3/4/2020
7.5.0-dev.15 446 3/3/2020
7.5.0-dev.14 426 3/3/2020
7.5.0-dev.13 420 2/29/2020
7.5.0-dev.12 567 2/29/2020
7.5.0-dev.10 416 2/25/2020
7.5.0-dev.9 471 2/20/2020
7.5.0-dev.8 508 2/18/2020
7.5.0-dev.7 437 2/18/2020
7.5.0-dev.6 473 2/14/2020
7.5.0-dev.5 457 2/12/2020
7.5.0-dev.4 437 2/11/2020
7.5.0-dev.3 421 2/11/2020
7.5.0-dev.2 546 2/8/2020
7.5.0-dev.1 467 2/7/2020
7.4.2 1,331 2/5/2020
7.4.1 1,440 2/3/2020
7.4.0 1,447 1/31/2020
7.4.0-dev.4 512 1/31/2020
7.4.0-dev.3 482 1/29/2020
7.4.0-dev.2 451 1/28/2020
7.4.0-dev.1 431 1/23/2020
7.3.1 1,348 1/21/2020
7.3.1-preview.7 458 1/21/2020
7.3.1-preview.1 467 1/20/2020
7.3.0 1,290 1/19/2020
7.2.6 1,429 1/18/2020
7.2.5 1,376 12/19/2019
7.2.4 1,356 12/19/2019
7.2.3 1,432 12/16/2019
7.2.2 1,347 12/9/2019
7.2.1 1,383 12/4/2019
7.2.0 1,359 11/26/2019
7.2.0-preview.10 457 11/20/2019
7.2.0-preview.9 447 11/19/2019
7.2.0-preview.8 458 11/18/2019
7.2.0-preview.6 466 11/14/2019
7.2.0-preview.5 434 11/14/2019
7.2.0-preview.4 457 11/14/2019
7.2.0-preview.2 444 11/11/2019
7.2.0-preview.1 454 11/9/2019
7.1.0 1,417 11/6/2019
7.1.0-preview.8 443 11/5/2019
7.1.0-preview.7 441 11/4/2019
7.1.0-preview.6 439 11/1/2019
7.1.0-preview.5 477 10/31/2019
7.1.0-preview.4.1 465 10/31/2019
7.1.0-preview.4 473 10/30/2019
7.1.0-preview.3 440 10/26/2019
7.1.0-preview.2 464 10/25/2019
7.1.0-preview.1 448 10/24/2019
7.0.0 1,202 10/16/2019
7.0.0-rc.41 469 10/15/2019
7.0.0-rc.40 465 10/15/2019
7.0.0-rc.39 459 10/12/2019
7.0.0-rc.38 441 10/11/2019
7.0.0-rc.37 451 10/10/2019
7.0.0-rc.36 463 10/9/2019
7.0.0-rc.35 441 10/8/2019
7.0.0-rc.34 466 10/8/2019
7.0.0-rc.33 443 10/7/2019
7.0.0-rc.32 460 10/5/2019
7.0.0-rc.31 450 10/3/2019
7.0.0-rc.30 460 10/1/2019
7.0.0-rc.28 492 10/1/2019
7.0.0-rc.27 452 9/30/2019
7.0.0-rc.26 461 9/30/2019
7.0.0-rc.25 447 9/27/2019
7.0.0-rc.24 452 9/27/2019
7.0.0-rc.23 438 9/26/2019
7.0.0-rc.22 444 9/25/2019
7.0.0-rc.21 451 9/24/2019
7.0.0-rc.20 451 9/23/2019
7.0.0-rc.19 458 9/20/2019
7.0.0-rc.18.1 448 9/20/2019
7.0.0-rc.18 458 9/20/2019
6.5.0-rc.17 475 9/19/2019
6.5.0-rc.16 479 9/18/2019
6.5.0-rc.15 484 9/18/2019
6.5.0-rc.14.1 462 9/18/2019
6.5.0-rc.14 490 9/17/2019
6.5.0-rc.13 479 9/16/2019
6.5.0-rc.12.2 457 9/13/2019
6.5.0-rc.12.1 479 9/12/2019
6.5.0-rc.12 467 9/12/2019
6.5.0-rc.11 453 9/11/2019
6.5.0-rc.10 478 9/10/2019
6.5.0-rc.9 489 9/9/2019
6.5.0-rc.8 445 9/6/2019
6.5.0-rc.7 469 9/6/2019
6.5.0-rc.6 464 9/6/2019
6.5.0-rc.5 449 9/2/2019
6.5.0-rc.4 487 9/2/2019
6.5.0-rc.3 456 8/30/2019
6.5.0-rc.2 473 8/29/2019
6.5.0-rc.1 499 8/28/2019
6.5.0-beta.5 513 8/28/2019
6.5.0-beta.4 471 8/27/2019
6.0.0 1,049 8/6/2019
6.0.0-rc.7 457 7/19/2019
6.0.0-rc.6 457 6/28/2019
6.0.0-rc.5 448 6/28/2019
6.0.0-rc.4 460 6/25/2019
6.0.0-rc.3 464 6/20/2019
6.0.0-rc.2 458 5/29/2019
6.0.0-rc.1 465 5/28/2019
6.0.0-beta.3 482 4/17/2019
5.3.0-beta.2 489 3/21/2019
5.3.0-beta.1 497 3/20/2019
5.2.0 1,026 3/19/2019
5.1.0 1,487 1/25/2019
5.0.0 1,497 12/21/2018
5.0.0-rc11 1,162 12/14/2018
5.0.0-rc10 896 11/16/2018
5.0.0-rc09 909 11/1/2018
5.0.0-rc08 882 10/31/2018
5.0.0-rc07 881 10/31/2018
5.0.0-rc06 913 10/30/2018
5.0.0-rc05 932 10/29/2018
5.0.0-rc04 974 10/29/2018
5.0.0-rc03 928 10/26/2018
5.0.0-rc02 917 10/25/2018
5.0.0-rc01 940 10/12/2018
5.0.0-beta03 989 9/21/2018
5.0.0-beta02 1,023 9/10/2018
5.0.0-beta01 1,000 9/7/2018
4.5.1 1,216 8/7/2018
4.5.0 1,665 8/7/2018
4.5.0-rc01 1,367 6/7/2018
4.5.0-beta09 1,141 6/7/2018
4.5.0-beta08 1,376 5/16/2018
4.5.0-beta07 1,275 5/9/2018
4.5.0-beta06 1,323 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.