From 187c5f55eaa6a15bb936437ee359d8e7b8d087c3 Mon Sep 17 00:00:00 2001 From: Andy Weidenbaum Date: Thu, 4 Feb 2021 11:09:05 +1100 Subject: [PATCH] init --- .gitignore | 2 ++ Cargo.toml | 14 ++++++++++++++ LICENSE | 21 +++++++++++++++++++++ README.md | 40 ++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 7 +++++++ 5 files changed, 84 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 LICENSE create mode 100644 README.md create mode 100644 src/lib.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..96ef6c0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..4af0684 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "rlua-searcher" +version = "0.1.0" +edition = "2018" +authors = ["Andy Weidenbaum "] +license = "MIT" +keywords = ["lua"] +homepage = "https://git.sr.ht/~ioiojo/rlua-searcher" +repository = "https://git.sr.ht/~ioiojo/rlua-searcher" +readme = "README.md" +description = "Require Lua modules by name" + +[dependencies] +rlua = "0.17" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e29e8a3 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2021 Andy Weidenbaum + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..544a6cd --- /dev/null +++ b/README.md @@ -0,0 +1,40 @@ +# rlua-searcher + +`require` Lua modules by name + +## Description + +Encode a Lua module as a `HashMap` of Lua strings indexed by module +name. In an `rlua::Context`, pass the `HashMap` to `add_searcher()`, +and `require` the module. + +## Synopsis + +```rust +use rlua_searcher::AddSearcher; + +fn main() { + let lume = read_lume_to_string(); + let name = "lume"; + let map = HashMap::new(); + map.insert(name, lume); + + let lua = Lua::new; + + let hello = lua.context::<_, rlua::Result<_>>(|lua_ctx| { + lua_ctx.add_searcher(map)?; + Ok(lua_ctx.load(r#"require("lume")"#).eval()?) + }).unwrap(); + + // prints "hello lume" + println!("{}", hello); +} + +fn read_lume_to_string() -> String { + r#"return "hello lume""#.to_string() +} +``` + +## License + +[MIT](LICENSE) diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..31e1bb2 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,7 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +}