Skip to content

Commit

Permalink
add a print_line rhai script helper
Browse files Browse the repository at this point in the history
Signed-off-by: karthik2804 <[email protected]>
  • Loading branch information
karthik2804 committed May 21, 2023
1 parent 61a2cb7 commit 6e17ca3
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/rhai_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@ pub fn custom_rhai_engine_init() -> Engine {
let mut rhai_engine = Engine::new();

rhai_engine.register_fn("current_date", current_date);
rhai_engine.register_fn("print_line", print_line);

rhai_engine
}

/* Allows access for current_date in rhai script to allow for filtering
The specific date format is to allow for comparision inside rhai scripts */
// Allows access for current_date in rhai script to allow for filtering
// The specific date format is to allow for comparision inside rhai scripts
fn current_date() -> String {
Utc::now().to_rfc3339_opts(SecondsFormat::Secs, true)
}

// Allows for some debugging capability for rhai scripts by printing to stdout
// instead of having to serially print output of steps on the webpage
fn print_line(message: String) {
println!("{message}");
}

0 comments on commit 6e17ca3

Please sign in to comment.