Skip to main content

Handling events

A raw call is a request, and onEvent is where the answer arrives. lk.raw.httpGet asks for a page, lk.raw.timerSet asks for a tick, lk.raw.subscribePaths asks for store changes: the response to each lands in your onEvent function. A file the mariner opens with your plugin arrives there too.

Your declared surface never does. Inputs, the draw timer, settings and connections handle their own events, so a plugin that makes no raw calls and claims no file types never hears onEvent fire.

const lk = @import("lk2");

comptime {
lk.plugin(@This());
}

/// Every event the SDK did not consume.
pub fn onEvent(e: lk.raw.Event) !void {
switch (e) {
.http_response => |r| lk.log(.info, "{d}, {d} bytes", .{ r.status, r.body.len }),
else => {},
}
}