Hello guys, I am trying to create a library and want my project to be structured something like this. How should i approach this? For example I am trying to use the same package everywhere, lets say package testlib but when i try to access any of the
In Odin each folder is treated as it’s own package, therefore package name and folders must be the same.
To keep the relative structure of your project, you could use package components in test_component.odin and reference it within testlib.odin using import "components" or import "./components", and then using components.component_init() to call your procedure.
Thank you, I got it now. A bit similar to how Rust is i guess. Is this good approach of separation for odin, or something else would be better when creating a “library” ?
One more thing, if i want to call the component_init, from outside of the library can i do something like.
testlib.components.component_init()
Because I will have plenty of functions that are not in the main package testlib and would like them to be callable? If this is not allowed maybe putting everything in same package will be better?
No. Packages are not namespaces, they are just directories. A package means that “every file in this directory is part of the same package”. Sub directories are just that, a separate package, the hierarchy is only for your organisational needs.
package outsidelib
import "path/to/TestLib/components"
main :: proc() {
components.component_init()
}
That’s false. What’s after package is used in ABI and to make sure all files in a dir are part of the same package, but it is separate from the directory name, like you can’t have a package named “foo-bar” but you can have that name for the dir.
In import baz "./foo-bar" you resolve the directory name by aliasing the path used.