Перейти к содержимому

API reference

The API a server-side plugin uses. Three faces, one description, all documented here:

Face Who uses it Reference
Lua node resources – Lua scripts in resources/<name>/server/ Lua API reference (node)
Lua node.raw the 1:1 mirror of the C ABI underneath node; the escape hatch Raw Lua reference (node.raw.*)
C NodeApi native modules – a .dll/.so in modules/ C ABI reference (NodeApi)
Events both Events reference

The reference pages are GENERATED from sdk/api.toml by python sdk/tools/apigen.py docs; apigen.py docs --check fails when they drift from the schema, when the Lua prelude defines something the schema does not document, or the other way round. The guides are written by hand:

  • Getting started – your first resource, in ten minutes
  • Resources – folder layout, resource.toml, lifecycle, client files, reload
  • Events – the three kinds of name, objects in handlers, cancelling, the streams
  • Concurrency – the worker thread, timers, coroutines, background jobs
  • Wire events and clients – talking to the client half of a resource, the domain:verb rule
  • Native modules – the C ABI, versioning, language hosts
  • Recipes – chat commands, permissions, teleport, persistence, HTTP, radar
  • Conventions and compatibility – naming, objects, return shapes, what is promised
Namespace Functions About
Top level: events, sending, timers, coroutines on, off, send, broadcast, after, every, cancel, defer, async, sleep, wait, yield, await, job, log What every resource uses every day sits directly on node: subscribing to events, sending to clients, timers, and the coroutine helpers.
node.players – the roster get, all, count, ids, find Look players up and iterate them.
Player objects isConnected, refresh, kick, ban, verify, setStrict, send, sendModule, setRole, setGroup, vehicles, position, focus, headPose, camera, inputs, seat, unseat, swapWith, resync, tell A Player is a table with id and a metatable.
node.vehicles – the registry get, all, count, spawn, deleteAll, byTag, byTags, transforms Look vehicles up and iterate them.
Vehicle objects exists, refresh, delete, transform, controls, inputs, electrics, powertrain, engine, controllers, couplers, nodes, breakGroups, paints, config, damage, sync, occupants, tag, setTag, removeTag, lock, unlock, lockState, setCoupler, trigger, resync, seat, setGroup A Vehicle is a table with id and a metatable, lazy like a Player: the registry record is fetched on the first field read and cached until refresh().
node.server – identity, limits, time, metrics name, setName, map, version, port, maxPlayers, setMaxPlayers, maxCars, setMaxCars, uptime, time, unixTime, metrics, snapshot, nodeGrabEnabled The server’s own facts and knobs..
node.bans add, remove, has, all IP bans, persisted in bans.json.
node.storage – persistent key/value get, set, delete A per-resource JSON store (storage/<resource>.json), flushed atomically on every write..
node.fs – files inside the resource folder read, write, writeAsync, list Files inside the resource’s own folder; paths that escape it are rejected..
node.http get, post, request, put, patch, delete, head, fetch Asynchronous HTTP.
node.pg – PostgreSQL enabled, ready, query, exec, tx Asynchronous, pooled PostgreSQL over the connection string in [Database] Url (enabled() is false without one).
node.json encode, decode JSON in and out.
node.crypto sha256, hmac, randomBytes, randomHex Digests and randomness..
node.log warn, error, tag, custom, raw, sink, title node.log(msg, ...) prints under the resource’s tag with string.format arguments; the table also carries the levels and the raw forms..
node.bus – between resources emit, on, off Publish/subscribe between resources on this server (and native modules).
node.modules – the binary channel on, off, send Raw bytes on a numbered channel, for native modules and their client halves..
node.relay – who sees what filter, unfilter, invalidate The packet filter and its cache.
node.resources and node.config reload, manifest The resource’s own manifest and settings, and reloading resources by name..
node.chat say, tell Speak into the chat as the server.
node.commands add, remove Chat commands: a line starting with / reaches the handler registered for its first word, with the sender as a Player.

Events: 42 (22 builtin, 7 notify, 9 cancellable, 1 special, 1 client, 1 module, 1 bus).

Totals: 145 public Lua functions and methods, 143 raw functions, 153 C entries, ABI 1.