(let [pathsepesc (escapepat pkg-config.pathsep)
pattern (: "([^%s]*)%s" :format pathsepesc pathsepesc)
no-dot-module (modulename:gsub "%." pkg-config.dirsep)
fullpath (.. (or ?pathstring utils.fennel-module.path)
pkg-config.pathsep)]
(fn try-path [path]
(let [filename (path:gsub (escapepat pkg-config.pathmark) no-dot-module)
filename2 (path:gsub (escapepat pkg-config.pathmark) modulename)]
(case (or (io.open filename) (io.open filename2))
file (do
(file:close)
filename)
_ (values nil (.. "no file '" filename "'")))))
it checks modulename
which was the value of that in (require :modulename)
as well as as no-dot-module
, but returns only the filename for no-dot-module
if either of them works.
this presents an issue when the module contains a dot. on requiring module.name
, it checks module/name.fnl
, and module.name.fnl
if only the latter exists, the filename is passed to dofile
, which then raises runtime error on failing to io.open
it.
checking module.name.fnl
(rather than just module/name.fnl
is also inconsistent with lua's behaviour.
use case: custom support for importing modules with dot in their names: https://git.sr.ht/~hedy/fssg/tree/67b30cdac878cc3b8809379abe1d2f23751f854b/item/fix-searcher.fnl
I see what you mean! There's not any reason ever to check
filename2
, because you'll only ever get false positives. This is a good catch; thanks. I've fixed it in c8e5f05.
awesome. thank you!