LuaLanes / lanes

Lanes is a lightweight, native, lazy evaluating multithreading library for Lua 5.1 to 5.4.
Other
465 stars 96 forks source link

"Bad library name: lfs" #226

Closed Frityet closed 6 months ago

Frityet commented 6 months ago

Code im running

local lanes = require("lanes").configure()
local lfs = lanes.require("lfs")

local function walk(dir, out)
    return lanes.gen("*,lfs", function()
        for file in lfs.dir(dir) do
            if file ~= "." and file ~= ".." then
                local path = dir .. "/" .. file
                if lfs.attributes(path, "mode") == "directory" then
                    walk(path, out)
                else
                    out:send(path)
                end
            end
        end
    end)()
end

local files = lanes.linda()
walk(".", files)

while true do
    local path = files:receive(1)
    if path then
        print(path)
    else
        break
    end
end

System information:

❯ lua -v
Lua 5.4.6  Copyright (C) 1994-2023 Lua.org, PUC-Rio

❯ uname -a
Darwin amrit-1642.local 22.6.0 Darwin Kernel Version 22.6.0: Mon Feb 19 19:48:53 PST 2024; root:xnu-8796.141.3.704.6~1/RELEASE_X86_64 x86_64

❯ sw_vers
ProductName:            macOS
ProductVersion:         13.6.6
BuildVersion:           22G630

without the ",lfs" in the lanes.gen call, i get

lua: /usr/local/share/lua/5.4/lanes.lua:336: main: function 'lfs/<SOME LFS SYMBOL, CHANGES EVERY RUN>' not found in Lane #0x7fcce800aa08 destination transfer database.
Frityet commented 6 months ago

Further tested on

📦[frityet@lanes-testing Documents]$ uname -a
Linux lanes-testing.fritpc 6.7.10-200.fc39.x86_64 #1 SMP PREEMPT_DYNAMIC Mon Mar 18 18:56:52 UTC 2024 x86_64 GNU/Linux

yields same result

Frityet commented 6 months ago

@benoit-germain Sorry for ping but I just can't find any way I can make this work, did there any known fix? This happens for any C module

benoit-germain commented 6 months ago

Hello,

As per the documentation, lib_str can only contain a combination of Lua (or LuaJIT) "standard libraries": base, bit, coroutine, debug, ffi, io, jit, math, os, package, string, table, utf8, or * as a shortcut for all of them. Regular Lua modules to be required when the lane starts go in the setting table:

local gen= lanes.gen( "math,package,string,table", {required={"lfs"}}, a_lane)

Hope this helps,

Benoit.

Frityet commented 6 months ago

Hello,

As per the documentation, lib_str can only contain a combination of Lua (or LuaJIT) "standard libraries": base, bit, coroutine, debug, ffi, io, jit, math, os, package, string, table, utf8, or * as a shortcut for all of them. Regular Lua modules to be required when the lane starts go in the setting table:

local gen= lanes.gen( "math,package,string,table", {required={"lfs"}}, a_lane)

Hope this helps,

Benoit.

Hello, that seemed to work, but now I get this error:

lua: /usr/local/share/lua/5.4/lanes.lua:336: can't copy non-deep full userdata across lanes
stack traceback:
        [C]: in function 'lanes.core.lane_new'
        /usr/local/share/lua/5.4/lanes.lua:336: in function </usr/local/share/lua/5.4/lanes.lua:334>
        (...tail calls...)
        main.lua:20: in main chunk
        [C]: in ?

Is the library itself counted as a full user data? The only userdata being used in this instance is the linda

Edit: same issue without the linda

Frityet commented 6 months ago

Nevermind, lfs.dir() does return a userdata, thank you!