Skip to content

macos #

macos

The macos module provides typed access to the Objective-C runtime on macOS. It includes Objective-C object, selector, rectangle, point, and range types together with typed message senders.

Choose the message sender whose return and argument types exactly match the Objective-C method. For example:

import macos

value := macos.msg_id_range(
    macos.get_class('NSValue'),
    'valueWithRange:',
    macos.range(2, 5),
)
result := macos.msg_range(value, 'rangeValue')
println('${result.location}, ${result.length}')

The typed senders hide the platform-specific objc_msgSend casts. Framework-specific methods still require the corresponding #flag darwin -framework ... declaration in the importing program.

Constants #

const assoc_assign = usize(0)
const assoc_retain_nonatomic = usize(1)
const assoc_copy_nonatomic = usize(3)
const assoc_retain = usize(0o1401)
const assoc_copy = usize(0o1403)
const run_loop_default_mode = 'kCFRunLoopDefaultMode'

fn add_method #

fn add_method(cls Id, sel_name string, imp voidptr, types string) bool

fn add_protocol #

fn add_protocol(cls Id, proto Protocol) bool

fn alloc #

fn alloc(class_name string) Id

── Allocation ─────────────────────────────────────────────────────

fn allocate_class_pair #

fn allocate_class_pair(superclass Id, name string) Id

── Runtime class helpers ──────────────────────────────────────────

fn autorelease_pool_new #

fn autorelease_pool_new() Id

fn description_string #

fn description_string(obj Id) string

fn get_associated_object #

fn get_associated_object(obj Id, key voidptr) Id

fn get_class #

fn get_class(name string) Id

fn get_protocol #

fn get_protocol(name string) Protocol

fn msg_bool #

fn msg_bool(obj Id, selector string) bool

fn msg_bool_id #

fn msg_bool_id(obj Id, selector string, a0 Id) bool

msg_bool_id sends a message that returns a boolean and accepts an object.

fn msg_bool_id_bool #

fn msg_bool_id_bool(obj Id, selector string, a0 Id, a1 bool) bool

msg_bool_id_bool sends a message that returns a boolean and accepts an object and a boolean.

fn msg_bool_sel_id_id #

fn msg_bool_sel_id_id(obj Id, selector string, a0 Sel, a1 Id, a2 Id) bool

msg_bool_sel_id_id sends a message that returns a boolean and accepts a selector and two objects.

fn msg_f64 #

fn msg_f64(obj Id, selector string) f64

fn msg_i64 #

fn msg_i64(obj Id, selector string) i64

fn msg_id #

fn msg_id(obj Id, selector string) Id

fn msg_id1 #

fn msg_id1(obj Id, selector string, a0 Id) Id

── Multi-argument message sending ─────────────────────────────────

fn msg_id2 #

fn msg_id2(obj Id, selector string, a0 Id, a1 Id) Id

fn msg_id3 #

fn msg_id3(obj Id, selector string, a0 Id, a1 Id, a2 Id) Id

fn msg_id4 #

fn msg_id4(obj Id, selector string, a0 Id, a1 Id, a2 Id, a3 Id) Id

fn msg_id_f64 #

fn msg_id_f64(obj Id, selector string, a0 f64) Id

fn msg_id_four_f64 #

fn msg_id_four_f64(obj Id, selector string, a0 f64, a1 f64, a2 f64, a3 f64) Id

msg_id_four_f64 sends a message that returns an object and accepts four f64 values.

fn msg_id_id_f64 #

fn msg_id_id_f64(obj Id, selector string, a0 Id, a1 f64) Id

msg_id_id_f64 sends a message that returns an object and accepts an object and an f64.

fn msg_id_id_u64 #

fn msg_id_id_u64(obj Id, selector string, a0 Id, a1 u64) Id

msg_id_id_u64 sends a message that returns an object and accepts an object and a u64.

fn msg_id_id_u64_i64_f64 #

fn msg_id_id_u64_i64_f64(obj Id, selector string, a0 Id, a1 u64, a2 i64, a3 f64) Id

msg_id_id_u64_i64_f64 sends a message that returns an object and accepts mixed numeric arguments.

fn msg_id_id_u64_range_ptr #

fn msg_id_id_u64_range_ptr(obj Id, selector string, a0 Id, a1 u64, range_ptr &Range) Id

msg_id_id_u64_range_ptr sends a message with an object, a u64, and a writable range pointer.

fn msg_id_range #

fn msg_id_range(obj Id, selector string, value Range) Id

msg_id_range sends a message that returns an object and accepts a range.

fn msg_id_rect #

fn msg_id_rect(obj Id, selector string, r Rect) Id

fn msg_id_rect_u64_u64_bool #

fn msg_id_rect_u64_u64_bool(obj Id, selector string, rect Rect, a1 u64, a2 u64, a3 bool) Id

msg_id_rect_u64_u64_bool sends a message that returns an object and accepts a rectangle, two unsigned integers, and a boolean.

fn msg_id_u64 #

fn msg_id_u64(obj Id, selector string, a0 u64) Id

