commit
253e43da30
@ -66,53 +66,56 @@ fn main() {
|
|||||||
|
|
||||||
// Load init scripts
|
// Load init scripts
|
||||||
|
|
||||||
let mut contents = String::new();
|
#[cfg(not(feature = "no_module"))]
|
||||||
let mut has_init_scripts = false;
|
{
|
||||||
|
let mut contents = String::new();
|
||||||
|
let mut has_init_scripts = false;
|
||||||
|
|
||||||
for filename in env::args().skip(1) {
|
for filename in env::args().skip(1) {
|
||||||
{
|
{
|
||||||
contents.clear();
|
contents.clear();
|
||||||
|
|
||||||
let mut f = match File::open(&filename) {
|
let mut f = match File::open(&filename) {
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Error reading script file: {}\n{}", filename, err);
|
eprintln!("Error reading script file: {}\n{}", filename, err);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
Ok(f) => f,
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Err(err) = f.read_to_string(&mut contents) {
|
||||||
|
println!("Error reading script file: {}\n{}", filename, err);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
Ok(f) => f,
|
}
|
||||||
|
|
||||||
|
let module = match engine
|
||||||
|
.compile(&contents)
|
||||||
|
.map_err(|err| err.into())
|
||||||
|
.and_then(|ast| Module::eval_ast_as_new(Default::default(), &ast, &engine))
|
||||||
|
{
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("{:=<1$}", "", filename.len());
|
||||||
|
eprintln!("{}", filename);
|
||||||
|
eprintln!("{:=<1$}", "", filename.len());
|
||||||
|
eprintln!("");
|
||||||
|
|
||||||
|
print_error(&contents, *err);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
Ok(m) => m,
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Err(err) = f.read_to_string(&mut contents) {
|
engine.register_global_module(module.into());
|
||||||
println!("Error reading script file: {}\n{}", filename, err);
|
|
||||||
exit(1);
|
has_init_scripts = true;
|
||||||
}
|
|
||||||
|
println!("Script '{}' loaded.", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
let module = match engine
|
if has_init_scripts {
|
||||||
.compile(&contents)
|
println!();
|
||||||
.map_err(|err| err.into())
|
}
|
||||||
.and_then(|ast| Module::eval_ast_as_new(Default::default(), &ast, &engine))
|
|
||||||
{
|
|
||||||
Err(err) => {
|
|
||||||
eprintln!("{:=<1$}", "", filename.len());
|
|
||||||
eprintln!("{}", filename);
|
|
||||||
eprintln!("{:=<1$}", "", filename.len());
|
|
||||||
eprintln!("");
|
|
||||||
|
|
||||||
print_error(&contents, *err);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
Ok(m) => m,
|
|
||||||
};
|
|
||||||
|
|
||||||
engine.register_global_module(module.into());
|
|
||||||
|
|
||||||
has_init_scripts = true;
|
|
||||||
|
|
||||||
println!("Script '{}' loaded.", filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
if has_init_scripts {
|
|
||||||
println!();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup Engine
|
// Setup Engine
|
||||||
|
Loading…
Reference in New Issue
Block a user