don't reload the runtime config and personal config on remote lua connect

This commit is contained in:
Squibid 2025-11-30 23:02:25 -05:00
parent 7ed5c4840d
commit 605c4c4a37
Signed by: squibid
GPG key ID: BECE5684D3C4005D
2 changed files with 51 additions and 44 deletions

View file

@ -1,6 +1,7 @@
const RemoteLua = @This(); const RemoteLua = @This();
const std = @import("std"); const std = @import("std");
const zlua = @import("zlua");
const wayland = @import("wayland"); const wayland = @import("wayland");
const Utils = @import("utils.zig"); const Utils = @import("utils.zig");
const Lua = @import("lua/lua.zig"); const Lua = @import("lua/lua.zig");
@ -12,7 +13,7 @@ const server = &@import("main.zig").server;
id: usize, id: usize,
remote_lua_v1: *mez.RemoteLuaV1, remote_lua_v1: *mez.RemoteLuaV1,
L: Lua, L: *zlua.Lua,
pub fn sendNewLogEntry(str: [*:0]const u8) void { pub fn sendNewLogEntry(str: [*:0]const u8) void {
for (server.remote_lua_clients.items) |c| { for (server.remote_lua_clients.items) |c| {
@ -28,10 +29,12 @@ pub fn create(client: *wl.Client, version: u32, id: u32) !void {
node.* = .{ node.* = .{
.remote_lua_v1 = remote_lua_v1, .remote_lua_v1 = remote_lua_v1,
.id = server.remote_lua_clients.items.len, .id = server.remote_lua_clients.items.len,
.L = undefined, .L = try zlua.Lua.init(gpa),
}; };
try node.L.init();
errdefer node.L.deinit(); errdefer node.L.deinit();
node.L.openLibs();
Lua.openLibs(node.L);
try server.remote_lua_clients.append(gpa, node); try server.remote_lua_clients.append(gpa, node);
remote_lua_v1.setHandler(*RemoteLua, handleRequest, handleDestroy, node); remote_lua_v1.setHandler(*RemoteLua, handleRequest, handleDestroy, node);
@ -46,14 +49,14 @@ remote: *RemoteLua,
.destroy => remote_lua_v1.destroy(), .destroy => remote_lua_v1.destroy(),
.push_lua => |req| { .push_lua => |req| {
const chunk = std.mem.sliceTo(req.lua_chunk, 0); const chunk = std.mem.sliceTo(req.lua_chunk, 0);
remote.L.state.loadString(chunk) catch catchLuaFail(remote); remote.L.loadString(chunk) catch catchLuaFail(remote);
remote.L.state.protectedCall(.{}) catch catchLuaFail(remote); remote.L.protectedCall(.{}) catch catchLuaFail(remote);
}, },
} }
} }
fn catchLuaFail(remote: *RemoteLua) void { fn catchLuaFail(remote: *RemoteLua) void {
const err_txt: []const u8 = remote.L.state.toString(-1) catch unreachable; const err_txt: []const u8 = remote.L.toString(-1) catch unreachable;
const txt = std.mem.concat(gpa, u8, &[_][]const u8{ "repl: ", err_txt }) catch Utils.oomPanic(); const txt = std.mem.concat(gpa, u8, &[_][]const u8{ "repl: ", err_txt }) catch Utils.oomPanic();
defer gpa.free(txt); defer gpa.free(txt);

View file

@ -45,49 +45,53 @@ fn loadConfigDir(self: *Lua) !void {
try self.state.doFile(path); try self.state.doFile(path);
} }
pub fn openLibs(self: *zlua.Lua) void {
{
self.newTable();
defer _ = self.setGlobal("mez");
{
self.newTable();
defer _ = self.setField(-2, "path");
}
{
const fs_funcs = zlua.fnRegsFromType(Fs);
self.newLib(fs_funcs);
self.setField(-2, "fs");
}
{
const input_funcs = zlua.fnRegsFromType(Input);
self.newLib(input_funcs);
self.setField(-2, "input");
}
{
const hook_funcs = zlua.fnRegsFromType(Hook);
self.newLib(hook_funcs);
self.setField(-2, "hook");
}
{
const api_funcs = zlua.fnRegsFromType(Api);
self.newLib(api_funcs);
self.setField(-2, "api");
}
{
const view_funcs = zlua.fnRegsFromType(View);
self.newLib(view_funcs);
self.setField(-2, "view");
}
{
const output_funcs = zlua.fnRegsFromType(Output);
self.newLib(output_funcs);
self.setField(-2, "output");
}
}
}
pub fn init(self: *Lua) !void { pub fn init(self: *Lua) !void {
self.state = try zlua.Lua.init(gpa); self.state = try zlua.Lua.init(gpa);
errdefer self.state.deinit(); errdefer self.state.deinit();
self.state.openLibs(); self.state.openLibs();
{ openLibs(self.state);
self.state.newTable();
defer _ = self.state.setGlobal("mez");
{
self.state.newTable();
defer _ = self.state.setField(-2, "path");
}
{
const fs_funcs = zlua.fnRegsFromType(Fs);
self.state.newLib(fs_funcs);
self.state.setField(-2, "fs");
}
{
const input_funcs = zlua.fnRegsFromType(Input);
self.state.newLib(input_funcs);
self.state.setField(-2, "input");
}
{
const hook_funcs = zlua.fnRegsFromType(Hook);
self.state.newLib(hook_funcs);
self.state.setField(-2, "hook");
}
{
const api_funcs = zlua.fnRegsFromType(Api);
self.state.newLib(api_funcs);
self.state.setField(-2, "api");
}
{
const view_funcs = zlua.fnRegsFromType(View);
self.state.newLib(view_funcs);
self.state.setField(-2, "view");
}
{
const output_funcs = zlua.fnRegsFromType(Output);
self.state.newLib(output_funcs);
self.state.setField(-2, "output");
}
}
loadRuntimeDir(self) catch |err| { loadRuntimeDir(self) catch |err| {
if (err == error.LuaRuntime) { if (err == error.LuaRuntime) {