Pure BT extension

Pure BT extension

Pure BT extension

Function

Pure BT extension uses BT source code as the back-end entry, which is suitable for encapsulating common script logic, business rules and the ability to require no external compilation tools. Its manifest.kind is bt and its manifest.abi is bts-bt-1.

Syntax

The entry point of a pure BT extension is usually src/lib.bt: When

is loaded, the host will parse and compile the entry source code, but will not execute ordinary top-level logic. Entry top level only allows:

Do not write include, ordinary assignments, loops, I/O calls, return or throw at the top level of pure BT extension entries.

Parameters

The number of parameters of the entry function and public method must be consistent with bindings.json. Parameter names are used by the source code itself, and parameter types are declared by bindings and checked at call boundary by the runtime.

Source code example

corresponding rules:

bindings statementpure BT source code requirements
functions[].name = "calc"The entry source code must have the same name fn calc(...).
objects[].name = "Calc"The entry source code must have the same name class Calc.
methods[].name = "add"Calc must have the same name as pub add(...).
Number of parametersThe number of source code parameters must be consistent with bindings.

Return Value

When the pure BT extension returns the original type, the runtime will check whether the actual return value is consistent with the bindings declaration. When returning an object type, a plain object or class instance must be returned.

Notes

  • If the class method is to be exposed to scripts, pub must be used.
- Methods that return chained objects usually return this.

- When the return type is written as an object type name, the object type must be declared in bindings.objects.

- Pure BT extensions are suitable for lightweight business logic; WASM extensions should be used when Rust ecology, WASI or more independent state management is required.