Skip to content

atl/sys

import "atl/sys"

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

const NetworkPacketLimit = 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.

func Log(ptr unsafe.Pointer, len int32)

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

func Warn(ptr unsafe.Pointer, len int32)
func Error(ptr unsafe.Pointer, len int32)
func Abort(ptr unsafe.Pointer, len int32)

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

func IsServer() int32

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

func ModID(out unsafe.Pointer, cap int32) int32

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.

func ValType(v Handle) int32

The Lua type of a value.

func ValToNumber(v Handle) float64

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

func ValToString(v Handle, out unsafe.Pointer, cap int32) int32

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

func ValToBool(v Handle) int32

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

func ValFree(v Handle)

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

func ValEquals(a, b Handle) int32

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

func ValSet(t, key, v Handle)

t[key] = v.

func ValSetField(t Handle, name unsafe.Pointer, len int32, v Handle)

t[name] = v with a string key.

func ValGetNumber(t Handle, name unsafe.Pointer, len int32) float64

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

func ValSetNumber(t Handle, name unsafe.Pointer, len int32, x float64)

t[name] = x without allocating a handle.

func ValSetIndex(t Handle, i int32, v Handle)

t[i] = v.

func ValLen(v Handle) int32

The length operator #v.

func CallBegin()

Starts a new call by clearing the argument buffer.

func ArgNil()

Append one argument to the current call.

func ArgNumber(x float64)
func ArgString(ptr unsafe.Pointer, len int32)
func ArgBool(b int32)
func ArgValue(v Handle)
func Call(fn Handle) int32

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

func CallMethod(obj Handle, name unsafe.Pointer, len int32) int32

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

func ResultNumber(i int32) float64

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

func LastError(out unsafe.Pointer, cap int32) int32

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

func Str(s string) unsafe.Pointer

Pointer to the bytes of s, for the imports above.

func LogStr(s string)

Writes s to the game log as info.

func WarnStr(s string)

Writes s to the game log as a warning.

func ErrorStr(s string)

Writes s to the game log as an error.

func AbortStr(s string)

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

type Handle = int32

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

func ValNumber(x float64) Handle

Creates a new Lua number.

func ValString(ptr unsafe.Pointer, len int32) Handle

Creates a new Lua string from len bytes at ptr.

func ValBool(b int32) Handle

Creates a new Lua boolean (nonzero is true).

func ValTable() Handle

Creates a new empty Lua table.

func ValBase64Encode(v Handle, prefix unsafe.Pointer, len int32) Handle

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

func ValBase64Decode(v Handle, prefix unsafe.Pointer, len int32) Handle

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

func ValCobsEncode(v Handle, prefix unsafe.Pointer, len int32) Handle

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

func ValCobsDecode(v Handle, prefix unsafe.Pointer, len int32) Handle
func ValDup(v Handle) Handle

Returns a new handle to the same value.

func ValGlobal(path unsafe.Pointer, len int32) Handle

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

func ValGet(t, key Handle) Handle

t[key], as a new handle.

func ValGetField(t Handle, name unsafe.Pointer, len int32) Handle

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

func ValGetIndex(t Handle, i int32) Handle

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

func ValNext(t, key Handle) Handle

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

func Result(i int32) Handle

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

func ValCallback(exportName unsafe.Pointer, len int32) Handle

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