Lua adding package.path to require doesn't work

Viewed 223

Here is my folder structure:

src/config/objects/bird.lua

src/objects/Bird.lua

In Bird.lua, I tried to import src/config/objects/bird.lua by using:

package.path = package.path .. ';../config/objects/?.lua'
local BIRD = require("bird")

But it doesn't work and no module is found. What I'm doing wrong ?

Here is my error screen:

module not found

2 Answers
package.path = package.path .. ';../config/objects/?.lua'

This should work.

I have found the answer. Love2d run the main.lua file, so that path in require must be relative to main.lua. And because my main.lua is at the root folder, I just need to use:

local BIRD = require("src.config.objects.bird")
Related