Newer
Older
use routing::request;
use server::LuaRuntime;
use rlua::{Lua};
use scripting::run_script;
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use rocket::request::{FromForm, FormItems};
use std::collections::HashMap;
#[derive(Debug)]
pub struct ScriptParams {
pub script_name: String,
pub script_params: HashMap<String, String>,
}
impl <'form> FromForm<'form> for ScriptParams {
type Error = ();
fn from_form(items: &mut FormItems<'form>, _: bool) -> Result<ScriptParams, Self::Error> {
let mut script_name: Option<String> = None;
let mut script_params: HashMap<String, String> = HashMap::new();
for (key, value) in items {
match key.as_str() {
"script_path" if script_name.is_none() => { script_name = Some(String::from(value.as_str())); },
_ => { script_params.insert(String::from(key.as_str()), String::from(value.as_str())); },
};
}
match script_name {
Some(name) => Ok(ScriptParams { script_name: name, script_params }),
None => Err(()),
}
}
}
#[get("/__run_script__?<params>")]
pub fn route_script(params: ScriptParams, runtime: LuaRuntime) -> String {
let lua: Lua = runtime.into(); //todo: Use This
println!("{:?}", params);
run_script("example/.swerve/get_user.lua", &lua);