init
This commit is contained in:
commit
187c5f55ea
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/target
|
||||
Cargo.lock
|
14
Cargo.toml
Normal file
14
Cargo.toml
Normal file
@ -0,0 +1,14 @@
|
||||
[package]
|
||||
name = "rlua-searcher"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
authors = ["Andy Weidenbaum <atweiden@ioiojo.com>"]
|
||||
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"
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -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.
|
40
README.md
Normal file
40
README.md
Normal file
@ -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<String, String>();
|
||||
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)
|
7
src/lib.rs
Normal file
7
src/lib.rs
Normal file
@ -0,0 +1,7 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn it_works() {
|
||||
assert_eq!(2 + 2, 4);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user