fn msg_id_u64_id #

fn msg_id_u64_id(obj Id, selector string, a0 u64, a1 Id) Id

msg_id_u64_id sends a message that returns an object and accepts a u64 and an object.

fn msg_id_u64_range_ptr #

fn msg_id_u64_range_ptr(obj Id, selector string, a0 u64, range_ptr &Range) Id

msg_id_u64_range_ptr sends a message with a u64 and a writable range pointer.

fn msg_point #

fn msg_point(obj Id, selector string) Point

msg_point sends a message that returns a point.

fn msg_point_point_id #

fn msg_point_point_id(obj Id, selector string, value Point, a1 Id) Point

msg_point_point_id sends a message that returns a point and accepts a point and an object.

fn msg_range #

fn msg_range(obj Id, selector string) Range

msg_range sends a message that returns a range.

fn msg_rect #

fn msg_rect(obj Id, selector string) Rect

fn msg_u64 #

fn msg_u64(obj Id, selector string) u64

fn msg_u64_id #

fn msg_u64_id(obj Id, selector string, a0 Id) u64

msg_u64_id sends a message that returns a u64 and accepts an object.

fn msg_void #

fn msg_void(obj Id, selector string)

fn msg_void1 #

fn msg_void1(obj Id, selector string, a0 Id)

fn msg_void2 #

fn msg_void2(obj Id, selector string, a0 Id, a1 Id)

fn msg_void3 #

fn msg_void3(obj Id, selector string, a0 Id, a1 Id, a2 Id)

fn msg_void_bool #

fn msg_void_bool(obj Id, selector string, a0 bool)

fn msg_void_f64 #

fn msg_void_f64(obj Id, selector string, a0 f64)

fn msg_void_i64 #

fn msg_void_i64(obj Id, selector string, a0 i64)

fn msg_void_id_i64_id #

fn msg_void_id_i64_id(obj Id, selector string, a0 Id, a1 i64, a2 Id)

msg_void_id_i64_id sends a void message with an object, an i64, and an object.

fn msg_void_id_id_range #

fn msg_void_id_id_range(obj Id, selector string, a0 Id, a1 Id, value Range)

msg_void_id_id_range sends a void message with two objects and a range.

fn msg_void_id_range #

fn msg_void_id_range(obj Id, selector string, a0 Id, value Range)

msg_void_id_range sends a void message with an object and a range.

fn msg_void_id_sel_id_id #

fn msg_void_id_sel_id_id(obj Id, selector string, a0 Id, a1 Sel, a2 Id, a3 Id)

msg_void_id_sel_id_id sends a void message with an object, a selector, and two objects.

fn msg_void_point #

fn msg_void_point(obj Id, selector string, value Point)

msg_void_point sends a void message with a point.

fn msg_void_range #

fn msg_void_range(obj Id, selector string, value Range)

msg_void_range sends a void message with a range.

fn msg_void_rect #

fn msg_void_rect(obj Id, selector string, r Rect)

fn msg_void_rect_id #

fn msg_void_rect_id(obj Id, selector string, rect Rect, a1 Id)

msg_void_rect_id sends a void message with a rectangle and an object.

fn msg_void_sel_id_bool #

fn msg_void_sel_id_bool(obj Id, selector string, a0 Sel, a1 Id, a2 bool)

msg_void_sel_id_bool sends a void message with a selector, an object, and a boolean.

fn msg_void_u64 #

fn msg_void_u64(obj Id, selector string, a0 u64)

fn new #

fn new(class_name string) Id

fn nsstring #

fn nsstring(s string) Id

fn point #

fn point(x f64, y f64) Point

point returns a Cocoa-compatible point with the supplied coordinates.

fn range #

fn range(location u64, length u64) Range

range returns a Cocoa-compatible range with the supplied location and length.

fn rect #

fn rect(x f64, y f64, width f64, height f64) Rect

fn register_class_pair #

fn register_class_pair(cls Id)

fn release #

fn release(obj Id)

fn responds_to #

fn responds_to(obj Id, selector string) bool

responds_to reports whether obj responds to selector.

fn retain #

fn retain(obj Id) Id

fn sel #

fn sel(name string) Sel

fn set_associated_object #

fn set_associated_object(obj Id, key voidptr, value Id, policy usize)

fn utf8_string #

fn utf8_string(obj Id) string

type Class #

type Class = voidptr

type Id #

type Id = voidptr

type Point #

type Point = C.macos_point

Point is a Cocoa-compatible point or size containing two f64 values.

type Protocol #

type Protocol = voidptr

type Range #

type Range = C.macos_range

Range is a Cocoa-compatible range containing a location and length.

type Rect #

type Rect = C.macos_rect

type Sel #

type Sel = voidptr

struct C.macos_point #

struct C.macos_point {
pub mut:
	x f64
	y f64
}

struct C.macos_range #

struct C.macos_range {
pub mut:
	location u64
	length   u64
}

struct C.macos_rect #

struct C.macos_rect {
pub mut:
	x      f64
	y      f64
	width  f64
	height f64
}