setRequirePath() correct usage
Posted: Sat Dec 07, 2019 3:09 pm
I'm new to Love and Lua, but I'm learning both by following along with Harvard's CS50's Introduction to Game Development on edx.org.
Their code targets an older version of Love, so I figured I'd clean things up while I'm at it.
The code uses some 3rd party Lua (such as https://github.com/Ulydev/push), so I wanted to drop the third party code into a common directory and just reference it from each project rather than leaving copies everywhere.
My directory structure is like this:
If love.filesystem.setRequirePath() isn't able to access files outside of the game's directory for sandboxing reasons, that makes sense. Is there a "proper" way for me to do this?
Their code targets an older version of Love, so I figured I'd clean things up while I'm at it.
The code uses some 3rd party Lua (such as https://github.com/Ulydev/push), so I wanted to drop the third party code into a common directory and just reference it from each project rather than leaving copies everywhere.
My directory structure is like this:
- common/push - Ulydev's push repo, so common/push/push.lua exists here
- pong/pong-0/main.lua - Initial version of the Pong implementation
- pong/pong-1/main.lua - next iteration
- ...
Code: Select all
-- Can't find push.lua at the require() call.
love.filesystem.setRequirePath(love.filesystem.getRequirePath() .. ';../../common/push')
-- Also doesn't work.
love.filesystem.setRequirePath(love.filesystem.getRequirePath() .. ';C:/cygwin64/home/Chris/git/harvard-game50/common/push')
-- This works, but I don't really understand why I have to include the filename, push.lua.
package.path = package.path .. ';../../common/push/push.lua'
push = require 'push'