2

I have a module foo.zig which is useful but I want to augment it with more functions, without modifying it, so I created foo-wrapper.zig that has one or two more functions, and foo.zig has dozens of functions.

How do I re-export (with pub or something) all functions from foo.zig to all consumers of foo-wrapper.zig?

1 Answer 1

5

just declare the function name in foo-wrapper.zig and add the pub keyword.


foo.zig

pub fn hello() void {
 std.debug.print("Hello", .{});
}

foo-wrapper.zig

const foo = @import("foo.zig");
pub const hello = foo.hello;
// or do
pub usingnamespace @import("foo.zig");

pub fn helloWorld() void {
 hello();
 std.debug.print(" World", .{});
}

main.zig

const foo_wrapper = @import("foo-wrapper.zig");

pub fn main() void {
  foo_wrapper.helloWorld();
  foo_wrapper.hello();
}
Sign up to request clarification or add additional context in comments.

1 Comment

pub const hello = foo.hello; did it! Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.