Skip to content

Commit 34d7504

Browse files
committed
Add README
1 parent 9ca238a commit 34d7504

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# include-lua #
2+
include-lua is a crate that allows the embedding of a lua source tree into a Rust application binary. This tree can then be loaded into an [`rlua`](https://github.com/kyren/rlua) context, and code imported from it via `require`.
3+
4+
## Usage ##
5+
First, create an instance of the `LuaModules` struct via the macro `include_lua!`. This macro takes a string literal parameter specifying a directory, relative to your crate's `src` folder. All `.lua` files in this directory and its subdirectories will be included as loadable modules.
6+
7+
It is possible to specify a name to use for the `LuaModules` struct, though at the moment this will only appear in lua stacktraces. Simply invoke the macro like `include_lua!("name": "path")`, instead of just `include_lua!("path")`.
8+
9+
Once you've created a `LuaModules` struct, you can import it into an `rlua::Context` by calling `ctx.add_modules(modules)`. This is an extension method provided by a trait, so make sure you have a `use include_lua::*;` statement in your code. Once it has been called, any calls to `require` executed in that context will be able to load modules from the embedded source tree.
10+
11+
If you would like to load the modules in a custom environment for some reason, call `ctx.add_modules_with_env(modules, env)`, where `env` is a table that will be used as the `_ENV` value of all modules within the source tree.
12+
13+
## Example ##
14+
See [example/main.rs](https://github.com/AlphaModder/include-lua/blob/master/example/src/main.rs) for a working example of the macro's use.
15+
16+
## Caveats ##
17+
Currently, this crate does not support paths that contain non-unicode characters. Any files along these paths will be omitted from an `include_lua!` call.

0 commit comments

Comments
 (0)