mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Call our main function from the applicationDidFinishLaunching callback
This commit is contained in:
parent
1b31f3a453
commit
f7e3be4d6a
2 changed files with 36 additions and 3 deletions
|
@ -1 +1 @@
|
||||||
Subproject commit 9a43115ca9f5309543f0646252a3d420fdd40628
|
Subproject commit ee0008f3e3adc815d45130d79d7d5d6d64d3a40b
|
|
@ -74,9 +74,23 @@ mod platform {
|
||||||
mod MainObj {
|
mod MainObj {
|
||||||
crust fn applicationDidFinishLaunching(this: id, _sel: SEL) {
|
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)) };
|
||||||
|
#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|
|
let NSObject = str::as_c_str("NSObject") { |s|
|
||||||
objc::objc_getClass(s)
|
objc::objc_getClass(s)
|
||||||
};
|
};
|
||||||
|
@ -84,6 +98,16 @@ mod platform {
|
||||||
objc::objc_allocateClassPair(NSObject, s, 0 as libc::size_t)
|
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::<libc::uintptr_t>() as libc::size_t,
|
||||||
|
16u8, types)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
assert res == true;
|
||||||
|
|
||||||
let launchfn = str::as_c_str("applicationDidFinishLaunching:") { |s|
|
let launchfn = str::as_c_str("applicationDidFinishLaunching:") { |s|
|
||||||
objc::sel_registerName(s)
|
objc::sel_registerName(s)
|
||||||
};
|
};
|
||||||
|
@ -103,6 +127,14 @@ mod platform {
|
||||||
};
|
};
|
||||||
objc::objc_msgSend(mainobj, sel);
|
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;
|
ret mainobj;
|
||||||
}
|
}
|
||||||
fn release(mainobj: id) {
|
fn release(mainobj: id) {
|
||||||
|
@ -118,7 +150,7 @@ mod platform {
|
||||||
NSAutoreleasePool::init(pool);
|
NSAutoreleasePool::init(pool);
|
||||||
let NSApp = NSApplication::sharedApplication();
|
let NSApp = NSApplication::sharedApplication();
|
||||||
|
|
||||||
let mainobj = MainObj::create();
|
let mainobj = MainObj::create(f);
|
||||||
NSApp::setDelegate(NSApp, mainobj);
|
NSApp::setDelegate(NSApp, mainobj);
|
||||||
NSApp::run(NSApp);
|
NSApp::run(NSApp);
|
||||||
|
|
||||||
|
@ -137,6 +169,7 @@ enum msg {
|
||||||
fn osmain() -> comm::chan<msg> {
|
fn osmain() -> comm::chan<msg> {
|
||||||
on_osmain::<msg> {|po|
|
on_osmain::<msg> {|po|
|
||||||
platform::runmain {||
|
platform::runmain {||
|
||||||
|
#debug("preparing to enter main loop");
|
||||||
mainloop(po);
|
mainloop(po);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue