@@ -3,9 +3,14 @@ use std::collections::HashMap;
33use proc_macro_hack:: proc_macro_hack;
44use rlua:: { Result , Context , UserData , UserDataMethods , MetaMethod , Value , Table , RegistryKey } ;
55
6+ /// A macro that embeds a lua source tree on disk into the binary, similarly to how `include_str!`
7+ /// can include a single file. Called like `include_lua!("name": "path")`, where name is a label
8+ /// that appears in lua stacktraces involving code loaded from the tree, and path specifies a folder
9+ /// relative to `src/` in which the tree can be found. `name` defaults to `path` if omitted.
610#[ proc_macro_hack]
711pub use include_lua_macro:: include_lua;
812
13+ /// Represents a Lua source tree embedded into a binary via [`include_lua!`][include_lua].
914pub struct LuaModules {
1015 files : HashMap < String , ( String , String ) > ,
1116 prefix : String ,
@@ -18,6 +23,9 @@ impl LuaModules {
1823 }
1924}
2025
26+ /// A piece of [`UserData`][UserData] that acts like a Lua searcher.
27+ /// When called as a function with a single string parameter, attempts to load
28+ /// (but not execute) a module by that name. If no module is found, returns nil.
2129pub struct Searcher ( LuaModules , RegistryKey ) ;
2230
2331impl UserData for Searcher {
@@ -37,10 +45,20 @@ impl UserData for Searcher {
3745 }
3846}
3947
48+ /// An extension trait for [`Context`][Context] that allows the loading of [`LuaModules`][LuaModules] instances.
4049pub trait ContextExt < ' a > {
50+ /// Makes the source tree represented by `modules` accessible to `require` calls within this context.
4151 fn add_modules ( & self , modules : LuaModules ) -> Result < ( ) > ;
52+
53+ /// Makes the source tree represented by `modules` accessible to `require` calls within this context.
54+ /// All modules loaded from the source tree will have their environment set to `environment`.
4255 fn add_modules_with_env ( & self , modules : LuaModules , environment : Table < ' a > ) -> Result < ( ) > ;
56+
57+ /// Creates a [`Searcher`][Searcher] instance from the given [`LuaModules`][LuaModules] instance.
4358 fn make_searcher ( & self , modules : LuaModules ) -> Result < Searcher > ;
59+
60+ /// Creates a [`Searcher`][Searcher] instance from the given [`LuaModules`][LuaModules] instance.
61+ /// All modules loaded by the searcher will have their environment set to `environment`.
4462 fn make_searcher_with_env ( & self , modules : LuaModules , environment : Table < ' a > ) -> Result < Searcher > ;
4563}
4664
0 commit comments