Unisay / purescript-lua

Purescript compiler back-end for Lua
GNU General Public License v3.0
56 stars 2 forks source link

Please add support for `Data.Lazy` to the package-set #18

Closed tomshackell closed 7 months ago

tomshackell commented 7 months ago

This commonly used library uses a tiny bit of javascript but appears to be missing from the package-set:

Foreign file for the module ".spago\\lazy\\v6.0.0\\src\\Data\\Lazy.purs" not found in the following locations:
-  C:\Dev\pslua-test\purs\.spago\lazy\v6.0.0\src\Data\Lazy.lua
-  C:\Dev\pslua-test\purs\.spago\lazy\v6.0.0\src\Data\Lazy.lua

Here is the javascript required:

export const defer = function (thunk) {
  var v = null;
  return function() {
    if (thunk === undefined) return v;

    v = thunk();
    thunk = undefined; // eslint-disable-line no-param-reassign
    return v;
  };
};

export const force = function (l) {
  return l();
};

A lua equivalent would be something like:

return {
    defer = (function (thunk)
        local v = nil
        return function ()
            if thunk == nil then return v end
            v = thunk()
            thunk = nil
            return v
        end
    end),
    force = (function (l) return l() end),
}
Unisay commented 7 months ago

I have forked the lazy library and will work on adding it to the package set asap. This library depends on a few other libs that aren't added (and those might depend on others...) so it might take a bit of time. Stay tuned!

tomshackell commented 7 months ago

I got it temporarily working (hacking my local .spago) by adding just the Lazy.lua I included above.

Unisay commented 7 months ago

Nice! It turned out to be easy

 * [new tag]         psc-0.15.15-20240417 -> psc-0.15.15-20240417

you can upgrade the package set, the lazy lib has been added!

Unisay commented 7 months ago

Please report if it works for you, I'll close the issue then.

tomshackell commented 7 months ago

Yup that works, thanks :-)