mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
samples: add Terra samples
source: https://github.com/zdevito/terra/tree/master/tests
This commit is contained in:
42
samples/Terra/objc2.t
Normal file
42
samples/Terra/objc2.t
Normal file
@@ -0,0 +1,42 @@
|
||||
local f = assert(io.popen("uname", 'r'))
|
||||
local s = assert(f:read('*a'))
|
||||
f:close()
|
||||
|
||||
if s~="Darwin\n" then
|
||||
print("Warning, not running test b/c this isn't a mac")
|
||||
else
|
||||
|
||||
|
||||
local OC = require("lib/objc")
|
||||
local IO = terralib.includec("stdio.h")
|
||||
|
||||
struct Rect {
|
||||
a : double,
|
||||
b : double,
|
||||
c : double,
|
||||
d : double
|
||||
}
|
||||
|
||||
terra str(data : &uint8)
|
||||
return OC.NSString:stringWithUTF8String(data)
|
||||
end
|
||||
|
||||
terra main()
|
||||
OC.NSAutoreleasePool:new()
|
||||
var app = OC.NSApplication:sharedApplication()
|
||||
var rec = Rect {0,0,200,200}
|
||||
var window = OC.NSWindow:alloc():initWithContentRect_styleMask_backing_defer(rec,1,2,false)
|
||||
window:makeKeyAndOrderFront(nil)
|
||||
--[[var img = OC.NSImage:alloc():initByReferencingFile(str("objc2.jpg"))
|
||||
var imgView = OC.NSImageView:alloc():initWithFrame(rec)
|
||||
imgView:setImage(img)
|
||||
window:setContentView(imgView)
|
||||
IO.printf("entering run loop\n")--]]
|
||||
app:run()
|
||||
end
|
||||
|
||||
terralib.saveobj("objc2", {main = main}, {"-framework","Cocoa"})
|
||||
|
||||
--os.execute("./objc2")
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user