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
<PackageReference Include="Kephas.Scripting" Version="11.1.0" />
paket add Kephas.Scripting --version 11.1.0
#r "nuget: Kephas.Scripting, 11.1.0"
// Install Kephas.Scripting as a Cake Addin #addin nuget:?package=Kephas.Scripting&version=11.1.0 // Install Kephas.Scripting as a Cake Tool #tool nuget:?package=Kephas.Scripting&version=11.1.0
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.1.0)
- Kephas.Logging (>= 11.1.0)
-
net6.0
- Kephas.Injection (>= 11.1.0)
- Kephas.Logging (>= 11.1.0)
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,493 | 4/13/2022 |
11.1.0-dev.4 | 156 | 4/6/2022 |
11.1.0-dev.3 | 139 | 3/30/2022 |
11.1.0-dev.2 | 147 | 3/23/2022 |
11.1.0-dev.1 | 132 | 3/23/2022 |
11.0.0 | 1,270 | 3/11/2022 |
11.0.0-dev.7 | 136 | 3/7/2022 |
11.0.0-dev.6 | 144 | 2/28/2022 |
11.0.0-dev.5 | 139 | 2/26/2022 |
11.0.0-dev.4 | 141 | 2/24/2022 |
11.0.0-dev.3 | 137 | 2/23/2022 |
11.0.0-dev.2 | 136 | 2/18/2022 |
11.0.0-dev.1 | 143 | 2/7/2022 |
10.3.0 | 1,298 | 1/18/2022 |
10.2.0 | 1,292 | 12/3/2021 |
10.1.0 | 5,364 | 11/23/2021 |
10.1.0-dev.7 | 216 | 11/17/2021 |
10.1.0-dev.6 | 181 | 11/16/2021 |
10.1.0-dev.5 | 177 | 11/10/2021 |
10.1.0-dev.4 | 175 | 11/8/2021 |
10.1.0-dev.3 | 152 | 11/8/2021 |
10.1.0-dev.2 | 165 | 11/4/2021 |
10.1.0-dev.1 | 170 | 11/3/2021 |
10.0.1 | 956 | 10/16/2021 |
10.0.0 | 912 | 10/13/2021 |
10.0.0-dev.4 | 161 | 10/13/2021 |
10.0.0-dev.3 | 171 | 10/11/2021 |
10.0.0-dev.2 | 224 | 10/8/2021 |
9.3.4 | 946 | 8/25/2021 |
9.3.3 | 888 | 8/25/2021 |
9.3.2 | 873 | 8/24/2021 |
9.3.1 | 894 | 8/12/2021 |
9.3.0 | 940 | 8/12/2021 |
9.2.0 | 952 | 6/17/2021 |
9.1.0 | 901 | 6/17/2021 |
9.1.0-dev.9 | 204 | 5/26/2021 |
9.1.0-dev.8 | 198 | 5/26/2021 |
9.1.0-dev.7 | 211 | 5/17/2021 |
9.1.0-dev.6 | 189 | 4/28/2021 |
9.1.0-dev.5 | 211 | 4/23/2021 |
9.1.0-dev.4 | 199 | 4/21/2021 |
9.1.0-dev.3 | 198 | 4/17/2021 |
9.1.0-dev.2 | 189 | 4/12/2021 |
9.1.0-dev.1 | 198 | 4/9/2021 |
9.0.5 | 892 | 3/31/2021 |
9.0.4 | 926 | 3/23/2021 |
9.0.3 | 954 | 3/20/2021 |
9.0.1 | 900 | 3/18/2021 |
9.0.0 | 947 | 3/17/2021 |
9.0.0-dev.4 | 193 | 3/4/2021 |
9.0.0-dev.3 | 196 | 3/1/2021 |
9.0.0-dev.2 | 230 | 2/22/2021 |
8.4.0 | 1,045 | 11/11/2020 |
8.3.0 | 1,032 | 10/28/2020 |
8.2.0 | 1,097 | 10/16/2020 |
8.1.0 | 1,129 | 9/23/2020 |
8.0.0 | 1,043 | 7/1/2020 |
8.0.0-dev.44 | 299 | 6/25/2020 |
8.0.0-dev.43 | 288 | 6/23/2020 |
8.0.0-dev.42 | 337 | 6/22/2020 |
8.0.0-dev.41 | 328 | 6/18/2020 |
8.0.0-dev.40 | 276 | 6/18/2020 |
8.0.0-dev.39 | 297 | 6/15/2020 |
8.0.0-dev.38 | 413 | 6/14/2020 |
8.0.0-dev.37 | 268 | 6/13/2020 |
8.0.0-dev.36 | 315 | 6/13/2020 |
8.0.0-dev.35 | 253 | 6/12/2020 |
8.0.0-dev.34 | 310 | 6/12/2020 |
8.0.0-dev.33 | 358 | 6/10/2020 |
8.0.0-dev.32 | 276 | 6/1/2020 |
8.0.0-dev.31 | 299 | 6/1/2020 |
8.0.0-dev.30 | 373 | 5/30/2020 |
8.0.0-dev.28 | 312 | 5/28/2020 |
8.0.0-dev.27 | 296 | 5/15/2020 |
8.0.0-dev.26 | 280 | 5/14/2020 |
8.0.0-dev.25 | 290 | 5/14/2020 |
8.0.0-dev.24 | 286 | 5/13/2020 |
8.0.0-dev.23 | 276 | 5/13/2020 |
8.0.0-dev.22 | 282 | 5/13/2020 |
8.0.0-dev.21 | 287 | 5/12/2020 |
8.0.0-dev.20 | 294 | 5/12/2020 |
8.0.0-dev.19 | 282 | 5/7/2020 |
8.0.0-dev.18 | 282 | 5/7/2020 |
8.0.0-dev.17 | 270 | 5/6/2020 |
8.0.0-dev.16 | 281 | 5/6/2020 |
8.0.0-dev.15 | 280 | 5/5/2020 |
8.0.0-dev.14 | 279 | 5/5/2020 |
8.0.0-dev.13 | 306 | 5/4/2020 |
7.6.0-dev.13 | 304 | 5/1/2020 |
7.6.0-dev.12 | 321 | 4/30/2020 |
7.6.0-dev.11 | 288 | 4/28/2020 |
7.6.0-dev.10 | 277 | 4/27/2020 |
7.6.0-dev.9 | 287 | 4/24/2020 |
7.6.0-dev.8 | 286 | 4/22/2020 |
7.6.0-dev.7 | 275 | 4/15/2020 |
7.6.0-dev.6 | 271 | 4/15/2020 |
7.6.0-dev.5 | 268 | 4/15/2020 |
7.6.0-dev.4 | 397 | 4/11/2020 |
7.6.0-dev.3 | 273 | 4/10/2020 |
7.6.0-dev.2 | 274 | 4/10/2020 |
7.6.0-dev.1 | 351 | 4/8/2020 |
7.5.2 | 1,171 | 3/20/2020 |
7.5.1 | 1,103 | 3/12/2020 |
7.5.0 | 1,154 | 3/10/2020 |
7.5.0-dev.18 | 298 | 3/5/2020 |
7.5.0-dev.17 | 299 | 3/5/2020 |
7.5.0-dev.16 | 328 | 3/4/2020 |
7.5.0-dev.15 | 267 | 3/3/2020 |
7.5.0-dev.14 | 273 | 3/3/2020 |
7.5.0-dev.13 | 260 | 2/29/2020 |
7.5.0-dev.12 | 382 | 2/29/2020 |
7.5.0-dev.10 | 255 | 2/25/2020 |
7.5.0-dev.9 | 311 | 2/20/2020 |
7.5.0-dev.8 | 343 | 2/18/2020 |
7.5.0-dev.7 | 270 | 2/18/2020 |
7.5.0-dev.6 | 285 | 2/14/2020 |
7.5.0-dev.5 | 300 | 2/12/2020 |
7.5.0-dev.4 | 280 | 2/11/2020 |
7.5.0-dev.3 | 257 | 2/11/2020 |
7.5.0-dev.2 | 391 | 2/8/2020 |
7.5.0-dev.1 | 284 | 2/7/2020 |
7.4.2 | 1,085 | 2/5/2020 |
7.4.1 | 1,185 | 2/3/2020 |
7.4.0 | 1,208 | 1/31/2020 |
7.4.0-dev.4 | 334 | 1/31/2020 |
7.4.0-dev.3 | 321 | 1/29/2020 |
7.4.0-dev.2 | 269 | 1/28/2020 |
7.4.0-dev.1 | 275 | 1/23/2020 |
7.3.1 | 1,116 | 1/21/2020 |
7.3.1-preview.7 | 275 | 1/21/2020 |
7.3.1-preview.1 | 309 | 1/20/2020 |
7.3.0 | 1,080 | 1/19/2020 |
7.2.6 | 1,191 | 1/18/2020 |
7.2.5 | 1,123 | 12/19/2019 |
7.2.4 | 1,104 | 12/19/2019 |
7.2.3 | 1,165 | 12/16/2019 |
7.2.2 | 1,120 | 12/9/2019 |
7.2.1 | 1,143 | 12/4/2019 |
7.2.0 | 1,108 | 11/26/2019 |
7.2.0-preview.10 | 280 | 11/20/2019 |
7.2.0-preview.9 | 276 | 11/19/2019 |
7.2.0-preview.8 | 278 | 11/18/2019 |
7.2.0-preview.6 | 283 | 11/14/2019 |
7.2.0-preview.5 | 274 | 11/14/2019 |
7.2.0-preview.4 | 284 | 11/14/2019 |
7.2.0-preview.2 | 289 | 11/11/2019 |
7.2.0-preview.1 | 289 | 11/9/2019 |
7.1.0 | 1,175 | 11/6/2019 |
7.1.0-preview.8 | 286 | 11/5/2019 |
7.1.0-preview.7 | 276 | 11/4/2019 |
7.1.0-preview.6 | 279 | 11/1/2019 |
7.1.0-preview.5 | 314 | 10/31/2019 |
7.1.0-preview.4.1 | 298 | 10/31/2019 |
7.1.0-preview.4 | 307 | 10/30/2019 |
7.1.0-preview.3 | 280 | 10/26/2019 |
7.1.0-preview.2 | 293 | 10/25/2019 |
7.1.0-preview.1 | 289 | 10/24/2019 |
7.0.0 | 996 | 10/16/2019 |
7.0.0-rc.41 | 302 | 10/15/2019 |
7.0.0-rc.40 | 299 | 10/15/2019 |
7.0.0-rc.39 | 291 | 10/12/2019 |
7.0.0-rc.38 | 284 | 10/11/2019 |
7.0.0-rc.37 | 291 | 10/10/2019 |
7.0.0-rc.36 | 288 | 10/9/2019 |
7.0.0-rc.35 | 283 | 10/8/2019 |
7.0.0-rc.34 | 292 | 10/8/2019 |
7.0.0-rc.33 | 282 | 10/7/2019 |
7.0.0-rc.32 | 293 | 10/5/2019 |
7.0.0-rc.31 | 293 | 10/3/2019 |
7.0.0-rc.30 | 283 | 10/1/2019 |
7.0.0-rc.28 | 291 | 10/1/2019 |
7.0.0-rc.27 | 287 | 9/30/2019 |
7.0.0-rc.26 | 295 | 9/30/2019 |
7.0.0-rc.25 | 283 | 9/27/2019 |
7.0.0-rc.24 | 281 | 9/27/2019 |
7.0.0-rc.23 | 278 | 9/26/2019 |
7.0.0-rc.22 | 280 | 9/25/2019 |
7.0.0-rc.21 | 287 | 9/24/2019 |
7.0.0-rc.20 | 284 | 9/23/2019 |
7.0.0-rc.19 | 295 | 9/20/2019 |
7.0.0-rc.18.1 | 283 | 9/20/2019 |
7.0.0-rc.18 | 295 | 9/20/2019 |
6.5.0-rc.17 | 305 | 9/19/2019 |
6.5.0-rc.16 | 313 | 9/18/2019 |
6.5.0-rc.15 | 304 | 9/18/2019 |
6.5.0-rc.14.1 | 305 | 9/18/2019 |
6.5.0-rc.14 | 303 | 9/17/2019 |
6.5.0-rc.13 | 299 | 9/16/2019 |
6.5.0-rc.12.2 | 295 | 9/13/2019 |
6.5.0-rc.12.1 | 301 | 9/12/2019 |
6.5.0-rc.12 | 306 | 9/12/2019 |
6.5.0-rc.11 | 292 | 9/11/2019 |
6.5.0-rc.10 | 290 | 9/10/2019 |
6.5.0-rc.9 | 300 | 9/9/2019 |
6.5.0-rc.8 | 284 | 9/6/2019 |
6.5.0-rc.7 | 307 | 9/6/2019 |
6.5.0-rc.6 | 299 | 9/6/2019 |
6.5.0-rc.5 | 290 | 9/2/2019 |
6.5.0-rc.4 | 308 | 9/2/2019 |
6.5.0-rc.3 | 291 | 8/30/2019 |
6.5.0-rc.2 | 315 | 8/29/2019 |
6.5.0-rc.1 | 313 | 8/28/2019 |
6.5.0-beta.5 | 305 | 8/28/2019 |
6.5.0-beta.4 | 304 | 8/27/2019 |
6.0.0 | 848 | 8/6/2019 |
6.0.0-rc.7 | 303 | 7/19/2019 |
6.0.0-rc.6 | 299 | 6/28/2019 |
6.0.0-rc.5 | 287 | 6/28/2019 |
6.0.0-rc.4 | 294 | 6/25/2019 |
6.0.0-rc.3 | 304 | 6/20/2019 |
6.0.0-rc.2 | 294 | 5/29/2019 |
6.0.0-rc.1 | 304 | 5/28/2019 |
6.0.0-beta.3 | 315 | 4/17/2019 |
5.3.0-beta.2 | 313 | 3/21/2019 |
5.3.0-beta.1 | 312 | 3/20/2019 |
5.2.0 | 816 | 3/19/2019 |
5.1.0 | 1,140 | 1/25/2019 |
5.0.0 | 1,154 | 12/21/2018 |
5.0.0-rc11 | 838 | 12/14/2018 |
5.0.0-rc10 | 678 | 11/16/2018 |
5.0.0-rc09 | 686 | 11/1/2018 |
5.0.0-rc08 | 657 | 10/31/2018 |
5.0.0-rc07 | 664 | 10/31/2018 |
5.0.0-rc06 | 693 | 10/30/2018 |
5.0.0-rc05 | 689 | 10/29/2018 |
5.0.0-rc04 | 730 | 10/29/2018 |
5.0.0-rc03 | 707 | 10/26/2018 |
5.0.0-rc02 | 688 | 10/25/2018 |
5.0.0-rc01 | 718 | 10/12/2018 |
5.0.0-beta03 | 759 | 9/21/2018 |
5.0.0-beta02 | 758 | 9/10/2018 |
5.0.0-beta01 | 751 | 9/7/2018 |
4.5.1 | 879 | 8/7/2018 |
4.5.0 | 1,281 | 8/7/2018 |
4.5.0-rc01 | 869 | 6/7/2018 |
4.5.0-beta09 | 762 | 6/7/2018 |
4.5.0-beta08 | 863 | 5/16/2018 |
4.5.0-beta07 | 778 | 5/9/2018 |
4.5.0-beta06 | 831 | 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.