Seperated Structs and Tables

This allows multiple tables to use the exsact same struct, it also allows substructs to be used multiple times.
This commit is contained in:
ookami125 2025-03-23 17:53:45 -04:00
parent bb444a9755
commit 2331a29358
4 changed files with 136 additions and 102 deletions

26
src/spacetime/utils.zig Normal file
View file

@ -0,0 +1,26 @@
const std = @import("std");
pub fn getMemberDefaultType(t: type, comptime member: []const u8) type {
const field = std.meta.fields(t)[std.meta.fieldIndex(t, member).?];
return field.type;
}
pub fn getMemberDefaultValue(t: type, comptime member: []const u8) getMemberDefaultType(t, member) {
const field = std.meta.fields(t)[std.meta.fieldIndex(t, member).?];
const value = @as(*const field.type, @alignCast(@ptrCast(field.default_value))).*;
return value;
}
pub fn itoa(comptime value: anytype) [:0]const u8 {
comptime var s: []const u8 = &[_]u8{};
comptime var n = value;
if (n == 0) {
s = s ++ .{'0'};
} else {
comptime while (n != 0) {
s = s ++ .{'0' + (n % 10)};
n = n / 10;
};
}
return @ptrCast(s ++ .{0});
}