Page 1 of 1

Any intermediary love objects that will allow importing images from outside the Love source folder on iOS?

Posted: Tue Aug 15, 2023 2:48 am
by SugarRayLua
Hello.

I've been trying to learn the subtleties about how to save and import different data into my love projects. It seems that at least on Love iOS, love.filesystem can only read and write to the source folder which contains my .love file. I'd like to be able to read and write to other locations: on iOS the most convenient place to read and write from would be the source base directory which contains my .love file as that way I could have a common place to store data objects that I could share between .love files. However, since love.filesystem can't seem to read and write to the sourceBaseDirectory, I've been using the nativefs library to do so which works great. Yet, the nativefs library doesn't have any specific functions for handling images, and it seems that love.graphics.newImage, like the base love.filesystem is unable to read images from the sourceBaseDirectory. I was wondering if there was then some way I could use nativefs to import a graphics object (e.g. png) from my sourceBaseDirectory and then somehow have love.graphics.newImage be able to read that file I imported from a file into a variable using nativefs.

I appreciate any suggests the forum community might have.

Thank you.

Re: Any intermediary love objects that will allow importing images from outside the Love source folder on iOS?

Posted: Tue Aug 15, 2023 5:39 am
by GVovkiv
In love 12 you will be able to "connect" to your filesystem directory outside of source and save directories.

Re: Any intermediary love objects that will allow importing images from outside the Love source folder on iOS?

Posted: Tue Aug 15, 2023 5:47 am
by SugarRayLua
Thanks for the heads up :-)

Re: Any intermediary love objects that will allow importing images from outside the Love source folder on iOS?

Posted: Tue Aug 15, 2023 6:22 am
by GVovkiv
If you curious, here wiki page on how it will work https://love2d.org/wiki/love.filesystem.mountFullPath
I don't see any IOS builds in artefacts here https://github.com/love2d/love/actions for 12.0, so if you really want to try it out, you probably need to build wip love 12 from source yourself

Re: Any intermediary love objects that will allow importing images from outside the Love source folder on iOS?

Posted: Tue Aug 15, 2023 6:28 am
by Kartik Agaram
Here's a program that will load images from anywhere on your system, using the pure-Lua nativefs library (https://github.com/EngineerSmith/nativefs) Just include nativefs.lua in the .love file with the following main.lua:

Code: Select all

nativefs = require 'nativefs'
Image = nil

function love.load()
  local filename = '/home/akkartik/Documents/akkartik2-sq.png'
  local file_data = nativefs.newFileData(filename)
  Image = love.graphics.newImage(file_data)
end

function love.draw()
  if Image then
    love.graphics.draw(Image)
  end
end

Re: Any intermediary love objects that will allow importing images from outside the Love source folder on iOS?

Posted: Tue Aug 15, 2023 8:44 pm
by SugarRayLua
That worked perfectly, thanks! 😊👍