Passing things along as generators

This commit is contained in:
greg 2017-10-29 04:09:10 -07:00
parent 5ebc96daa7
commit 8fd29b5090
2 changed files with 11 additions and 14 deletions

View File

@ -47,20 +47,17 @@ fn main() {
Box::new(maaru_lang::Maaru::new()), Box::new(maaru_lang::Maaru::new()),
Box::new(robo_lang::Robo::new()), Box::new(robo_lang::Robo::new()),
]; ];
let languages2: Vec<Box<ProgrammingLanguageInterface>> =
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<ProgrammingLanguageInterface> = Box::new(schala_lang::Schala::new()); x }); let generators: Vec<PLIGenerator> = vec![
Box::new(|| { let x: Box<ProgrammingLanguageInterface> = Box::new(schala_lang::Schala::new()); x }),
Box::new(|| { let x: Box<ProgrammingLanguageInterface> = Box::new(maaru_lang::Maaru::new()); x }),
Box::new(|| { let x: Box<ProgrammingLanguageInterface> = Box::new(robo_lang::Robo::new()); x }),
];
webapp::web_main(languages2, func); schala_main(languages, generators);
schala_main(languages);
} }
fn schala_main(languages: Vec<Box<ProgrammingLanguageInterface>>) { fn schala_main(languages: Vec<Box<ProgrammingLanguageInterface>>, generators: Vec<PLIGenerator>) {
let option_matches = program_options().parse(std::env::args()).unwrap_or_else(|e| { let option_matches = program_options().parse(std::env::args()).unwrap_or_else(|e| {
println!("{:?}", e); println!("{:?}", e);
@ -80,7 +77,7 @@ fn schala_main(languages: Vec<Box<ProgrammingLanguageInterface>>) {
} }
if option_matches.opt_present("webapp") { if option_matches.opt_present("webapp") {
//webapp::web_main(languages); webapp::web_main(languages, generators);
exit(0); exit(0);
} }

View File

@ -32,12 +32,12 @@ struct Output {
} }
#[post("/input", format = "application/json", data = "<input>")] #[post("/input", format = "application/json", data = "<input>")]
fn interpreter_input(input: Json<Input>, schala_gen: State<PLIGenerator>) -> Json<Output> { fn interpreter_input(input: Json<Input>, schala_gen: State<Vec<PLIGenerator>>) -> Json<Output> {
let mut schala: Box<ProgrammingLanguageInterface> = schala_gen(); let mut schala: Box<ProgrammingLanguageInterface> = (schala_gen.get(0).unwrap())();
let code_output = schala.evaluate_in_repl(&input.source, &EvalOptions::default()); let code_output = schala.evaluate_in_repl(&input.source, &EvalOptions::default());
Json(Output { text: code_output.to_string() }) Json(Output { text: code_output.to_string() })
} }
pub fn web_main(language_generators: Vec<Box<ProgrammingLanguageInterface>>, func: PLIGenerator) { pub fn web_main(language_generators: Vec<Box<ProgrammingLanguageInterface>>, func: Vec<PLIGenerator>) {
rocket::ignite().manage(func).mount("/", routes![index, js_bundle, interpreter_input]).launch(); rocket::ignite().manage(func).mount("/", routes![index, js_bundle, interpreter_input]).launch();
} }