aboutsummaryrefslogtreecommitdiff
path: root/src/lua.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua.rs')
-rw-r--r--src/lua.rs43
1 files changed, 0 insertions, 43 deletions
diff --git a/src/lua.rs b/src/lua.rs
index 5caf3f1..e9c4841 100644
--- a/src/lua.rs
+++ b/src/lua.rs
@@ -16,23 +16,6 @@ use self::template::ArgIndex;
mod serde;
pub mod template;
-pub struct Script<'a> {
- pub lua_module_name: &'a str,
- input: &'a str,
-}
-
-pub fn parse_shebang(text: &str) -> Option<Script> {
- if let Some(rest) = text.strip_prefix("#!") {
- if let Some((lua_module_name, input)) = rest.split_once('\n') {
- return Some(Script {
- lua_module_name,
- input,
- });
- }
- }
- None
-}
-
pub enum ScriptError {
ModuleNotFound,
ModuleNotUtf8,
@@ -90,32 +73,6 @@ pub fn lua_context<A>(run: impl FnOnce(rlua::Context) -> rlua::Result<A>) -> rlu
})
}
-impl<'a> Script<'a> {
- pub fn module_path(&self) -> String {
- format!("bin/{}.lua", self.lua_module_name)
- }
-
- pub fn run(&self, ctx: &Context) -> Result<String, ScriptError> {
- let filename = self.module_path();
-
- let lua_entr = ctx
- .branch_head()
- .unwrap()
- .tree()
- .and_then(|tree| tree.get_path(Path::new(&filename)))
- .map_err(|_| ScriptError::ModuleNotFound)?;
-
- let lua_blob = ctx.repo.find_blob(lua_entr.id()).unwrap();
- let lua_code = from_utf8(lua_blob.content()).map_err(|_| ScriptError::ModuleNotUtf8)?;
- lua_context(|ctx| {
- let module: Table = ctx.load(lua_code).eval()?;
- let view: Function = module.get("view")?;
- view.call(self.input)
- })
- .map_err(ScriptError::LuaError)
- }
-}
-
fn module_path(module_name: &str) -> String {
format!("modules/{}.lua", module_name)
}