Receive project path in macOS from Lua (SOLVED)


Hi all.

In my project I recieve some data from external files. In Windows project read files from application dir by default, but in macOS no and required absolute path. My question - how recieve current dir in macOS. I know about os.getenv(“HOME”) , but it return user home, but i need app dir. Thank you


What do you need app dir for? You shouldn’t write to the application directory but to user data folders.


I need read some PNG files (long animation sequences). I dont need write for current moment :slight_smile:


There are a couple of ways to do it and I’m not sure the best way… you can make a native extension to use built in osx functions to get it

std::string([NSBundle mainBundle].executablePath.UTF8String)

Would return full path to the engine exectuable I think.

You can also do it based on PID.

I don’t have a Mac handy at the moment to test.

Keep in mind it’s non-trivial to get access to the files Defold packs into the game’s resource files. If you add the files to the .app file it’s no problem.

It would probably be useful if someone made a “where am I” native extension for the various platforms.

#5 and sys.load() works on the application root on OSX. So does

You mean like lfs.currentdir()? :wink: ( and


Thank you guys. I think LFS resolve my problem.


defos.get_bundle_root() also does this now (thanks to @AGulev).