Skip to content

Commit

Permalink
add /scripting
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-frmr committed Jul 22, 2024
1 parent f1100a2 commit e4672df
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ pub mod timer;
/// `vfs:distro:sys` to use this module.
pub mod vfs;

/// A set of types and macros for writing "script" processes.
pub mod scripting;

mod types;
pub use types::{
address::{Address, AddressParseError},
Expand Down
24 changes: 24 additions & 0 deletions src/scripting/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#[macro_export]
/// A macro for writing a "script" process. Using this will create the initial
/// entry point for your process, including the standard `init` function which
/// is called by the system, and a set of calls that:
/// 1. Parse the `our` string into an `Address` object.
/// 2. Wait for the first message to be sent to the process.
/// 3. Convert the message body into a string.
/// 4. Call the `init` function you provide with the `Address` and the message body string.
///
/// This is best used by then using `clap` to create a `Command` and parsing the body string with it.
macro_rules! script {
($init_func:ident) => {
struct Component;
impl Guest for Component {
fn init(our: String) {
let our: Address = our.parse().unwrap();
let body: Vec<u8> = await_next_message_body().unwrap();
let body_string = format!("{} {}", our.process(), String::from_utf8(body).unwrap());
$init_func(our, body);
}
}
export!(Component);
};
}

0 comments on commit e4672df

Please sign in to comment.