Support shebangs in scripts.

This commit is contained in:
Stephen Chung
2021-03-28 16:36:56 +08:00
parent ea970631ff
commit 7825cb1c56
4 changed files with 31 additions and 7 deletions

View File

@@ -1185,6 +1185,15 @@ impl Engine {
)
})?;
if contents.starts_with("#!") {
// Remove shebang
if let Some(n) = contents.find('\n') {
contents.drain(0..n).count();
} else {
contents.clear();
}
};
Ok(contents)
}
/// Compile a script file into an [`AST`], which can be used later for evaluation.