Skip to content

Writing a mod in C

atl.h is a header-only SDK over the raw GDT. It needs no libc. Any language with a C FFI can use the same imports. The full list is in the atl.h reference.

#include "atl.h"
ATL_EXPORT(server_onCreate)
void server_onCreate(void) {
atl_begin();
atl_arg_str("#00ff00Hello from C!");
atl_call_global("sm.gui.chatMessage");
}

Compile it with clang for wasm32-unknown-unknown, put the .wasm in your mod folder and run atl-build.

Lifecycle callbacks are exports with the game's names, such as server_onCreate and server_onFixedUpdate.

A script class in C is a set of exports named <Class>_<method>. They take (self, args) handles, where args[1..n] are the callback's arguments. Returning an atl_value hands a return value back to the game, as client_canInteract needs.

Every Lua value the C code sees is an atl_value handle held by the host. Handles are owned: free them with atl_free when you're done. 0 (ATL_NIL) is nil.