diff --git a/src/rust-cocoa b/src/rust-cocoa index 9a43115ca9f..ee0008f3e3a 160000 --- a/src/rust-cocoa +++ b/src/rust-cocoa @@ -1 +1 @@ -Subproject commit 9a43115ca9f5309543f0646252a3d420fdd40628 +Subproject commit ee0008f3e3adc815d45130d79d7d5d6d64d3a40b diff --git a/src/servo/osmain.rs b/src/servo/osmain.rs index 3793723892d..0cac86f7aaa 100644 --- a/src/servo/osmain.rs +++ b/src/servo/osmain.rs @@ -74,9 +74,23 @@ mod platform { mod MainObj { crust fn applicationDidFinishLaunching(this: id, _sel: SEL) { #debug("applicationDidFinishLaunching"); + + 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); + + unsafe { + // FIXME: We probably don't want to run the main routine in a crust function + (*fptr)(); + } } - fn create() -> id { + fn create(f: fn()) -> id { let NSObject = str::as_c_str("NSObject") { |s| objc::objc_getClass(s) }; @@ -84,6 +98,16 @@ mod platform { 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| + objc::class_addIvar(MainObj, name, + sys::size_of::() as libc::size_t, + 16u8, types) + } + }; + assert res == true; + let launchfn = str::as_c_str("applicationDidFinishLaunching:") { |s| objc::sel_registerName(s) }; @@ -103,6 +127,14 @@ mod platform { }; 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) { @@ -118,7 +150,7 @@ mod platform { NSAutoreleasePool::init(pool); let NSApp = NSApplication::sharedApplication(); - let mainobj = MainObj::create(); + let mainobj = MainObj::create(f); NSApp::setDelegate(NSApp, mainobj); NSApp::run(NSApp); @@ -137,6 +169,7 @@ enum msg { fn osmain() -> comm::chan { on_osmain:: {|po| platform::runmain {|| + #debug("preparing to enter main loop"); mainloop(po); } }