aboutsummaryrefslogtreecommitdiffstats
path: root/src/servo/platform/osmain.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/servo/platform/osmain.rs')
-rw-r--r--src/servo/platform/osmain.rs164
1 files changed, 69 insertions, 95 deletions
diff --git a/src/servo/platform/osmain.rs b/src/servo/platform/osmain.rs
index 9f8c24fe141..a0e304f3cb3 100644
--- a/src/servo/platform/osmain.rs
+++ b/src/servo/platform/osmain.rs
@@ -18,12 +18,12 @@ enum Msg {
}
fn OSMain() -> OSMain {
- on_osmain::<Msg> {|po|
- platform::runmain {||
+ on_osmain::<Msg>(|po| {
+ platform::runmain(|| {
#debug("preparing to enter main loop");
- mainloop(po);
- }
- }
+ mainloop(po);
+ })
+ })
}
fn mainloop(po: port<Msg>) {
@@ -43,17 +43,15 @@ fn mainloop(po: port<Msg>) {
let surfaces = surface_set();
loop {
- sdl::event::poll_event {|event|
+ sdl::event::poll_event(|event| {
alt event {
sdl::event::keydown_event(_) {
- key_handlers.iter {|key_ch|
- key_ch.send(())
- }
+ key_handlers.iter(|key_ch| key_ch.send(()))
}
_ { }
}
- }
+ });
// Handle messages
if po.peek() {
@@ -229,13 +227,9 @@ mod platform {
mod NSApplication {
fn sharedApplication() -> id {
- let klass = str::as_c_str("NSApplication") { |s|
- objc::objc_getClass(s)
- };
+ let klass = str::as_c_str("NSApplication", |s| objc::objc_getClass(s));
- let sel = str::as_c_str("sharedApplication") { |s|
- objc::sel_registerName(s)
- };
+ let sel = str::as_c_str("sharedApplication", |s| objc::sel_registerName(s));
let nsapp = objc::objc_msgSend(klass, sel);
#debug("nsapp: %d", (nsapp as int));
@@ -246,120 +240,100 @@ mod platform {
mod NSAutoreleasePool {
fn alloc() -> id {
- let klass = str::as_c_str("NSAutoreleasePool") { |s|
- objc::objc_getClass(s)
- };
- let sel = str::as_c_str("alloc") { |s|
- objc::sel_registerName(s)
- };
+ let klass = str::as_c_str("NSAutoreleasePool", |s| objc::objc_getClass(s));
+ let sel = str::as_c_str("alloc", |s| objc::sel_registerName(s));
let pool = objc::objc_msgSend(klass, sel);
#debug("autorelease pool: %?", pool);
ret pool;
}
fn init(pool: id) {
- let sel = str::as_c_str("init") { |s|
- objc::sel_registerName(s)
- };
+ let sel = str::as_c_str("init", |s| objc::sel_registerName(s));
objc::objc_msgSend(pool, sel);
}
fn release(pool: id) {
- let sel = str::as_c_str("release") { |s|
- objc::sel_registerName(s)
- };
+ let sel = str::as_c_str("release", |s| objc::sel_registerName(s));
objc::objc_msgSend(pool, sel);
}
}
mod NSApp {
fn setDelegate(nsapp: id, main: id) {
- #debug("NSApp::setDelegate");
- let sel = str::as_c_str("setDelegate:") { |s|
- objc::sel_registerName(s)
- };
- cocoa::msgSend1Id(nsapp, sel, main);
+ #debug("NSApp::setDelegate");
+ let sel = str::as_c_str("setDelegate:", |s| objc::sel_registerName(s));
+ cocoa::msgSend1Id(nsapp, sel, main);
}
- fn run(nsapp: id) {
- #debug("NSApp::run");
- let sel = str::as_c_str("run") { |s|
- objc::sel_registerName(s)
- };
+ fn run(nsapp: id) {
+ #debug("NSApp::run");
+ let sel = str::as_c_str("run", |s| objc::sel_registerName(s));
objc::objc_msgSend(nsapp, sel);
}
}
mod MainObj {
crust fn applicationDidFinishLaunching(this: id, _sel: SEL) {
- #debug("applicationDidFinishLaunching");
+ #debug("applicationDidFinishLaunching");
- let fptr: *fn() = ptr::null();
- str::as_c_str("fptr") { |name|
- let outValue = unsafe { unsafe::reinterpret_cast(ptr::addr_of(fptr)) };
+ let fptr: *fn() = ptr::null();
+ str::as_c_str("fptr", |name| {
+ let outValue = unsafe { unsafe::reinterpret_cast(ptr::addr_of(fptr)) };
#debug("*fptr %?", outValue);
objc::object_getInstanceVariable(this, name, outValue)
- };
+ });
- #debug("getting osmain fptr: %?", fptr);
+ #debug("getting osmain fptr: %?", fptr);
- unsafe {
- // FIXME: We probably don't want to run the main routine in a crust function
+ unsafe {
+ // FIXME: We probably don't want to run the main routine in a crust function
(*fptr)();
}
- }
+ }
- fn create(f: fn()) -> id {
- let NSObject = str::as_c_str("NSObject") { |s|
- objc::objc_getClass(s)
- };
- let MainObj = str::as_c_str("MainObj") { |s|
- objc::objc_allocateClassPair(NSObject, s, 0 as libc::size_t)
- };
+ fn create(f: fn()) -> id {
+ let NSObject = str::as_c_str("NSObject", |s| ojc::objc_getClass(s));
+ let MainObj = str::as_c_str("MainObj", |s| {
+ objc::objc_allocateClassPair(NSObject, s, 0 as libc::size_t)
+ });
// Add a field to our class to contain a pointer to a rust closure
- let res = str::as_c_str("fptr") { |name|
- str::as_c_str("^i") { |types|
+ let res = str::as_c_str("fptr", |name| {
+ str::as_c_str("^i", |types| {
objc::class_addIvar(MainObj, name,
sys::size_of::<libc::uintptr_t>() as libc::size_t,
16u8, types)
- }
- };
- assert res == true;
-
- let launchfn = str::as_c_str("applicationDidFinishLaunching:") { |s|
- objc::sel_registerName(s)
- };
- let _ = str::as_c_str("@@:") { |types|
- objc::class_addMethod(MainObj, launchfn, applicationDidFinishLaunching, types)
- };
-
- objc::objc_registerClassPair(MainObj);
-
- let sel = str::as_c_str("alloc") { |s|
- objc::sel_registerName(s)
- };
- let mainobj = objc::objc_msgSend(MainObj, sel);
-
- let sel = str::as_c_str("init") { |s|
- objc::sel_registerName(s)
- };
- objc::objc_msgSend(mainobj, sel);
-
- let fptr = ptr::addr_of(f);
- str::as_c_str("fptr") { |name|
- #debug("setting osmain fptr: %?", fptr);
- let value = unsafe { unsafe::reinterpret_cast(fptr) };
- #debug("*fptr: %?", value);
- objc::object_setInstanceVariable(mainobj, name, value)
- };
-
- ret mainobj;
- }
- fn release(mainobj: id) {
- let sel = str::as_c_str("release") { |s|
- objc::sel_registerName(s)
- };
- objc::objc_msgSend(mainobj, sel);
- }
+ })
+ });
+ assert res == true;
+
+ let launchfn = str::as_c_str("applicationDidFinishLaunching:", |s| {
+ objc::sel_registerName(s)
+ });
+ let _ = str::as_c_str("@@:", |types| {
+ objc::class_addMethod(MainObj, launchfn, applicationDidFinishLaunching, types)
+ });
+
+ objc::objc_registerClassPair(MainObj);
+
+ let sel = str::as_c_str("alloc", |s| objc::sel_registerName(s));
+ let mainobj = objc::objc_msgSend(MainObj, sel);
+
+ let sel = str::as_c_str("init", |s| objc::sel_registerName(s));
+ objc::objc_msgSend(mainobj, sel);
+
+ let fptr = ptr::addr_of(f);
+ str::as_c_str("fptr", |name| {
+ #debug("setting osmain fptr: %?", fptr);
+ let value = unsafe { unsafe::reinterpret_cast(fptr) };
+ #debug("*fptr: %?", value);
+ objc::object_setInstanceVariable(mainobj, name, value)
+ });
+
+ ret mainobj;
+ }
+ fn release(mainobj: id) {
+ let sel = str::as_c_str("release", |s| objc::sel_registerName(s));
+ objc::objc_msgSend(mainobj, sel);
+ }
}
fn runmain(f: fn()) {