we can now pass arbitrary zig data to lua through hooks

This commit is contained in:
Squibid 2025-11-25 16:48:04 -05:00
parent 91578d583a
commit 0bb1ba2963
Signed by: squibid
GPG key ID: BECE5684D3C4005D
3 changed files with 6 additions and 12 deletions

View file

@ -59,8 +59,7 @@ end
-- })
mez.hook.add("ViewMapPre", {
callback = function(a)
print(a)
print("hello world")
callback = function(v)
mez.view.set_size(v, 1000, 1000)
end
})

View file

@ -31,19 +31,14 @@ pub fn callback(self: *const Hook, args: anytype) void {
return;
}
// allow passing any arguments to the lua hook
var i: u8 = 0;
inline for (args, 0..) |field, k| {
// std.log.debug("{any}", .{field});
// oh dear god I hope this works
std.log.debug("sldkjf {any}", .{field});
inline for (args, 1..) |field, k| {
try Lua.state.pushAny(field);
i = k;
}
// TODO: we need to send some data along with the callback, this data will
// change based on the event which the user is hooking into
Lua.state.protectedCall(.{ .args = i, .results = 0 }) catch {
Lua.state.protectedCall(.{ .args = i }) catch {
};
Lua.state.pop(-1);
}

View file

@ -137,7 +137,7 @@ fn handleMap(listener: *wl.Listener(void)) void {
view.mapped = true;
server.events.exec("ViewMapPost", .{});
server.events.exec("ViewMapPost", .{view.id});
}
fn handleUnmap(listener: *wl.Listener(void)) void {