peachy icon indicating copy to clipboard operation
peachy copied to clipboard

Requiring doesn't work when the library is in a subdirectory

Open steveRoll-git opened this issue 1 year ago • 2 comments

When the peachy directory is right at the project's root, doing require "peachy" works fine. But if you place peachy in your own subdirectory, for example lib/peachy, requiring with require "lib.peachy" breaks peachy's own imports:

Error

lib/peachy/init.lua:35: module 'lib.lib.json' not found:
no field package.preload['lib.lib.json']
no 'lib/lib/json' in LOVE game directories.
...

This probably happens because of how the library tries to detect the directory that it was required from:

local PATH = (...):gsub("%.[^%.]+$", "")
local json = require(PATH..".lib.json")
local cron = require(PATH..".lib.cron")

steveRoll-git avatar Aug 21 '23 19:08 steveRoll-git

This can be sorta fixed by requiring peachy with require "lib.peachy.init"

steveRoll-git avatar Aug 21 '23 19:08 steveRoll-git

yeah I noticed this a while ago and figured out that this:

local json = require(.....".lib.json")
local cron = require(.....".lib.cron")

seems to work just fine? I didn't push it up because I don't understand why it works really (besides looking a little silly).

josh-perry avatar Aug 21 '23 20:08 josh-perry