MCPcopy Create free account
hub / github.com/Notgnoshi/generative / build_function_from_lines

Function build_function_from_lines

tools/streamline.rs:143–166  ·  view source on GitHub ↗
(lines: &[String])

Source from the content-addressed store, hash-verified

141type VectorFieldFunction = Box<dyn Fn(f64, f64) -> (f64, f64)>;
142
143fn build_function_from_lines(lines: &[String]) -> eyre::Result<VectorFieldFunction> {
144 let context = rune::Context::with_default_modules()?;
145 let runtime = rune::sync::Arc::try_new(context.runtime()?)?;
146 let mut script = build_script_from_lines(lines)?;
147 let mut diagnostics = rune::Diagnostics::new();
148 let maybe_unit = rune::prepare(&mut script)
149 .with_context(&context)
150 .with_diagnostics(&mut diagnostics)
151 .build();
152 if !diagnostics.is_empty() {
153 let mut writer =
154 rune::termcolor::StandardStream::stderr(rune::termcolor::ColorChoice::Always);
155 diagnostics.emit(&mut writer, &script)?;
156 }
157 let unit = rune::sync::Arc::try_new(maybe_unit?)?;
158 let vm = rune::Vm::new(runtime, unit);
159 let eval_field = vm.lookup_function(["eval_field"])?;
160 let eval_expr = move |x: f64, y: f64| -> (f64, f64) {
161 eval_field
162 .call((x, y))
163 .expect("Failed to call eval_field()")
164 };
165 Ok(Box::new(eval_expr))
166}
167
168fn build_script_from_lines(lines: &[String]) -> eyre::Result<rune::Sources> {
169 let mut sources = rune::Sources::new();

Callers 1

mainFunction · 0.85

Calls 2

build_script_from_linesFunction · 0.85
buildMethod · 0.80

Tested by

no test coverage detected