-
Notifications
You must be signed in to change notification settings - Fork 1
/
hammermoon_app.lua
54 lines (45 loc) · 1.54 KB
/
hammermoon_app.lua
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
return function(onLaunched,onTerminate)
assert(type(onLaunched)=='function')
local c=require'objc'
c.load'AppKit'
c.load'Foundation'
local NSApp=c.class('NSApp','NSApplication <NSApplicationDelegate>')
function NSApp:applicationWillFinishLaunching() end
function NSApp:applicationDidFinishLaunching()
hm._lua_setup()
onLaunched()
end
function NSApp:applicationShouldTerminateAfterLastWindowClosed() return true end
function NSApp:applicationShouldTerminate()
if onTerminate then onTerminate() end
os.exit(1,1)
end
local app=NSApp:sharedApplication()
app:setDelegate(app)
app:setActivationPolicy(c.NSApplicationActivationPolicyRegular)
local NSWin=c.class('NSWin','NSWindow <NSWindowDelegate>')
function NSWin:windowWillClose()
-- print'window will close...'
end
local style = bit.bor(
c.NSTitledWindowMask,
c.NSClosableWindowMask,
c.NSMiniaturizableWindowMask,
c.NSResizableWindowMask)
local win = NSWin:alloc():initWithContentRect_styleMask_backing_defer(
c.NSMakeRect(300, 300, 500, 300), style, c.NSBackingStoreBuffered, false)
win:setReleasedWhenClosed(false)
win:setDelegate(win)
win:setTitle"Hammermoon"
app:activateIgnoringOtherApps(true)
win:makeKeyAndOrderFront(nil)
win.alphaValue=0.5
local ok,err=pcall(app.run,app)
if not ok then
local s,e=err:find('[NSApp run]',1,true)
if e then err=err:sub(e+1) end
io.stderr:write('\n\n[RUNTIME ERROR] ------------\n'..err..'\n----------------------------\n\n')
io.stderr:flush()
os.exit(1,1)
end
end