qwac_sys/
core.rs

1use crate::Buffer;
2
3#[derive(Clone, Copy, Hash, Debug, Eq, PartialEq, Ord, PartialOrd)]
4#[repr(u8)]
5pub enum LogLevel {
6    Log,
7    Debug,
8    Info,
9    Warning,
10    Error,
11}
12
13pub type Callback = extern "C" fn(user_data: *mut ());
14
15#[link(wasm_import_module = "qwac_core")]
16extern "C" {
17    pub fn log(string: *const u8, length: i32, level: i32);
18
19    /// Execute the callback after the timeout.
20    /// callback is expected to clean up the userdata.
21    /// cleanup is called if the console is shut down before the timeout fires.
22    pub fn timeout_create(
23        seconds: f32,
24        callback: Callback,
25        shutdown_cleanup: Callback,
26        userdata: *mut (),
27    ) -> i32;
28
29    /// Clear the timeout or the interval. This returns the user data associated
30    /// with the timeout if it has not fired yet.  If it has fired, a null
31    /// pointer is returned.  This allows you to clean it up.
32    /// This automatically drops the timeout.
33    pub fn timeout_cancel(timeout: i32) -> *mut ();
34
35    /// Drop the timeout.
36    /// This does not cancel it, but simply makes the slot available for reuse.
37    pub fn timeout_drop(timeout: i32);
38
39    /// Execute the callback every interval seconds.
40    /// cleanup is called only if timeout is cancelled, including on shutdown.
41    pub fn interval_create(
42        seconds: f32,
43        callback: Callback,
44        shutdown_cleanup: Callback,
45        userdata: *mut (),
46    ) -> i32;
47
48    /// Clear the interval or the interval. This returns the user data associated
49    /// with the interval.
50    /// This also drops the interval.
51    pub fn interval_cancel(interval: i32) -> *mut ();
52
53    /// Drop the interval.
54    /// This does not cancel it, but simply makes the slot available for reuse.
55    pub fn interval_drop(interval: i32);
56
57    /// Seconds since the unix epoch.
58    pub fn time() -> f64;
59
60    /// Get the error message from the code, removing the error from the
61    /// available ones.
62    #[allow(improper_ctypes)]
63    pub fn error_get(error: i32) -> *mut Buffer;
64
65    /// Set the interval for updates (not graphics refreshes), in seconds.
66    pub fn set_update_interval(interval: f32);
67
68    /// Notify the event loop that the numbered task is finished.
69    pub fn resolve_promise(promise: i32);
70}