include_once
include_once
Function
The BT file is introduced and executed at runtime, but the same real file is only executed once within the current execution context.
Syntax
include_once(path) include_once path
Parameters
| Parameters | Type | Required | Default value | Description |
|---|---|---|---|---|
| path | String | Yes | None | The path of the BT file to be imported. |
Return value
| Type | Description |
|---|---|
| Any/Empty | Returns the return value of the imported file when executed for the first time; returns Empty when the same real file is imported repeatedly. |
Example
fs('once-demo.bt').write('counter++') counter = 0 include_once 'once-demo.bt' include_once './once-demo.bt' // Output: 1 echo(counter)
Notes
- Repeated judgment uses the normalized real file path instead of the original string path.
- The once state belongs only to the current execution context; the state is re-created with every request to the Web and every call to the desktop
bt.call(). - include_once shares the file compilation cache, but does not cache variable scopes, return values, or execution status.
- Bracketless syntax only supports statement form; please use
include_once(path)when you need to assign the return value to a variable.