lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Rici Lake wrote:

Is there another way to avoid the GC problem?

One of us is not being clear :)

You said:

This leaves the userdata on the stack, so my Object ctor fiddles with it (gives it a common metatable and refs it so it doesn't get GC'ed). Then it gets popped.

I assumed you meant by "refs it" that you used luaL_ref to create a reference to it so that it *wouldn't* be collected. Now you seem to be saying that you *want* it to be collected.

You could do either of those things, as Mark points out, by using both a weak and a strong table with the weak table backing the strong table via an __index meta

But perhaps I still don't understand...

You would not be the first to accuse me of obfuscation :-)

What I failed to say is that this ref I add to the object is temporary. It is there long enough to pop out of all the C++ creation logic and get back a fully initialized object. This is then handed off to Lua as a global object or a member of some other table. Then the ref is removed. After that, I want it to be under GC control like anything else.

Sorry about the confusion...

chris marrin                ,""$, b`    $                             ,,.
(408) 955-3049          mP     b'                            , 1$'
Sony    ,.`           ,b`    ,`                              :$$'
     ,|`             mP    ,`                                       ,mm
   ,b"              b"   ,`            ,mm      m$$    ,m         ,`P$$
  m$`             ,b`  .` ,mm        ,'|$P   ,|"1$`  ,b$P       ,`  :$1
 b$`             ,$: :,`` |$$      ,`   $$` ,|` ,$$,,`"$$     .`    :$|
b$|            _m$`,:`    :$1   ,`     ,$Pm|`    `    :$$,..;"'     |$:
P$b,      _;b$$b$1"       |$$ ,`      ,$$"             ``'          $$
 ```"```'"    `"`         `""`        ""`                          ,P`
"As a general rule,don't solve puzzles that open portals to Hell"'