Skip to content

Commit

Permalink
feat(runtime_example): add example of hot reloading in the Mun Runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
Wodann committed Nov 5, 2019
1 parent d3be990 commit 34085a6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
22 changes: 22 additions & 0 deletions crates/mun_runtime/examples/hot_reloading.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use mun_runtime::{invoke_fn, RetryResultExt, RuntimeBuilder};
use std::env;

// How to run?
// 1. On the CLI, navigate to the `crates/mun_runtime/examples` directory.
// 2. Run the compiler daemon from the CLI: `/path/to/mun build resources/fibonacci.mun --watch`
// 3. Run the application from the CLI: cargo run --example hot_reloading -- fibonacci.dll
fn main() {
let lib_dir = env::args().nth(1).expect("Expected path to a Mun library.");
println!("lib: {}", lib_dir);

let mut runtime = RuntimeBuilder::new(lib_dir)
.spawn()
.expect("Failed to spawn Runtime");

loop {
let n: i64 = invoke_fn!(runtime, "nth").wait();
let result: i64 = invoke_fn!(runtime, "fibonacci", n).wait();
println!("fibonacci({}) = {}", n, result);
runtime.update();
}
}
11 changes: 11 additions & 0 deletions crates/mun_runtime/examples/resources/fibonacci.mun
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
fn nth(): int {
3
}

fn fibonacci(n:int):int {
if n <= 1 {
n
} else {
fibonacci(n-1) + fibonacci(n-2)
}
}

0 comments on commit 34085a6

Please sign in to comment.