-
| Greetings! 
 P.S. There are definitely patterns and antipatterns for this. Anyone wants to share? | 
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 3 replies
-
| 
 Hm, there is no such requirement. Any data structure can be passed to Lua without implementing  | 
Beta Was this translation helpful? Give feedback.
-
| Partially.
But I fail to access it:
```
   |
33 |     let test: Result<&MyUserData,LuaError> = exports.get("userdata");
   |                                                      ^^^ the trait
`mlua::UserData` is not implemented for `&MyUserData`
```
The `get()` getter returns the copy of the stored object. I see no way to get the ref.
[full source link](https://paste.rs/b98.rs) | 
Beta Was this translation helpful? Give feedback.
-
| This is because you need to use  let ud = exports.get::<_, AnyUserData>("userdata")?;
let mydata = ud.borrow::<MyUserData>()?; | 
Beta Was this translation helpful? Give feedback.
-
| Just what I need! Thanks.
BTW, do you know other "expose a Rust external crate as a Lua module" examples? I found https://crates.io/crates/distant-lua but it uses mlua 0.6 and is relatively simple. | 
Beta Was this translation helpful? Give feedback.
-
| hmm, `borrow()` implies `'static` lifetime to UserData contents which isn't
always true, I think. Need to elaborate that. Meanwhile JFYI, I'm stumbling
on the error:
```
error[E0621]: explicit lifetime required in parameter type
  --> src/lib.rs:37:25
   |
37 |         let mut el = el.borrow_mut::<EventLoop>()?;
   |                         ^^^^^^^^^^ lifetime `'static` required
```
full project: https://github.com/ildar/lua-module-calloop
 | 
Beta Was this translation helpful? Give feedback.
-
| Surprisingly, I managed to skip using `scope()`. After some meditation and
a few experiments I declared exported function's argument as 'static:
ildar/lua-module-calloop@a57ff0b#diff-b1a35a68f14e696205874893c07fd24fdb88882b47c23cc0e0c80a30c7d53759R34
Builds and works for me. | 
Beta Was this translation helpful? Give feedback.

This is because you need to use
AnyUserDatainstead of&MyUserDatato get your data from the table.And then borrow it using
borrow()orborrow_mutmethods.Eg: