Update README, small example changes.
This commit is contained in:
parent
8156b7e529
commit
6f0caa4a6d
14
README.md
14
README.md
|
@ -2,11 +2,13 @@
|
|||
|
||||
[![Build Status](https://travis-ci.org/chucklefish/rlua.svg?branch=master)](https://travis-ci.org/chucklefish/rlua)
|
||||
|
||||
[WIP API Documentation](https://docs.rs/rlua)
|
||||
[API Documentation](https://docs.rs/rlua)
|
||||
|
||||
This library is a WIP high level interface between Rust and Lua. Its major
|
||||
goal is to expose as easy to use, practical, and flexible of an API between
|
||||
Rust and Lua as possible, while also being completely safe.
|
||||
[Examples](examples/examples.rs)
|
||||
|
||||
This library is a high level interface between Rust and Lua. Its major goal is
|
||||
to expose as easy to use, practical, and flexible of an API between Rust and Lua
|
||||
as possible, while also being completely safe.
|
||||
|
||||
There are other high level Lua bindings systems for rust, and this crate is an
|
||||
exploration of a different part of the design space. The main high level
|
||||
|
@ -115,7 +117,3 @@ Panic / abort considerations when using this API:
|
|||
abort, from exceeding LUAI_MAXCCALLS.
|
||||
* There are no checks on argument sizes, and I think you can cause an abort by
|
||||
providing a large enough `LuaVariadic`.
|
||||
|
||||
## Examples
|
||||
|
||||
There's sort of a guided tour of the API [here](examples/examples.rs).
|
||||
|
|
|
@ -14,9 +14,9 @@ fn examples() -> LuaResult<()> {
|
|||
let lua = Lua::new();
|
||||
|
||||
// You can get and set global variables. Notice that the globals table here
|
||||
// is a permanent reference to _G, it is mutated behind the scenes as lua
|
||||
// code is loaded. This API is based heavily around internal mutation (just
|
||||
// like lua itself).
|
||||
// is a permanent reference to _G, and it is mutated behind the scenes as
|
||||
// lua code is loaded. This API is based heavily around internal mutation
|
||||
// (just like lua itself).
|
||||
|
||||
let globals = lua.globals();
|
||||
|
||||
|
@ -78,9 +78,8 @@ fn examples() -> LuaResult<()> {
|
|||
let print: LuaFunction = globals.get("print")?;
|
||||
print.call::<_, ()>("hello from rust")?;
|
||||
|
||||
// There is a specific method for handling variadics that involves
|
||||
// Heterogeneous Lists. This is one way to call a function with multiple
|
||||
// parameters:
|
||||
// This API handles variadics using Heterogeneous Lists. This is one way to
|
||||
// call a function with multiple parameters:
|
||||
|
||||
print.call::<_, ()>(
|
||||
hlist!["hello", "again", "from", "rust"],
|
||||
|
@ -107,7 +106,8 @@ fn examples() -> LuaResult<()> {
|
|||
});
|
||||
globals.set("check_equal", check_equal)?;
|
||||
|
||||
// You can also accept variadic arguments to rust functions
|
||||
// You can also accept variadic arguments to rust callbacks.
|
||||
|
||||
let join = lua.create_function(|lua, args| {
|
||||
let strings = lua.unpack::<LuaVariadic<String>>(args)?.0;
|
||||
// (This is quadratic!, it's just an example!)
|
||||
|
@ -130,8 +130,8 @@ fn examples() -> LuaResult<()> {
|
|||
assert_eq!(lua.eval::<String>(r#"join("a", "b", "c")"#)?, "abc");
|
||||
|
||||
// You can create userdata with methods and metamethods defined on them.
|
||||
// Here's a more complete example that shows many of the features of this
|
||||
// API together
|
||||
// Here's a worked example that shows many of the features of this API
|
||||
// together
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
struct Vec2(f32, f32);
|
||||
|
|
Loading…
Reference in New Issue