lua-users home
lua-l archive

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


> No. It happens with a plain Lua script that only requires and runs it, or
> `busted`. The last example that I gave was the entire contents of the test
> script. As long as collectgarbage() was called, it happened 100% of the
> time.

Lua tries to reuse closures when possible, but this reuse should
not prevent them from being collected. So, depending on the order that
objects are marked, the GC has to clean the "reuse slot", and later a
new (and therefore different) closure is created. That is why the
specification cannot give many garanties about function identity. If you
want functions to be equal, create just one instance, once, and reuse
that same one whenever you need it.

-- Roberto