Skip to content

Why does the value obtained from the nested userdata keep changing? #308

Closed Answered by BERADQ
BERADQ asked this question in Q&A
Discussion options

You must be logged in to vote
pub struct KissaEventNode {
    name: String,
}

impl LuaUserData for KissaEventNode {
    fn add_fields<'lua, F: LuaUserDataFields<'lua, Self>>(fields: &mut F) {
        fields.add_field_method_get("name", |_, this| Ok(this.name.clone()));
        fields.add_field_function_get("listeners", |lua, this| {
            let list = this.user_value::<LuaValue>()?;
            let list = match list {
                LuaNil => {
                    let new_list = lua.create_table()?;
                    let list = new_list.clone();
                    this.set_user_value(new_list)?;
                    list
                }
                LuaValue::Table(t) => t,
                _ => panic!("li…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by BERADQ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant