diff --git a/engine/src/core/winlib.zig b/engine/src/core/winlib.zig index e39b02e..b7e2118 100644 --- a/engine/src/core/winlib.zig +++ b/engine/src/core/winlib.zig @@ -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)), diff --git a/engine/src/main.zig b/engine/src/main.zig index 14487f8..9d80e2d 100644 --- a/engine/src/main.zig +++ b/engine/src/main.zig @@ -184,18 +184,17 @@ fn loadPod(args: []const u8) i32 { const entrypointFn = *const fn (_core: *core.core_api) callconv(.c) i32; - 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!", .{}); - } - } 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!", .{}); + const lib = blk: { + if (builtin.os.tag == .windows) { + break :blk core.WinLib.open(fullPath) catch return -1; + } else { + 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;