Skip to content

Commit

Permalink
green: Add a helper macro for booting libgreen
Browse files Browse the repository at this point in the history
This one-liner should help booting libgreen with librustuv without having to
worry about all the fiddly bits of argc/argv and whatnot.
  • Loading branch information
alexcrichton committed Apr 16, 2014
1 parent 55f02b2 commit 0754d1d
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/libgreen/lib.rs
Expand Up @@ -144,6 +144,19 @@
//! }
//! ```
//!
//! The above code can also be shortened with a macro from libgreen.
//!
//! ```
//! #![feature(phase)]
//! #[phase(syntax)] extern crate green;
//!
//! green_start!(main)
//!
//! fn main() {
//! // run inside of a green pool
//! }
//! ```
//!
//! # Using a scheduler pool
//!
//! ```rust
Expand Down Expand Up @@ -229,6 +242,33 @@ pub mod sleeper_list;
pub mod stack;
pub mod task;

/// A helper macro for booting a program with libgreen
///
/// # Example
///
/// ```
/// #![feature(phase)]
/// #[phase(syntax)] extern crate green;
///
/// green_start!(main)
///
/// fn main() {
/// // running with libgreen
/// }
/// ```
#[macro_export]
macro_rules! green_start( ($f:ident) => (
mod __start {
extern crate green;
extern crate rustuv;

#[start]
fn start(argc: int, argv: **u8) -> int {
green::start(argc, argv, rustuv::event_loop, super::$f)
}
}
) )

/// Set up a default runtime configuration, given compiler-supplied arguments.
///
/// This function will block until the entire pool of M:N schedulers have
Expand Down

0 comments on commit 0754d1d

Please sign in to comment.