Skip to content

Difficulty deserializing Lua functions with mlua #426

@tickox

Description

@tickox

Hello,

I am new to Rust and trying to use mlua. I am having difficulty deserializing Lua functions in Rust. What steps are necessary to make this work correctly?

In case of an error due to extra or missing fields, is it possible to identify which Lua line is causing the problem to facilitate debugging ?

Here is an example code:

#[derive(Deserialize)]
struct Test<'lua> {
    name: String,
    callback: Option<Function<'lua>>,
}

fn main() -> Result<()> {
    let lua = Lua::new();

    let lua_file = r#"
    {
        "name"= "test",
        "callback"= function(table)
            print("ok")
        end
    }
    "#;

    let test: Test = lua.from_value(lua.load(lua_file).eval()?)?;

    Ok(())
}

Thank you for your help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions