I am trying to import source files from another project. The path to the other project is defined in the LUA_PATH environment variable but "import" does not seem to respect this and those files get an error for not being found. If I change the "import" statements to "require" statement the code compiles fine. How should this case be handled with the PlayDate SDK?
I don't think you're going to be able to do things that way with the Playdate SDK (someone hopefully will correct me if I'm completely off base).
All of your .lua files need to go in one directory (typically 'yourprojectpath/Source'), and 'import' is going to look in that one directory (the one with 'main.lua' in it) for any specified files.
Thanks. Well I had figured out that I could use paths relative the the current directory but for some reason I had to add a .lua extension to get it to work. Not a very elegant solution IMHO but it does work. Thanks for your input.
The bug where you have to add the lua extension is fixed in the 2.0.1 release, fyi. As far as being able to use import
with folders outside the source folder, on macOS you can add a LibPath
directive to your ~/.Playdate/config
folder, but I don't think have have a config file like that on Windows and Linux.. Since we have the mechanism to support that in the cross-platform code we should add a compiler flag that lets you specify other folders to search for imported code. I'll file that now!
Hi Dave. Thanks for the info and for filing the enhancement request. I think that would be a good feature for the compiler to support. Just curious, why would a compiler flag be preferable to an environment variable? Since the search path may vary by platform it seems it would be better if it was external to the project. At any rate I appreciate your support.
My personal preference is to have everything declared explicitly and avoid hidden data, but there's no reason not to support that as well. I'll add it to the issue!