peachy
peachy copied to clipboard
Requiring doesn't work when the library is in a subdirectory
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")
This can be sorta fixed by requiring peachy with require "lib.peachy.init"
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).