Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Difficulty creating a wrapper type #400

Open
nickeb96 opened this issue May 9, 2024 · 1 comment
Open

Difficulty creating a wrapper type #400

nickeb96 opened this issue May 9, 2024 · 1 comment
Labels
question Further information is requested

Comments

@nickeb96
Copy link

nickeb96 commented May 9, 2024

This is more of a question than a bug, but I'm trying to get the following simplified example to work:

struct LuaVec<'lua>(pub Vec<Value<'lua>>);

impl<'lua> UserData for LuaVec<'lua> {
  fn add_methods<'lua2, M: UserDataMethods<'lua2, Self>>(methods: &mut M) {
    methods.add_method_mut("push", |_, this, value: Value<'lua2>| {
      this.0.push(value);
      Ok(())
    });
  }
}

I've tried a few different variations of having one lifetime depend on the other, but everything I've tried gives me error[E0276]: impl has stricter requirements than trait.

Is it possible with the current userdata api to implement UserData on a type that already has lua values in it? I realize that the two lifetimes need to be the same, but I can't figure out how to represent that and still implement the trait properly.

@khvzak
Copy link
Member

khvzak commented May 12, 2024

There are few options how to solve this:

  1. Store Lua values in userdata using set_nth_user_value api (recommended)

  2. Store Lua values in Registry using crate_registry_value api and then store generated RegistryKey in userdata.

@khvzak khvzak added the question Further information is requested label May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants