[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: How to unregister a lua_CFunction?
- From: "Jerome Vuarand" <jerome.vuarand@...>
- Date: Mon, 4 Dec 2006 11:02:02 -0500
Carsten Fuchs wrote:
> Is it sufficient to set the variable that holds the function to nil?
> The problem is that if someone makes a copy of the variable
> with the function, and continues to use the copy to call the
> function after the DLL has been unloaded, I expect to get a
> bad crash... Is there anything I can do to prevent this kind
> of scenario?
I think you're right about the potential crash. You can encapsulate your
function in a userdata with a __call metamethod. And then when the
function is called after the dll is unloaded you have to make sure your
__call function can detect it and raise an error. However this means
that your __call function is never unloaded, and whether it's feasible
depends on your dll loader/unloader.