Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Builtins

The only globals of scripts. Everything else is imported from a namespace, see the namespace pages under Types, i.e. import_namespace("bms").world.

Functions

NameSummary
export_namespaceExports a callback of the calling script as a function in a script namespace, so that any script (in any language) can…
import_namespaceImports a namespace, returning a table of the types, functions, values, events, system sets and exports in it by name.
register_callbackRegisters a function as the handler of a callback, taking precedence over a top level function of that name.

export_namespace

export_namespace(name: String, callback: String, arg3: String)

Exports a callback of the calling script as a function in a script namespace, so that any script (in any language) can call it.

The callback is either a function registered with register_callback, or a top level function with that name. Calls run in the exporting script and return what the callback returns.

register_callback("spawn_enemy_impl", function(health) ... end)
export_namespace("script.game", "spawn_enemy", "spawn_enemy_impl")
-- in another script, once the first one has run
import_namespace("script.game").spawn_enemy(5)

Arguments

  • name: the name of the function within the namespace.
  • callback: the label of the callback of this script to export.

Returns: Nothing if the function was exported.

import_namespace

import_namespace(arg1: String) -> ScriptValue

Imports a namespace, returning a table of the types, functions, values, events, system sets and exports in it by name.

Bevy types with bindings live in a namespace per category (math, ecs, transform, ui, …), BMS’ own types and functions in bms, any other type in the namespace named after the crate defining it. Namespaces defined by scripts start with script..

local bms = import_namespace("bms")
local Vec3 = import_namespace("math").Vec3
bms.world.spawn()

Fails with a list of similar namespaces if the namespace does not exist.

Returns: a table of the contents of the namespace keyed by name.

register_callback

register_callback(callback: String, function: DynamicFunction)

Registers a function as the handler of a callback, taking precedence over a top level function of that name.

register_callback("on_script_unloaded", function() print("unloading!") end)

Arguments

  • callback: the callback label to register the function against.
  • function: the function handling the callback.