qwac-sys 0.28.1

The FFI crates for QWAC
Documentation
use crate::Buffer;

#[derive(Clone, Copy, Hash, Debug, Eq, PartialEq, Ord, PartialOrd)]
#[repr(u8)]
pub enum LogLevel {
    Log,
    Debug,
    Info,
    Warning,
    Error,
}

pub type Callback = extern "C" fn(user_data: *mut ());

#[link(wasm_import_module = "qwac_core")]
extern "C" {
    pub fn log(string: *const u8, length: i32, level: i32);

    /// Execute the callback after the timeout.
    /// callback is expected to clean up the userdata.
    /// cleanup is called if the console is shut down before the timeout fires.
    pub fn timeout_create(
        seconds: f32,
        callback: Callback,
        shutdown_cleanup: Callback,
        userdata: *mut (),
    ) -> i32;

    /// Clear the timeout or the interval. This returns the user data associated
    /// with the timeout if it has not fired yet.  If it has fired, a null
    /// pointer is returned.  This allows you to clean it up.
    /// This automatically drops the timeout.
    pub fn timeout_cancel(timeout: i32) -> *mut ();

    /// Drop the timeout.
    /// This does not cancel it, but simply makes the slot available for reuse.
    pub fn timeout_drop(timeout: i32);

    /// Execute the callback every interval seconds.
    /// cleanup is called only if timeout is cancelled, including on shutdown.
    pub fn interval_create(
        seconds: f32,
        callback: Callback,
        shutdown_cleanup: Callback,
        userdata: *mut (),
    ) -> i32;

    /// Clear the interval or the interval. This returns the user data associated
    /// with the interval.
    /// This also drops the interval.
    pub fn interval_cancel(interval: i32) -> *mut ();

    /// Drop the interval.
    /// This does not cancel it, but simply makes the slot available for reuse.
    pub fn interval_drop(interval: i32);

    /// Seconds since the unix epoch.
    pub fn time() -> f64;

    /// Get the error message from the code, removing the error from the
    /// available ones.
    #[allow(improper_ctypes)]
    pub fn error_get(error: i32) -> *mut Buffer;

    /// Set the interval for updates (not graphics refreshes), in seconds.
    pub fn set_update_interval(interval: f32);

    /// Notify the event loop that the numbered task is finished.
    pub fn resolve_promise(promise: i32);
}