MoonBit bindings for GLib non-GObject types (GError, GMainLoop, GVariant, etc.)
///|
test {
let error = @glib.Error_::new(1U, 42, "Operation failed")
assert_eq(error.domain(), 1U)
assert_eq(error.code(), 42)
assert_true(error.message().contains("Operation failed"))
assert_true(error.matches(1U, 42))
assert_false(error.matches(1U, 99))
let copy = error.copy()
assert_eq(copy.code(), error.code())
// No need to free — GC handles cleanup
}///|
test {
let ctx = @glib.MainContext::new()
let main_loop = @glib.MainLoop::new(ctx, false)
assert_false(main_loop.is_running())
assert_false(ctx.pending())
let dispatched = ctx.iteration(false)
assert_false(dispatched)
// No need to unref — GC handles cleanup
}///|
test {
let main_loop = @glib.MainLoop::new_default(false)
let ctx = main_loop.get_context()
let _ = ctx
}| Method | Description |
|---|---|
| Error_::new(domain, code, message) | Create new error |
| error.copy() | Deep copy error |
| error.matches(domain, code) | Check if error matches |
| error.message() | Get error message |
| error.code() | Get error code |
| error.domain() | Get error domain |
| Method | Description |
|---|---|
| MainContext::new() | Create new context |
| MainContext::default() | Get global default context |
| ctx.iteration(may_block) | Run one iteration |
| ctx.pending() | Check for pending events |
| ctx.wakeup() | Wake up blocked context |
| Method | Description |
|---|---|
| MainLoop::new(ctx, is_running) | Create with context |
| MainLoop::new_default(is_running) | Create with default context |
| loop.run() | Run until quit |
| loop.quit() | Signal loop to quit |
| loop.is_running() | Check if running |
| loop.get_context() | Get loop's context |
pub(open) trait IUri {
fn as_uri(Self) -> Uri
fn get_auth_params(Self) -> String? = _
fn get_flags(Self) -> UriFlags = _
fn get_fragment(Self) -> String? = _
fn get_host(Self) -> String? = _
fn get_password(Self) -> String? = _
fn get_path(Self) -> String = _
fn get_port(Self) -> Int = _
fn get_query(Self) -> String? = _
fn get_scheme(Self) -> String = _
fn get_user(Self) -> String? = _
fn get_userinfo(Self) -> String? = _
fn parse_relative(Self, String, UriFlags) -> Uri raise Error_ = _
fn to_string(Self) -> String = _
fn to_string_partial(Self, UriHideFlags) -> String = _
}pub suberror Error_test {
let error = @glib.Error_::new(5U, 100, "Network error")
assert_true(error.matches(5U, 100))
assert_false(error.matches(5U, 101))
assert_false(error.matches(6U, 100))
}test {
let error = @glib.Error_::new(1U, 42, "Something went wrong")
assert_eq(error.code(), 42)
assert_eq(error.domain(), 1U)
assert_true(error.message().contains("Something went wrong"))
}#external
pub type HashTablepub type HashTableIterpub struct IOCondition {
// private fields
}pub(all) enum IOConditionFlag {
In
Out
Pri
Err
Hup
Nval
}pub type MainContexttest {
let ctx = @glib.MainContext::new()
assert_false(ctx.pending())
}pub type MainLooptest {
let ctx = @glib.MainContext::new()
let main_loop = @glib.MainLoop::new(ctx, false)
assert_false(main_loop.is_running())
}test {
let main_loop = @glib.MainLoop::new_default(false)
assert_false(main_loop.is_running())
}pub type Mutextype Nullable[T]pub type Urifn Uri::escape_string(unescaped : String, reserved_chars_allowed : String?, allow_utf8 : Bool) -> Stringfn Uri::parse_params(params : String, length : Int64, separators : String, flags : UriParamsFlags) -> Map[String, String] raise Error_fn Uri::unescape_segment(escaped_string : String?, escaped_string_end : String?, illegal_characters : String?) -> String?pub(all) enum UriFlag {
None
ParseRelaxed
HasPassword
HasAuthParams
Encoded
NonDns
EncodedQuery
EncodedPath
EncodedFragment
SchemeNormalize
}pub struct UriFlags {
// private fields
}pub(all) enum UriHideFlag {
None
Userinfo
Password
AuthParams
Query
Fragment
}pub struct UriHideFlags {
// private fields
}pub(all) enum UriParamsFlag {
None
CaseInsensitive
WwwForm
ParseRelaxed
}pub struct UriParamsFlags {
// private fields
}pub type Varianttest {
let v = @glib.Variant::from_bool(true)
@debug.assert_eq(v.type_string(), "b")
@debug.assert_eq(v.as_bool(), Some(true))
}test {
let v = @glib.Variant::from_int32(42)
@debug.assert_eq(v.type_string(), "i")
@debug.assert_eq(v.as_int32(), Some(42))
}test {
let v = @glib.Variant::from_string("hello")
@debug.assert_eq(v.type_string(), "s")
@debug.assert_eq(v.as_string(), Some("hello"))
}let UNICHAR_MAX_DECOMPOSITION_LENGTH : Intfn idle_add(callback : () -> Bool) -> UIntfn source_remove(tag : UInt) -> Boolfn timeout_add(interval : UInt, callback : () -> Bool) -> UIntfn utf8_collate(left : String, right : String) -> IntMoonBit bindings for GLib non-GObject types (GError, GMainLoop, GVariant, etc.)