LuaJIT require module error
Asked Answered
G

1

8
require "utils.lua"
stdin:1: module 'utils.lua' not found:
        no field package.preload['utils.lua']
        no file 'D:\blizzard\Projects\Lua'
        no file '.\utils\lua.dll'
        no file 'D:\blizzard\Projects\Lua\utils\lua.dll'
        no file 'D:\blizzard\Projects\Lua\loadall.dll'
        no file '.\utils.dll'
        no file 'D:\blizzard\Projects\Lua\utils.dll'
        no file 'D:\blizzard\Projects\Lua\loadall.dll'

Why LuaJIT searches for .dll instead of .lua and how to fix this behavior?

Gossett answered 20/7, 2011 at 10:6 Comment(0)
M
12

You should require utils (ditch the .lua) , and utils.lua should be on your package.path variable, or passed as the LUA_PATH environment variable.

More info in the Lua Reference Manual about package.loaders, require() and package.path

Magnific answered 20/7, 2011 at 10:15 Comment(5)
"and utils . lus should be ... passed as the LUA_PATH". I haven't understood this. Directory where I placed utils.lua is in the LUA_PATH env. variable and I omitted ".lua" but this doesn't help.Gossett
utils.lua. Sorry typo. So your package.path variable contains a lot of directories where Lua looks for libraries. utils.lua should be in one of them.Magnific
OK, I changed LUA_PATH to D:\blizzard\Projects\Lua\?.lua and it worked.Gossett
How do I make lua search for .\file.lua instead of .\file.dll? I just want to require some files in my project directory without having to set LUA_PATH each time.Modie
you can use package.path=package.path..'./?.lua;' before using require. Also note the difference between package.path and package.cpath (and LUA_PATH and LUA_CPATH). Ther former concerns Lua files, while the latter concerns compiled C libraries.Magnific

© 2022 - 2024 — McMap. All rights reserved.