tony / oxwm

Fixed config directory not picking up required files, and also fixed config to be backwards compatible with both multi string and single string spawn commands. Rust mlua abstracted yet another thing away. Browse files
tonybanters committed 2026-02-08 parent 6592028 commit 1b7f7f2e3deb501d2cc1c507efc8df9ca30b6468
Showing 1 changed file with 43 additions and 1 deletions. UnifiedSplit
+43 −1 src/config/lua.zig
@@ -44,6 +44,16 @@ pub fn load_file(path: []const u8) bool {
44 @memcpy(path_buf[0..path.len], path); 44 @memcpy(path_buf[0..path.len], path);
45 path_buf[path.len] = 0; 45 path_buf[path.len] = 0;
46 46
47 + if (std.mem.lastIndexOfScalar(u8, path, '/')) |last_slash| {
48 + const dir = path[0..last_slash];
49 + var setup_buf: [600]u8 = undefined;
50 + const setup_code = std.fmt.bufPrint(&setup_buf, "package.path = '{s}/?.lua;' .. package.path\x00", .{dir}) catch return false;
51 + if (c.luaL_loadstring(state, setup_code.ptr) != 0 or c.lua_pcallk(state, 0, 0, 0, 0, null) != 0) {
52 + c.lua_settop(state, -2);
53 + return false;
54 + }
55 + }
56 +
47 if (c.luaL_loadfilex(state, &path_buf, null) != 0) { 57 if (c.luaL_loadfilex(state, &path_buf, null) != 0) {
48 const err = c.lua_tolstring(state, -1, null); 58 const err = c.lua_tolstring(state, -1, null);
49 if (err != null) { 59 if (err != null) {
@@ -389,6 +399,8 @@ fn lua_key_bind(state: ?*c.lua_State) callconv(.c) c_int {
389 int_arg = @intCast(c.lua_tointegerx(s, -1, null)); 399 int_arg = @intCast(c.lua_tointegerx(s, -1, null));
390 } else if (c.lua_type(s, -1) == c.LUA_TSTRING) { 400 } else if (c.lua_type(s, -1) == c.LUA_TSTRING) {
391 str_arg = get_lua_string(s, -1); 401 str_arg = get_lua_string(s, -1);
402 + } else if (c.lua_type(s, -1) == c.LUA_TTABLE) {
403 + str_arg = extract_spawn_command(s, -1);
392 } 404 }
393 c.lua_settop(s, -2); 405 c.lua_settop(s, -2);
394 406
@@ -1097,6 +1109,35 @@ fn get_string_arg(state: *c.lua_State, idx: c_int) ?[]const u8 {
1097 return get_lua_string(state, idx); 1109 return get_lua_string(state, idx);
1098 } 1110 }
1099 1111
1112 +fn extract_spawn_command(state: *c.lua_State, idx: c_int) ?[]const u8 {
1113 + const len = c.lua_rawlen(state, idx);
1114 + if (len == 0) return null;
1115 +
1116 + if (len >= 3) {
1117 + _ = c.lua_rawgeti(state, idx, 1);
1118 + const first = get_lua_string(state, -1);
1119 + c.lua_settop(state, -2);
1120 +
1121 + _ = c.lua_rawgeti(state, idx, 2);
1122 + const second = get_lua_string(state, -1);
1123 + c.lua_settop(state, -2);
1124 +
1125 + if (first != null and second != null and
1126 + std.mem.eql(u8, first.?, "sh") and std.mem.eql(u8, second.?, "-c"))
1127 + {
1128 + _ = c.lua_rawgeti(state, idx, 3);
1129 + const cmd = get_lua_string(state, -1);
1130 + c.lua_settop(state, -2);
1131 + return cmd;
1132 + }
1133 + }
1134 +
1135 + _ = c.lua_rawgeti(state, idx, 1);
1136 + const first_elem = get_lua_string(state, -1);
1137 + c.lua_settop(state, -2);
1138 + return first_elem;
1139 +}
1140 +
1100 fn get_lua_string(state: *c.lua_State, idx: c_int) ?[]const u8 { 1141 fn get_lua_string(state: *c.lua_State, idx: c_int) ?[]const u8 {
1101 const cstr = c.lua_tolstring(state, idx, null); 1142 const cstr = c.lua_tolstring(state, idx, null);
1102 if (cstr == null) return null; 1143 if (cstr == null) return null;
@@ -1139,7 +1180,8 @@ fn parse_modifiers(state: *c.lua_State, idx: c_int) u32 {
1139 while (i <= len) : (i += 1) { 1180 while (i <= len) : (i += 1) {
1140 _ = c.lua_rawgeti(state, idx, @intCast(i)); 1181 _ = c.lua_rawgeti(state, idx, @intCast(i));
1141 if (get_lua_string(state, -1)) |mod_str| { 1182 if (get_lua_string(state, -1)) |mod_str| {
1142 - mod_mask |= parse_single_modifier(mod_str); 1183 + const parsed = parse_single_modifier(mod_str);
1184 + mod_mask |= parsed;
1143 } 1185 }
1144 c.lua_settop(state, -2); 1186 c.lua_settop(state, -2);
1145 } 1187 }