luao3-macros

Crates.ioluao3-macros
lib.rsluao3-macros
version0.1.0
sourcesrc
created_at2022-03-13 00:03:02.241097
updated_at2022-03-13 00:03:02.241097
descriptionMacros/derive for luao3.
homepage
repositoryhttps://github.com/Techcable/luao3
max_upload_size
id548963
size29,498
(Techcable)

documentation

README

luao3

Lua bindings for Rust, oriented around macros.

Modeled loosely after PyO3. Based on mlua.

WARNING: This software is ALPHA quality. Expect breaking changes and API removals/additions.

Examples

use luao3::prelude::*;
use mlua::prelude::*;

#[derive(Debug, FromLua, ToLua)]
struct Foo {
    foo: String,
    #[lua(default)]
    bar: Vec<String>
}

#[lua_function]
pub fn bar(a: Foo) -> LuaResult<Foo> {
    Ok(Foo {
        foo: format!("baz{}", a.foo),
        bar: vec!["foo".into(), "baz".into(), a.bar.get(0).cloned()
            .unwrap_or_else(|| "baz".into())]
    })
}

#[lua_function]
pub fn baz(txt: String) -> LuaResult<i32> {
    txt.parse::<i32>().map_err(mlua::Error::external)
}

luao3::declare_simple_module! {
    name => foobar,
    members => {
        fn bar,
        fn baz as baz2
    }
}
Commit count: 19

cargo fmt