You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Lua, tables and userdata may be marked for finalisation using the __gc metamethod. (For details, see §2.5.1 of the Lua Reference Manual). This is currently not possible in Rembulan.
The text was updated successfully, but these errors were encountered:
I'm interested to hear how this could be implemented. Java does have finalizers/destructors, but they are not reliable, while Lua metamethod should be.
The tricky part here is to execute the finalisers (which may be arbitrary Lua functions) within an execution context. But I think it's doable: the main idea would be to use a ReferenceQueue to register objects marked for finalisation, and pull them out of the queue once they have been GC'd.
There are quite a few degrees of freedom the implementation has when it comes to deciding when the finaliser is then actually run. Per the Lua Reference Manual, the finaliser is not called immediately once its object is GC'd, but "at some point" after -- and I would see that as compatible with Java's behaviour.
Of course, the problem is that the GC behaviour is unpredictable on the JVM, but not entirely unpredictable in PUC-Lua: PUC-Lua's standard library function collectgarbage allows you to run a full GC cycle. On the (generic) JVM we don't have that. (System.gc() only guarantees that "a best effort" will be made.)
However, I would see this as a limitation of Rembulan's standard library, and argue that it does not really get in the way of implementing the Lua programming language with the same semantics. Besides, Lua programs that depend on the GC behaviour as fundamentally broken anyway. 😉
In Lua, tables and userdata may be marked for finalisation using the
__gc
metamethod. (For details, see §2.5.1 of the Lua Reference Manual). This is currently not possible in Rembulan.The text was updated successfully, but these errors were encountered: