From 8fd29b509088ca63af59bdb331d59c4d4c5c2f62 Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 29 Oct 2017 04:09:10 -0700 Subject: [PATCH] Passing things along as generators --- src/main.rs | 19 ++++++++----------- src/webapp.rs | 6 +++--- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7518f52..36772b3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -47,20 +47,17 @@ fn main() { Box::new(maaru_lang::Maaru::new()), Box::new(robo_lang::Robo::new()), ]; - let languages2: Vec> = - vec![ - Box::new(schala_lang::Schala::new()), - Box::new(maaru_lang::Maaru::new()), - Box::new(robo_lang::Robo::new()), - ]; - let func = Box::new(|| { let x: Box = Box::new(schala_lang::Schala::new()); x }); + let generators: Vec = vec![ + Box::new(|| { let x: Box = Box::new(schala_lang::Schala::new()); x }), + Box::new(|| { let x: Box = Box::new(maaru_lang::Maaru::new()); x }), + Box::new(|| { let x: Box = Box::new(robo_lang::Robo::new()); x }), + ]; - webapp::web_main(languages2, func); - schala_main(languages); + schala_main(languages, generators); } -fn schala_main(languages: Vec>) { +fn schala_main(languages: Vec>, generators: Vec) { let option_matches = program_options().parse(std::env::args()).unwrap_or_else(|e| { println!("{:?}", e); @@ -80,7 +77,7 @@ fn schala_main(languages: Vec>) { } if option_matches.opt_present("webapp") { - //webapp::web_main(languages); + webapp::web_main(languages, generators); exit(0); } diff --git a/src/webapp.rs b/src/webapp.rs index 11120ed..1918f55 100644 --- a/src/webapp.rs +++ b/src/webapp.rs @@ -32,12 +32,12 @@ struct Output { } #[post("/input", format = "application/json", data = "")] -fn interpreter_input(input: Json, schala_gen: State) -> Json { - let mut schala: Box = schala_gen(); +fn interpreter_input(input: Json, schala_gen: State>) -> Json { + let mut schala: Box = (schala_gen.get(0).unwrap())(); let code_output = schala.evaluate_in_repl(&input.source, &EvalOptions::default()); Json(Output { text: code_output.to_string() }) } -pub fn web_main(language_generators: Vec>, func: PLIGenerator) { +pub fn web_main(language_generators: Vec>, func: Vec) { rocket::ignite().manage(func).mount("/", routes![index, js_bundle, interpreter_input]).launch(); }