///
/// # Arguments
///
-/// * `main` - A C-abi function that takes no arguments and returns `c_void`.
-/// It is a wrapper around the user-defined `main` function, and will be run
-/// in a task.
/// * `argc` & `argv` - The argument vector. On Unix this information is used
/// by os::args.
/// * `crate_map` - Runtime information about the executing crate, mostly for logging
/// # Return value
///
/// The return value is used as the process return code. 0 on success, 101 on error.
-pub fn start(main: *u8, _argc: int, _argv: **c_char, _crate_map: *u8) -> int {
+pub fn start(_argc: int, _argv: **c_char, _crate_map: *u8, main: ~fn()) -> int {
use self::sched::{Scheduler, Task};
use self::uv::uvio::UvEventLoop;
- use sys::Closure;
- use ptr;
- use cast;
let loop_ = ~UvEventLoop::new();
let mut sched = ~Scheduler::new(loop_);
-
- let main_task = ~do Task::new(&mut sched.stack_pool) {
-
- unsafe {
- // `main` is an `fn() -> ()` that doesn't take an environment
- // XXX: Could also call this as an `extern "Rust" fn` once they work
- let main = Closure {
- code: main as *(),
- env: ptr::null(),
- };
- let mainfn: &fn() = cast::transmute(main);
-
- mainfn();
- }
- };
+ let main_task = ~Task::new(&mut sched.stack_pool, main);
sched.task_queue.push_back(main_task);
sched.run();
pub fn start(main: *u8, argc: int, argv: **c_char,
crate_map: *u8) -> int {
use libc::getenv;
- use rt::start;
+ use rt;
+ use sys::Closure;
+ use ptr;
+ use cast;
unsafe {
let use_old_rt = do str::as_c_str("RUST_NEWRT") |s| {
return rust_start(main as *c_void, argc as c_int, argv,
crate_map as *c_void) as int;
} else {
- return start(main, argc, argv, crate_map);
+ return do rt::start(argc, argv, crate_map) {
+ unsafe {
+ // `main` is an `fn() -> ()` that doesn't take an environment
+ // XXX: Could also call this as an `extern "Rust" fn` once they work
+ let main = Closure {
+ code: main as *(),
+ env: ptr::null(),
+ };
+ let mainfn: &fn() = cast::transmute(main);
+
+ mainfn();
+ }
+ };
}
}
--- /dev/null
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// A simple test of starting the runtime manually
+
+#[start]
+fn start(argc: int, argv: **u8, crate_map: *u8) -> int {
+ do core::rt::start(argc, argv, crate_map) {
+ debug!("creating my own runtime is joy");
+ }
+}
\ No newline at end of file