omt/script/
script.rs

1use crate::util::OmError;
2
3use std::fs;
4
5use rlua::Lua;
6
7pub struct Script {
8
9}
10
11impl Script {
12
13	pub fn build(
14		input: &str,
15		_mode: &str,
16		output: &str
17	) -> Result<u32, OmError>{
18		let data = match fs::read_to_string(input) {
19			Ok( data ) => data,
20			Err( e ) => return Err(OmError::Generic(e.to_string())),
21		};
22
23		let lua = Lua::new();
24
25		let r = lua.context(|lua_ctx| {
26			match lua_ctx.load( &data ).into_function() {
27				Ok( _ ) => Ok( 0 ),
28				Err( e ) => Err( e ),
29			}
30		});
31
32//		println!( "{:?}", r );
33
34		match r {
35			Ok( _f ) => {
36				println!("Writing lua to {}", output);
37				fs::write(output, data).expect("// Unable to write file");
38				return Ok( 1 );
39			}
40			Err( _e ) => {
41				return Err(OmError::Generic("Error in script".to_string()));
42			}
43		};
44	}
45}
46