lua-users home
lua-l archive

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

On 8 February 2017 at 09:27, chris beck <> wrote:
> If JS doesn't have destructors, finalizers, RAII, or any other such built-in
> language feature for the clean up of objects, then I guess you can just add
> explicit "release" methods to your JS representation of a lua object?
> Which would call `luaL_unref`, and tell lua that it is now okay to garbage
> collect that object. I mean presumably this is idiomatic in JS as you also
> will have to call "close" explicitly on file handles and such?

lua.vm.js *does* have this function. but it's essentially unusable.
e.g. if you attach a expose a function as a callback, you generally
have no idea when the DOM will be done with it.
The whole scheme is a dead end.

> Don't have much knowledge of JS myself but I never encountered a problem
> like this before -- I guess it should be workable somehow? JS is a very
> mature technology, and iiuc you'd have the same issue making
> bindings to any other garbage collected programming language.

No it's not fixable.
Weak-refs ( will get us
*some* of the way: bringing collection callbacks to javascript.
However you still have the (unsolvable) problem of cycles across the
two garbage collectors.

The approach taken by Benoit is the *only* good way forward to get lua
working in in web browsers to full effect:
  - You need to use native javascript objects so that the javascript
garbage collector can do a full sweep
  - You need to use a VM dispatch *in* javascript (rather than a
source=>source transpiler) so that coroutines work correctly.