implement add_static_searcher

to facilitate compile-time includes
This commit is contained in:
Andy Weidenbaum
2021-02-13 17:15:35 +11:00
parent a7c9fbdba8
commit f159a7cc27
2 changed files with 68 additions and 1 deletions

View File

@@ -3,7 +3,7 @@ use rlua_searcher::{AddSearcher, Result};
use std::collections::HashMap;
#[test]
fn it_works() {
fn add_searcher_works() {
let lume = read_lume_to_string();
let name = "lume".to_string();
let mut map = HashMap::new();
@@ -21,6 +21,29 @@ fn it_works() {
assert_eq!("hello lume", hello);
}
#[test]
fn add_static_searcher_works() {
let lume = read_lume_to_str();
let name = "lume".to_string();
let mut map = HashMap::new();
map.insert(name, lume);
let lua = Lua::new();
let hello = lua
.context::<_, Result<String>>(|lua_ctx| {
lua_ctx.add_static_searcher(map)?;
Ok(lua_ctx.load(r#"return require("lume")"#).eval()?)
})
.unwrap();
assert_eq!("hello lume", hello);
}
fn read_lume_to_string() -> String {
r#"return "hello lume""#.to_string()
}
fn read_lume_to_str() -> &'static str {
r#"return "hello lume""#
}