Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Go言語からCocoaを使ってみた
Search
safx
August 09, 2014
Programming
240
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Go言語からCocoaを使ってみた
safx
August 09, 2014
Other Decks in Programming
See All in Programming
HTML-in-Canvasで作る未来のWeb UI表現
clockmaker
5
5.1k
JAWS-UG 東京支部が始める、JAWS-UG支部コラボ / JAWS-UG lunchtime LT Collaboration
y0hgi
0
270
複雑なUIコンポーネントとの ⻑い付き合い⽅:波及するバグからテスト戦略を経て、安全な再設計へ
mixplace
0
410
AmebaブログはKMPから卒業します
kmars0605
0
180
Compiling a real-world CLI tool to native with Static Hermes
tmikov2023
0
120
Findy - エンジニア向け会社紹介/Findy Company Deck
findyinc
6
400k
気持ちぃ〜角丸 Squircle
ryu1013
0
310
IBM Bob Dojo #1 仕様駆動開発入門
oniak3ibm
PRO
0
390
PumaからFalconに移行したRailsアプリケーションでの実践
falcon8823
0
170
AIで開発が速くなった先で、開発チームは何を目指すか
shihochan
0
880
Railsのためのパスキー実践入門 〜マルチテナントSaaSでの意思決定〜
utakaha
2
540
TechTown - Creating Composable Callables in Contemporary C++
rollbear
0
130
Featured
See All Featured
The browser strikes back
jonoalderson
0
1.8k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
400
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
550
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
1
450
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
710
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Navigating Team Friction
lara
192
16k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
480
Bash Introduction
62gerente
615
220k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
600
Testing 201, or: Great Expectations
jmmastey
46
8.3k
Transcript
(Pݴޠ͔Β$PDPB ΛͬͯΈͨ @matuyuji ! Cocoaษڧձؔ 2014.8.9
!NBUVZVKJ w TBGYEFWCMPHTQPUKQ w &NBDT͍ w 3FBDUJWF$PDPBؔ
(P͔Β$PDPBΛ͍͍ͨ
! func main() { app := cocoa.NSApplication_sharedApplication() win := cocoa.NSWindow_initWithContentRectStyleMaskBackingDefer(
cocoa.NSRect{0,0, 200,200}, NSTitledWindowMask, NSBackingStoreBuffered, false) win.CascadeTopLeftFromPoint(cocoa.NSPoint{20,20}) win.SetTitle(cocoa.NSString_initWithUTF8String("SomeApp")) win.MakeKeyAndOrderFront(nil) app.ActivateIgnoringOtherApps(true) ! fmt.Println(app, win) fmt.Println(app.GetClassName(), win.GetClassName()) ! app.Run(); } ͜ͷίʔυ͕ಈ͘Α͏ʹ͍ͨ͠ʂ
(P͔Β0CKFDUJWF$ ΛݺͿํ๏
$HP
$HP w (P͔Β$ݴޠίʔυΛݺͼग़͢Έ w ΘΓͱ͍ͮΒ͍
1BDLBHFz$z ! package main ! // #include <stdio.h> import "C"
! func main() { C.puts(C.CString("hello, world!")) } લͷίϝϯτ͕ ύοέʔδCͷͨΊͷ ίʔυʹͳΔ (Pจࣈྻˠ$จࣈྻ $ݴޠͷTUEJPIͷؔ
1BDLBHF$ )FMQFSGVODUJPO • func C.CString(string) *C.char (Pจࣈྻˠ$จࣈྻ • func C.GoString(*C.char)
string $จࣈྻˠ(Pจࣈྻ • func C.GoBytes(unsafe.Pointer, C.int) []byte $όΠτྻˠ(PόΠτྻ
! package main ! /* #include <stdio.h> ! char* hello()
{ return "hello, world!"; } */ import "C" ! func main() { C.puts(C.hello()) }
! package main ! /* int add(int x, int y)
{ return x + y; } */ import "C" import "fmt" ! func main() { fmt.Println(C.add(2, 3)) }
HPCVJMEYGPPHP foo.go foo.cgo1.go foo.cgo2.c Object Object Object cgo Binary 6l
6g clang pack _cgo_defun.c Object 6c ࣮ࡍͬͱෳࡶ‥
(PDPNNBOET 6a 8a 5a 6c 8c 5c 6g 8g 5g
6l 8l 5l assembler c compiler go compiler linker 6 (x86-64) 8 (x86-32) 5 (ARM) Plan 9 ༝དྷ ΞʔΩςΫνϟ πʔϧ
HPCVJMEYGPPHP foo.go foo.cgo1.go foo.cgo2.c Object Object Object cgo Binary 6l
6g clang pack _cgo_defun.c Object 6c
! void _cgo_2434c0b5a67e_Cfunc_add(void *v) { struct { int p0; int
p1; int r; char __pad12[4]; } __attribute__((__packed__)) *a = v; a->r = add(a->p0, a->p1); } ! int add(int x, int y) { return x + y; } ! void ɾ_Cfunc_add(struct{void *y[2];}p) { runtimeɾcgocall(_cgo_2434c0b5a67e_Cfunc_add, &p); } foo.cgo2.c _cgo_defun.c
HPCVJMEYGPPHP foo.go foo.cgo1.go foo.cgo2.c Object Object Object cgo Binary 6l
6g clang pack _cgo_defun.c Object 6c
! package main /* #cgo CFLAGS: -x objective-c #cgo LDFLAGS:
-framework Foundation #import <Cocoa/Cocoa.h> ! NSString* NSString_initWithUTF8String(char* text) { return [[NSString alloc] initWithUTF8String:text]; } ! const char* NSString_descripton(NSString* obj) { return [[obj description] UTF8String]; } */ import "C" import "fmt" ! func main() { str := C.NSString_initWithUTF8String(C.CString("foobar")) fmt.Println(C.GoString(C.NSString_descripton(str))) }
! package main /* #cgo CFLAGS: -x objective-c #cgo LDFLAGS:
-framework Cocoa #import <Cocoa/Cocoa.h> int StartApp(void) { [NSAutoreleasePool new]; [NSApplication sharedApplication]; [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; id menubar = [[NSMenu new] autorelease]; id appMenuItem = [[NSMenuItem new] autorelease]; [menubar addItem:appMenuItem]; [NSApp setMainMenu:menubar]; id appMenu = [[NSMenu new] autorelease]; id appName = [[NSProcessInfo processInfo] processName]; id quitTitle = [@"Quit " stringByAppendingString:appName]; id quitMenuItem = [[[NSMenuItem alloc] initWithTitle:quitTitle action:@selector(terminate:) keyEquivalent:@“q"] autorelease]; [appMenu addItem:quitMenuItem]; [appMenuItem setSubmenu:appMenu]; id window = [[[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 200, 200) styleMask:NSTitledWindowMask backing:NSBackingStoreBuffered defer:NO] autorelease]; [window cascadeTopLeftFromPoint:NSMakePoint(20,20)]; [window setTitle:appName]; [window makeKeyAndOrderFront:nil]; [NSApp activateIgnoringOtherApps:YES]; [NSApp run]; return 0; } */ import "C" ! func main() { C.StartApp() } LBWVFYBNQMFHP ˒
! func main() { app := cocoa.NSApplication_sharedApplication() win := cocoa.NSWindow_initWithContentRectStyleMaskBackingDefer(
cocoa.NSRect{0,0, 200,200}, NSTitledWindowMask, NSBackingStoreBuffered, false) win.CascadeTopLeftFromPoint(cocoa.NSPoint{20,20}) win.SetTitle(cocoa.NSString_initWithUTF8String("SomeApp")) win.MakeKeyAndOrderFront(nil) app.ActivateIgnoringOtherApps(true) ! fmt.Println(app, win) fmt.Println(app.GetClassName(), win.GetClassName()) ! app.Run(); }
TBGYDMBOHPCKDHP w $MBOH1ZUIPO#JOEJOHTΛར༻ w 0CKFDUJWF$ͷϔομ͔Β(PίʔυΛੜ python scripts/clang-objcgo.py import.h \ >
src/cocoa/import.go go build main ./main
$MBOH1ZUIPO#JOEJOHT w ιʔείʔυ͔Βநߏจ "45 Λੜ ! w 1ZUIPO͔Β؆୯ʹ͍͡ΕΔ w 4BGY$MBOHͷ1ZUIPOόΠϯσΟϯάͰ0CKFDUJWF$ͷ
ιʔείʔυΛύʔεͯ͠ΈΔ TBGYEFWCMPHTQPUKQ DMBOHQZUIPOPCKFDUJWFDIUNM python cindex-dump.py sample.h -c -m64 -ObjC DOMπϦʔΈ͍ͨͳͷ
translation_unit objc_interface_decl objc_property_decl objc_class_ref objc_instance_method_decl objc_instance_method_decl parm_decl objc_instance_method_decl parm_decl objc_class_ref
parm_decl sample.h foo hoge NSArray hoge setHoge: hoge barWithArray:limit: array NSArray limit @class NSArray; ! @interface Foo @property NSArray* hoge; - (int)barWithArray:(NSArray*)array limit:(int)limit; @end
ؔ࿈ϓϩδΣΫτ NLSBVU[PCKD ˒ PCKD@NTH4FOEͰ0CKFDUJWF$Λ͑ΔΑ͏ʹ͢Δ(PϥΠϒϥϦ NLSBVU[WBSJBEJD ˒
$ͷՄมҾͷؔΛݺΔΑ͏ʹͳΔ(PϥΠϒϥϦ 3JQ3JQDMBOH@DPNQMFUF ˒ WJNͷิϓϥάΠϯ DMBOHQZUIPOόΠϯσΟϯάར༻ TIJMHBQJSB0CK$SVTU ˒ 3VTUͰJ04ͷϥΠϒϥϦΛ࡞Δαϯϓϧ