Skip to content

atl.h

AllTheLanguages C SDK: header-only bindings to the loader's GDT imports.

#define ATL_NIL

The nil handle.

#define ATL_EXPORT(name)

Exports a function from the module under name, so the loader can call it (lifecycle callbacks, script-class methods, callbacks).

#define ATL_NETWORK_PACKET_LIMIT

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.

typedef int atl_value;

A handle to a Lua value held by the host. Handles are owned: free them with atl_free when done. 0 is nil.

ATL__IMPORT(log) void atl_raw_log(const char *ptr, int len);

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

Parameters

  • ptr (const char *)
  • len (int)
ATL__IMPORT(warn) void atl_raw_warn(const char *ptr, int len);

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

Parameters

  • ptr (const char *)
  • len (int)
ATL__IMPORT(error) void atl_raw_error(const char *ptr, int len);

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

Parameters

  • ptr (const char *)
  • len (int)
ATL__IMPORT(abort) void atl_raw_abort(const char *ptr, int len);

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

Parameters

  • ptr (const char *)
  • len (int)
ATL__IMPORT(is_server) int atl_is_server(void);

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

Returns int

ATL__IMPORT(mod_id) int atl_mod_id(char *out, int cap);

Copies this mod's id into out (up to cap bytes) and returns its full length; a result larger than cap means it was truncated.

Parameters

  • out (char *)
  • cap (int)

Returns int

ATL__IMPORT(val_type) int atl_type(atl_value v);

The atl_type of a value.

Parameters

  • v (atl_value)

Returns int

ATL__IMPORT(val_number) atl_value atl_number(double x);

Creates a new Lua number.

Parameters

  • x (double)

Returns atl_value

ATL__IMPORT(val_string) atl_value atl_raw_string(const char *ptr, int len);

Creates a new Lua string from len bytes at ptr.

Parameters

  • ptr (const char *)
  • len (int)

Returns atl_value

ATL__IMPORT(val_bool) atl_value atl_bool(int b);

Creates a new Lua boolean (nonzero is true).

Parameters

  • b (int)

Returns atl_value

ATL__IMPORT(val_table) atl_value atl_table(void);

Creates a new empty Lua table.

Returns atl_value

ATL__IMPORT(val_to_number) double atl_to_number(atl_value v);

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

Parameters

  • v (atl_value)

Returns double

ATL__IMPORT(val_to_string) int atl_to_string(atl_value v, char *out, int cap);

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

Parameters

  • v (atl_value)
  • out (char *)
  • cap (int)

Returns int

ATL__IMPORT(val_base64_encode) atl_value atl_raw_base64_encode(atl_value v, const char *prefix, int len);

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

Parameters

  • v (atl_value)
  • prefix (const char *)
  • len (int)

Returns atl_value

ATL__IMPORT(val_base64_decode) atl_value atl_raw_base64_decode(atl_value v, const char *prefix, int len);

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

Parameters

  • v (atl_value)
  • prefix (const char *)
  • len (int)

Returns atl_value

ATL__IMPORT(val_cobs_encode) atl_value atl_raw_cobs_encode(atl_value v, const char *prefix, int len);

Like the base64 pair, but COBS-encoded: no zero bytes and ~0.4% larger. Use it for strings sent over the game's network.

Parameters

  • v (atl_value)
  • prefix (const char *)
  • len (int)

Returns atl_value

ATL__IMPORT(val_cobs_decode) atl_value atl_raw_cobs_decode(atl_value v, const char *prefix, int len);

Like the base64 pair, but COBS-encoded: no zero bytes and ~0.4% larger. Use it for strings sent over the game's network.

Parameters

  • v (atl_value)
  • prefix (const char *)
  • len (int)

Returns atl_value

ATL__IMPORT(val_to_bool) int atl_to_bool(atl_value v);

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

Parameters

  • v (atl_value)

Returns int

ATL__IMPORT(val_dup) atl_value atl_dup(atl_value v);

Returns a new handle to the same value.

Parameters

  • v (atl_value)

Returns atl_value

ATL__IMPORT(val_free) void atl_free(atl_value v);

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

Parameters

  • v (atl_value)
