Hi list!
I'm using Lua VM to drive a custom scripting language and I'm hacking deep into the Lua core.
I want to add a flag (lets name it 'keepAlive') to gc-managed Lua values (tables, closures, strings) that will prevent garbage collection of this values even if there are no strong references to them (please, do not recommend using the registry, I am aware of it and already using it heavily).
As far as I can tell, I can do nothing in the 'mark' phase because when object has no references to it, it will not be marked. I suppose that I have to resurrect the object (mark it non-dead, and prevent collection of objects this one keeps reference to) in the sweep phase, if it has the 'keepAlive' flag set.
What is the best way to do this?
There is an 'if' statement at the line 737 of lgc.c (function sweeplist, lua 5.2.3):
if (isdeadm(ow, marked)) { /* is 'curr' dead? */
*p = gch(curr)->next; /* remove 'curr' from list */
freeobj(L, curr); /* erase 'curr' */
}
else {
If I will add my condition to this statement, it will prevent the object itself from being collected. But how to prevent collection of objects, referenced by this object?