tomaka / hlua

Rust library to interface with Lua
MIT License
507 stars 48 forks source link

Drop closure environment #139

Closed mkpankov closed 7 years ago

mkpankov commented 7 years ago

This fixes #138 . However, see comments for newly added test.

tomaka commented 7 years ago

Your test always passes because the closure doesn't contain move.

I'd even suggest using an Arc<Foo> instead of a Foo so that you are sure that it's not the local variable that is destroyed.

jonas-schievink commented 7 years ago

You can also have the destructor increment a static variable and check its expected value in multiple places

mkpankov commented 7 years ago

Don't merge this, still WIP.

Using Arc or Rc starts to cause SIGSEGV, investigating.

mkpankov commented 7 years ago

Ok, so it segfaults because for closure userdata, I don't push a TypeId and then destructor_wrapper does wrong stuff here: https://github.com/tomaka/hlua/blob/master/hlua/src/userdata.rs#L24

Gonna add another destructor wrapper for closures specifically, as I don't want to require 'static on Z in Push for Function<Z,.... Closure pushed to Lua must just outlive Lua, not be static.

mkpankov commented 7 years ago

Should be good to go now.

tomaka commented 7 years ago

Thanks, looks good other than the nit.