detached ab59a38

objc: change the test package (#16)

commit
ab59a38e38563186347abec3934f6996f24d645b
author
Hajime Hoshi · · 2022-08-12 02:47 UTC
committer
GitHub · · 2022-08-12 02:47 UTC
parent
8c4da10
signature
GPG Unverified4AEE18F83AFDEB23 The key is unknown
1 file · +13 -12
M objc/objc_runtime_darwin_test.go +13 -12
@@ -1,7 +1,7 @@
11 // SPDX-License-Identifier: Apache-2.0
22 // SPDX-FileCopyrightText: 2022 The Ebitengine Authors
33
4-package objc
4+package objc_test
55
66 import (
77 "fmt"
@@ -9,6 +9,7 @@ import (
99 "unsafe"
1010
1111 "github.com/ebitengine/purego"
12+ "github.com/ebitengine/purego/objc"
1213 )
1314
1415 func init() {
@@ -20,38 +21,38 @@ func init() {
2021 }
2122
2223 func ExampleAllocateClassPair() {
23- var class = AllocateClassPair(GetClass("NSObject\x00"), "FooObject\x00", 0)
24- class.AddMethod(RegisterName("run\x00"), IMP(func(self ID, _cmd SEL) {
24+ var class = objc.AllocateClassPair(objc.GetClass("NSObject\x00"), "FooObject\x00", 0)
25+ class.AddMethod(objc.RegisterName("run\x00"), objc.IMP(func(self objc.ID, _cmd objc.SEL) {
2526 fmt.Println("Hello World!")
2627 }), "v@:\x00")
2728 class.Register()
2829
29- var fooObject = ID(class).Send(RegisterName("new\x00"))
30- fooObject.Send(RegisterName("run\x00"))
30+ var fooObject = objc.ID(class).Send(objc.RegisterName("new\x00"))
31+ fooObject.Send(objc.RegisterName("run\x00"))
3132 // Output: Hello World!
3233 }
3334
3435 func ExampleClass_AddIvar() {
35- var class = AllocateClassPair(GetClass("NSObject\x00"), "BarObject\x00", 0)
36+ var class = objc.AllocateClassPair(objc.GetClass("NSObject\x00"), "BarObject\x00", 0)
3637 class.AddIvar("bar\x00", int(0), "q\x00")
3738 var barOffset = class.InstanceVariable("bar\x00").Offset()
38- class.AddMethod(RegisterName("bar\x00"), IMP(func(self ID, _cmd SEL) int {
39+ class.AddMethod(objc.RegisterName("bar\x00"), objc.IMP(func(self objc.ID, _cmd objc.SEL) int {
3940 return *(*int)(unsafe.Pointer(uintptr(unsafe.Pointer(self)) + barOffset))
4041 }), "q@:\x00")
41- class.AddMethod(RegisterName("setBar:\x00"), IMP(func(self ID, _cmd SEL, bar int) {
42+ class.AddMethod(objc.RegisterName("setBar:\x00"), objc.IMP(func(self objc.ID, _cmd objc.SEL, bar int) {
4243 *(*int)(unsafe.Pointer(uintptr(unsafe.Pointer(self)) + barOffset)) = bar
4344 }), "v@:q\x00")
4445 class.Register()
4546
46- var barObject = ID(class).Send(RegisterName("new\x00"))
47- barObject.Send(RegisterName("setBar:\x00"), 123)
48- var bar = int(barObject.Send(RegisterName("bar\x00")))
47+ var barObject = objc.ID(class).Send(objc.RegisterName("new\x00"))
48+ barObject.Send(objc.RegisterName("setBar:\x00"), 123)
49+ var bar = int(barObject.Send(objc.RegisterName("bar\x00")))
4950 fmt.Println(bar)
5051 // Output: 123
5152 }
5253
5354 func ExampleIMP() {
54- imp := IMP(func(self ID, _cmd SEL) {
55+ imp := objc.IMP(func(self objc.ID, _cmd objc.SEL) {
5556 fmt.Println("IMP:", self, _cmd)
5657 })
5758
@@ -1,7 +1,7 @@
1 // SPDX-License-Identifier: Apache-2.01 // SPDX-License-Identifier: Apache-2.0
2 // SPDX-FileCopyrightText: 2022 The Ebitengine Authors2 // SPDX-FileCopyrightText: 2022 The Ebitengine Authors
3 3
4-package objc4+package objc_test
5 5
6 import (6 import (
7 "fmt"7 "fmt"
@@ -9,6 +9,7 @@ import (
9 "unsafe"9 "unsafe"
10 10
11 "github.com/ebitengine/purego"11 "github.com/ebitengine/purego"
12+ "github.com/ebitengine/purego/objc"
12 )13 )
13 14
14 func init() {15 func init() {
@@ -20,38 +21,38 @@ func init() {
20 }21 }
21 22
22 func ExampleAllocateClassPair() {23 func ExampleAllocateClassPair() {
23- var class = AllocateClassPair(GetClass("NSObject\x00"), "FooObject\x00", 0)24+ var class = objc.AllocateClassPair(objc.GetClass("NSObject\x00"), "FooObject\x00", 0)
24- class.AddMethod(RegisterName("run\x00"), IMP(func(self ID, _cmd SEL) {25+ class.AddMethod(objc.RegisterName("run\x00"), objc.IMP(func(self objc.ID, _cmd objc.SEL) {
25 fmt.Println("Hello World!")26 fmt.Println("Hello World!")
26 }), "v@:\x00")27 }), "v@:\x00")
27 class.Register()28 class.Register()
28 29
29- var fooObject = ID(class).Send(RegisterName("new\x00"))30+ var fooObject = objc.ID(class).Send(objc.RegisterName("new\x00"))
30- fooObject.Send(RegisterName("run\x00"))31+ fooObject.Send(objc.RegisterName("run\x00"))
31 // Output: Hello World!32 // Output: Hello World!
32 }33 }
33 34
34 func ExampleClass_AddIvar() {35 func ExampleClass_AddIvar() {
35- var class = AllocateClassPair(GetClass("NSObject\x00"), "BarObject\x00", 0)36+ var class = objc.AllocateClassPair(objc.GetClass("NSObject\x00"), "BarObject\x00", 0)
36 class.AddIvar("bar\x00", int(0), "q\x00")37 class.AddIvar("bar\x00", int(0), "q\x00")
37 var barOffset = class.InstanceVariable("bar\x00").Offset()38 var barOffset = class.InstanceVariable("bar\x00").Offset()
38- class.AddMethod(RegisterName("bar\x00"), IMP(func(self ID, _cmd SEL) int {39+ class.AddMethod(objc.RegisterName("bar\x00"), objc.IMP(func(self objc.ID, _cmd objc.SEL) int {
39 return *(*int)(unsafe.Pointer(uintptr(unsafe.Pointer(self)) + barOffset))40 return *(*int)(unsafe.Pointer(uintptr(unsafe.Pointer(self)) + barOffset))
40 }), "q@:\x00")41 }), "q@:\x00")
41- class.AddMethod(RegisterName("setBar:\x00"), IMP(func(self ID, _cmd SEL, bar int) {42+ class.AddMethod(objc.RegisterName("setBar:\x00"), objc.IMP(func(self objc.ID, _cmd objc.SEL, bar int) {
42 *(*int)(unsafe.Pointer(uintptr(unsafe.Pointer(self)) + barOffset)) = bar43 *(*int)(unsafe.Pointer(uintptr(unsafe.Pointer(self)) + barOffset)) = bar
43 }), "v@:q\x00")44 }), "v@:q\x00")
44 class.Register()45 class.Register()
45 46
46- var barObject = ID(class).Send(RegisterName("new\x00"))47+ var barObject = objc.ID(class).Send(objc.RegisterName("new\x00"))
47- barObject.Send(RegisterName("setBar:\x00"), 123)48+ barObject.Send(objc.RegisterName("setBar:\x00"), 123)
48- var bar = int(barObject.Send(RegisterName("bar\x00")))49+ var bar = int(barObject.Send(objc.RegisterName("bar\x00")))
49 fmt.Println(bar)50 fmt.Println(bar)
50 // Output: 12351 // Output: 123
51 }52 }
52 53
53 func ExampleIMP() {54 func ExampleIMP() {
54- imp := IMP(func(self ID, _cmd SEL) {55+ imp := objc.IMP(func(self objc.ID, _cmd objc.SEL) {
55 fmt.Println("IMP:", self, _cmd)56 fmt.Println("IMP:", self, _cmd)
56 })57 })
57 58

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