System function
System function
Function
system function is the global basic capability of BT runtime, covering environment introspection, dynamic calling, type conversion, JSON serialization, regularization, path, sleep, random number and standard library construction entry.
API list
| API | Description |
|---|---|
| envs | Read system environment objects, or read system functions, standard library constructors, and system constants by name. |
| env | Read the user global environment object, or read the user global variable by name. |
| has_envs | Determine whether the specified name exists in the system environment. |
| has_env | Determine whether the specified variable exists in the user's global environment. |
| pause | Output an optional prompt to the console and wait for the user to press Enter. |
| assert | Assert that the condition is true and throw a runtime error when it fails. |
| echo | Convert all parameters into strings, connect them with spaces and output them to the console. |
| bool | Convert the value to a Boolean value according to BT truth rules. |
| eval | Compile and execute a string script, returning the value of the script's explicit return or exit. |
| exit | Set the exit value and end the current script execution. |
| include | Introduce and execute the BT file during runtime, and return the value of the explicit return or exit of the imported file. |
| include_once | BT files are introduced and executed during runtime. The same real file in the same execution context is only executed once. |
| cur_dir | Return to the directory where the current source code file is located. |
| cur_file | Return the current source code file path. |
| cur_root | Returns the current VM project root directory. |
| type | The script-visible type name of the return value. |
| call | Dynamically call a function by function name or function value. |
| task | Create a lightweight background task and read the status and results through await, done, result, on_done. |
| task_all | Wait for a set of Tasks to be completed and return an array of successful results in the order of input. |
| task_race | Wait for the first completed task in a set of Tasks and return its result. |
| set_timeout | Register a one-time delay callback and return the Timer object immediately. |
| set_interval | Register a fixed-delay repeating callback and return a Timer object immediately. |
| Timer.cancel | Cancel a timeout or subsequent interval that has not yet been triggered. |
| number | Convert the value to a number. |
| string | Convert the value to a string. |
| float | Convert a value to a floating point number. |
| int | Convert the value to an integer. |
| array | Convert a value to an array. |
| object | Convert a value to an object. |
| json | Serializes a value into a standard JSON string. |
| regex | Compiles a regular expression and returns a Regex object. |
| is_empty | Determine whether the value is empty. |
| is_null | Determine whether the value is Null. |
| sleep | Let the current thread sleep for the specified number of milliseconds. |
| rand | Generate pseudo-random numbers. |
Examples
result = type(json({name: 'BT'})) // Output: String print result
Notes
- System functions are stateless; object standard library entries such as fs, html, crypto, url, path, bytes, mysql, modbus, reqwest are created by the library construction branch of the VM.
print and println are language output statements and are not system functions dynamically callable through call(); their usage is described in Output .
-
echois a system function that supportsecho(value)and single-argument parentheses-free syntax.