lua-users home
lua-l archive

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



On Mon, Jun 3, 2019 at 9:37 AM Francisco Olarte <folarte@peoplecall.com> wrote:
I'll just assume finalizers
are tainted and avoid them [...]

Finalizers can run at any time, and could potentially run in the middle of the execution of any statement, this is true even if Lua had a guarantee that the lifetime of the object extends to the end of the block/scope containing the last reference. They're not "tainted", but you have to guarantee that the finalizer can be run at any possible point in your main program without breaking any of the assumptions (invariants) you make in your code. If the finalizer just closes a file that's no longer needed that is obvious, because it does not reference anything but the object that's 'invisible' to the rest of your program, but if the finalizer changes global state that'll be very difficult if not impossible, because that finalizer may run in the middle of any statement.

If you're using a finalizer in a userdata object you have a little bit more freedom because you can write your object's methods in such a way that state updates look atomic from the point of view of the Lua interpreter, but you still have to be very careful.