file-ioluadirectorylove2dplatform-specific

Can I save into a specific folder?


While learning how to create Lua file output code with the support of LÖVE, I've always hated that LÖVE filesystem handler always saved the specific file somewhere in C:/Documents and Settings/...

How can I create a code that saves a file into a specific folder that I'd like to define (and maybe to change while running the application)?


Solution

  • The love.filesystem library doesn't let you do anything outside the sandbox. However, LÖVE doesn't disable Lua's built in io library, so you can use io.open to open files outside the sandbox and read/write them as normal, as well as other Lua functions like require and loadfile.

    It also doesn't restrict loading of external modules, so you can (for example) require "lfs" to load LuaFileSystem and use that, if it is installed.