Skip to content

platform

This package provides a unified abstraction layer for platform-specific functions. It exposes a single, agnostic API that handles the differences between desktop and web environments.

Features:


loadBytes :: proc (key: string, allocator := context.allocator) -> (data: []byte, success: bool)

Loads raw bytes from persistent storage.


loadStruct :: proc (key: string, value: ^$T) -> (success: bool)

Loads a struct from persistent storage. Returns false if the key doesn’t exist or data is corrupted.


read_entire_file :: proc (
name: string,
allocator := context.allocator,
loc := #caller_location,
) -> (
data: []byte,
success: bool,
)

Reads an entire file into memory.

Platform-agnostic wrapper.

  • Web: Reads from the Emscripten Virtual File System.
  • Desktop: Reads directly from the disk.

saveBytes :: proc (key: string, data: []byte) -> (success: bool)

Saves raw bytes to persistent storage.


saveStruct :: proc (key: string, value: ^$T) -> (success: bool)

Serializes and saves a struct to persistent storage.

  • Desktop: Saves to saves directory as a binary file. (by default)
  • Web: Saves to LocalStorage (Base64 encoded string).

write_entire_file :: proc (name: string, data: []byte, truncate := true) -> (success: bool)

Writes a byte slice to a file.

Platform-agnostic wrapper.

  • Web: Writes to the Emscripten Virtual File System (non-persistent between sessions).
  • Desktop: Writes directly to the disk.