Skip to content

Commit

Permalink
Merge pull request #160 from juchiast/patch-rs-binding
Browse files Browse the repository at this point in the history
patch-rs binding
  • Loading branch information
dariusc93 authored Dec 14, 2018
2 parents 8912d61 + e5fe426 commit e1af877
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 1 deletion.
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ blake2 = "0.8.0"
tar = "0.4.20"
xz2 = "0.1.6"
unidiff = { git = "https://github.com/foundpatterns/difflib" }
patch-rs = "0.3"


[dev-dependencies]
Expand Down
2 changes: 2 additions & 0 deletions src/bindings/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub mod log;
pub mod markdown;
pub mod tera;
pub mod diff;
pub mod patch;

use rlua::prelude::*;

Expand All @@ -22,6 +23,7 @@ pub fn init(lua: &Lua) -> ::Result<()> {
tantivy::init(&lua)?;
tera::init(&lua)?;
diff::init(&lua)?;
patch::init(&lua)?;

Ok(())
}
24 changes: 24 additions & 0 deletions src/bindings/app/patch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use rlua::{Lua, UserData, UserDataMethods};

struct PatchParser(patch_rs::PatchParser);

impl UserData for PatchParser {
fn add_methods<'lua, M: UserDataMethods<'lua, Self>>(methods: &mut M) {
methods.add_method("process", |_, this, _: ()| {
this.0.process().map_err(rlua::Error::external)
});
}
}

pub fn init(lua: &Lua) -> Result<(), rlua::Error> {
let module = lua.create_table()?;
module.set(
"new",
lua.create_function(|_, (text, patch): (Vec<String>, String)| {
Ok(PatchParser(patch_rs::PatchParser::new(text, patch)))
})?,
)?;
let g = lua.globals();
g.set("patch_parser", module)?;
Ok(())
}
2 changes: 1 addition & 1 deletion src/bindings/string/stringset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,4 @@ mod tests {
symmetric(a, b)
"#, None).unwrap();
}
}
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ extern crate tar;
extern crate xz2;
extern crate unidiff;
extern crate blake2;
extern crate patch_rs;

#[cfg(feature = "tantivy_bindings")]
extern crate tantivy;
Expand Down

0 comments on commit e1af877

Please sign in to comment.