mirror of
https://github.com/MezzalunaWM/Mezzaluna.git
synced 2026-03-07 19:49:53 -05:00
don't reload the runtime config and personal config on remote lua connect
This commit is contained in:
parent
7ed5c4840d
commit
605c4c4a37
2 changed files with 51 additions and 44 deletions
|
|
@ -1,6 +1,7 @@
|
|||
const RemoteLua = @This();
|
||||
|
||||
const std = @import("std");
|
||||
const zlua = @import("zlua");
|
||||
const wayland = @import("wayland");
|
||||
const Utils = @import("utils.zig");
|
||||
const Lua = @import("lua/lua.zig");
|
||||
|
|
@ -12,7 +13,7 @@ const server = &@import("main.zig").server;
|
|||
|
||||
id: usize,
|
||||
remote_lua_v1: *mez.RemoteLuaV1,
|
||||
L: Lua,
|
||||
L: *zlua.Lua,
|
||||
|
||||
pub fn sendNewLogEntry(str: [*:0]const u8) void {
|
||||
for (server.remote_lua_clients.items) |c| {
|
||||
|
|
@ -28,10 +29,12 @@ pub fn create(client: *wl.Client, version: u32, id: u32) !void {
|
|||
node.* = .{
|
||||
.remote_lua_v1 = remote_lua_v1,
|
||||
.id = server.remote_lua_clients.items.len,
|
||||
.L = undefined,
|
||||
.L = try zlua.Lua.init(gpa),
|
||||
};
|
||||
try node.L.init();
|
||||
errdefer node.L.deinit();
|
||||
node.L.openLibs();
|
||||
Lua.openLibs(node.L);
|
||||
|
||||
try server.remote_lua_clients.append(gpa, node);
|
||||
|
||||
remote_lua_v1.setHandler(*RemoteLua, handleRequest, handleDestroy, node);
|
||||
|
|
@ -46,14 +49,14 @@ remote: *RemoteLua,
|
|||
.destroy => remote_lua_v1.destroy(),
|
||||
.push_lua => |req| {
|
||||
const chunk = std.mem.sliceTo(req.lua_chunk, 0);
|
||||
remote.L.state.loadString(chunk) catch catchLuaFail(remote);
|
||||
remote.L.state.protectedCall(.{}) catch catchLuaFail(remote);
|
||||
remote.L.loadString(chunk) catch catchLuaFail(remote);
|
||||
remote.L.protectedCall(.{}) catch catchLuaFail(remote);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
defer gpa.free(txt);
|
||||
|
||||
|
|
|
|||
|
|
@ -45,49 +45,53 @@ fn loadConfigDir(self: *Lua) !void {
|
|||
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 {
|
||||
self.state = try zlua.Lua.init(gpa);
|
||||
errdefer self.state.deinit();
|
||||
self.state.openLibs();
|
||||
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
openLibs(self.state);
|
||||
|
||||
loadRuntimeDir(self) catch |err| {
|
||||
if (err == error.LuaRuntime) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue