cleaner implementation

This commit is contained in:
peterino2 2026-11-24 22:12:53 -08:00
parent 9546d84b24
commit 680732230f
2 changed files with 11 additions and 12 deletions

View File

@ -14,7 +14,7 @@ pub fn open(path: []const u8) !@This() {
return .{ .handle = handle };
}
pub fn lookup(self: *@This(), comptime T: type, name: [:0]const u8) ?T {
pub fn lookup(self: @This(), comptime T: type, name: [:0]const u8) ?T {
var addr: windows.PVOID = undefined;
switch (windows.ntdll.LdrGetProcedureAddress(self.handle, &.init(name), 0, &addr)) {
.SUCCESS => return @ptrCast(@alignCast(addr)),

View File

@ -184,19 +184,18 @@ fn loadPod(args: []const u8) i32 {
const entrypointFn = *const fn (_core: *core.core_api) callconv(.c) i32;
const lib = blk: {
if (builtin.os.tag == .windows) {
var lib = core.WinLib.open(fullPath) catch return -1;
if (lib.lookup(entrypointFn, "entrypoint")) |func| {
if (func(&core.gApi) == 0)
println("module load success!", .{});
}
break :blk core.WinLib.open(fullPath) catch return -1;
} else {
var lib = std.DynLib.open(fullPath) catch return -1;
break :blk std.DynLib.open(fullPath) catch return -1;
}
};
if (lib.lookup(entrypointFn, "entrypoint")) |func| {
if (func(&core.gApi) == 0)
println("module load success!", .{});
}
}
return 0;
}