### World setup and stepping example Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Example of creating a world, a ground body, a dynamic crate, stepping 90 times at 60 Hz with 4 substeps, and printing the crate's y position. The crate rests on the ground at about 0.5. ```goose let world = physics::create_world(); let ground = physics::create_body(world, physics::BodyDef { position: float3 { 0.0, -1.0, 0.0 } }); physics::create_box_shape(ground, physics::ShapeDef {}, float3 { 20.0, 1.0, 20.0 }); let crate = physics::create_body(world, physics::BodyDef { body_type: physics::DYNAMIC, position: float3 { 0.0, 4.0, 0.0 } }); physics::create_box_shape(crate, physics::ShapeDef {}, float3 { 0.5, 0.5, 0.5 }); for i in 90 { physics::step(world, 1.0 / 60.0, 4); } print(physics::position(crate).y); // resting on the ground: about 0.5 physics::destroy(world); ``` -------------------------------- ### Install prebuilt extension with code --install-extension Source: https://github.com/aardappel/goose/blob/master/vscode/README.md Installs the prebuilt goose-language.vsix from a checkout. No Python, Node.js, or npm is required for installation; compiler checks and running programs still need the Goose compiler. ```sh code --install-extension vscode/goose-language.vsix ``` -------------------------------- ### Install VS Code extension Source: https://github.com/aardappel/goose/blob/master/README.md Installs the VS Code extension for syntax highlighting, language server, and JIT runs. ```bash code --install-extension vscode/goose-language.vsix ``` -------------------------------- ### Heap usage example Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md A `[>..<]` is the natural heap and queue container; a limited `[..k]` field works as well. This example pushes values and pops the smallest. ```goose var q: i64[>..<] = []; q.heap_push(5); q.heap_push(1); let smallest = q.heap_pop(); ``` -------------------------------- ### Generate the parser with build.py Source: https://github.com/aardappel/goose/blob/master/tree-sitter/README.md Run from the tree-sitter directory. The first command generates the parser; the second also runs the corpus and parses every .goose file. Node.js is the only requirement; build.py installs the pinned tree-sitter CLI into node_modules/ on first use. ```shell python tree-sitter/build.py # generate the parser ``` ```shell python tree-sitter/build.py --check # also run the corpus and parse every .goose file ``` -------------------------------- ### base64 encode and decode usage example Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Shows encoding the string "foobar" to "Zm9vYmFy" and decoding it back. `decode` returns false on invalid input, so the example aborts if decoding fails. ```goose var text: u8[>..] = []; base64::encode(text, "foobar"); // "Zm9vYmFy" var bytes: u8[>..] = []; if !base64::decode(bytes, text) { abort("not base64"); } ``` -------------------------------- ### Goose output of order book example Source: https://github.com/aardappel/goose/blob/master/docs/tutorial.md Output of the previous order book example: alice owes 4498 cents over 2 items. ```text alice owes 4498 cents over 2 items ``` -------------------------------- ### Output for serialization and tamper examples Source: https://github.com/aardappel/goose/blob/master/docs/tutorial.md Expected output for the two preceding Goose examples: a successful load and a rejected tampered image. ```text loaded true, 9 nodes, 'fox' = 4 accepted: false, nodes 0 ``` -------------------------------- ### Goose reusable pool output for linked list example Source: https://github.com/aardappel/goose/blob/master/docs/tutorial.md Shows the output of running the linked list example through the reusable pool: 6 slots used, evens removed, and two more elements allocated from the freelist. ```text built: 10 20 30 40 50 (6 slots) evens removed: 10 30 50 (6 slots) two more, both from the freelist: 10 30 50 7 8 (6 slots) ``` -------------------------------- ### starts_with(xs: T[:], p: T[:]) -> bool Source: https://github.com/aardappel/goose/blob/master/docs/design/stdlib_design.md Returns true if the slice starts with the prefix p. ```APIDOC ## starts_with(xs: T[:], p: T[:]) -> bool ### Description Returns true if the slice starts with the prefix p. ### Function Signature `fn starts_with(xs: T[:], p: T[:]) -> bool` ### Parameters - **xs** (T[:]) - Required - The slice to check. - **p** (T[:]) - Required - The prefix to check for. ### Returns - **bool** - True if the slice starts with p, false otherwise. ``` -------------------------------- ### Example loader error messages from gs_panic Source: https://github.com/aardappel/goose/blob/master/docs/design/dynamic_externs.md Shows the runtime error text produced when a library cannot be loaded or a symbol is missing. The first line reports a failed dlopen, the second a missing symbol. ```text cannot load SDL2 (libSDL2.so): libSDL2.so: cannot open shared object file: No such file or directory SDL2 (libSDL2.so) has no symbol SDL_Foo ``` -------------------------------- ### start_recording Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Starts recording the world's state into the given recording. The recording continues until `stop_recording` is called. ```APIDOC ## [FUNCTION] start_recording ### Description Starts recording the world's state into the given recording. The recording continues until `stop_recording` is called. ### Signature `fn start_recording(w: World, r: Recording)` ### Parameters - **w** (World) - Required - The world to record. - **r** (Recording) - Required - The recording to write to. ``` -------------------------------- ### Loop forms: for, while, and loop Source: https://github.com/aardappel/goose/blob/master/docs/tutorial.md Loops are `for x in range_or_array`, `while`, and `loop`. The examples show range iteration, explicit type annotations, copying vs. references, and index iteration. ```goose for i in 3 { } // 0, 1, 2 for i in 10..13 { } // 10, 11, 12 for i: i32 in 0..n { } // i is an i32; n must widen to one for i: u8 in 0..256 { } // every u8 for x in xs { } // copies, for fixed-size elements for &x in xs { x *= 2; } // references: the mutation form for x, i in xs { } // with the index ``` -------------------------------- ### Run test suite and samples Source: https://github.com/aardappel/goose/blob/master/README.md Runs the test suite and samples on Windows, macOS, and Linux. ```bash python test/run_tests.py python samples/run_samples.py ``` -------------------------------- ### Neovim 0.10 LSP configuration for Goose Source: https://github.com/aardappel/goose/blob/master/docs/editors.md Start the Goose language server in Neovim 0.10 using a FileType autocmd. This alternative setup is required for Neovim 0.10, which lacks vim.lsp.config. ```lua vim.filetype.add({ extension = { goose = 'goose' } }) vim.api.nvim_create_autocmd('FileType', { pattern = 'goose', callback = function(ev) vim.lsp.start({ name = 'goose', cmd = { 'goose', 'lsp' }, root_dir = vim.fs.root(ev.buf, { '.git' }) }) end, }) ``` -------------------------------- ### goose_init(argc, argv) Source: https://github.com/aardappel/goose/blob/master/docs/goose_spec.md Initializes the runtime and globals, then runs the Goose `fn main()` if present. Must be called by a C host before any exported function. A second call does nothing. ```APIDOC ## [FUNCTION] goose_init(argc, argv) ### Description Initializes the runtime and globals, then runs the Goose `fn main()` if present. Must be called by a C host before any exported function. A second call does nothing. ### Method FUNCTION ### Endpoint goose_init(argc, argv) ### Parameters #### Parameters - **argc** (int) - Required - Argument count passed to the program - **argv** (char**) - Required - Argument vector passed to the program ### Request Example ```c goose_init(argc, argv); ``` ### Response #### Success Response (200) No return value. ``` -------------------------------- ### Parsing and accessing a JSON document Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Example of parsing text into a document tree, guarding against errors, and accessing nested members. Uses member and as_i64 to get a window width, and each to iterate over items. Accessors return a bool indicating success. ```goose var doc: json::Node[>..] = []; var decoded: u8[>..] = []; let root, err = json::parse(text, doc, decoded); guard root else { abort(err); } let w, ok = json::as_i64(json::member(json::member(root, "window"), "width")); let items = json::member(root, "items"); if items { json::each(items) { item => let name, named = json::as_string(json::member(item, "name")); if named { print(name); } }; } ``` -------------------------------- ### menubar_begin Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Begins a menu bar. Must be the first in its window. ```APIDOC ## menubar_begin ### Description Begins a menu bar. Must be the first in its window. ### Parameters - `c` (context) - Required - The UI context. ``` -------------------------------- ### Struct literals with defaults and globals Source: https://github.com/aardappel/goose/blob/master/docs/tutorial.md A struct literal names its fields or lists them in order, and may leave out those that declare a default. Ending it in `..` leaves out any field: one without a declared default gets its type's own (zero, an empty array or string, null). Globals are declared like locals, and a `var` global given only a type starts out the same way. ```goose struct Unit { kind: i32, hp: i32 = 100, x: f32, y: f32, name: u8[] } let scout = Unit { kind: 2, x: 1.5, .. }; // hp 100, y 0, name "" var selected: Unit; // kind 0, hp 100, x 0, y 0, name "" var log: u8[][>..]; // empty ``` -------------------------------- ### Contained worker with thread_spawn_contained and thread_wait(id, msg) Source: https://github.com/aardappel/goose/blob/master/docs/reference.md A supervisor starts a contained worker with thread_spawn_contained and retries while thread_wait returns false. The first thread_wait(id, msg) appends the worker's abort message (with source location) to msg; later waits get no message. A failed check or abort in a contained worker ends only that worker. ```goose thread_fn serve(attempt: i64) { assert(attempt >= 2); // a bug the first two hit print("attempt ", attempt, " served"); } fn main() { var attempt = 0; var why: u8[>..] = []; while !thread_wait(thread_spawn_contained(serve, attempt), why) { print("attempt ", attempt, " failed: ", why); why.clear(); attempt++; } } ``` -------------------------------- ### In-place construction examples (push, filter, record building) Source: https://github.com/aardappel/goose/blob/master/README.md Demonstrates the copy-free construction guarantee: values are built directly into their final location. `str` formats into a new array element, `filter` builds the result directly into `evens`, and `push` constructs a record with nested parsing directly into the array. ```goose words.push(str("word", i)); // formatted straight into the new element let evens = xs.filter() { it % 2 == 0 }; // built straight into `evens`: no temporary book.push(Order { id: 1001, customer: "alice", items: parse_items("SKU-441:2:1999;SKU-7:1:500") }); ``` -------------------------------- ### ffi usage: SDL_Init and SDL_GetError Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Binds SDL2 functions and uses ffi::cstr to read the error string returned by SDL_GetError. The example aborts with a formatted message when SDL_Init fails. ```goose import ffi; extern "SDL2" { fn SDL_Init(flags: u32) -> i32; fn SDL_GetError() -> u64; } if SDL_Init(0x20) < 0 { abort(str("SDL: ", ffi::cstr(SDL_GetError()))); } ``` -------------------------------- ### Array transforming functions: map, filter, fold, sum, concat Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Declares higher-order functions for transforming arrays. map returns a new array of the block's result type, filter returns a new array of matching elements, fold accumulates with an initial value, sum starts from default(), and concat joins two slices. The block syntax is shown in the usage example. ```goose fn map(xs: T[:]) // -> U[>..], U the block's result type fn filter(xs: T[:]) -> T[>..] fn fold(xs: T[:], acc: A) -> A // acc = F(acc, x) fn sum(xs: T[:]) -> T // from default() fn concat(a: T[:], b: T[:]) -> T[>..] ``` -------------------------------- ### compare.py commands for build, check, run, and ab Source: https://github.com/aardappel/goose/blob/master/bench/kostya2/README.md Commands to build, check, run, and compare benchmarks using compare.py. Requires clang, cargo, and git; fetches C libraries. Use --reps to set repetitions, --only to filter tests, --langs to select languages, and --build-dir to change build directory. ```bash python3 bench/kostya2/compare.py build # Goose, C, C++ and Rust python3 bench/kostya2/compare.py check # every output, once python3 bench/kostya2/compare.py run --reps 5 # the tables above python3 bench/kostya2/compare.py run --only json --langs goose,rust python3 bench/kostya2/compare.py ab bench.b old/bf new/bf --reps 10 ``` -------------------------------- ### input_begin(c) Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Begins a new input frame. This should be called before any input functions for the frame. ```APIDOC ## input_begin(c) ### Description Begins a new input frame. This should be called before any input functions for the frame. ### Method Function ### Signature `fn input_begin(c)` ### Parameters - **c** (Context) - Required - The context. ``` -------------------------------- ### String formatting and parsing usage Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Plain rendering of scalars and strings is the builtin format/str/print; these add control and parsing. This example formats an integer in hex with padding, splits lines, parses an integer, and extracts words. ```goose var line: u8[>..] = []; format(line, "x="); format_int(line, x, 16, 8, '0'); each_split(text, '\n') { handle(trim(it)); }; let n, ok = parse_int(trim(field)); let cmd = words(input); // "take the sword": ["take", "the", "sword"] if cmd.len > 1 && cmd[0] == "take" { take(cmd[cmd.len - 1]); } ``` -------------------------------- ### UI window with slider, checkbox, and button Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Immediate-mode UI example: creates a context, opens a window, adds a slider, checkbox, and button, then renders. The button returns true on the clicked frame, checkbox flips the given bool, slider moves the f32. Must call ui::end after ui::begin even if begin returns false. ```goose guard gfx::open("sound", 400, 300) else { abort(str("gfx: ", gfx::error())); } let ctx = ui::create(13.0); var volume: f32 = 0.5; var muted = false; while gfx::frame() { ui::input_from_gfx(ctx); if ui::begin(ctx, "Sound", ui::rect(20, 20, 220, 130), ui::WINDOW_TITLE | ui::WINDOW_MOVABLE) { ui::layout_row_dynamic(ctx, 24.0, 1); ui::slider_float(ctx, 0.0, volume, 1.0, 0.05); ui::checkbox_label(ctx, "Muted", muted); if ui::button_label(ctx, "Reset") { volume = 0.5; } } ui::end(ctx); gfx::begin_screen(float4 { 0.1, 0.1, 0.1, 1.0 }); gfx::end_pass(); ui::render(ctx); } ui::destroy(ctx); ``` -------------------------------- ### ui::begin Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Begins a UI window. Returns true if the window is visible and should be drawn into. Must be paired with ui::end. ```APIDOC ## ui::begin ### Description Starts a UI window with the given title, bounds, and flags. Returns true if the window is open and should be drawn. ### Signature `ui::begin(ctx: ui::Context, title: const u8[:], bounds: ui::Rect, flags: u32) -> bool` ### Parameters - **ctx** (ui::Context) - Required - The UI context. - **title** (const u8[:]) - Required - Window title. - **bounds** (ui::Rect) - Required - Window rectangle. - **flags** (u32) - Required - Window flags (e.g., `ui::WINDOW_NO_INPUT`, `ui::WINDOW_NO_SCROLLBAR`). ### Returns - **bool** - True if the window is visible and should be drawn. ``` -------------------------------- ### audio::open(sample_rate = 48000) -> bool Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Opens the default output device with stereo output. Returns true on success, false on failure. ```APIDOC ## audio::open(sample_rate = 48000) -> bool ### Description Opens the default output device with stereo output. Returns true on success, false on failure. ### Method Function ### Signature `open(sample_rate = 48000) -> bool` ### Parameters - **sample_rate** (integer) - Optional - Default 48000. Sample rate for the output device. ### Return Value - **bool** - True if the device opened successfully, false otherwise. ``` -------------------------------- ### Equivalent constructor after const for expansion Source: https://github.com/aardappel/goose/blob/master/docs/design/const_for.md Shows the resulting constructor for `struct Point { x: i64, y: i64 }` after the `const for` expansion in the previous example. Each field is assigned the result of calling `F` with the field name and the corresponding value. ```goose Point { x: F("x", value.x), y: F("y", value.y), } ``` -------------------------------- ### contextual_begin Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Begins a contextual menu. Returns true if the menu is open. ```APIDOC ## contextual_begin ### Description Begins a contextual menu. Returns true if the menu is open. ### Parameters - `c` (context) - Required - The UI context. - `flags` (i64) - Required - Flags for the menu. - `size` (float2) - Required - The size of the menu. - `trigger_bounds` (Rect) - Required - The bounds that trigger the menu. ### Returns - `bool` - True if the menu is open. ``` -------------------------------- ### Output of export fn example Source: https://github.com/aardappel/goose/blob/master/docs/reference.md Expected output from running the export fn example: prints the string result and the sum 42. ```text Hello, world! 42 ``` -------------------------------- ### ui::begin Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Begins a new UI window. Returns true if the window is open and should be drawn. Must be paired with a matching ui::end call. ```APIDOC ## ui::begin ### Description Begins a new UI window. Returns true if the window is open and should be drawn. Must be paired with a matching ui::end call. ### Method Function ### Signature `ui::begin(ctx: context, title: string, rect: rect, flags: u32) -> bool` ### Parameters - **ctx** (context) - Required - The UI context. - **title** (string) - Required - The title of the window. - **rect** (rect) - Required - The position and size of the window. - **flags** (u32) - Required - Window flags (e.g., `ui::WINDOW_TITLE`, `ui::WINDOW_MOVABLE`). ### Returns - **bool** - True if the window is open and should be drawn. ### Example ```goose if ui::begin(ctx, "Sound", ui::rect(20, 20, 220, 130), ui::WINDOW_TITLE | ui::WINDOW_MOVABLE) { // ... } ``` ``` -------------------------------- ### Output of long-distance return example Source: https://github.com/aardappel/goose/blob/master/docs/reference.md Expected output from running the `main` function in the preceding example. It shows the three reports: one success and two errors with line numbers. ```text loaded 2 users error: line 2: expected name,age error: line 1: bad age ``` -------------------------------- ### Type alias example Source: https://github.com/aardappel/goose/blob/master/docs/reference.md `type Name = T;` names a type; an alias is the same type, not a new one. The example shows aliases used for a scalar and a growable array of fixed-size strings. ```goose type Id = u32; type Names = u8[..16][>..]; fn main() { let a: Id = 7; let b: u32 = a; var ns: Names = []; ns.push("goose"); print(a + b, " ", ns); } ``` ```text 14 ["goose"] ``` -------------------------------- ### Build and run a Goose program with goose build Source: https://github.com/aardappel/goose/blob/master/docs/tutorial.md Compiles the whole program to C, builds it with the system C compiler, and produces an executable beside the source. The command `goose -o hello.c hello.goose` writes the C for manual building, and `goose build --dry-run hello.goose` prints the commands. ```bash goose build hello.goose && ./hello ``` -------------------------------- ### Build the documentation site with build.py Source: https://github.com/aardappel/goose/blob/master/docs/site/README.md Run this command from the repository root to build the static site into `build/site`. Requires pandoc 2.11 or later on PATH. The `--check` flag verifies all internal links and fragments, including `spec §` links, and fails on any broken link. ```bash python docs/site/build.py --out build/site --check ``` -------------------------------- ### Build and format a string with u8[>..] Source: https://github.com/aardappel/goose/blob/master/docs/tutorial.md Shows building a string with a u8[>..] builder, appending literals and formatted text, then printing length. Output: 'hello, world! 42 [16 bytes]'. ```goose var s: u8[>..] = []; s.append("hello"); s.push(','); format(s, " world! ", 6 * 7); // format appends the text of anything print(s, " [", s.len, " bytes]"); ``` ```text hello, world! 42 [16 bytes] ``` -------------------------------- ### qget() -> T Source: https://github.com/aardappel/goose/blob/master/docs/goose_spec.md Gets a value from a typed queue. ```APIDOC ## qget() -> T ### Description Gets a value from a typed queue. ### Parameters None. ### Return Value - **T** - The value retrieved from the queue. ``` -------------------------------- ### Git clone/fetch commands for tags, branches, and commit hashes Source: https://github.com/aardappel/goose/blob/master/docs/design/packages.md Commands used to fetch a package ref. Tags and branches use a shallow clone; commit hashes use git init, fetch, and checkout. Fetches land in .tmp and are renamed when complete. ```text git clone --depth 1 --branch --recurse-submodules --shallow-submodules ``` ```text git init git fetch --depth 1 origin git checkout FETCH_HEAD ``` -------------------------------- ### restitution_threshold / set_restitution_threshold Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Gets or sets the restitution threshold for a world. ```APIDOC ## restitution_threshold ### Description Returns the restitution threshold of the world. ### Function Signature ```goose fn restitution_threshold(w) -> f32 ``` ### Parameters - **w** (World) - Required - The world. ### Returns - **f32** - The restitution threshold. --- ## set_restitution_threshold ### Description Sets the restitution threshold for the world. ### Function Signature ```goose fn set_restitution_threshold(w, value: f32) ``` ### Parameters - **w** (World) - Required - The world. - **value** (f32) - Required - The new restitution threshold. ``` -------------------------------- ### begin_screen(clear: float4) -> bool Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Begins a render pass targeting the screen (default framebuffer) with the given clear color. ```APIDOC ## begin_screen(clear: float4) -> bool ### Description Begins a render pass targeting the screen (default framebuffer) with the given clear color. ### Signature `fn begin_screen(clear: float4) -> bool` ### Parameters - **clear** (float4) - Required - Clear color. ### Returns - **bool** - True if the pass began successfully. ``` -------------------------------- ### gravity / set_gravity Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Gets or sets the gravity vector for a world. ```APIDOC ## gravity ### Description Returns the current gravity vector of the world. ### Function Signature ```goose fn gravity(w) -> float3 ``` ### Parameters - **w** (World) - Required - The world. ### Returns - **float3** - The gravity vector. --- ## set_gravity ### Description Sets the gravity vector for the world. ### Function Signature ```goose fn set_gravity(w, gravity: float3) ``` ### Parameters - **w** (World) - Required - The world. - **gravity** (float3) - Required - The new gravity vector. ``` -------------------------------- ### layout_row Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Starts a row layout with custom ratios for each column. ```APIDOC ## layout_row ### Description Starts a row layout with custom ratios for each column. ### Function Signature ```goose fn layout_row(c, format: i64, height: f32, ratios: const f32[:]) ``` ### Parameters - **c** - The context. - **format** (i64) - DYNAMIC or STATIC. - **height** (f32) - The row height. - **ratios** (const f32[:]) - The column ratios. ``` -------------------------------- ### Defer with gfx::open and ui::create_from_memory Source: https://github.com/aardappel/goose/blob/master/docs/design/scope_exit_cleanup.md Shows how to use defer to ensure gfx::close() and ui::destroy() are called after opening a window and creating a UI context, even on early return. The guard checks for errors and returns if the context is invalid. ```goose guard gfx::open("Goose: a ui to-do list", 760, 520, gfx::WINDOW_RESIZABLE) else { … } defer gfx::close(); var ctx = ui::create_from_memory(ROBOTO, 16.0); guard ctx.id != 0 else { write_stderr(str("ui: ", ui::error(), "\n")); return; } defer ui::destroy(ctx); ``` -------------------------------- ### user_data / set_user_data Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Gets or sets user data associated with a world. ```APIDOC ## user_data ### Description Returns the user data associated with the world. ### Function Signature ```goose fn user_data(w) -> u64 ``` ### Parameters - **w** (World) - Required - The world. ### Returns - **u64** - The user data. --- ## set_user_data ### Description Sets user data associated with the world. ### Function Signature ```goose fn set_user_data(w, data: u64) ``` ### Parameters - **w** (World) - Required - The world. - **data** (u64) - Required - The user data to set. ``` -------------------------------- ### list_view_begin Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Begins a list view with the given id, flags, row height, and row count. Returns a ListView and a boolean indicating whether the view is visible. ```APIDOC ## list_view_begin ### Description Begins a list view with the given id, flags, row height, and row count. Returns a ListView and a boolean indicating whether the view is visible. ### Function Signature ```goose fn list_view_begin(c, id, flags, row_height: i64, row_count: i64) -> ListView, bool ``` ### Parameters - **c** - The context. - **id** - The list view id. - **flags** - List view flags. - **row_height** (i64) - The row height. - **row_count** (i64) - The number of rows. ### Return Value - **ListView** - The list view object. - **bool** - True if the view is visible. ``` -------------------------------- ### contact_recycle_distance / set_contact_recycle_distance Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Gets or sets the contact recycle distance for a world. ```APIDOC ## contact_recycle_distance ### Description Returns the contact recycle distance of the world. ### Function Signature ```goose fn contact_recycle_distance(w) -> f32 ``` ### Parameters - **w** (World) - Required - The world. ### Returns - **f32** - The contact recycle distance. --- ## set_contact_recycle_distance ### Description Sets the contact recycle distance for the world. ### Function Signature ```goose fn set_contact_recycle_distance(w, value: f32) ``` ### Parameters - **w** (World) - Required - The world. - **value** (f32) - Required - The new contact recycle distance. ``` -------------------------------- ### Generate and play a 440 Hz tone with audio::open, create_sound, play, playing Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Opens the default audio device, synthesizes a one-second 440 Hz sine tone with a linear envelope, plays it, and waits until the voice finishes plus a short tail. Requires the audio module from the gfx package; all calls must run on the main thread. The example uses TAU, sin, sleep_ms, and print from the standard library. ```goose import audio; import math; import os; fn main() { if !audio::open() { print(audio::error()); return; } var pcm: f32[>..] = []; for i in 12000 { let t = i as f64 / 48000.0; let envelope = 1.0 - i as f64 / 12000.0; pcm.push((sin(TAU * 440.0 * t) * 0.2 * envelope) as f32); } let tone = audio::create_sound(pcm); let voice = audio::play(tone); while audio::playing(voice) { sleep_ms(5); } sleep_ms(100); // Let the device finish the already mixed tail. audio::close(); } ``` -------------------------------- ### maximum_linear_speed / set_maximum_linear_speed Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Gets or sets the maximum linear speed for a world. ```APIDOC ## maximum_linear_speed ### Description Returns the maximum linear speed of the world. ### Function Signature ```goose fn maximum_linear_speed(w) -> f32 ``` ### Parameters - **w** (World) - Required - The world. ### Returns - **f32** - The maximum linear speed. --- ## set_maximum_linear_speed ### Description Sets the maximum linear speed for the world. ### Function Signature ```goose fn set_maximum_linear_speed(w, value: f32) ``` ### Parameters - **w** (World) - Required - The world. - **value** (f32) - Required - The new maximum linear speed. ``` -------------------------------- ### ui::create Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Creates a new UI context. This function initializes the UI system and returns a context handle that must be used in subsequent UI calls. ```APIDOC ## ui::create ### Description Creates a new UI context. This function initializes the UI system and returns a context handle that must be used in subsequent UI calls. ### Method Function ### Signature `ui::create(scale: f32) -> context` ### Parameters - **scale** (f32) - Required - The scaling factor for the UI. ### Returns - **context** - A handle to the newly created UI context. ### Example ```goose let ctx = ui::create(13.0); ``` ``` -------------------------------- ### hit_event_threshold / set_hit_event_threshold Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Gets or sets the hit event threshold for a world. ```APIDOC ## hit_event_threshold ### Description Returns the hit event threshold of the world. ### Function Signature ```goose fn hit_event_threshold(w) -> f32 ``` ### Parameters - **w** (World) - Required - The world. ### Returns - **f32** - The hit event threshold. --- ## set_hit_event_threshold ### Description Sets the hit event threshold for the world. ### Function Signature ```goose fn set_hit_event_threshold(w, value: f32) ``` ### Parameters - **w** (World) - Required - The world. - **value** (f32) - Required - The new hit event threshold. ``` -------------------------------- ### begin Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Begins a window with the given title, bounds, and flags. Returns false if the window is collapsed or hidden, but the corresponding end call must still be made. ```APIDOC ## begin ### Description Begins a window with the given title, bounds, and flags. Returns false if the window is collapsed or hidden, but the corresponding end call must still be made. ### Function Signature ```goose fn begin(c, title: const u8[:], bounds: Rect, flags: i64) -> bool ``` ### Parameters - **c** - The context. - **title** (const u8[:]) - The window title. - **bounds** (Rect) - The window bounds. - **flags** (i64) - WINDOW_* flags. ### Return Value - **bool** - True if the window is visible and not collapsed; false otherwise. ``` -------------------------------- ### layout_row_static Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Starts a static row layout with fixed item widths. ```APIDOC ## layout_row_static ### Description Starts a static row layout with fixed item widths. ### Function Signature ```goose fn layout_row_static(c, height: f32, item_width: i64, cols: i64) ``` ### Parameters - **c** - The context. - **height** (f32) - The row height. - **item_width** (i64) - The width of each item. - **cols** (i64) - The number of columns. ``` -------------------------------- ### tooltip_begin Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Begins a tooltip. Returns true if the tooltip is open. ```APIDOC ## tooltip_begin ### Description Begins a tooltip. Returns true if the tooltip is open. ### Parameters - `c` (context) - Required - The UI context. - `width` (f32) - Required - The width of the tooltip. ### Returns - `bool` - True if the tooltip is open. ``` -------------------------------- ### layout_row_dynamic Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Starts a dynamic row layout with equal parts of the width. ```APIDOC ## layout_row_dynamic ### Description Starts a dynamic row layout with equal parts of the width. ### Function Signature ```goose fn layout_row_dynamic(c, height: f32, cols: i64) ``` ### Parameters - **c** - The context. - **height** (f32) - The row height. - **cols** (i64) - The number of columns. ``` -------------------------------- ### Goose parse_items function and order book example Source: https://github.com/aardappel/goose/blob/master/docs/tutorial.md Shows parsing a string into Item structs and building an Order with inline items. The parse_items function returns a growable array by value at no cost, writing items directly into the order's field. The example prints the total owed by a customer. ```goose // "SKU:qty:cents;..." -> items, built straight into the field that gets them fn parse_items(field: u8[:]) -> Item[>..] { var items: Item[>..] = []; each_split(field, ';') { let p = split(it, ':'); let qty, ok1 = parse_int(p[1]); let cents, ok2 = parse_int(p[2]); assert(ok1 && ok2); items.push(Item { sku: p[0], qty: qty, cents: cents }); }; return items; } var book: Order[>..] = []; book.push(Order { id: 1001, customer: "alice", items: parse_items("SKU-441:2:1999;SKU-7:1:500") }); for o in book { var t = 0; for it in o.items { t += it.qty * it.cents; } print(o.customer, " owes ", t, " cents over ", o.items.len, " items"); } ``` -------------------------------- ### shadow_sampler() Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Creates a sampler for sampler2DShadow. ```APIDOC ## [FUNCTION] shadow_sampler() ### Description Creates a sampler for sampler2DShadow. ### Signature `fn shadow_sampler() -> Sampler` ### Returns - **Sampler** - The created shadow sampler. ``` -------------------------------- ### qget(ms) -> T, bool Source: https://github.com/aardappel/goose/blob/master/docs/goose_spec.md Gets a value from a typed queue with a timeout in milliseconds. ```APIDOC ## qget(ms) -> T, bool ### Description Gets a value from a typed queue with a timeout in milliseconds. ### Parameters - **ms** (i64) - Required - Timeout in milliseconds. ### Return Value - **T** - The value retrieved from the queue. - **bool** - True if a value was retrieved, false if timeout occurred. ``` -------------------------------- ### layout_space_begin Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Begins a space layout with a specified number of widgets. ```APIDOC ## layout_space_begin ### Description Begins a space layout with a specified number of widgets. ### Function Signature ```goose fn layout_space_begin(c, format, height, widget_count) ``` ### Parameters - **c** - The context. - **format** - The layout format. - **height** - The layout height. - **widget_count** - The number of widgets. ``` -------------------------------- ### get Source: https://github.com/aardappel/goose/blob/master/docs/design/stdlib_design.md Returns a reference to the value associated with the given key, or null if the key is not present. ```APIDOC ## get ### Description Returns a reference to the value associated with the given key, or null if the key is not present. ### Signature ```goose fn get(d: dictionary&, key: K) -> V? ``` ### Parameters - **d** (dictionary&) - Required - The dictionary to query. - **key** (K) - Required - The key to look up. ### Returns - **V?** - A reference to the value, or null if the key is not present. ``` -------------------------------- ### sum Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Returns the sum of all elements in a slice, starting from the default value of the element type. ```APIDOC ## sum ### Description Returns the sum of all elements in a slice, starting from the default value of the element type. ### Function Signature `fn sum(xs: T[:]) -> T` ### Parameters - **xs** (T[:]) - Required - The input slice. ### Returns - **T** - The sum of all elements. ### Example ```goose let total = sum(xs); ``` ``` -------------------------------- ### popup_begin Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Begins a popup window. Returns true if the popup is open. Must be followed by popup_end. ```APIDOC ## popup_begin ### Description Begins a popup window. Returns true if the popup is open. Must be followed by popup_end. ### Parameters - `c` (context) - Required - The UI context. - `type` (i64) - Required - The popup type: POPUP_STATIC or POPUP_DYNAMIC. - `title` (string) - Required - The popup title. - `flags` (i64) - Required - Flags for the popup. - `rect` (Rect) - Required - The popup rectangle. ### Returns - `bool` - True if the popup is open. ``` -------------------------------- ### fold Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Accumulates a value by applying a block to each element and an accumulator, starting with an initial accumulator. ```APIDOC ## fold ### Description Accumulates a value by applying a block to each element and an accumulator, starting with an initial accumulator. ### Function Signature `fn fold(xs: T[:], acc: A) -> A` ### Parameters - **xs** (T[:]) - Required - The input slice. - **acc** (A) - Required - The initial accumulator value. - **F** - Required - A block that takes the accumulator and an element, and returns the new accumulator. ### Returns - **A** - The final accumulator value. ### Example ```goose let total = fold(xs, 0.0) { a, x => a + x }; ``` ``` -------------------------------- ### begin_titled Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Begins a window with a separate name and title. Useful for distinguishing windows with the same title. ```APIDOC ## begin_titled ### Description Begins a window with a separate name and title. Useful for distinguishing windows with the same title. ### Function Signature ```goose fn begin_titled(c, name, title, bounds, flags) -> bool ``` ### Parameters - **c** - The context. - **name** - The window name. - **title** - The window title. - **bounds** - The window bounds. - **flags** - WINDOW_* flags. ### Return Value - **bool** - True if the window is visible and not collapsed; false otherwise. ``` -------------------------------- ### sum(xs: T[:]) -> T Source: https://github.com/aardappel/goose/blob/master/docs/design/stdlib_design.md Returns the sum of all elements in the slice. Uses fold starting from default(). ```APIDOC ## sum(xs: T[:]) -> T ### Description Returns the sum of all elements in the slice. Uses fold starting from default(). ### Function Signature `fn sum(xs: T[:]) -> T` ### Parameters - **xs** (T[:]) - Required - The slice to sum. ### Returns - **T** - The sum of the elements. ``` -------------------------------- ### Open window, render loop, and close with gfx Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Shows the standard gfx window lifecycle: open a window, loop while `frame()` returns true, draw into the screen texture with `begin_screen` and `end_pass`, then close. `open` returns false on failure, and `error()` provides the reason. ```goose guard gfx::open("demo", 1280, 720) else { abort(str("gfx: ", gfx::error())); } while gfx::frame() { gfx::begin_screen(float4 { 0.1, 0.1, 0.1, 1.0 }); // bind, uniforms, draw ... gfx::end_pass(); } gfx::close(); ``` -------------------------------- ### make_heap(xs: A&) Source: https://github.com/aardappel/goose/blob/master/docs/design/stdlib_design.md Rearranges the array into a min-heap in O(n) time. ```APIDOC ## make_heap(xs: A&) ### Description Rearranges the array into a min-heap in O(n) time. ### Method Function ### Signature `fn make_heap(xs: A&)` ### Parameters - **xs** (A&) - Required - The array to heapify. ### Behavior O(n) heapify. ``` -------------------------------- ### Build VSIX with python vscode/build_vsix.py Source: https://github.com/aardappel/goose/blob/master/vscode/README.md Rebuilds the VSIX from the repository root. Requires Python 3 and Node.js with npm (Node.js 22+ recommended). Installs locked npm dependencies, runs extension tests, bundles the extension and language client into dist/extension.js with esbuild, and writes vscode/goose-language.vsix. Use --skip-install to reuse existing node_modules. The VSIX file is tracked in Git and must be committed with extension updates. ```sh python vscode/build_vsix.py ``` -------------------------------- ### Storing references as values with Cell? Source: https://github.com/aardappel/goose/blob/master/docs/stdlib.md Shows a dictionary whose values are optional references (Cell?) into a pool. insert stores the reference, get returns the stored reference itself, and the reference remains valid across subsequent mutations because it points at the pointee, not into the slot array. get returns null for a null value as for an absent key; contains distinguishes them. ```goose var owner = dictionary {}; owner.insert(7, cells[3]); let c = owner.get(7); owner.insert(7, cells[4]); // cells[3] is unchanged, and c still refers to it if c { c.v += 1; } ```