Wasmtime bindings for Zig
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.4 KiB

const Name = @import("./vec.zig").Name;
/// This opaque type represents an error generated by Wasmtime. Errors
/// primarily have an error message associated with them at this time, which
/// you can acquire by calling `format`.
///
/// Errors are safe to share across threads and must be deleted with `deinit`.
pub const Error = opaque {
/// Creates a new error with the provided message.
pub fn init(message: [:0]const u8) *Error {
return wasmtime_error_new(message.ptr);
}
pub fn deinit(self: *Error) void {
wasmtime_error_delete(self);
}
pub fn getMessage(self: *const Error) Name {
var result: Name = undefined;
wasmtime_error_message(self, &result);
return result;
}
/// Attempts to extract a WASI-specific exit status from this error.
/// Returns status if error is a WASI "exit" trap, or `null` otherwise.
pub fn getExitStatus(self: *Error) ?c_int {
var result: c_int = undefined;
const has_status = wasmtime_error_exit_status(self, &result);
return if (has_status) result else null;
}
extern "c" fn wasmtime_error_new([*:0]const u8) *Error;
extern "c" fn wasmtime_error_delete(*Error) void;
extern "c" fn wasmtime_error_message(*const Error, *Name) void;
extern "c" fn wasmtime_error_exit_status(*const Error, *c_int) bool;
// extern "c" fn wasmtime_error_wasm_trace(*const Error, *FrameVec) void;
};