Skip to content

The GDT

The Global Descriptor Table is the only way out of a mod's linear memory. It doesn't bind the large and changing sm.* API function by function. It's a small reflective bridge over Lua values instead: the host holds every value, and WASM works with integer handles.

SDKs call it through named imports from the atl module, such as (import "atl" "val_global"). Any language that can declare those imports can write a mod.

Group Imports
logging log warn error abort
environment is_server mod_id
values val_number val_string val_bool val_table val_to_number val_to_string val_to_bool val_type val_dup val_free val_equals val_base64_encode val_base64_decode val_cobs_encode val_cobs_decode
lookup val_global val_get val_set val_get_field val_set_field val_get_number val_set_number val_get_index val_set_index val_len val_next
calls call_begin arg_nil arg_number arg_string arg_bool arg_value call call_method result result_number last_error
callbacks val_callback

Anything reachable from Lua is reachable this way:

  • every sm.* function, looked up by path: val_global("sm.vec3.new")
  • methods on userdata, such as self.network:sendToServer
  • globals of Lua mods
  • other WASM mods, through sm.allthelanguages.getMod(id):call(...)

val_callback("export") goes the other way: it makes a Lua function that calls back into one of the mod's exports.

A handle refers to a Lua value the host keeps alive. Handles are owned, so each one must be freed with val_free (atl_free in C) when it's no longer needed. Handle 0 is nil. The C++ and Rust SDKs manage this for you through atl::Value and Value.

The C signatures for every import are in the atl.h reference.

Every GDT call is a round trip from the WASM engine to the host. Code that runs every tick should keep the number of calls down, for example by doing math on Vec3 in WASM, which the C++ and Rust SDKs already do.