# 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 ```json { "kind": "bt", "abi": "bts-bt-1", "entry": "src/lib.bt" } ``` 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: ```text fn declaration class declaration empty statement UPPERCASE_CONSTANT = literal ``` 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 ```bt class Calc { value_num: 0 new(value) { this.value_num = value this } pub add(value) { this.value_num += value this } pub value() { this.value_num } pub close() { true } } fn calc(value) { Calc::new(value) } ``` corresponding rules: | bindings statement | pure 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 parameters | The 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. ```bt value = calc(2).add(8).value() // Output: 10 print value ``` ## 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.