cleaner implementation
This commit is contained in:
parent
9546d84b24
commit
680732230f
|
|
@ -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)),
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue