#Correctly exposing modules.

1 messages · Page 1 of 1 (latest)

misty cypress
#

I have a hirachy like this

src/
  main.zig
  game.zig
  utility.zig
  game/
    components/
      AnimationPlayer.zig

The AnimationPlayer now needs to import a specific module from utils. How do I make utils visible to that file?

#

Correctly exposing modules.

drowsy ridge
#

You should be able to just import with a relative path (../../utility.zig)

#

Unless you are making AnimationPlayer the root of a different module, and arent able to import further up, which would feel like a weird design decision with the limited context shared

misty cypress
#

I know that relative paths work but they feel like a workaround. Is there not a way to make game.zig and util.zig top level and directly importable from anywhere?

#

AnimationPlayer is not a root of something.

drowsy ridge
#

It is not a workaround, its effectively the same as importing from a folder further down the tree

#

You could make your "top level" files a module and add them, to import like @import("utils"), but that would feel like a workaround for me, not the relative imports

It would also be extra work in the build script for no real benefit. In fact, it will likely cause the LSP (if you use one) to work worse, since extra steps would be required to "find" the modules' source

misty cypress
#

My intention was to have it similar like the stdlib.

#

All the other modules that need some other modules go through the std module to import them.

#

There are also no relative paths

#

I just want to have clean and readable imports

keen yew
misty cypress
#

I do prefer to have my imports

const module = @import("util").<whatever path mighe be here later>.<final module>

(or utils.zig instead of utils)
instead of

const module = @import("../../../../util/<whatever path>/<final module>.zig")

(I made it a bit extreme in this example, but you get the idea)

misty cypress
#

Anybody know how to do this?

keen yew
misty cypress
misty cypress
#

I give up