[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Loadlib's callfromlib() - anybody using it?!?
- From: Roberto Ierusalimschy <roberto@...>
- Date: Mon, 10 Jun 2002 10:50:30 -0300
> Each time you open a library that needs to clean itselt up, create
> a userdata, store it in the registry (using itself as both key and
> value), and set up a GC method for this userdata that does the
> cleanup. When lua_close is called, your GC method will be called
> automatically.
As an improvement, if you want your library to be unloaded when no one
uses it anymore, you can put your userdata as a upvalue in all functions
from this library (and not in the registry). When the last function is
collected, the library will be closed.
(Or yet, you can use a common table as the upvalue, which is useful by
itself to store other data about the library, and then put the userdata
into that table.)
-- Roberto