(
args: &CmdlineOptions,
)
| 122 | } |
| 123 | |
| 124 | fn build_dynamical_system_function_from_args( |
| 125 | args: &CmdlineOptions, |
| 126 | ) -> eyre::Result<DynamicalSystemFn> { |
| 127 | let context = rune::Context::with_default_modules()?; |
| 128 | let runtime = rune::sync::Arc::try_new(context.runtime()?)?; |
| 129 | let mut script = rune::Sources::new(); |
| 130 | script.insert(build_rune_script(args)?)?; |
| 131 | let mut diagnostics = rune::Diagnostics::new(); |
| 132 | let maybe_unit = rune::prepare(&mut script) |
| 133 | .with_context(&context) |
| 134 | .with_diagnostics(&mut diagnostics) |
| 135 | .build(); |
| 136 | if !diagnostics.is_empty() { |
| 137 | let mut writer = |
| 138 | rune::termcolor::StandardStream::stderr(rune::termcolor::ColorChoice::Always); |
| 139 | diagnostics.emit(&mut writer, &script)?; |
| 140 | } |
| 141 | let unit = rune::sync::Arc::try_new(maybe_unit?)?; |
| 142 | |
| 143 | // the Vm is captured and retains state between calls |
| 144 | let vm = rune::Vm::new(runtime, unit); |
| 145 | let iterate = vm.lookup_function(["iterate"])?; |
| 146 | let closure = move |x: f64, y: f64| -> (f64, f64) { |
| 147 | iterate |
| 148 | .call((x, y)) |
| 149 | .expect("Failed to call iterate function") |
| 150 | }; |
| 151 | Ok(Box::new(closure)) |
| 152 | } |
| 153 | |
| 154 | fn params_from_letters(letters: &str) -> eyre::Result<Vec<String>> { |
| 155 | let mut params = Vec::new(); |
no test coverage detected