lua does not set search paths

OpenSubmitted by Ricardo Wurmus.
Details
2 participants
  • Ludovic Courtès
  • Ricardo Wurmus
Owner
unassigned
Severity
normal
R
R
Ricardo Wurmus wrote on 12 Jan 2017 11:57
(name . 'bug-guix@gnu.org')(address . bug-guix@gnu.org)
87shoo7dgx.fsf@mdc-berlin.de
The lua interpreter packages do not set native search paths, so theycannot find lua modules.
$ guix environment --ad-hoc lua lua-lpeg $ lua > require('lpeg') … ERROR …
However:
$ guix environment --ad-hoc lua lua-lpeg $ export LUA_PATH="$GUIX_ENVIRONMENT/share/lua/5.3/?.lua;$GUIX_ENVIRONMENT/share/lua/5.3/?/?.lua" $ export LUA_CPATH="$GUIX_ENVIRONMENT/lib/lua/5.3/?.so;$GUIX_ENVIRONMENT/lib/lua/5.3/?/?.so" $ lua > require('lpeg') table: 0x1b80300

--Ricardo
GPG: BCA6 89B6 3655 3801 C3C6 2150 197A 5888 235F ACAChttp://elephly.net
R
R
Ricardo Wurmus wrote on 12 Jan 2017 13:19
cannot express search path
(address . 25425@debbugs.gnu.org)
87r34879o1.fsf@elephly.net
It seems that the “search-path-specification” cannot be used to includeplaceholders such as “?” as required by LUA_PATH and LUA_CPATH. Thesearch paths in Lua are not directories and they are not actual filenames.
I suggest adding an optional “placeholder” field to“search-path-specification”, which would hold a string like “?/?.lua” inthis case.
L
L
Ludovic Courtès wrote on 12 Jan 2017 15:38
(name . Ricardo Wurmus)(address . rekado@elephly.net)(address . 25425@debbugs.gnu.org)
87bmvc2vjn.fsf@gnu.org
Ricardo Wurmus <rekado@elephly.net> skribis:
Toggle quote (5 lines)> It seems that the “search-path-specification” cannot be used to include> placeholders such as “?” as required by LUA_PATH and LUA_CPATH. The> search paths in Lua are not directories and they are not actual file> names.
Indeed.
Toggle quote (4 lines)> I suggest adding an optional “placeholder” field to> “search-path-specification”, which would hold a string like “?/?.lua” in> this case.
I think this should work:
(search-path-specification (variable "LUA_PATH") (separator ";") (files '("share/lua/5.3")) (file-pattern "\\.lua$") (file-type 'regular))
See libxml2 for an example with similar requirements.
HTH!
Ludo’.
R
R
Ricardo Wurmus wrote on 12 Jan 2017 15:46
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 25425@debbugs.gnu.org)
87lgug72vc.fsf@elephly.net
Ludovic Courtès <ludo@gnu.org> writes:
Toggle quote (9 lines)> I think this should work:>> (search-path-specification> (variable "LUA_PATH")> (separator ";")> (files '("share/lua/5.3"))> (file-pattern "\\.lua$")> (file-type 'regular))
I tried this very same thing but it doesn’t work because Lua expectsplaceholders (“?”) in the search paths. The placeholders are replacedwith the actual package names. If the actual file name does not existit will try the next pattern. If the file *does* exist – which *will* bethe case for any of the files on LUA_PATH that have been generated bythe search-path-specification — Lua will try to load the package fromthat path.
This will fail because a search for the “lpeg” module would be satisfiedby the file “re.lua”, because that’s the first valid file on theLUA_PATH. “re.lua” requires “lpeg” itself, so another lookup isperformed, which will again result in “re.lua” to be loaded…
AIUI we must generate a value for LUA_PATH that keeps the placeholdersintact.
--Ricardo
GPG: BCA6 89B6 3655 3801 C3C6 2150 197A 5888 235F ACAChttp://elephly.net
L
L
Ludovic Courtès wrote on 22 Jan 2017 22:56
(name . Ricardo Wurmus)(address . rekado@elephly.net)(address . 25425@debbugs.gnu.org)
87d1feep2q.fsf@gnu.org
Hello!
Ricardo Wurmus <rekado@elephly.net> skribis:
Toggle quote (27 lines)> Ludovic Courtès <ludo@gnu.org> writes:>>> I think this should work:>>>> (search-path-specification>> (variable "LUA_PATH")>> (separator ";")>> (files '("share/lua/5.3"))>> (file-pattern "\\.lua$")>> (file-type 'regular))>> I tried this very same thing but it doesn’t work because Lua expects> placeholders (“?”) in the search paths. The placeholders are replaced> with the actual package names. If the actual file name does not exist> it will try the next pattern. If the file *does* exist – which *will* be> the case for any of the files on LUA_PATH that have been generated by> the search-path-specification — Lua will try to load the package from> that path.>> This will fail because a search for the “lpeg” module would be satisfied> by the file “re.lua”, because that’s the first valid file on the> LUA_PATH. “re.lua” requires “lpeg” itself, so another lookup is> performed, which will again result in “re.lua” to be loaded…>> AIUI we must generate a value for LUA_PATH that keeps the placeholders> intact.
So are you saying that it’s important for the question marks to remainintact?
This sounds terrible. I’m not sure how to address it, and I don’t feellike stretching the search path mechanism this much.
Thoughts?
Ludo’.
R
R
Ricardo Wurmus wrote on 22 Jan 2017 23:34
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 25425@debbugs.gnu.org)
874m0q2087.fsf@elephly.net
Ludovic Courtès <ludo@gnu.org> writes:
Toggle quote (34 lines)> Hello!>> Ricardo Wurmus <rekado@elephly.net> skribis:>>> Ludovic Courtès <ludo@gnu.org> writes:>>>>> I think this should work:>>>>>> (search-path-specification>>> (variable "LUA_PATH")>>> (separator ";")>>> (files '("share/lua/5.3"))>>> (file-pattern "\\.lua$")>>> (file-type 'regular))>>>> I tried this very same thing but it doesn’t work because Lua expects>> placeholders (“?”) in the search paths. The placeholders are replaced>> with the actual package names. If the actual file name does not exist>> it will try the next pattern. If the file *does* exist – which *will* be>> the case for any of the files on LUA_PATH that have been generated by>> the search-path-specification — Lua will try to load the package from>> that path.>>>> This will fail because a search for the “lpeg” module would be satisfied>> by the file “re.lua”, because that’s the first valid file on the>> LUA_PATH. “re.lua” requires “lpeg” itself, so another lookup is>> performed, which will again result in “re.lua” to be loaded…>>>> AIUI we must generate a value for LUA_PATH that keeps the placeholders>> intact.>> So are you saying that it’s important for the question marks to remain> intact?
Yes, that seems to be the case.
Toggle quote (5 lines)> This sounds terrible. I’m not sure how to address it, and I don’t feel> like stretching the search path mechanism this much.>> Thoughts?
I agree. It’s a really odd special case. On the other hand, notextending the search path mechanism would mean that we have to findother ways to fix “guix environment”, build phases, and profiles whenLua packages are involved.
Build phases are easy to fix (by using a procedure that sets theappropriate environment variables depending on the build inputs), but Idon’t know how to make profiles behave the way they should. Maybe itwould be fine to set a single value for LUA_PATH (and LUA_CPATH) thatassumes a single prefix (the profile path) and contains the necessaryplaceholders.
--Ricardo
GPG: BCA6 89B6 3655 3801 C3C6 2150 197A 5888 235F ACAChttps://elephly.net
?