Added support for nested structs

This commit is contained in:
ookami125 2025-03-23 05:24:55 -04:00
parent ba5cadfb1b
commit bb444a9755
5 changed files with 296 additions and 117 deletions

3
.gitignore vendored
View file

@ -1,4 +1,3 @@
.zig-cache/ .zig-cache/
csharp-reference/ references/
rust-reference/
zig-out/ zig-out/

View file

@ -7,23 +7,30 @@ pub export fn spacetime_includes() void {
} }
pub const moduleTablesDef = .{ pub const moduleTablesDef = .{
.Person = Person, .person = Person,
}; };
pub const moduleReducersDef = .{ pub const moduleReducersDef = .{
.Init = spacetime.Reducer(Init){ .lifecycle = .Init }, .Init = spacetime.Reducer(Init){ .lifecycle = .Init },
.OnConnect = spacetime.Reducer(OnConnect){ .lifecycle = .OnConnect }, .OnConnect = spacetime.Reducer(OnConnect){ .lifecycle = .OnConnect },
.OnDisconnect = spacetime.Reducer(OnDisconnect){ .lifecycle = .OnDisconnect }, .OnDisconnect = spacetime.Reducer(OnDisconnect){ .lifecycle = .OnDisconnect },
.add = spacetime.Reducer(add){ .param_names = &[_][:0]const u8{ "name", "age", "blah" }}, .add = spacetime.Reducer(add){ .param_names = &[_][:0]const u8{ "name" }},
.say_hello = spacetime.Reducer(say_hello){}, .say_hello = spacetime.Reducer(say_hello){},
}; };
pub const DbVector2 = spacetime.Struct(.{
.name = "DbVector2",
.fields = &[_]spacetime.StructFieldDecl{
.{ .name = "x", .type = f32, },
.{ .name = "y", .type = f32 },
},
});
pub const Person = spacetime.Struct(.{ pub const Person = spacetime.Struct(.{
.name = "person", .name = "person",
.fields = &[_]spacetime.StructFieldDecl{ .fields = &[_]spacetime.StructFieldDecl{
.{ .name = "name", .type = .String, }, .{ .name = "name", .type = []const u8, },
.{ .name = "age", .type = .U32, }, .{ .name = "pos", .type = DbVector2, },
.{ .name = "blah", .type = .U64, },
}, },
}); });
@ -45,21 +52,21 @@ pub fn OnDisconnect(ctx: *spacetime.ReducerContext) void {
spacetime.print("[OnDisconnect]"); spacetime.print("[OnDisconnect]");
} }
pub fn add(ctx: *spacetime.ReducerContext, name: []const u8, age: u32, blah: u64) void { pub fn add(ctx: *spacetime.ReducerContext, name: []const u8) void {
const personTable = ctx.*.db.get(moduleTablesDef.Person); const personTable = ctx.*.db.get(moduleTablesDef.person);
personTable.insert(Person{ .name = name, .age = age, .blah = blah }); personTable.insert(Person{ .name = name, .pos = DbVector2{ .x = 10.4, .y = 20.6 } });
var buf: [128]u8 = undefined; var buf: [128]u8 = undefined;
spacetime.print(std.fmt.bufPrint(&buf, "[add] {{{s}, {}}}!", .{ name, age }) catch "[add] Error: name to long"); spacetime.print(std.fmt.bufPrint(&buf, "[add] {{{s}}}!", .{ name }) catch "[add] Error: name to long");
} }
pub fn say_hello(ctx: *spacetime.ReducerContext) void { pub fn say_hello(ctx: *spacetime.ReducerContext) void {
var personIter = ctx.*.db.get(moduleTablesDef.Person).iter(); var personIter = ctx.*.db.get(moduleTablesDef.person).iter();
while(personIter.next() catch { while(personIter.next() catch {
@panic("person Iter errored!"); @panic("person Iter errored!");
}) |person| { }) |person| {
var buffer: [512]u8 = undefined; var buffer: [512]u8 = undefined;
const msg = std.fmt.bufPrint(&buffer, "Hello, {s} (age: {})!", .{ person.name, person.age }) catch "<Unknown>"; const msg = std.fmt.bufPrint(&buffer, "Hello, {s} (pos: {{{d}, {d}}})!", .{ person.name, person.pos.x, person.pos.y }) catch "<Unknown>";
spacetime.print(msg); spacetime.print(msg);
} }
spacetime.print("Hello, World!"); spacetime.print("Hello, World!");

View file

@ -64,6 +64,13 @@ pub const RowIter = extern struct { _inner: u32, pub const INVALID = RowIter{ ._
pub extern "spacetime_10.0" fn row_iter_bsatn_advance(iter: RowIter, buffer_ptr: [*c]u8, buffer_len_ptr: *usize) i16; pub extern "spacetime_10.0" fn row_iter_bsatn_advance(iter: RowIter, buffer_ptr: [*c]u8, buffer_len_ptr: *usize) i16;
pub extern "spacetime_10.0" fn datastore_table_scan_bsatn(table_id: TableId, out: [*c]RowIter) u16; pub extern "spacetime_10.0" fn datastore_table_scan_bsatn(table_id: TableId, out: [*c]RowIter) u16;
// pub const Identity = struct {
// __identity__: u256,
// };
pub const MagicStruct = "spacetime_10.0__struct_";
pub const MagicTable = "spacetime_10.0__table_";
pub const EXHAUSTED = -1; pub const EXHAUSTED = -1;
pub const OK = 0; pub const OK = 0;
pub const NO_SUCH_ITER = 6; pub const NO_SUCH_ITER = 6;
@ -120,7 +127,7 @@ pub fn Reducer(comptime func: anytype) type {
pub const StructFieldDecl = struct { pub const StructFieldDecl = struct {
name: [:0]const u8, name: [:0]const u8,
type: AlgebraicType, type: type,
isPrimaryKey: bool = false, isPrimaryKey: bool = false,
autoInc: bool = false, autoInc: bool = false,
}; };
@ -140,7 +147,7 @@ fn spacetimeType2ZigType(t: AlgebraicType) type {
} }
pub fn Struct(comptime decl: StructDecl) type { pub fn Struct(comptime decl: StructDecl) type {
const @"spacetime_10.0__table_" = struct { const @"spacetime_10.0__struct_" = struct {
name: ?[]const u8 = decl.name, name: ?[]const u8 = decl.name,
table_type: TableType = .User, table_type: TableType = .User,
table_access: TableAccess = .Private, table_access: TableAccess = .Private,
@ -148,9 +155,9 @@ pub fn Struct(comptime decl: StructDecl) type {
var zigStructMembers: []const std.builtin.Type.StructField = &[_]std.builtin.Type.StructField{ var zigStructMembers: []const std.builtin.Type.StructField = &[_]std.builtin.Type.StructField{
std.builtin.Type.StructField{ std.builtin.Type.StructField{
.name = "spacetime_10.0__table_", .name = MagicStruct,
.type = @"spacetime_10.0__table_", .type = @"spacetime_10.0__struct_",
.default_value = @as(?*const anyopaque, &@"spacetime_10.0__table_"{}), .default_value = @as(?*const anyopaque, &@"spacetime_10.0__struct_"{}),
.is_comptime = false, .is_comptime = false,
.alignment = 0, .alignment = 0,
}, },
@ -160,7 +167,7 @@ pub fn Struct(comptime decl: StructDecl) type {
zigStructMembers = zigStructMembers ++ &[_]std.builtin.Type.StructField{ zigStructMembers = zigStructMembers ++ &[_]std.builtin.Type.StructField{
std.builtin.Type.StructField{ std.builtin.Type.StructField{
.name = field.name, .name = field.name,
.type = spacetimeType2ZigType(field.type), .type = field.type,
.default_value = null, .default_value = null,
.is_comptime = false, .is_comptime = false,
.alignment = 0, .alignment = 0,
@ -178,6 +185,17 @@ pub fn Struct(comptime decl: StructDecl) type {
}); });
} }
// pub fn Table(comptime decl: type) type {
// const @"spacetime_10.0__table_" = struct {
// name: []const u8,
// table_type: TableType = .User,
// table_access: TableAccess = .Private,
// type: decl = std.mem.zeroes(decl),
// };
// return @"spacetime_10.0__table_";
//}
pub fn readArg(allocator: std.mem.Allocator, args: BytesSource, comptime t: AlgebraicType) !spacetimeType2ZigType(t) { pub fn readArg(allocator: std.mem.Allocator, args: BytesSource, comptime t: AlgebraicType) !spacetimeType2ZigType(t) {
switch(t) { switch(t) {
.String => { .String => {
@ -209,6 +227,8 @@ pub fn zigTypeToSpacetimeType(comptime param: ?type) AlgebraicType {
[]const u8 => .{ .String = {} }, []const u8 => .{ .String = {} },
u32 => .{ .U32 = {}, }, u32 => .{ .U32 = {}, },
u64 => .{ .U64 = {}, }, u64 => .{ .U64 = {}, },
f32 => .{ .F32 = {}, },
//Identity => .{ .U256 = {}, },
else => { else => {
@compileLog(param.?); @compileLog(param.?);
@compileError("Unmatched type passed to zigTypeToSpacetimeType!"); @compileError("Unmatched type passed to zigTypeToSpacetimeType!");
@ -216,6 +236,64 @@ pub fn zigTypeToSpacetimeType(comptime param: ?type) AlgebraicType {
}; };
} }
pub fn buildTypeList(name: []const u8, default_values: type, raw_types: *[]const AlgebraicType, types: *[]const RawTypeDefV9) usize
{
var product_elements: []const ProductTypeElement = &[_]ProductTypeElement{};
inline for(@typeInfo(default_values).@"struct".fields, 0..) |table_field, i| {
if(i == 0) continue;
if(@typeInfo(table_field.type) == .@"struct" and std.meta.fieldIndex(table_field.type, MagicStruct) != null) {
const table = std.meta.fields(table_field.type)[std.meta.fieldIndex(table_field.type, MagicStruct).?];
const subname = @as(*table.type, @constCast(@alignCast(@ptrCast(table.default_value)))).*.name.?;
//_ = subname;
//@compileLog(table_field.type);
const id = buildTypeList(subname, table_field.type, raw_types, types);
product_elements = product_elements ++ &[_]ProductTypeElement{
.{
.name = table_field.name,
.algebraic_type = .{
.Ref = .{
.inner = id,
}
}
}
};
} else {
product_elements = product_elements ++ &[_]ProductTypeElement{
.{
.name = table_field.name,
.algebraic_type = zigTypeToSpacetimeType(table_field.type)
}
};
}
}
raw_types.* = raw_types.* ++ &[_]AlgebraicType{
.{
.Product = .{
.elements = product_elements,
}
},
};
types.* = types.* ++ &[_]RawTypeDefV9{
.{
.name = .{
.scope = &[_][]u8{},
.name = name
},
.ty = .{ .inner = raw_types.len-1, },
.custom_ordering = true,
}
};
return types.len-1;
}
pub fn compile(comptime moduleTables : anytype, comptime moduleReducers : anytype) !RawModuleDefV9 { pub fn compile(comptime moduleTables : anytype, comptime moduleReducers : anytype) !RawModuleDefV9 {
var def : RawModuleDefV9 = undefined; var def : RawModuleDefV9 = undefined;
_ = &def; _ = &def;
@ -227,50 +305,20 @@ pub fn compile(comptime moduleTables : anytype, comptime moduleReducers : anytyp
var types: []const RawTypeDefV9 = &[_]RawTypeDefV9{}; var types: []const RawTypeDefV9 = &[_]RawTypeDefV9{};
inline for(std.meta.fields(@TypeOf(moduleTables))) |field| { inline for(std.meta.fields(@TypeOf(moduleTables))) |field| {
//const struct_decl = @as(*const field.type, @alignCast(@ptrCast(field.default_value.?))).*;
//@compileLog(@TypeOf(struct_decl.type));
const default_values = @as(*const field.type, @alignCast(@ptrCast(field.default_value.?))).*; const default_values = @as(*const field.type, @alignCast(@ptrCast(field.default_value.?))).*;
const structInfo = blk: { const structInfo = blk: {
for(@typeInfo(default_values).@"struct".fields) |structInfoField| { for(@typeInfo(default_values).@"struct".fields) |structInfoField| {
if(std.mem.eql(u8, structInfoField.name, "spacetime_10.0__table_")) { if(std.mem.eql(u8, structInfoField.name, MagicStruct)) {
break :blk structInfoField.type{}; break :blk structInfoField.type{};
} }
} }
}; };
var product_type_ref: AlgebraicTypeRef = undefined; const product_type_ref: AlgebraicTypeRef = AlgebraicTypeRef{
{ .inner = buildTypeList(field.name, default_values, &raw_types, &types),
var product_elements: []const ProductTypeElement = &[_]ProductTypeElement{};
inline for(@typeInfo(default_values).@"struct".fields, 0..) |table_field, i| {
if(i == 0) continue;
product_elements = product_elements ++ &[_]ProductTypeElement{
.{
.name = table_field.name,
.algebraic_type = zigTypeToSpacetimeType(table_field.type)
}
}; };
}
raw_types = raw_types ++ &[_]AlgebraicType{
.{
.Product = .{
.elements = product_elements,
}
},
};
types = types ++ &[_]RawTypeDefV9{
.{
.name = .{
.scope = &[_][]u8{},
.name = field.name
},
.ty = .{ .inner = raw_types.len-1, },
.custom_ordering = true,
}
};
product_type_ref.inner = types.len-1;
}
const name: []const u8 = structInfo.name.?; const name: []const u8 = structInfo.name.?;
const table_type: TableType = structInfo.table_type; const table_type: TableType = structInfo.table_type;
@ -352,6 +400,76 @@ pub fn callReducer(comptime mdef: anytype, id: usize, args: anytype) void {
} }
} }
pub fn PrintModule(data: anytype) void {
var buf: [64]u8 = undefined;
print(std.fmt.bufPrint(&buf, "\"{s}\": {{", .{@typeName(@TypeOf(data))}) catch "<Error>");
switch(@TypeOf(data)) {
RawModuleDefV9 => {
PrintModule(data.typespace);
PrintModule(data.tables);
PrintModule(data.reducers);
PrintModule(data.types);
},
Typespace => {
for(data.types) |_type| {
PrintModule(_type);
}
},
AlgebraicType => {
switch(data) {
.Ref => PrintModule(data.Ref),
.Product => PrintModule(data.Product),
else => {},
}
},
AlgebraicTypeRef => {
PrintModule(data.inner);
},
ProductType => {
for(data.elements) |elem| {
PrintModule(elem);
}
},
ProductTypeElement => {
PrintModule(data.name);
PrintModule(data.algebraic_type);
},
[]const RawTableDefV9 => {
for(data) |elem| {
PrintModule(elem);
}
},
[]const RawTypeDefV9 => {
for(data) |elem| {
PrintModule(elem);
}
},
RawTypeDefV9 => {
PrintModule(data.name);
PrintModule(data.ty);
},
RawScopedTypeNameV9 => {
PrintModule(data.scope);
PrintModule(data.name);
},
[][]const u8 => {
for(data) |elem| {
PrintModule(elem);
}
},
[]const u8 => {
print(std.fmt.bufPrint(&buf, "\"{s}\"", .{data}) catch "<Error>");
},
u32 => {
print(std.fmt.bufPrint(&buf, "{}", .{data}) catch "<Error>");
},
else => {
print("\"...\"");
},
}
print("},");
}
const moduleTablesDef = @import("root").moduleTablesDef; const moduleTablesDef = @import("root").moduleTablesDef;
const moduleReducersDef = @import("root").moduleReducersDef; const moduleReducersDef = @import("root").moduleReducersDef;
@ -362,17 +480,24 @@ pub export fn __describe_module__(description: BytesSink) void {
var moduleDefBytes = std.ArrayList(u8).init(allocator); var moduleDefBytes = std.ArrayList(u8).init(allocator);
defer moduleDefBytes.deinit(); defer moduleDefBytes.deinit();
serialize_module(&moduleDefBytes, comptime compile(moduleTablesDef, moduleReducersDef) catch |err| { const compiledModule = comptime compile(moduleTablesDef, moduleReducersDef) catch |err| {
var buf: [1024]u8 = undefined; var buf: [1024]u8 = undefined;
const fmterr = std.fmt.bufPrint(&buf, "Error: {}", .{err}) catch { const fmterr = std.fmt.bufPrint(&buf, "Error: {}", .{err}) catch {
@compileError("ERROR2: No Space Left! Expand error buffer size!"); @compileError("ERROR2: No Space Left! Expand error buffer size!");
}; };
@compileError(fmterr); @compileError(fmterr);
}) catch { };
//PrintModule(compiledModule);
serialize_module(&moduleDefBytes, compiledModule) catch {
print("Allocator Error: Cannot continue!"); print("Allocator Error: Cannot continue!");
@panic("Allocator Error: Cannot continue!"); @panic("Allocator Error: Cannot continue!");
}; };
//var buffer: [8196]u8 = undefined;
//print(std.fmt.bufPrint(&buffer, "{any}", .{moduleDefBytes.items}) catch "Expand buffer");
write_to_sink(description, moduleDefBytes.items); write_to_sink(description, moduleDefBytes.items);
} }

View file

@ -148,10 +148,8 @@ fn serialize_table_access(array: *std.ArrayList(u8), val: TableAccess) !void {
fn serialize_product_type_element(array: *std.ArrayList(u8), val: ProductTypeElement) !void { fn serialize_product_type_element(array: *std.ArrayList(u8), val: ProductTypeElement) !void {
try array.appendSlice(&[_]u8{ 0 }); try array.appendSlice(&[_]u8{ 0 });
//if(val.name) |name| {
try array.appendSlice(&std.mem.toBytes(@as(u32, @intCast(val.name.len)))); try array.appendSlice(&std.mem.toBytes(@as(u32, @intCast(val.name.len))));
try array.appendSlice(val.name); try array.appendSlice(val.name);
//}
try serialize_algebraic_type(array, val.algebraic_type); try serialize_algebraic_type(array, val.algebraic_type);
} }
@ -168,6 +166,10 @@ fn serialize_algebraic_type(array: *std.ArrayList(u8), val: AlgebraicType) !void
try array.appendSlice(&[_]u8{@intFromEnum(val)}); try array.appendSlice(&[_]u8{@intFromEnum(val)});
try serialize_product_type(array, product); try serialize_product_type(array, product);
}, },
AlgebraicType.Ref => |ref| {
try array.appendSlice(&[_]u8{@intFromEnum(val)});
try array.appendSlice(&std.mem.toBytes(ref.inner));
},
else => try array.appendSlice(&[_]u8{@intFromEnum(val)}), else => try array.appendSlice(&[_]u8{@intFromEnum(val)}),
} }
} }

View file

@ -128,12 +128,10 @@ pub const Lifecycle = enum {
OnDisconnect, OnDisconnect,
}; };
pub fn StructSerializer(struct_type: type) fn(std.mem.Allocator, struct_type) std.mem.Allocator.Error![]u8 { fn getStructSize(data: anytype) usize {
const struct_type = @TypeOf(data);
const @"spacetime_10.0__table_" = std.meta.fields(struct_type)[std.meta.fieldIndex(struct_type, spacetime.MagicStruct).?].type;
const @"spacetime_10.0__table_" = std.meta.fields(struct_type)[std.meta.fieldIndex(struct_type, "spacetime_10.0__table_").?].type;
return struct {
pub fn serialize(allocator: std.mem.Allocator, data: struct_type) ![]u8 {
const fields = std.meta.fields(@TypeOf(data)); const fields = std.meta.fields(@TypeOf(data));
var size: usize = 0; var size: usize = 0;
inline for(fields) |field| { inline for(fields) |field| {
@ -148,14 +146,30 @@ pub fn StructSerializer(struct_type: type) fn(std.mem.Allocator, struct_type) st
u64 => { u64 => {
size += 8; size += 8;
}, },
f32 => {
size += 4;
},
@"spacetime_10.0__table_" => {}, @"spacetime_10.0__table_" => {},
else => { else => blk: {
if(@typeInfo(field.type) == .@"struct" and std.meta.fieldIndex(field.type, spacetime.MagicStruct) != null) {
size += getStructSize(@field(data, field.name));
break :blk;
}
//const subname = @as(*field.type, @constCast(@alignCast(@ptrCast(field.default_value)))).*.name.?;
@compileLog(field.type); @compileLog(field.type);
@compileError("Unsupported type in StructSerializer"); @compileError("Unsupported type in StructSerializer");
}, },
} }
} }
const mem = try allocator.alloc(u8, size);
return size;
}
fn getStructData(data: anytype, mem: []u8) []u8 {
const struct_type = @TypeOf(data);
const @"spacetime_10.0__table_" = std.meta.fields(struct_type)[std.meta.fieldIndex(struct_type, spacetime.MagicStruct).?].type;
const fields = std.meta.fields(@TypeOf(data));
var offset_mem = mem; var offset_mem = mem;
inline for(fields) |field| { inline for(fields) |field| {
switch(field.type) { switch(field.type) {
@ -175,10 +189,31 @@ pub fn StructSerializer(struct_type: type) fn(std.mem.Allocator, struct_type) st
std.mem.bytesAsValue(u64, offset_mem[0..4]).* = val; std.mem.bytesAsValue(u64, offset_mem[0..4]).* = val;
offset_mem = offset_mem[8..]; offset_mem = offset_mem[8..];
}, },
f32 => {
const val = @field(data, field.name);
std.mem.bytesAsValue(f32, offset_mem[0..4]).* = val;
offset_mem = offset_mem[4..];
},
@"spacetime_10.0__table_" => {}, @"spacetime_10.0__table_" => {},
else => @compileError("Unsupported type in StructSerializer"), else => blk: {
if(@typeInfo(field.type) == .@"struct" and std.meta.fieldIndex(field.type, spacetime.MagicStruct) != null) {
offset_mem = getStructData(@field(data, field.name), offset_mem);
break :blk;
}
@compileLog(field.type);
@compileError("Unsupported type in StructSerializer");
},
} }
} }
return offset_mem;
}
pub fn StructSerializer(struct_type: type) fn(std.mem.Allocator, struct_type) std.mem.Allocator.Error![]u8 {
return struct {
pub fn serialize(allocator: std.mem.Allocator, data: struct_type) ![]u8 {
const size: usize = getStructSize(data);
const mem = try allocator.alloc(u8, size);
_ = getStructData(data, mem);
return mem; return mem;
} }
}.serialize; }.serialize;
@ -186,7 +221,7 @@ pub fn StructSerializer(struct_type: type) fn(std.mem.Allocator, struct_type) st
pub fn StructDeserializer(struct_type: type) fn(allocator: std.mem.Allocator, *[]const u8) std.mem.Allocator.Error!*struct_type { pub fn StructDeserializer(struct_type: type) fn(allocator: std.mem.Allocator, *[]const u8) std.mem.Allocator.Error!*struct_type {
const @"spacetime_10.0__table_" = std.meta.fields(struct_type)[std.meta.fieldIndex(struct_type, "spacetime_10.0__table_").?].type; const @"spacetime_10.0__table_" = std.meta.fields(struct_type)[std.meta.fieldIndex(struct_type, spacetime.MagicStruct).?].type;
return struct { return struct {
pub fn deserialize(allocator: std.mem.Allocator, data: *[]const u8) std.mem.Allocator.Error!*struct_type { pub fn deserialize(allocator: std.mem.Allocator, data: *[]const u8) std.mem.Allocator.Error!*struct_type {
@ -209,8 +244,19 @@ pub fn StructDeserializer(struct_type: type) fn(allocator: std.mem.Allocator, *[
@field(ret.*, field.name) = std.mem.bytesAsValue(u64, offset_mem[0..4]).*; @field(ret.*, field.name) = std.mem.bytesAsValue(u64, offset_mem[0..4]).*;
offset_mem = offset_mem[8..]; offset_mem = offset_mem[8..];
}, },
f32 => {
@field(ret.*, field.name) = std.mem.bytesAsValue(f32, offset_mem[0..4]).*;
offset_mem = offset_mem[4..];
},
@"spacetime_10.0__table_" => {}, @"spacetime_10.0__table_" => {},
else => @compileError("Unsupported type in StructDeserializer"), else => blk: {
if(@typeInfo(field.type) == .@"struct" and std.meta.fieldIndex(field.type, spacetime.MagicStruct) != null) {
@field(ret.*, field.name) = (try StructDeserializer(field.type)(allocator, &offset_mem)).*;
break :blk;
}
@compileLog(field.type);
@compileError("Unsupported type in StructDeserializer");
},
} }
} }
data.* = offset_mem; data.* = offset_mem;
@ -222,7 +268,7 @@ pub fn StructDeserializer(struct_type: type) fn(allocator: std.mem.Allocator, *[
pub fn Table2Struct(comptime table_type: type) type { pub fn Table2Struct(comptime table_type: type) type {
const fields = std.meta.fields(table_type); const fields = std.meta.fields(table_type);
const field = fields[std.meta.fieldIndex(table_type, "spacetime_10.0__table_").?]; const field = fields[std.meta.fieldIndex(table_type, spacetime.MagicStruct).?];
const struct_type = @as(*const field.type, @alignCast(@ptrCast(field.default_value.?))).*; const struct_type = @as(*const field.type, @alignCast(@ptrCast(field.default_value.?))).*;
const table_name: []const u8 = struct_type.name.?; const table_name: []const u8 = struct_type.name.?;