Lua: require fails to find submodule, but searchpath succeeds? -
usually when have question remotely software related find else has asked same thing, , gotten answers works me too.
this time, though, i've failed find answer predicament.
here go: i'm trying move lua-programming notch or 3 , want use modules. so, i've got structure this:
main.lua foo/bar.lua now, in main.lua do
require("foo.bar") which fails,
main.lua:1 module 'foo.bar' not found: no field package.preload['foo.bar'] no file 'foo.bar.lua' no file 'foo.bar.lua' no file 'foo.lua' ok, might wrong package.path use package.searchpath("foo.bar", package.path) see i', doing wrong.
the problem package.searchpath resolves foo.bar foo/bar.lua right.
as i've understood it, package.searchpath tries find module in same way require, there seems som glitch in case.
what strikes me odd repetition of no file 'foo.bar.lua' in error output
have misunderstood use of require?
i'm using luajit-2.0.0 run chunks
update:
i'm using luajit-2.0.0 run chunks <- reason problem, stock lua-5.2.2 behaves expected
package.path = debug.getinfo(1,"s").source:match[[^@?(.*[\/])[^\/]-$]] .."?.lua;".. package.path require("foo.bar") this line causes
requirein same directory current file when asked load other files. if want instead search directory relative current directory, insert relative path between " , ?.lua
here part of require description:
[...] otherwise require searches lua loader using path stored in
package.path. if fails, searches c loader using path stored in package.cpath. if fails, tries all-in-one loader (seepackage.loaders).
default path package.path .exe executes specified script.
Comments
Post a Comment