The standard library
Slide 55 of 85
55assetThe standard library

Where a program is

hive.file also says where the program is, each answer an absolute path with / between its parts on every platform — which every call in the module takes, 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 a Result<Str, hive.file.FileError>, NotFound where the system cannot say.

A program can also carry files of its own. An assets/ folder beside the entrypoint is built into the executable whenever the program reads from it, and hive.file.asset(path) reads a file back out 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, and so is every path in a program built with no assets/ folder. Files whose names open 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
	}
}