Go to file
2022-06-23 10:42:35 +10:00
src impl From<Error> for rlua::Error 2022-06-23 10:42:35 +10:00
tests s/’/' to be more tty friendly 2022-01-19 20:20:46 +11:00
.gitignore init 2021-02-04 11:09:05 +11:00
Cargo.toml update rlua to 0.18 2022-01-22 21:28:10 +11:00
LICENSE-APACHE relicense under dual MIT/Apache scheme 2021-03-22 11:57:11 +11:00
LICENSE-MIT 2022 2022-01-12 17:56:13 +11:00
README.md update readme example 2021-06-15 07:55:12 +10:00

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

use rlua::Lua;
use rlua_searcher::{AddSearcher, Result};
use std::collections::HashMap;

fn main() {
    let lume = Cow::from(read_lume_to_string());
    let name = Cow::from("lume");
    let mut map = HashMap::new();
    map.insert(name, lume);

    let lua = Lua::new();

    let hello = lua
        .context::<_, Result<String>>(|lua_ctx| {
            lua_ctx.add_searcher(map)?;
            Ok(lua_ctx.load(r#"return require("lume")"#).eval()?)
        })
        .unwrap();

    // prints "hello lume"
    println!("{}", hello);
}

fn read_lume_to_string() -> String {
    r#"return "hello lume""#.to_string()
}

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.