# BSL- :
OneScript BSL- (), , . , - .
. [`docs/developer_docs.md`](developer_docs.md) .
##
1. [ BSL-](#1---bsl-)
2. [ BSL- ()](#2---bsl--)
3. [ ](#3--)
4. [ ](#4--)
5. [ ](#5------)
6. [ package-loader.os](#6----package-loaderos)
7. [i18n API ( )](#7-i18n--api--)
8. [ ](#8---)
9. [ (C# BSL)](#9--c--bsl)
10. [ (OneScriptDocumenter)](#10--onescriptdocumenter)
11. [](#11-)
12. [- ](#12---)
## 1. BSL-
- .NET-, BSL. `` (-) ( ).
- :
- `[ContextClass("", "EngName")]` -;
- `[ContextMethod("", "EngName")]` (/);
- `[ContextProperty("", "EngName", CanRead = true, CanWrite = false, ...)]` ;
- `[GlobalContext(...)]` ;
- `[ScriptConstructor]` ``.
- : API /Eng.
:
- : `src/OneScript.Core/Contexts/*`.
- : `src/ScriptEngine/Machine/Contexts/*`.
- : `GlobalContextBase` `src/ScriptEngine/Machine/Contexts/GlobalContextBase.cs`.
## 2. BSL- ()
###
```csharp
using OneScript.Contexts; // ContextClass, ContextMethod, ContextProperty, ScriptConstructor
using OneScript.Execution; // IBslProcess
using OneScript.Types; // TypeActivationContext
using ScriptEngine.Machine; // IValue, ValueFactory
using ScriptEngine.Machine.Contexts; // AutoContext
[ContextClass("", "SampleClass")]
public class SampleClass : AutoContext
{
// BSL: ()
[ScriptConstructor(Name = " ")]
public static SampleClass Ctor(TypeActivationContext ctx)
=> new SampleClass();
//
[ContextProperty("", "Version", CanWrite = false)]
public IValue Version => ValueFactory.Create("1.0");
// bsl- ( BSL- C#)
[ContextMethod("", "Message")]
public void Message(IBslProcess process, IValue text)
{
// bsl- ,
process.Run(/*...*/);
}
//
[ContextMethod("", "Add")]
public IValue Add(IValue a, IValue b)
{
var sum = a.AsNumber() + b.AsNumber();
return ValueFactory.Create(sum);
}
}
```
###
- `AutoContext` -.
- `[ScriptConstructor]` , `TypeActivationContext`. .
- `IBslProcess` , / .
- :
- **** (`void`).
- **** `IValue` C# (. `ContextValuesMarshaller`).
###
`ContextDiscoverer` (`src/ScriptEngine/Machine/Contexts/ContextDiscoverer.cs`) , `ContextClass`, `GlobalContext` `EnumerationType`. .
## 3.
```csharp
[ContextProperty("", "Threshold", CanRead = true, CanWrite = true)]
public IValue Threshold
{
get => ValueFactory.Create(_threshold);
set => _threshold = value.AsNumber();
}
private decimal _threshold = 0m;
```
:
- `CanRead`/`CanWrite` BSL. , `get`/`set` .
- `ContextValuesMarshaller`.
- , , `IValue` , .
## 4.
```csharp
// ,
[ContextMethod("", "DoubleNumber")]
public int DoubleNumber(int number)
{
return number * 2;
}
```
C# BSL.
:
- ** ** `IVariable` . `.Value`.
- ** ** C# , , `IValue`.
- ** ** C# (`int count = 0`, `string mode = null`). BSL.
- **** : `ContextMethod`-, .
## 5.
###
```csharp
using OneScript.Contexts; // GlobalContext, ContextMethod, IAttachableContext
using ScriptEngine.Machine; // IValue, ValueFactory
using ScriptEngine.Machine.Contexts; // GlobalContextBase
[GlobalContext(Category = " ")]
public class MyGlobals : GlobalContextBase
{
//
public static IAttachableContext CreateInstance() => new MyGlobals();
[ContextMethod("", "MyFunc")]
public IValue MyFunc(IValue x)
{
return ValueFactory.Create(x.ToString().Length);
}
}
```
:
- (`ManualRegistration = false`). , .
- `HostedScriptEngine.InjectObject` `IRuntimeEnvironment.InjectObject`.
###
- , `StandardGlobalContext` (`src/OneScript.StandardLibrary/StandardGlobalContext.cs`): `[ContextMethod]` .
- : API .
## 6. package-loader.os
- `HostedScript` `package-loader.os` ( ).
- (. `src/ScriptEngine.HostedScript/LibraryLoader.cs`):
- ``/`AddClass("path", "")` BSL-;
- ``/`AddModule("path", "")` ;
- ``/`AddTemplate` .
- `FileSystemDependencyResolver.cs` .
## 7. i18n API ( )
- API (, , , , ) :
```csharp
[ContextClass("", "EnglishName")]
[ContextMethod("", "Perform")]
[ContextProperty("", "Size")]
```
- API: `OneScript.StandardLibrary` (. [](#10--onescriptdocumenter)).
- ( , , 1).
- (`GlobalContext(Category = "...")`) .
## 8.
, , `DeprecatedNameAttribute` (`src/OneScript.Core/Contexts/DeprecatedNameAttribute.cs`):
```csharp
[ContextMethod("", "NewFunc")]
[DeprecatedName("")]
[DeprecatedName("OldFunc")]
public IValue NewFunc() { /* ... */ }
```
- `name` . BSL , .
- `throwOnUse: true` . , .
- (`[DeprecatedName("OldName")]` `[ContextMethod]`), /.
- , , `ISupportsDeprecation` (`src/OneScript.Core/Contexts/ISupportsDeprecation.cs`) `IsDeprecated = true`. .
.
## 9. (C# BSL)
.
### (xUnit/NUnit)
- `src/Tests/*` (xUnit/NUnit).
- `OneScript.StandardLibrary` `src/Tests/OneScript.StandardLibrary.Tests`. `DeprecatedName` (`ObsoleteEnumTest.cs`).
- , , `src/Tests/OneScript.Dynamic.Tests` (`CompilerTestBase`, `CompileHelper`).
- : `dotnet test` :
```bat
dotnet msbuild Build.csproj /t:UnitTests
```
### BSL
- `tests/*.os` xUnitFor1C.
- `tests/.os` . :
```bsl
;
()
= ;
= ;
.("_");
;
_()
= ();
.("1.0", .);
```
- `oscript` (. [`README.md`](../README.md), ):
```bat
rem Windows
dotnet build src/oscript/oscript.csproj
tests\run-bsl-tests.cmd src\oscript\bin\Debug\net8.0\oscript.exe
```
```bash
# Linux/macOS
dotnet build src/oscript/oscript.csproj
tests/run-bsl-tests.sh src/oscript/bin/Debug/net8.0/oscript
```
- : ` tests/testrunner.os -run tests/.os`.
## 10. (OneScriptDocumenter)
- `OneScriptDocumenter` (. `src/OneScriptDocumenter`) XML- `default_toc.json`.
- :
- XML- ( `oscommon.targets`);
- // XML- ``, ``, ``, `` ;
- `src/OneScriptDocumenter/default_toc.json`, .
- : `dotnet msbuild Build.csproj /t:BuildDocumentation`. `built/docs/` (markdown + json).
## 11.
- , . BSL, , (`IBslProcess.Run`/`Eval`), , .
- URL, . .
- (, , `Authorization`) .
- : JSON/XML `OneScript.StandardLibrary` .
- API, XML-, ( , , ).
- API, .
## 12. -
Pull Request , :
- [ ] API .
- [ ] // XML- (``, ``, ``).
- [ ] C#, -.
- [ ] `DeprecatedName` .
- [ ] C# / BSL.
- [ ] (`dotnet msbuild Build.csproj /t:Test`).
- [ ] [`CODESTYLE.md`](../CODESTYLE.md).
- [ ] , (`/t:BuildDocumentation`), .
- [ ] PR /issue.