Extension Quick Start
Extension Quick Start
Function
This page starts with a calc compute extension example, demonstrating how to create the extension development directory, build the .bts package, install it into the project and call it in main.bt. Users with no basic knowledge are recommended to run through the process according to this page first, and then read Operating Mechanism .
Syntax
quick start will use these commands:
bt ext new calc bt ext build calc -o calc.bts bt ext check calc.bts bt ext info calc.bts bt ext install calc.bts project bt main.bt
Parameters
| Parameter | Description |
|---|---|
calc | Extended development directory name, will also be used as the default extension. |
calc.bts | Build output expansion pack file. |
project | The target BT project directory to install the extension. |
main.bt | Project entry script. |
Prepare the project
First prepare a common BT project directory:
project/ └── main.bt
main.bt to call the extension:
result = calc(1).add(2).value() // Output: 3 print result
The calc extension has not been installed at this time. If you run it directly, you will not find calc. The next step is to create the extension.
Create an extension
and execute:
bt ext new calc
This will generate a pure BT extension development directory:
calc/ ├── manifest.json ├── bindings.json └── src/ └── lib.bt
The default scaffolding already contains a chained calculation object: calc(1).add(2).value().
Build the extension package
and execute it outside the calc directory: When building,
bt ext build calc -o calc.bts
will read manifest.json and bindings.json, check the entry source code, and package the development directory into calc.bts. After
is built, you can check the package information first:
bt ext check calc.bts bt ext info calc.bts
Install into the project
Install the extension into the project directory:
bt ext install calc.bts project
The structure after installation is:
project/ ├── main.bt └── extensions/ └── calc.bts
Then run the project in the project directory:
bt main.bt
The output should be:
3
Return Value
bt ext When the command is successful, the creation, build, check or installation results will be output in the terminal; when it fails, a Chinese error will be output. calc(1).add(2).value() in the example script returns the integer 3.
Code Examples
extension object can continue to be called in the chain:
num = calc(10) value = num.add(5).add(2).value() closed = num.close() // Output: [17,true] print [value, closed]
Notes
-
bt ext new calcwill generate an extension name based on the directory name. The directory name must use lowercase letters, numbers and underscores, and start with a lowercase letter. -
bt ext install calc.bts projectwill copy the package toproject/extensions/calc.bts; extensions with the same name will be overwritten. - The
.btspackage underextensions/will be loaded only when the project is started. The development directorycalc/will not be automatically loaded by the project. - If the BT build used for running does not enable the
extensionsfeature, projects that exist in theextensions/directory will report an error indicating that the extension capability is not available.