Skip to content

Commit 576840e

Browse files
committed
Add documentation, remove dependency on rlua default features.
1 parent 969aa4a commit 576840e

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

include-lua/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ name = "include-lua"
33
description = "A crate that allows the embedding of a lua source tree into a Rust application binary."
44
repository = "https://github.com/AlphaModder/include-lua"
55
readme = "../README.md"
6-
version = "0.1.3"
6+
version = "0.1.4"
77
license = "MIT"
88
authors = ["AlphaModder"]
99
edition = "2018"
1010

1111
[dependencies]
12-
rlua = "0.16.2"
12+
rlua = { version = "0.16", default-features = false }
1313
include-lua-macro = "0.1.2"
1414
proc-macro-hack = "0.5.4"

include-lua/src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ use std::collections::HashMap;
33
use proc_macro_hack::proc_macro_hack;
44
use 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]
711
pub use include_lua_macro::include_lua;
812

13+
/// Represents a Lua source tree embedded into a binary via [`include_lua!`][include_lua].
914
pub 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.
2129
pub struct Searcher(LuaModules, RegistryKey);
2230

2331
impl 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.
4049
pub 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

Comments
 (0)