TopStats SDK
Lua analytics SDK
Lua has no standard HTTP, JSON or timers, so the core takes a platform table - http, set_timeout, json_encode, now_iso, log, random - and everything else (batching, retries, queue bounds, the wire contract) is shared, tested code. The FiveM, Garry’s Mod and Roblox integrations are thin platform tables over this exact file.
Install
-- vendored: copy src/topstats.lua into your project (the integrations do this with a CI drift check)Capture your first event
local TopStatsCore = require('topstats')
local client = TopStatsCore.new(platform, { api_key = os.getenv('TOPSTATS_API_KEY') })
client:capture('zone_captured', { zone = 'north' }, { actor = 'player-1' })
client:flush()Behaviour you can rely on
- Capture never throws into your code and never blocks on the network - a bounded queue buffers and a background loop batches.
- Retries only 429, 5xx and network failures, with jittered backoff honouring Retry-After; your API key never appears in error output.
- Tested on Lua 5.1 and 5.4, and guards runtimes with no os.getenv (GLua, Luau).
- Empty property tables are omitted rather than encoded as arrays - a real Lua wire-format trap, handled.