]> git.lizzy.rs Git - rust.git/commitdiff
green: Add a helper macro for booting libgreen
authorAlex Crichton <alex@alexcrichton.com>
Tue, 15 Apr 2014 13:27:09 +0000 (06:27 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Wed, 16 Apr 2014 02:47:03 +0000 (19:47 -0700)
This one-liner should help booting libgreen with librustuv without having to
worry about all the fiddly bits of argc/argv and whatnot.

src/libgreen/lib.rs

index 820627b6b7d13d8d395f04449926b90248608a06..dd897b9db4bafe8564a40f35044d4f0f2588541b 100644 (file)
 //! }
 //! ```
 //!
+//! 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
 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