System function

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

APIDescription
envsRead system environment objects, or read system functions, standard library constructors, and system constants by name.
envRead the user global environment object, or read the user global variable by name.
has_envsDetermine whether the specified name exists in the system environment.
has_envDetermine whether the specified variable exists in the user's global environment.
pauseOutput an optional prompt to the console and wait for the user to press Enter.
assertAssert that the condition is true and throw a runtime error when it fails.
echoConvert all parameters into strings, connect them with spaces and output them to the console.
boolConvert the value to a Boolean value according to BT truth rules.
evalCompile and execute a string script, returning the value of the script's explicit return or exit.
exitSet the exit value and end the current script execution.
includeIntroduce and execute the BT file during runtime, and return the value of the explicit return or exit of the imported file.
include_onceBT files are introduced and executed during runtime. The same real file in the same execution context is only executed once.
cur_dirReturn to the directory where the current source code file is located.
cur_fileReturn the current source code file path.
cur_rootReturns the current VM project root directory.
typeThe script-visible type name of the return value.
callDynamically call a function by function name or function value.
taskCreate a lightweight background task and read the status and results through await, done, result, on_done.
task_allWait for a set of Tasks to be completed and return an array of successful results in the order of input.
task_raceWait for the first completed task in a set of Tasks and return its result.
set_timeoutRegister a one-time delay callback and return the Timer object immediately.
set_intervalRegister a fixed-delay repeating callback and return a Timer object immediately.
Timer.cancelCancel a timeout or subsequent interval that has not yet been triggered.
numberConvert the value to a number.
stringConvert the value to a string.
floatConvert a value to a floating point number.
intConvert the value to an integer.
arrayConvert a value to an array.
objectConvert a value to an object.
jsonSerializes a value into a standard JSON string.
regexCompiles a regular expression and returns a Regex object.
is_emptyDetermine whether the value is empty.
is_nullDetermine whether the value is Null.
sleepLet the current thread sleep for the specified number of milliseconds.
randGenerate pseudo-random numbers.

Examples

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 .
  • echo is a system function that supports echo(value) and single-argument parentheses-free syntax.