Require is not working properly
Posted: Sun Jul 09, 2023 10:50 am
I'm trying to use library called 'Slab', and I have a directory structure like this:
And this is my main.lua:
When I try to run my project, I have this error:
It seems /lib/slab/const.lua cannot be loaded by /lib/slab/init.lua, so I think I'm doing something wrong on the first line of main.lua.
How can I use 'require' properly in this case?
Code: Select all
myproject/
|- main.lua
|- conf.lua
|- ...
└lib/
└slab/
├const.lua
├API.lua
├Slab.lua
├...
└init.lua
Code: Select all
local Slab = require 'lib/slab'
function love.load(args)
Slab.DisableDocks({'Left', 'Right', 'Bottom'})
-- love.graphics.setBackgroundColor(0.4, 0.88, 1.0)
Slab.Initialize(args)
end
function love.update(dt)
Slab.Update(dt)
Slab.BeginWindow('MyFirstWindow', {Title = "My First Window", AllowMove = false, ShowMinimize = false})
Slab.Text("Welcome.")
Slab.EndWindow()
end
function love.draw()
Slab.Draw()
end
Code: Select all
Error
lib/slab/init.lua:28: module 'const' not found:
no field package.preload['const']
no 'const' in LOVE game directories.
no file 'const' in LOVE paths.
no file '.\const.lua'
no file 'C:\Program Files\LOVE\lua\const.lua'
no file 'C:\Program Files\LOVE\lua\const\init.lua'
no file 'C:\Program Files (x86)\Lua\5.1\lua\const.luac'
no file '.\const.dll'
no file 'C:\Program Files\LOVE\const.dll'
no file 'C:\Program Files\LOVE\loadall.dll'
Traceback
[love "callbacks.lua"]:228: in function 'handler'
[C]: in function 'require'
lib/slab/init.lua:28: in main chunk
[C]: in function 'require'
main.lua:1: in main chunk
[C]: in function 'require'
[C]: in function 'xpcall'
[C]: in function 'xpcall'
How can I use 'require' properly in this case?