Skip to content

Request: Add BOOT callback for compiled/WASM runtimesΒ #1773

Closed

Description

@joshgoebel

Many compile languages can't have a concept "top-level" code (all the code must be in functions)... so there is no opportunity to perform start-ups tasks... having to do a manual check in TIC isn't terrible, but is kind of an ugly pattern IMHO. If we supported a init or start or boot hook or something like PICO-8 we would eliminate this problem.

For example from my Zig cartridge:

export fn TIC() void {
    if (!started) { start(); }

  // actual TIC code here
}

It could be nice if this wasn't necessary and we could instead do:

export fn BOOT() void {
  // startup code
}
export fn TIC() void {
  // per tick code
}

Activity

  1. added
    enhancement
    lang: wasm
    on Jan 1, 2022
  2. nesbox commented on Jan 2, 2022

    @nesbox
    Owner

    Ok, let's add BOOT() function.

  3. changed the title [-]Request: Add `start` callback for compiled/WASM runtimes[/-] [+]Request: Add `BOOT` callback for compiled/WASM runtimes[/+] on Jan 2, 2022
  4. paul59 commented on Jan 3, 2022

    @paul59
    Contributor

    Can we get an INIT() for regular cartridges using Lua etc?

  5. nesbox commented on Jan 3, 2022

    @nesbox
    Owner

    Can we get an INIT() for regular cartridges using Lua etc?

    Yes, the callback will work everywhere, if we add it, INIT() or BOOT() doesn't matter.

  6. paul59 commented on Jan 3, 2022

    @paul59
    Contributor

    Can we get an INIT() for regular cartridges using Lua etc?

    Yes, the callback will work everywhere, if we add it, INIT() or BOOT() doesn't matter.

    INIT() would be my preference - that's the function name used by many other 'game engines' (eg Defold, Godot, Pico, Love2d, Unreal. 'Boot' implies loading the system itself (and out of the user's control).

  7. joshgoebel commented on Jan 3, 2022

    @joshgoebel
    CollaboratorAuthor

    'Boot' implies loading the system itself

    You boot a cartridge in my thinking... I think many early systems didn't have much of an OS, so I actually think it's a nice throwback name... but also I think if many other engines use 'INIT' that would be enough of an argument for me.

    I see this as useful for, but entirely separate from the WASM work... so if someone else wanted to pick this up and run with it, that'd be fine. It's also not required for WASM, but just a "very nice to have"... so may not be something I get to myself.

  8. added
    API
    on Jan 3, 2022
  9. nesbox commented on Mar 21, 2022

    @nesbox
    Owner

    Added BOOT() callback to all the supported scripts and WASM aeffb6d

  10. self-assigned this
    on Mar 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

APIenhancementlang: wasm

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions