The standard librarySlide 55 of 86
55assetThe standard library

Where a program is

hive.file also tells a program where it is. Each answer is an absolute path with / between its parts on every platform, a form every call in the module accepts, Windows included:

  • workingDirectory() is the folder relative paths are read from; under hive run, the entrypoint's.
  • home() is the user's home folder.
  • executable() is the running program's own file — under hive run, the copy the compiler built.
  • isDir(path) is whether a path is a folder, where exists says yes to both.

The first three answer with a Result<Str, hive.file.FileError>, NotFound where the system cannot say.

A program can also carry files of its own. When a program reads from an assets/ folder beside its entrypoint, the folder is built into the executable, and hive.file.asset(path) reads a file back by its path under assets/ — so a program copied anywhere, with nothing beside it, still has them. A path the build put nothing at is NotFound, as is every path in a program built with no assets/ folder. Files whose names start with . or _ are left out.

Where it is running
proc main(): void {
	if hive.file.workingDirectory() is Result.Ok(here) {
		echo "running in {here}"
	}
	if hive.file.home() is Result.Ok(home) {
		echo "home is {home}"
	}
	if hive.file.executable() is Result.Ok(me) {
		echo "this program is {me}"
	}
	echo hive.file.isDir(".")
}
A file it carries
proc main(): void {
	// A file at assets/notes.txt, beside this one, is built into the program,
	// and read from there wherever the program is copied to.
	read := hive.file.asset("notes.txt")
	if read is Result.Ok(notes) {
		echo notes
	} else if read is Result.Error(why) {
		echo why.message
	}
}