module nspkg #include "@DIR/native_log.h" // the message is borrowed for the callback; copy it before retaining it. pub type CbLogLine = fn (voidptr, LogLevel, &u8) fn C.v_alpm_log_line_function() CbLog fn C.v_alpm_log_line_create(CbLogLine, voidptr) voidptr fn C.v_alpm_log_line_receiver(voidptr) CbLogLine fn C.v_alpm_log_line_context(voidptr) voidptr fn (handle &Handle) owned_log_line_context() voidptr { if handle == unsafe { nil } { return unsafe { nil } } if voidptr(handle.option_get_logcb()) == voidptr(C.v_alpm_log_line_function()) { return handle.option_get_logcb_ctx() } return unsafe { nil } } // formatting stays behind the library boundary rather than in frontend C shims. pub fn (handle &Handle) option_set_logcb_line(callback CbLogLine, context voidptr) ! { if voidptr(callback) == unsafe { nil } { return handle.option_set_logcb(unsafe { nil }, context) } state := C.v_alpm_log_line_create(callback, context) if state == unsafe { nil } { return Errno.memory.ierror() } handle.option_set_logcb(C.v_alpm_log_line_function(), state) or { C.free(state) return err } } pub fn (handle &Handle) option_get_logcb_line() CbLogLine { return C.v_alpm_log_line_receiver(handle.owned_log_line_context()) } pub fn (handle &Handle) option_get_logcb_line_ctx() voidptr { return C.v_alpm_log_line_context(handle.owned_log_line_context()) }