1 unstable release

0.1.0 Aug 2, 2023

#4 in #rlua

Download history 237/week @ 2024-08-18 423/week @ 2024-08-25 30/week @ 2024-09-01 18/week @ 2024-09-08 22/week @ 2024-09-15 40/week @ 2024-09-22 38/week @ 2024-09-29 31/week @ 2024-10-06 24/week @ 2024-10-13 23/week @ 2024-10-20 22/week @ 2024-10-27 16/week @ 2024-11-03

89 downloads per month
Used in 2 crates

MIT/Apache

21KB
448 lines

rlua-searcher

require Lua modules by name

(This is a fork of https://git.sr.ht/~ioiojo/rlua-searcher, I don't maintain this code, I just need to available on crates.io for other dependent packages.)

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.

Dependencies

~0.8–1.3MB
~22K SLoC