Tomasu / LuaGlue

C++11 Lua 5.2 Binding Library
zlib License
79 stars 22 forks source link

update std::shared_ptr ref counter when set to "nil" #26

Closed JMLX42 closed 10 years ago

JMLX42 commented 10 years ago

Hello,

it looks like setting a std::shared_ptr variable to "nil" in Lua won't have the desired effect.

The expected effect is to have this very std::share_ptr object destroyed and the internal ref counter to be decremented.

The current behavior is not as expected: I suspect the GC has to run for things to be updated properly.

How can we fix this? Can't we override the "=" operator to do this?

Thanks for your help,

Tomasu commented 10 years ago

I think we're at the mercy of the GC here. There is no way to overload lua's assignment operator. We just have to wait for the GC to run. You can technically force a gc run though. I don't think its a great idea, but we could possibly add some kind of internal method that is added to all bound objects to say "hey, delete the contents of this LuaGlueObject, kthx." like obj:__really_please_delete_me_I_know_what_im_doing_serously_I_do_honest();