ATL__IMPORT(val_equals) int atl_equals(atl_value a, atl_value b);

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

Parameters

  • a (atl_value)
  • b (atl_value)

Returns int

ATL__IMPORT(val_global) atl_value atl_raw_global(const char *path, int len);

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

Parameters

  • path (const char *)
  • len (int)

Returns atl_value

ATL__IMPORT(val_get) atl_value atl_get(atl_value t, atl_value key);

t[key], as a new handle.

Parameters

  • t (atl_value)
  • key (atl_value)

Returns atl_value

ATL__IMPORT(val_set) void atl_set(atl_value t, atl_value key, atl_value v);

t[key] = v.

Parameters

  • t (atl_value)
  • key (atl_value)
  • v (atl_value)
ATL__IMPORT(val_get_field) atl_value atl_raw_get_field(atl_value t, const char *name, int len);

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

Parameters

  • t (atl_value)
  • name (const char *)
  • len (int)

Returns atl_value

ATL__IMPORT(val_set_field) void atl_raw_set_field(atl_value t, const char *name, int len, atl_value v);

t[name] = v with a string key.

Parameters

  • t (atl_value)
  • name (const char *)
  • len (int)
  • v (atl_value)
ATL__IMPORT(val_get_number) double atl_raw_get_number(atl_value t, const char *name, int len);

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

Parameters

  • t (atl_value)
  • name (const char *)
  • len (int)

Returns double

ATL__IMPORT(val_set_number) void atl_raw_set_number(atl_value t, const char *name, int len, double x);

t[name] = x without allocating a handle.

Parameters

  • t (atl_value)
  • name (const char *)
  • len (int)
  • x (double)
ATL__IMPORT(val_get_index) atl_value atl_get_index(atl_value t, int i);

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

Parameters

  • t (atl_value)
  • i (int)

Returns atl_value

ATL__IMPORT(val_set_index) void atl_set_index(atl_value t, int i, atl_value v);

t[i] = v.

Parameters

  • t (atl_value)
  • i (int)
  • v (atl_value)
ATL__IMPORT(val_len) int atl_len(atl_value v);

The length operator #v.

Parameters

  • v (atl_value)

Returns int

ATL__IMPORT(val_next) atl_value atl_next(atl_value t, atl_value key);

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

Parameters

  • t (atl_value)
  • key (atl_value)

Returns atl_value

ATL__IMPORT(call_begin) void atl_begin(void);

Starts a new call by clearing the argument buffer.

ATL__IMPORT(arg_nil) void atl_arg_nil(void);

Append one argument to the current call.

ATL__IMPORT(arg_number) void atl_arg_number(double x);

Append one argument to the current call.

Parameters

  • x (double)
ATL__IMPORT(arg_string) void atl_raw_arg_string(const char *ptr, int len);

Append one argument to the current call.

Parameters

  • ptr (const char *)
  • len (int)
ATL__IMPORT(arg_bool) void atl_arg_bool(int b);

Append one argument to the current call.

Parameters

  • b (int)
ATL__IMPORT(arg_value) void atl_arg(atl_value v);

Append one argument to the current call.

Parameters

  • v (atl_value)
ATL__IMPORT(call) int atl_call(atl_value fn);

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

Parameters

  • fn (atl_value)

Returns int

ATL__IMPORT(call_method) int atl_raw_call_method(atl_value obj, const char *name, int len);

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

Parameters

  • obj (atl_value)
  • name (const char *)
  • len (int)

Returns int

ATL__IMPORT(result) atl_value atl_result(int i);

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

Parameters

  • i (int)

Returns atl_value

ATL__IMPORT(result_number) double atl_result_number(int i);

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

Parameters

  • i (int)

Returns double

ATL__IMPORT(last_error) int atl_last_error(char *out, int cap);

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

Parameters

  • out (char *)
  • cap (int)

Returns int

ATL__IMPORT(val_callback) atl_value atl_raw_callback(const char *export_name, int len);

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

Parameters

  • export_name (const char *)
  • len (int)

Returns atl_value

__attribute__((weak, no_builtin)) __SIZE_TYPE__ strlen(const char *s);

