[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: luaclose_mylib function (inverse of "luaopen_mylib" C function)
- From: Viacheslav Usov <via.usov@...>
- Date: Mon, 24 Aug 2020 22:04:05 +0200
On Mon, Aug 24, 2020 at 8:46 PM bel <bel2125@gmail.com> wrote:
> What would be the appropriate way to implement a "luaclose_mylib" function in C, that would work as an inverse of "luaopen_mylib"?
Have you considered that your library might be used by a process with
multiple Lua states, which come and go dynamically in parallel
threads?
My advice is NOT to have any global state in a library. Instead, all
the state should be linked to the object that the require function
returns. Doing otherwise is a source of persistent problems,
especially in the scenario above.
Cheers,
V.