Merge pull request #179 from rpkak/allow-custom-dispatch-types

Allow custom Dispatch structs
This commit is contained in:
Robin Voetter
2025-03-31 21:27:53 +02:00
committed by GitHub

View File

@@ -1440,12 +1440,13 @@ fn Renderer(comptime WriterType: type) type {
const name = dispatch_type.name(); const name = dispatch_type.name();
try self.writer.print( try self.writer.print(
\\pub const {0s}Wrapper = struct {{ \\pub const {0s}Wrapper = {0s}WrapperWithCustomDispatch({0s}Dispatch);
\\ const Self = @This(); \\pub fn {0s}WrapperWithCustomDispatch(DispatchType: type) type {{
\\ pub const Dispatch = {0s}Dispatch; \\ return struct {{
\\ \\ const Self = @This();
\\ dispatch: Dispatch, \\ pub const Dispatch = DispatchType;
\\ \\
\\ dispatch: Dispatch,
\\ \\
, .{name}); , .{name});
@@ -1473,7 +1474,7 @@ fn Renderer(comptime WriterType: type) type {
} }
} }
try self.writer.writeAll("};\n"); try self.writer.writeAll("};}\n");
} }
fn renderWrapperLoader(self: *Self, dispatch_type: CommandDispatchType) !void { fn renderWrapperLoader(self: *Self, dispatch_type: CommandDispatchType) !void {
@@ -1520,11 +1521,13 @@ fn Renderer(comptime WriterType: type) type {
const loader_name = dispatch_type.name(); const loader_name = dispatch_type.name();
try self.writer.print( try self.writer.print(
\\pub const {0s}Proxy = struct {{ \\pub const {0s}Proxy = {0s}ProxyWithCustomDispatch({1s}Dispatch);
\\ const Self = @This(); \\pub fn {0s}ProxyWithCustomDispatch(DispatchType: type) type {{
\\ pub const Wrapper = {1s}Wrapper; \\ return struct {{
\\ const Self = @This();
\\ pub const Wrapper = {1s}WrapperWithCustomDispatch(DispatchType);
\\ \\
\\ handle: {0s}, \\ handle: {0s},
// Note: This is a pointer because in the past there were some performance // Note: This is a pointer because in the past there were some performance
// issues with putting an object and vtable in the same structure. This also // issues with putting an object and vtable in the same structure. This also
// affected std.mem.Allocator, which is why its like that too. // affected std.mem.Allocator, which is why its like that too.
@@ -1571,8 +1574,8 @@ fn Renderer(comptime WriterType: type) type {
} }
try self.writer.writeAll( try self.writer.writeAll(
\\}; \\ };
\\ \\}
); );
} }