v0.1.1 5378e2e

objc_runtime_darwin_test.go RawHistoryFolder

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: 2022 The Ebitengine Authors
3
4package objc_test
5
6import (
7	"fmt"
8	"unsafe"
9
10	"github.com/ebitengine/purego"
11	"github.com/ebitengine/purego/objc"
12)
13
14func ExampleAllocateClassPair() {
15	var class = objc.AllocateClassPair(objc.GetClass("NSObject"), "FooObject", 0)
16	class.AddMethod(objc.RegisterName("run"), objc.NewIMP(func(self objc.ID, _cmd objc.SEL) {
17		fmt.Println("Hello World!")
18	}), "v@:")
19	class.Register()
20
21	var fooObject = objc.ID(class).Send(objc.RegisterName("new"))
22	fooObject.Send(objc.RegisterName("run"))
23	// Output: Hello World!
24}
25
26func ExampleClass_AddIvar() {
27	var class = objc.AllocateClassPair(objc.GetClass("NSObject"), "BarObject", 0)
28	class.AddIvar("bar", int(0), "q")
29	var barOffset = class.InstanceVariable("bar").Offset()
30	class.AddMethod(objc.RegisterName("bar"), objc.NewIMP(func(self objc.ID, _cmd objc.SEL) int {
31		return *(*int)(unsafe.Pointer(uintptr(unsafe.Pointer(self)) + barOffset))
32	}), "q@:")
33	class.AddMethod(objc.RegisterName("setBar:"), objc.NewIMP(func(self objc.ID, _cmd objc.SEL, bar int) {
34		*(*int)(unsafe.Pointer(uintptr(unsafe.Pointer(self)) + barOffset)) = bar
35	}), "v@:q")
36	class.Register()
37
38	var barObject = objc.ID(class).Send(objc.RegisterName("new"))
39	barObject.Send(objc.RegisterName("setBar:"), 123)
40	var bar = int(barObject.Send(objc.RegisterName("bar")))
41	fmt.Println(bar)
42	// Output: 123
43}
44
45func ExampleIMP() {
46	imp := objc.NewIMP(func(self objc.ID, _cmd objc.SEL, a3, a4, a5, a6, a7, a8, a9 int) {
47		fmt.Println("IMP:", self, _cmd, a3, a4, a5, a6, a7, a8, a9)
48	})
49
50	purego.SyscallN(uintptr(imp), 105, 567, 9, 2, 3, ^uintptr(4), 4, 8, 9)
51
52	// Output: IMP: 105 567 9 2 3 -5 4 8 9
53}
54
55func ExampleID_SendSuper() {
56	super := objc.AllocateClassPair(objc.GetClass("NSObject"), "SuperObject", 0)
57	super.AddMethod(objc.RegisterName("doSomething"), objc.NewIMP(func(self objc.ID, _cmd objc.SEL) {
58		fmt.Println("In Super!")
59	}), "v@:")
60	super.Register()
61
62	child := objc.AllocateClassPair(super, "ChildObject", 0)
63	child.AddMethod(objc.RegisterName("doSomething"), objc.NewIMP(func(self objc.ID, _cmd objc.SEL) {
64		fmt.Println("In Child")
65		self.SendSuper(_cmd)
66	}), "v@:")
67	child.Register()
68
69	objc.ID(child).Send(objc.RegisterName("new")).Send(objc.RegisterName("doSomething"))
70
71	// Output: In Child
72	// In Super!
73}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 102

↑↓ moveenter openesc close