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 }; 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; var addr: windows.PVOID = undefined;
switch (windows.ntdll.LdrGetProcedureAddress(self.handle, &.init(name), 0, &addr)) { switch (windows.ntdll.LdrGetProcedureAddress(self.handle, &.init(name), 0, &addr)) {
.SUCCESS => return @ptrCast(@alignCast(addr)), .SUCCESS => return @ptrCast(@alignCast(addr)),

View File

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