Parameters

  • s (const char *)

Returns __size_t

__attribute__((weak, no_builtin)) void *memcpy(void *dst, const void *src, __SIZE_TYPE__ n);

With bulk memory, each is a single memory.copy / memory.fill instruction, which the VM runs natively instead of as a byte loop.

Parameters

  • dst (void *)
  • src (const void *)
  • n (unsigned long)

Returns void *

__attribute__((weak, no_builtin)) void *memmove(void *dst, const void *src, __SIZE_TYPE__ n);

With bulk memory, each is a single memory.copy / memory.fill instruction, which the VM runs natively instead of as a byte loop.

Parameters

  • dst (void *)
  • src (const void *)
  • n (unsigned long)

Returns void *

__attribute__((weak, no_builtin)) void *memset(void *dst, int c, __SIZE_TYPE__ n);

With bulk memory, each is a single memory.copy / memory.fill instruction, which the VM runs natively instead of as a byte loop.

Parameters

  • dst (void *)
  • c (int)
  • n (unsigned long)

Returns void *

static inline int atl_strlen(const char *s);

Length of a zero-terminated string.

Parameters

  • s (const char *)

Returns int

static inline void atl_log(const char *s);

Zero-terminated string versions of the logging imports.

Parameters

  • s (const char *)
static inline void atl_warn(const char *s);

Zero-terminated string versions of the logging imports.

Parameters

  • s (const char *)
static inline void atl_error(const char *s);

Zero-terminated string versions of the logging imports.

Parameters

  • s (const char *)
static inline void atl_abort(const char *s);

Zero-terminated string versions of the logging imports.

Parameters

  • s (const char *)
static inline atl_value atl_string(const char *s);

Zero-terminated string versions of the value, lookup and call imports.

Parameters

  • s (const char *)

Returns atl_value

static inline atl_value atl_global(const char *path);

Zero-terminated string versions of the value, lookup and call imports.

Parameters

  • path (const char *)

Returns atl_value

static inline atl_value atl_get_field(atl_value t, const char *name);

Zero-terminated string versions of the value, lookup and call imports.

Parameters

  • t (atl_value)
  • name (const char *)

Returns atl_value

static inline void atl_set_field(atl_value t, const char *name, atl_value v);

Zero-terminated string versions of the value, lookup and call imports.

Parameters

  • t (atl_value)
  • name (const char *)
  • v (atl_value)
static inline double atl_get_number(atl_value t, const char *name);

Zero-terminated string versions of the value, lookup and call imports.

Parameters

  • t (atl_value)
  • name (const char *)

Returns double

static inline void atl_set_number(atl_value t, const char *name, double x);

Zero-terminated string versions of the value, lookup and call imports.

Parameters

  • t (atl_value)
  • name (const char *)
  • x (double)
static inline void atl_arg_str(const char *s);

Zero-terminated string versions of the value, lookup and call imports.

Parameters

  • s (const char *)
static inline int atl_call_method(atl_value obj, const char *name);

Zero-terminated string versions of the value, lookup and call imports.

Parameters

  • obj (atl_value)
  • name (const char *)

Returns int

static inline atl_value atl_callback(const char *export_name);

Zero-terminated string versions of the value, lookup and call imports.

Parameters

  • export_name (const char *)

Returns atl_value

static inline int atl_arg_count(atl_value args);

The number of arguments in a script-class callback's args table.

Parameters

  • args (atl_value)

Returns int

static inline int atl_call_global(const char *path);

Looks up a global function by path and calls it with the buffered arguments. Returns like atl_call.

Parameters

  • path (const char *)

Returns int

The Lua type of a value, as returned by atl_type. Game objects (Shape, Vec3, Player, ...) report ATL_TYPE_USERDATA.

enum atl_type {
ATL_TYPE_NIL = 0,
ATL_TYPE_BOOLEAN = 1,
ATL_TYPE_NUMBER = 2,
ATL_TYPE_STRING = 3,
ATL_TYPE_TABLE = 4,
ATL_TYPE_FUNCTION = 5,
ATL_TYPE_USERDATA = 6,
ATL_TYPE_THREAD = 7,
};