unify "slot" construct

This commit is contained in:
David Allemang
2025-07-25 17:17:20 -04:00
parent f010478e59
commit 5487901d10

View File

@@ -38,40 +38,6 @@ const std = @import("std");
// Things should be done in a thread-safe manner. Signal to a module that it should unload gracefully, and the
// module signal when it can safely be unloaded.
pub fn CFunc(Function: type) type {
const Arguments = std.meta.ArgsTuple(Function);
const Return = @typeInfo(Function).@"fn".return_type.?;
return fn (*const Arguments, *Return) callconv(.c) void;
}
pub fn hook(impl: anytype) CFunc(@TypeOf(impl)) {
const Function = @TypeOf(impl);
const Arguments = std.meta.ArgsTuple(Function);
const Return = @typeInfo(Function).@"fn".return_type.?;
return struct {
pub fn cimpl(args: *const Arguments, ret: *Return) callconv(.c) void {
ret.* = @call(.auto, impl, .{args.*});
}
}.cimpl;
}
// pub fn Func(PFunction: type) type {
// const CFunction = @typeInfo(PFunction).pointer.child;
// const F = @typeInfo(CFunction).@"fn";
// const PArgs = F.params[0].type.?;
// const PRet = F.params[1].type.?;
// const Args = @typeInfo(PArgs).pointer.child;
// const Ret = @typeInfo(PRet).pointer.child;
// return fn (Args) Ret;
// }
// pub fn slot(cimpl: anytype) Func(@TypeOf(cimpl)) {
// return struct{
// pub fn impl(args: )
// }.impl;
// }
pub fn Slot(Function: type) type {
const Arguments = std.meta.ArgsTuple(Function);
const Return = @typeInfo(Function).@"fn".return_type.?;