Modules

Assets

moduleSource
macOSLinuxWindows

#import "Extensions/Assets";

Load a file a program ships with (a texture, a sound, a level) by a relative path, from disk natively and over fetch() in the browser playground. A jaic extension, not official Jai. See docs/extensions/assets.md.

ExampleOpen in playground ↗
#import "Extensions/Assets";

bytes, ok := load_asset("assets/texture.png");
defer array_free(bytes);
Show moreShow less

Natively the path is tried as given (from the working directory), then next to the executable. In the browser the page answers jai_asset_fetch by fetching the path relative to the asset base URL it was set up with; without that host function (a page with no asset base, a WASI command) the path is read from the program's file system instead. The bytes are allocated with context.allocator.