Skip to content
Snippets Groups Projects
Unverified Commit 630e0e83 authored by Louis's avatar Louis :fire:
Browse files

Tmp route for script testing

parent 5146efaa
No related branches found
No related tags found
No related merge requests found
...@@ -12,4 +12,5 @@ extern crate hyper; ...@@ -12,4 +12,5 @@ extern crate hyper;
extern crate rand; extern crate rand;
pub mod cli; pub mod cli;
pub mod routing; pub mod routing;
\ No newline at end of file pub mod scripting;
\ No newline at end of file
...@@ -149,7 +149,11 @@ fn main() { ...@@ -149,7 +149,11 @@ fn main() {
printq!("[SETUP] Accepting uploads at /upload"); printq!("[SETUP] Accepting uploads at /upload");
server = server.mount("/upload", routes![swerve::routing::mock_upload::to_file]); server = server.mount("/upload", routes![swerve::routing::mock_upload::to_file]);
} }
server = server.mount("/", routes![serve_root, serve_files]);; server = server.mount("/", routes![
serve_root,
serve_files,
routing::scripting::route_script
]);
if !args.flag_quiet { if !args.flag_quiet {
server = server.attach(rocket::fairing::AdHoc::on_launch(move |rckt| { server = server.attach(rocket::fairing::AdHoc::on_launch(move |rckt| {
......
pub mod mock_upload; pub mod mock_upload;
pub mod request; pub mod request;
\ No newline at end of file pub mod scripting;
\ No newline at end of file
use scripting::run_script;
use std::path::PathBuf;
#[get("/__testing__/run-script")]
pub fn route_script() -> String {
let path = PathBuf::from("example/.swerve/get_user_by_id.rhai");
run_script(path).unwrap_or(String::from("No script"))
}
\ No newline at end of file
mod run_script;
pub use self::run_script::run_script;
\ No newline at end of file
//use dyon::{Runtime,Module,load_str,Variable,Dfn,Type};
//use dyon::ast::convert;
use std::convert::AsRef;
use std::path::Path;
use std::fs::File;
use std::sync::Arc;
use std::io::Read;
use std::collections::HashMap;
const SCRIPT_FOOTER: &'static str = "
fn main() {
println(\"Don't directly execute the module, nimrod\")
}";
pub fn run_script<P: AsRef<Path>>(path: P) -> Option<String> {
// let mut resolution: Option<Variable> = None;
// dyon_fn!(fn resolve(val: Variable) {
// resolution = Some(val); // if let Ok(val) = runtime.pop() { Some(val) } else { None };
// });
//
// println!("{:?}", resolution);
let mut file = File::open(&path).unwrap();
let mut buf = String::new();
file.read_to_string(&mut buf);
buf.push_str(SCRIPT_FOOTER);
// let mut script_module = Module::new();
//
// {
// load_str(path.as_ref().to_str().unwrap(), Arc::new(buf), &mut script_module);
// }
Some(buf)
// script_module.add(Arc::new("resolve".into()), resolve, Dfn {
// lts: vec![],
// tys: vec![Type::Object],
// ret: Type::Void,
// });
//
// let mut hashmap: HashMap<Arc<String>, Variable> = HashMap::new();
// runtime.call_str("handle", &[Variable::f64(123f64)], &Arc::new(script_module));
// None
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment