-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello.ex
32 lines (27 loc) · 1.05 KB
/
hello.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
defmodule Hello do
use ObjC, compile: "-lobjc -framework AppKit"
defobjc(:hello, 0, ~S"""
#import "AppKit/AppKit.h"
extern int erl_drv_steal_main_thread(char *name, ErlNifTid *dtid, void* (*func)(void*), void* arg, ErlNifThreadOpts *opts);
extern int erl_drv_stolen_main_thread_join(ErlNifTid tid, void **respp);
ErlNifTid hello_thread;
void *hello_main_loop(void * _unused)
{
[NSAutoreleasePool new];
[NSApplication sharedApplication];
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
[NSApp activateIgnoringOtherApps:YES];
NSAlert *alert = [[NSAlert alloc] init];
[alert setMessageText:@"Hello from ObjC!"];
[alert addButtonWithTitle:@"OK"];
[alert runModal];
return NULL;
}
static ERL_NIF_TERM hello(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
erl_drv_steal_main_thread((char *)"hello", &hello_thread, hello_main_loop, (void *)NULL, NULL);
erl_drv_stolen_main_thread_join(hello_thread, NULL);
return enif_make_atom(env, "ok");
}
""")
end