rust-lua53-ext
Abstraction layer between Rust and Lua
This is an extension to jcmoyer's rust-lua53 Lua bindings. It makes interfacing between Rust and Lua much simpler and more Rust-like.
Even though this is an abstraction layer, you still need to have an understanding of Lua's state system and how to use rust-lua53.
Why use this?
When interfacing with a Lua State, you have to remember things about the Lua stack such as what the type of a given value at a position is, where each value you are working with is on the stack, how big the stack is, etc.
lua53-ext doest all of this stuff for you. Instead of working with the stack, instead you work with a series of Contexts. When you push some variables onto the stack with a context, all of the pushed values are popped when the Context goes out of scope.
Context
A Context
is really just a wrapper over a Lua State. A Context can be created anywhere you have a Lua State or another Context using the Context::new
function or the Context::push_context
function.
Variables
When you push a value onto the lua stack with a Context, you get a value as a return that represents the pushed value's Index. For example, you can push an integer onto the stack via Context::push_integer
. It takes a single argument, an integer, and returns a LuaInteger
, which represents the index of the newly pushed integer (as well as some helpful abstractions).
Example
use Context;
use ;
use LuaFunction;
Caveats
Lua types are independent from the context that they are created from. The following are all valid: