mirror of
https://github.com/ziglang/zig.git
synced 2026-02-15 22:09:49 +00:00
load dynamic library test: update API usage code
This commit is contained in:
parent
fd6b7b160d
commit
80882bda59
@ -144,7 +144,7 @@ pub const LinuxDynLib = struct {
|
||||
|
||||
pub fn lookup(self: *LinuxDynLib, comptime T: type, name: []const u8) ?T {
|
||||
if (self.elf_lib.lookup("", name)) |symbol| {
|
||||
return @ptrCast(T, symbol);
|
||||
return @intToPtr(T, symbol);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -9,8 +9,7 @@ pub fn main() !void {
|
||||
var lib = try std.DynLib.open(dynlib_name);
|
||||
defer lib.close();
|
||||
|
||||
const addr = lib.lookup("add") orelse return error.SymbolNotFound;
|
||||
const addFn = @intToPtr(extern fn (i32, i32) i32, addr);
|
||||
const addFn = lib.lookup(extern fn (i32, i32) i32, "add") orelse return error.SymbolNotFound;
|
||||
|
||||
const result = addFn(12, 34);
|
||||
std.debug.assert(result == 46);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user