josh-perry / peachy

A parser/renderer for Aseprite animations in LÖVE. :peach:
https://josh-perry.github.io/peachy/
MIT License
104 stars 15 forks source link

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

Open steveRoll-git opened 1 year ago

steveRoll-git commented 1 year ago

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 commented 1 year ago

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

josh-perry commented 1 year ago

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).