Skip to content

Commit 0754d1d

Browse files
committed
green: Add a helper macro for booting libgreen
This one-liner should help booting libgreen with librustuv without having to worry about all the fiddly bits of argc/argv and whatnot.
1 parent 55f02b2 commit 0754d1d

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/libgreen/lib.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,19 @@
144144
//! }
145145
//! ```
146146
//!
147+
//! The above code can also be shortened with a macro from libgreen.
148+
//!
149+
//! ```
150+
//! #![feature(phase)]
151+
//! #[phase(syntax)] extern crate green;
152+
//!
153+
//! green_start!(main)
154+
//!
155+
//! fn main() {
156+
//! // run inside of a green pool
157+
//! }
158+
//! ```
159+
//!
147160
//! # Using a scheduler pool
148161
//!
149162
//! ```rust
@@ -229,6 +242,33 @@ pub mod sleeper_list;
229242
pub mod stack;
230243
pub mod task;
231244

245+
/// A helper macro for booting a program with libgreen
246+
///
247+
/// # Example
248+
///
249+
/// ```
250+
/// #![feature(phase)]
251+
/// #[phase(syntax)] extern crate green;
252+
///
253+
/// green_start!(main)
254+
///
255+
/// fn main() {
256+
/// // running with libgreen
257+
/// }
258+
/// ```
259+
#[macro_export]
260+
macro_rules! green_start( ($f:ident) => (
261+
mod __start {
262+
extern crate green;
263+
extern crate rustuv;
264+
265+
#[start]
266+
fn start(argc: int, argv: **u8) -> int {
267+
green::start(argc, argv, rustuv::event_loop, super::$f)
268+
}
269+
}
270+
) )
271+
232272
/// Set up a default runtime configuration, given compiler-supplied arguments.
233273
///
234274
/// This function will block until the entire pool of M:N schedulers have

0 commit comments

Comments
 (0)