Kephas.Scripting
11.0.0-dev.5
Prefix Reserved
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
<PackageReference Include="Kephas.Scripting" Version="11.0.0-dev.5" />
paket add Kephas.Scripting --version 11.0.0-dev.5
#r "nuget: Kephas.Scripting, 11.0.0-dev.5"
// 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 aStream
.FileScript
: constructed using a file path. If not provided, theLanguage
is considered to be the file extension.
Product | Versions 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. |
-
.NETStandard 2.1
- Kephas.Injection (>= 11.0.0-dev.5)
- Kephas.Logging (>= 11.0.0-dev.5)
-
net6.0
- Kephas.Injection (>= 11.0.0-dev.5)
- Kephas.Logging (>= 11.0.0-dev.5)
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,481 | 4/13/2022 |
11.1.0-dev.4 | 153 | 4/6/2022 |
11.1.0-dev.3 | 136 | 3/30/2022 |
11.1.0-dev.2 | 144 | 3/23/2022 |
11.1.0-dev.1 | 129 | 3/23/2022 |
11.0.0 | 1,262 | 3/11/2022 |
11.0.0-dev.7 | 133 | 3/7/2022 |
11.0.0-dev.6 | 141 | 2/28/2022 |
11.0.0-dev.5 | 136 | 2/26/2022 |
11.0.0-dev.4 | 138 | 2/24/2022 |
11.0.0-dev.3 | 134 | 2/23/2022 |
11.0.0-dev.2 | 131 | 2/18/2022 |
11.0.0-dev.1 | 140 | 2/7/2022 |
10.3.0 | 1,290 | 1/18/2022 |
10.2.0 | 1,284 | 12/3/2021 |
10.1.0 | 5,356 | 11/23/2021 |
10.1.0-dev.7 | 213 | 11/17/2021 |
10.1.0-dev.6 | 178 | 11/16/2021 |
10.1.0-dev.5 | 174 | 11/10/2021 |
10.1.0-dev.4 | 172 | 11/8/2021 |
10.1.0-dev.3 | 149 | 11/8/2021 |
10.1.0-dev.2 | 162 | 11/4/2021 |
10.1.0-dev.1 | 167 | 11/3/2021 |
10.0.1 | 948 | 10/16/2021 |
10.0.0 | 904 | 10/13/2021 |
10.0.0-dev.4 | 158 | 10/13/2021 |
10.0.0-dev.3 | 168 | 10/11/2021 |
10.0.0-dev.2 | 221 | 10/8/2021 |
9.3.4 | 938 | 8/25/2021 |
9.3.3 | 880 | 8/25/2021 |
9.3.2 | 865 | 8/24/2021 |
9.3.1 | 887 | 8/12/2021 |
9.3.0 | 933 | 8/12/2021 |
9.2.0 | 946 | 6/17/2021 |
9.1.0 | 892 | 6/17/2021 |
9.1.0-dev.9 | 201 | 5/26/2021 |
9.1.0-dev.8 | 195 | 5/26/2021 |
9.1.0-dev.7 | 208 | 5/17/2021 |
9.1.0-dev.6 | 186 | 4/28/2021 |
9.1.0-dev.5 | 208 | 4/23/2021 |
9.1.0-dev.4 | 196 | 4/21/2021 |
9.1.0-dev.3 | 195 | 4/17/2021 |
9.1.0-dev.2 | 186 | 4/12/2021 |
9.1.0-dev.1 | 195 | 4/9/2021 |
9.0.5 | 885 | 3/31/2021 |
9.0.4 | 919 | 3/23/2021 |
9.0.3 | 947 | 3/20/2021 |
9.0.1 | 893 | 3/18/2021 |
9.0.0 | 940 | 3/17/2021 |
9.0.0-dev.4 | 188 | 3/4/2021 |
9.0.0-dev.3 | 193 | 3/1/2021 |
9.0.0-dev.2 | 227 | 2/22/2021 |
8.4.0 | 1,038 | 11/11/2020 |
8.3.0 | 1,025 | 10/28/2020 |
8.2.0 | 1,090 | 10/16/2020 |
8.1.0 | 1,122 | 9/23/2020 |
8.0.0 | 1,036 | 7/1/2020 |
8.0.0-dev.44 | 296 | 6/25/2020 |
8.0.0-dev.43 | 285 | 6/23/2020 |
8.0.0-dev.42 | 331 | 6/22/2020 |
8.0.0-dev.41 | 325 | 6/18/2020 |
8.0.0-dev.40 | 273 | 6/18/2020 |
8.0.0-dev.39 | 294 | 6/15/2020 |
8.0.0-dev.38 | 410 | 6/14/2020 |
8.0.0-dev.37 | 265 | 6/13/2020 |
8.0.0-dev.36 | 310 | 6/13/2020 |
8.0.0-dev.35 | 250 | 6/12/2020 |
8.0.0-dev.34 | 305 | 6/12/2020 |
8.0.0-dev.33 | 351 | 6/10/2020 |
8.0.0-dev.32 | 273 | 6/1/2020 |
8.0.0-dev.31 | 296 | 6/1/2020 |
8.0.0-dev.30 | 370 | 5/30/2020 |
8.0.0-dev.28 | 309 | 5/28/2020 |
8.0.0-dev.27 | 291 | 5/15/2020 |
8.0.0-dev.26 | 273 | 5/14/2020 |
8.0.0-dev.25 | 287 | 5/14/2020 |
8.0.0-dev.24 | 283 | 5/13/2020 |
8.0.0-dev.23 | 273 | 5/13/2020 |
8.0.0-dev.22 | 279 | 5/13/2020 |
8.0.0-dev.21 | 284 | 5/12/2020 |
8.0.0-dev.20 | 289 | 5/12/2020 |
8.0.0-dev.19 | 279 | 5/7/2020 |
8.0.0-dev.18 | 277 | 5/7/2020 |
8.0.0-dev.17 | 267 | 5/6/2020 |
8.0.0-dev.16 | 278 | 5/6/2020 |
8.0.0-dev.15 | 277 | 5/5/2020 |
8.0.0-dev.14 | 274 | 5/5/2020 |
8.0.0-dev.13 | 303 | 5/4/2020 |
7.6.0-dev.13 | 299 | 5/1/2020 |
7.6.0-dev.12 | 318 | 4/30/2020 |
7.6.0-dev.11 | 285 | 4/28/2020 |
7.6.0-dev.10 | 274 | 4/27/2020 |
7.6.0-dev.9 | 282 | 4/24/2020 |
7.6.0-dev.8 | 283 | 4/22/2020 |
7.6.0-dev.7 | 272 | 4/15/2020 |
7.6.0-dev.6 | 268 | 4/15/2020 |
7.6.0-dev.5 | 265 | 4/15/2020 |
7.6.0-dev.4 | 394 | 4/11/2020 |
7.6.0-dev.3 | 270 | 4/10/2020 |
7.6.0-dev.2 | 271 | 4/10/2020 |
7.6.0-dev.1 | 348 | 4/8/2020 |
7.5.2 | 1,164 | 3/20/2020 |
7.5.1 | 1,096 | 3/12/2020 |
7.5.0 | 1,147 | 3/10/2020 |
7.5.0-dev.18 | 295 | 3/5/2020 |
7.5.0-dev.17 | 296 | 3/5/2020 |
7.5.0-dev.16 | 323 | 3/4/2020 |
7.5.0-dev.15 | 264 | 3/3/2020 |
7.5.0-dev.14 | 270 | 3/3/2020 |
7.5.0-dev.13 | 257 | 2/29/2020 |
7.5.0-dev.12 | 379 | 2/29/2020 |
7.5.0-dev.10 | 250 | 2/25/2020 |
7.5.0-dev.9 | 306 | 2/20/2020 |
7.5.0-dev.8 | 340 | 2/18/2020 |
7.5.0-dev.7 | 267 | 2/18/2020 |
7.5.0-dev.6 | 280 | 2/14/2020 |
7.5.0-dev.5 | 295 | 2/12/2020 |
7.5.0-dev.4 | 277 | 2/11/2020 |
7.5.0-dev.3 | 254 | 2/11/2020 |
7.5.0-dev.2 | 388 | 2/8/2020 |
7.5.0-dev.1 | 281 | 2/7/2020 |
7.4.2 | 1,078 | 2/5/2020 |
7.4.1 | 1,176 | 2/3/2020 |
7.4.0 | 1,201 | 1/31/2020 |
7.4.0-dev.4 | 331 | 1/31/2020 |
7.4.0-dev.3 | 318 | 1/29/2020 |
7.4.0-dev.2 | 266 | 1/28/2020 |
7.4.0-dev.1 | 272 | 1/23/2020 |
7.3.1 | 1,109 | 1/21/2020 |
7.3.1-preview.7 | 272 | 1/21/2020 |
7.3.1-preview.1 | 304 | 1/20/2020 |
7.3.0 | 1,073 | 1/19/2020 |
7.2.6 | 1,184 | 1/18/2020 |
7.2.5 | 1,116 | 12/19/2019 |
7.2.4 | 1,097 | 12/19/2019 |
7.2.3 | 1,158 | 12/16/2019 |
7.2.2 | 1,113 | 12/9/2019 |
7.2.1 | 1,136 | 12/4/2019 |
7.2.0 | 1,101 | 11/26/2019 |
7.2.0-preview.10 | 275 | 11/20/2019 |
7.2.0-preview.9 | 273 | 11/19/2019 |
7.2.0-preview.8 | 273 | 11/18/2019 |
7.2.0-preview.6 | 277 | 11/14/2019 |
7.2.0-preview.5 | 269 | 11/14/2019 |
7.2.0-preview.4 | 281 | 11/14/2019 |
7.2.0-preview.2 | 286 | 11/11/2019 |
7.2.0-preview.1 | 286 | 11/9/2019 |
7.1.0 | 1,168 | 11/6/2019 |
7.1.0-preview.8 | 283 | 11/5/2019 |
7.1.0-preview.7 | 273 | 11/4/2019 |
7.1.0-preview.6 | 276 | 11/1/2019 |
7.1.0-preview.5 | 309 | 10/31/2019 |
7.1.0-preview.4.1 | 295 | 10/31/2019 |
7.1.0-preview.4 | 302 | 10/30/2019 |
7.1.0-preview.3 | 277 | 10/26/2019 |
7.1.0-preview.2 | 290 | 10/25/2019 |
7.1.0-preview.1 | 282 | 10/24/2019 |
7.0.0 | 987 | 10/16/2019 |
7.0.0-rc.41 | 299 | 10/15/2019 |
7.0.0-rc.40 | 296 | 10/15/2019 |
7.0.0-rc.39 | 288 | 10/12/2019 |
7.0.0-rc.38 | 281 | 10/11/2019 |
7.0.0-rc.37 | 286 | 10/10/2019 |
7.0.0-rc.36 | 285 | 10/9/2019 |
7.0.0-rc.35 | 280 | 10/8/2019 |
7.0.0-rc.34 | 287 | 10/8/2019 |
7.0.0-rc.33 | 279 | 10/7/2019 |
7.0.0-rc.32 | 286 | 10/5/2019 |
7.0.0-rc.31 | 288 | 10/3/2019 |
7.0.0-rc.30 | 280 | 10/1/2019 |
7.0.0-rc.28 | 288 | 10/1/2019 |
7.0.0-rc.27 | 284 | 9/30/2019 |
7.0.0-rc.26 | 292 | 9/30/2019 |
7.0.0-rc.25 | 280 | 9/27/2019 |
7.0.0-rc.24 | 278 | 9/27/2019 |
7.0.0-rc.23 | 273 | 9/26/2019 |
7.0.0-rc.22 | 277 | 9/25/2019 |
7.0.0-rc.21 | 284 | 9/24/2019 |
7.0.0-rc.20 | 281 | 9/23/2019 |
7.0.0-rc.19 | 290 | 9/20/2019 |
7.0.0-rc.18.1 | 280 | 9/20/2019 |
7.0.0-rc.18 | 292 | 9/20/2019 |
6.5.0-rc.17 | 302 | 9/19/2019 |
6.5.0-rc.16 | 304 | 9/18/2019 |
6.5.0-rc.15 | 301 | 9/18/2019 |
6.5.0-rc.14.1 | 300 | 9/18/2019 |
6.5.0-rc.14 | 299 | 9/17/2019 |
6.5.0-rc.13 | 290 | 9/16/2019 |
6.5.0-rc.12.2 | 292 | 9/13/2019 |
6.5.0-rc.12.1 | 298 | 9/12/2019 |
6.5.0-rc.12 | 303 | 9/12/2019 |
6.5.0-rc.11 | 289 | 9/11/2019 |
6.5.0-rc.10 | 287 | 9/10/2019 |
6.5.0-rc.9 | 297 | 9/9/2019 |
6.5.0-rc.8 | 281 | 9/6/2019 |
6.5.0-rc.7 | 304 | 9/6/2019 |
6.5.0-rc.6 | 297 | 9/6/2019 |
6.5.0-rc.5 | 287 | 9/2/2019 |
6.5.0-rc.4 | 305 | 9/2/2019 |
6.5.0-rc.3 | 289 | 8/30/2019 |
6.5.0-rc.2 | 312 | 8/29/2019 |
6.5.0-rc.1 | 310 | 8/28/2019 |
6.5.0-beta.5 | 302 | 8/28/2019 |
6.5.0-beta.4 | 301 | 8/27/2019 |
6.0.0 | 841 | 8/6/2019 |
6.0.0-rc.7 | 301 | 7/19/2019 |
6.0.0-rc.6 | 297 | 6/28/2019 |
6.0.0-rc.5 | 284 | 6/28/2019 |
6.0.0-rc.4 | 292 | 6/25/2019 |
6.0.0-rc.3 | 299 | 6/20/2019 |
6.0.0-rc.2 | 291 | 5/29/2019 |
6.0.0-rc.1 | 301 | 5/28/2019 |
6.0.0-beta.3 | 311 | 4/17/2019 |
5.3.0-beta.2 | 309 | 3/21/2019 |
5.3.0-beta.1 | 309 | 3/20/2019 |
5.2.0 | 809 | 3/19/2019 |
5.1.0 | 1,131 | 1/25/2019 |
5.0.0 | 1,145 | 12/21/2018 |
5.0.0-rc11 | 834 | 12/14/2018 |
5.0.0-rc10 | 666 | 11/16/2018 |
5.0.0-rc09 | 678 | 11/1/2018 |
5.0.0-rc08 | 649 | 10/31/2018 |
5.0.0-rc07 | 656 | 10/31/2018 |
5.0.0-rc06 | 683 | 10/30/2018 |
5.0.0-rc05 | 681 | 10/29/2018 |
5.0.0-rc04 | 720 | 10/29/2018 |
5.0.0-rc03 | 698 | 10/26/2018 |
5.0.0-rc02 | 680 | 10/25/2018 |
5.0.0-rc01 | 708 | 10/12/2018 |
5.0.0-beta03 | 749 | 9/21/2018 |
5.0.0-beta02 | 750 | 9/10/2018 |
5.0.0-beta01 | 740 | 9/7/2018 |
4.5.1 | 869 | 8/7/2018 |
4.5.0 | 1,269 | 8/7/2018 |
4.5.0-rc01 | 865 | 6/7/2018 |
4.5.0-beta09 | 758 | 6/7/2018 |
4.5.0-beta08 | 859 | 5/16/2018 |
4.5.0-beta07 | 774 | 5/9/2018 |
4.5.0-beta06 | 827 | 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.