mirror of
https://github.com/fairyglade/ly.git
synced 2026-11-05 09:41:43 +00:00
Update to Zig 0.17.0 (#1028)
Now compiles! (Tested with Zig 0.17.0-dev.2375+d8aab4878) ## What are the changes about? Updates dependencies & code for Zig 0.17.0 compatibility. ## What existing issue(s) does this resolve? N/A ## Pre-requisites - [x] I have tested & confirmed the changes work locally - [x] I have read and fully adhere to the rules set in the contributing guidelines found in `CONTRIBUTING.md` Reviewed-on: https://codeberg.org/fairyglade/ly/pulls/1028
This commit is contained in:
1 parent
55de3bc26c
commit
f1fc335bb8
13 files changed
+91
-87
No files matched your search
@@ -54,7 +54,7 @@ pub fn info(self: *LogFile, io: std.Io, category: []const u8, comptime message:
|
||||
} else {
|
||||
var buffer: [1024]u8 = undefined;
|
||||
const slice = try std.fmt.bufPrint(&buffer, message, args);
|
||||
const msg = try std.fmt.bufPrintZ(buffer[slice.len..], "[info/{s}] {s}", .{ category, slice });
|
||||
const msg = try std.fmt.bufPrintSentinel(buffer[slice.len..], "[info/{s}] {s}", .{ category, slice }, 0);
|
||||
|
||||
std.posix.system.syslog(std.posix.LOG.INFO, msg.ptr);
|
||||
}
|
||||
@@ -72,7 +72,7 @@ pub fn err(self: *LogFile, io: std.Io, category: []const u8, comptime message: [
|
||||
} else {
|
||||
var buffer: [1024]u8 = undefined;
|
||||
const slice = try std.fmt.bufPrint(&buffer, message, args);
|
||||
const msg = try std.fmt.bufPrintZ(buffer[slice.len..], "[info/{s}] {s}", .{ category, slice });
|
||||
const msg = try std.fmt.bufPrintSentinel(buffer[slice.len..], "[info/{s}] {s}", .{ category, slice }, 0);
|
||||
|
||||
std.posix.system.syslog(std.posix.LOG.ERR, msg.ptr);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const std = @import("std");
|
||||
|
||||
const ErrInt = std.meta.Int(.unsigned, @bitSizeOf(anyerror));
|
||||
const PaddingInt = std.meta.Int(.unsigned, 8 - (@bitSizeOf(ErrInt) + @bitSizeOf(bool)) % 8);
|
||||
const ErrInt = @Int(.unsigned, @bitSizeOf(anyerror));
|
||||
const PaddingInt = @Int(.unsigned, 8 - (@bitSizeOf(ErrInt) + @bitSizeOf(bool)) % 8);
|
||||
|
||||
const ErrorHandler = packed struct {
|
||||
has_error: bool = false,
|
||||
|
||||
@@ -376,7 +376,7 @@ pub fn setNumlock(val: bool) !void {
|
||||
}
|
||||
|
||||
pub fn setUserContext(allocator: std.mem.Allocator, entry: UsernameEntry) !void {
|
||||
const username_z = try allocator.dupeZ(u8, entry.username.?);
|
||||
const username_z = try allocator.dupeSentinel(u8, entry.username.?, 0);
|
||||
defer allocator.free(username_z);
|
||||
|
||||
return platform_struct.setUserContextImpl(username_z.ptr, entry);
|
||||
@@ -392,10 +392,10 @@ pub fn setUserShell(entry: *UsernameEntry) void {
|
||||
}
|
||||
|
||||
pub fn setEnvironmentVariable(allocator: std.mem.Allocator, name: []const u8, value: []const u8, replace: bool) !void {
|
||||
const name_z = try allocator.dupeZ(u8, name);
|
||||
const name_z = try allocator.dupeSentinel(u8, name, 0);
|
||||
defer allocator.free(name_z);
|
||||
|
||||
const value_z = try allocator.dupeZ(u8, value);
|
||||
const value_z = try allocator.dupeSentinel(u8, value, 0);
|
||||
defer allocator.free(value_z);
|
||||
|
||||
const status = stdlib.setenv(name_z.ptr, value_z.ptr, @intFromBool(replace));
|
||||
@@ -422,7 +422,7 @@ pub fn getNextUsernameEntry() ?UsernameEntry {
|
||||
}
|
||||
|
||||
pub fn getUsernameEntry(allocator: std.mem.Allocator, username: []const u8) ?UsernameEntry {
|
||||
const username_z = allocator.dupeZ(u8, username) catch return null;
|
||||
const username_z = allocator.dupeSentinel(u8, username, 0) catch return null;
|
||||
defer allocator.free(username_z);
|
||||
|
||||
const entry = pwd.getpwnam(username_z);
|
||||
|
||||
+43
-25
@@ -131,13 +131,11 @@ pub fn LuaParser(comptime Struct: type) type {
|
||||
var arena = std.heap.ArenaAllocator.init(allocator);
|
||||
const arena_alloc = arena.allocator();
|
||||
|
||||
var maybe_load_error: ?anyerror = null;
|
||||
errdefer |err| maybe_load_error = err;
|
||||
|
||||
const data = parseLua(arena_alloc, path) catch load_error: {
|
||||
break :load_error Struct{};
|
||||
};
|
||||
|
||||
var maybe_load_error: ?anyerror = null;
|
||||
if (global_errors.items.len != 0) {
|
||||
maybe_load_error = error.InvalidConfig;
|
||||
}
|
||||
@@ -176,8 +174,8 @@ pub fn LuaParser(comptime Struct: type) type {
|
||||
defer lua.pop(1); // pop ly table
|
||||
if (ly_type == .nil) return error.MissingLyTable;
|
||||
|
||||
inline for (struc.fields) |field| {
|
||||
try setField(allocator, lua, field, &data);
|
||||
inline for (struc.field_names, struc.field_types) |name, ftype| {
|
||||
try setField(allocator, lua, name, ftype, &data);
|
||||
}
|
||||
},
|
||||
else => @compileError("Expected a struct."),
|
||||
@@ -188,21 +186,47 @@ pub fn LuaParser(comptime Struct: type) type {
|
||||
return data;
|
||||
}
|
||||
|
||||
pub fn setField(allocator: std.mem.Allocator, lua: *Lua, comptime field: std.builtin.Type.StructField, data: *Struct) !void {
|
||||
const type_info = @typeInfo(field.type);
|
||||
pub fn setField(
|
||||
allocator: std.mem.Allocator,
|
||||
lua: *Lua,
|
||||
comptime field_name: [:0]const u8,
|
||||
field_type: type,
|
||||
data: *Struct,
|
||||
) !void {
|
||||
return setFieldInner(
|
||||
allocator,
|
||||
lua,
|
||||
field_name,
|
||||
field_type,
|
||||
data,
|
||||
) catch |err| {
|
||||
const value = lua.toString(-1) catch "";
|
||||
const duped = allocator.dupe(u8, value) catch "";
|
||||
errorHandler(@typeName(field_type), field_name, duped, err);
|
||||
};
|
||||
}
|
||||
|
||||
fn setFieldInner(
|
||||
allocator: std.mem.Allocator,
|
||||
lua: *Lua,
|
||||
comptime field_name: [:0]const u8,
|
||||
field_type: type,
|
||||
data: *Struct,
|
||||
) !void {
|
||||
const type_info = @typeInfo(field_type);
|
||||
const actual_type, const is_optional = blk: {
|
||||
if (type_info == .optional) {
|
||||
break :blk .{ type_info.optional.child, true };
|
||||
}
|
||||
break :blk .{ field.type, false };
|
||||
break :blk .{ field_type, false };
|
||||
};
|
||||
// push value to top of stack
|
||||
_ = lua.getField(-1, field.name);
|
||||
_ = lua.getField(-1, field_name);
|
||||
defer lua.pop(1);
|
||||
|
||||
// handle null, i.e. undefined fields
|
||||
if (is_optional and lua.isNil(-1)) {
|
||||
@field(data, field.name) = null;
|
||||
@field(data, field_name) = null;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -210,17 +234,11 @@ pub fn LuaParser(comptime Struct: type) type {
|
||||
if (lua.isNil(-1)) return;
|
||||
const actual_type_info = @typeInfo(actual_type);
|
||||
|
||||
errdefer |err| {
|
||||
const value = lua.toString(-1) catch "";
|
||||
const duped = allocator.dupe(u8, value) catch "";
|
||||
errorHandler(@typeName(field.type), field.name, duped, err);
|
||||
}
|
||||
|
||||
// dispatch depending on type
|
||||
if (actual_type_info == .int and is_optional) {
|
||||
if (lua.isNumber(-1)) {
|
||||
const value = try lua.toNumber(-1);
|
||||
@field(data, field.name) = @trunc(value);
|
||||
@field(data, field_name) = @trunc(value);
|
||||
} else {
|
||||
const str = try lua.toString(-1);
|
||||
|
||||
@@ -231,13 +249,13 @@ pub fn LuaParser(comptime Struct: type) type {
|
||||
|
||||
if (iter.nextCodepoint() != null) return error.ExpectedSingleCharacter;
|
||||
|
||||
@field(data, field.name) = if (codepoint) |cp| @intCast(cp) else null;
|
||||
@field(data, field_name) = if (codepoint) |cp| @intCast(cp) else null;
|
||||
}
|
||||
// non null integer
|
||||
} else if (actual_type_info == .int) {
|
||||
if (lua.isNumber(-1)) {
|
||||
const value = try lua.toNumber(-1);
|
||||
@field(data, field.name) = @trunc(value);
|
||||
@field(data, field_name) = @trunc(value);
|
||||
} else {
|
||||
const str = try lua.toString(-1);
|
||||
|
||||
@@ -248,27 +266,27 @@ pub fn LuaParser(comptime Struct: type) type {
|
||||
|
||||
if (iter.nextCodepoint() != null) return error.ExpectedSingleCharacter;
|
||||
|
||||
@field(data, field.name) = @intCast(codepoint);
|
||||
@field(data, field_name) = @intCast(codepoint);
|
||||
}
|
||||
} else if (actual_type_info == .float) { // all floats
|
||||
const value = try lua.toNumber(-1);
|
||||
@field(data, field.name) = @floatCast(value);
|
||||
@field(data, field_name) = @floatCast(value);
|
||||
} else if (actual_type_info == .bool) {
|
||||
if (!lua.isBoolean(-1)) return error.ExpectedBoolean;
|
||||
const value = lua.toBoolean(-1);
|
||||
@field(data, field.name) = value;
|
||||
@field(data, field_name) = value;
|
||||
} else if (actual_type == []const u8) {
|
||||
const value = try lua.toString(-1);
|
||||
const duped = try allocator.dupe(u8, value);
|
||||
@field(data, field.name) = duped;
|
||||
@field(data, field_name) = duped;
|
||||
} else if (actual_type == [:0]const u8) {
|
||||
const value = try lua.toString(-1);
|
||||
const duped = try allocator.dupeSentinel(u8, value, 0);
|
||||
@field(data, field.name) = duped;
|
||||
@field(data, field_name) = duped;
|
||||
} else if (actual_type_info == .@"enum") {
|
||||
const value = try lua.toString(-1);
|
||||
const variant = std.meta.stringToEnum(actual_type, value) orelse return error.InvalidVariant;
|
||||
@field(data, field.name) = variant;
|
||||
@field(data, field_name) = variant;
|
||||
} else unreachable;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user