A better alternative to @import.
Add this package to your project easily with the Zigmod package manager.
fn import(path: comptime []const u8)- Similar to the
@importbuiltin, but will try to return the value of the provideddefaultdeclaration if it exists.
- Similar to the
// test.zig
const std = @import("std");
const import = @import("import").import;
pub fn main() anyerror!void {
const result = import("./add.zig")(4, 5);
std.log.info("{}", .{result});
// info: 9
}// add.zig
pub fn default(a: i32, b: i32) i32 {
return a + b;
}MIT