Skip to main content

Module lua_convert

Module lua_convert 

Source
Expand description

FromLua / IntoLua — bidirectional conversion between Rust types and LuaValue.

These traits allow Lua function arguments and return values to be expressed with native Rust types instead of manually calling get_arg / push_value.

§Built-in impls

  • (), bool, i8..i64, u8..u64, f32, f64
  • String, &str (via intermediate String)
  • Option<T> where T: FromLua / T: IntoLua
  • LuaValue (identity — zero-cost passthrough)

§Usage in derive macros

The #[lua_methods] macro generates calls to FromLua::from_lua for each parameter and IntoLua::into_lua for the return value, keeping the codegen type-agnostic and user-extensible.

§User extensibility

Users can implement FromLua / IntoLua for their own types:

impl FromLua for MyVec3 {
    fn from_lua(value: LuaValue, state: &LuaState) -> Result<Self, String> {
        // extract from userdata or table
    }
}

Traits§

FromLua
Convert a LuaValue into a Rust type.
IntoLua
Convert a Rust type into a LuaValue and push it.