From 0bb1ba29632ecce7810cdb22af1f5aa539a0fe01 Mon Sep 17 00:00:00 2001 From: Squibid Date: Tue, 25 Nov 2025 16:48:04 -0500 Subject: [PATCH] we can now pass arbitrary zig data to lua through hooks --- runtime/share/mezzaluna/init.lua | 5 ++--- src/types/hook.zig | 11 +++-------- src/view.zig | 2 +- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/runtime/share/mezzaluna/init.lua b/runtime/share/mezzaluna/init.lua index f52fc52..ec74bdd 100644 --- a/runtime/share/mezzaluna/init.lua +++ b/runtime/share/mezzaluna/init.lua @@ -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 }) diff --git a/src/types/hook.zig b/src/types/hook.zig index cfa4c0c..7b2693f 100644 --- a/src/types/hook.zig +++ b/src/types/hook.zig @@ -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); } diff --git a/src/view.zig b/src/view.zig index 772d323..61aa3a3 100644 --- a/src/view.zig +++ b/src/view.zig @@ -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 {