ui_access

source of std::web

1// The browser's side of a `web-wasm32` program, whose event loop is the2// browser's: the program sets up what the browser calls back, such as3// animation frames and input events, then lets `main` return while it4// keeps running. Externs a module declares come from the JavaScript5// beside it, `<module>.web.js` (section 6.3), as this module's do.67import std::process;89extern al_keep_running(); // the runtime: skip what ends a program10extern al_web_keep_running(); // web.web.js: leave the instance serving callbacks11extern al_web_local_offset(seconds: i64) -> i64; // web.web.js: the page's time zone1213// Lets `main` return to the browser with the program still running: the14// checks made when `main` returns (heap and resources left over) are15// skipped, and the browser calls back what the program gave it until the16// page closes. What the callbacks use must outlive `main`, on the heap or17// in statics. Only a browser has an event loop to return to: elsewhere18// this panics.19exp fn keep_running() {20    if (target() == "web-wasm32") {21        al_web_keep_running();22        al_keep_running();23    } else {24        panic "std::web::keep_running needs a browser: build for web-wasm32";25    }26}2728// Seconds east of UTC in the page's time zone at the moment, in seconds29// since 1970-01-01 UTC: std::time's local_offset on the web.30pub fn page_offset(seconds: i64) -> i64 => al_web_local_offset(seconds);