1 个不稳定版本
| 0.1.0 | 2023 年 8 月 2 日 | 
|---|
#8 in #searcher
被  2 crates 使用
21KB
448 行代码(不包括注释)
rlua-searcher
require Lua 模块按名称
(这是 https://git.sr.ht/~ioiojo/rlua-searcher 的分支,我不维护此代码,只是为了在 crates.io 上对其他依赖包可用。)
描述
将 Lua 模块编码为按模块名称索引的 Lua 字符串的 HashMap。在一个 rlua::Context 中,将 HashMap 传递给 add_searcher(),并 require 该模块。
概要
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()
}
许可证
根据您的选择,受以下任一许可证的许可:
- Apache 许可证 2.0 版 (LICENSE-APACHE 或 https://apache.ac.cn/licenses/LICENSE-2.0)
- MIT 许可证 (LICENSE-MIT 或 https://open-source.org.cn/licenses/MIT)
。
贡献
除非您明确声明,否则根据 Apache-2.0 许可证定义的,您有意提交以包含在作品中的任何贡献,均应双重许可如上所述,不附加任何其他条款或条件。
依赖
~0.8–1.4MB
~24K SLoC