Skip to content

atl::sys

Raw bindings to the loader's GDT imports (the "atl" import module), as in the C SDK's atl.h.

pub fn log(ptr: *const u8, len: i32)

Writes len bytes at ptr to the game log as info / warning / error.

pub fn warn(ptr: *const u8, len: i32)
pub fn error(ptr: *const u8, len: i32)
pub fn abort(ptr: *const u8, len: i32)

Raises a Lua error with the message, trapping (disabling) the mod.

pub fn is_server() -> i32

1 when running on the server side, 0 on a client.

pub fn mod_id(out: *mut u8, cap: i32) -> i32

Copies this mod's id into out (up to cap bytes) and returns its full length.

pub fn val_type(v: Handle) -> i32

The Type of a value.

pub fn val_number(x: f64) -> Handle

Creates a new Lua number.

pub fn val_string(ptr: *const u8, len: i32) -> Handle

Creates a new Lua string from len bytes at ptr.

pub fn val_bool(b: i32) -> Handle

Creates a new Lua boolean (nonzero is true).

pub fn val_table() -> Handle

Creates a new empty Lua table.

pub fn val_to_number(v: Handle) -> f64

Reads a value as a number: true is 1, anything not convertible is 0.

pub fn val_to_string(v: Handle, out: *mut u8, cap: i32) -> i32

Copies tostring(v) into out (up to cap bytes) and returns its full length.

pub fn val_base64_encode(v: Handle, prefix: *const u8, len: i32) -> Handle

Returns a new string prefix .. base64(v), or nil if v isn't a string.

pub fn val_base64_decode(v: Handle, prefix: *const u8, len: i32) -> Handle

Reverses val_base64_encode: the decoded bytes, or nil if v doesn't start with prefix or isn't valid base64.

pub fn val_cobs_encode(v: Handle, prefix: *const u8, len: i32) -> Handle

Like the base64 pair, but COBS-encoded: no zero bytes and ~0.4% larger.

pub fn val_cobs_decode(v: Handle, prefix: *const u8, len: i32) -> Handle
pub fn val_to_bool(v: Handle) -> i32

Lua truthiness of a value: 0 for nil and false, 1 otherwise.

pub fn val_dup(v: Handle) -> Handle

Returns a new handle to the same value.

pub fn val_free(v: Handle)

Releases a handle. Freeing nil is a no-op.

pub fn val_equals(a: Handle, b: Handle) -> i32

1 if two values are equal by Lua's ==, else 0.

pub fn val_global(path: *const u8, len: i32) -> Handle

Looks up a dotted path from the Lua globals, e.g. "sm.vec3.new". Nil if any part is missing.

pub fn val_get(t: Handle, key: Handle) -> Handle

t[key], as a new handle.

pub fn val_set(t: Handle, key: Handle, v: Handle)

t[key] = v.

pub fn val_get_field(t: Handle, name: *const u8, len: i32) -> Handle

t[name] with a string key, as a new handle.

pub fn val_set_field(t: Handle, name: *const u8, len: i32, v: Handle)

t[name] = v with a string key.

pub fn val_get_number(t: Handle, name: *const u8, len: i32) -> f64

t[name] read as a number, without allocating a handle.

pub fn val_set_number(t: Handle, name: *const u8, len: i32, x: f64)

t[name] = x without allocating a handle.

pub fn val_get_index(t: Handle, i: i32) -> Handle

t[i], as a new handle. Lua indices start at 1.

pub fn val_set_index(t: Handle, i: i32, v: Handle)

t[i] = v.

pub fn val_len(v: Handle) -> i32

The length operator #v.

pub fn val_next(t: Handle, key: Handle) -> Handle

The key after key in t (Lua's next), or nil at the end. Start with nil.

pub fn call_begin()

Starts a new call by clearing the argument buffer.

pub fn arg_nil()

Appends one argument to the current call.

pub fn arg_number(x: f64)
pub fn arg_string(ptr: *const u8, len: i32)
pub fn arg_bool(b: i32)
pub fn arg_value(v: Handle)
pub fn call(f: Handle) -> i32

Calls a function with the buffered arguments. Returns the number of results, or -1 if it raised an error (see last_error).

pub fn call_method(obj: Handle, name: *const u8, len: i32) -> i32

Calls obj:name(...) with the buffered arguments. Returns like call.

pub fn result(i: i32) -> Handle

Result i (from 0) of the last call, as a new handle.

pub fn result_number(i: i32) -> f64

Result i (from 0) of the last call, read as a number.

pub fn last_error(out: *mut u8, cap: i32) -> i32

Copies the last failed call's error message into out and returns its full length.

pub fn val_callback(export_name: *const u8, len: i32) -> Handle

Wraps one of this module's exports as a Lua function. Calling it from Lua calls the export with (self, args) handles.

pub fn log_str(s: &str)

Writes s to the game log as info.

pub fn warn_str(s: &str)

Writes s to the game log as a warning.

pub fn error_str(s: &str)

Writes s to the game log as an error.

pub fn abort_str(s: &str) -> !

Raises a Lua error with the message, trapping (disabling) the mod.

pub const NETWORK_PACKET_LIMIT: usize = 65437

The largest single game network send in bytes, counting the method name, the data and the game's framing. A string payload costs its length + the method name's length + 14. The network also cuts strings at their first zero byte.

pub type Handle = i32

A handle to a Lua value held by the host. 0 is nil.