[SOLVED] Using io.open() inside AppImage-packed game

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
alberto_lara
Party member
Posts: 372
Joined: Wed Oct 30, 2013 8:59 pm

[SOLVED] Using io.open() inside AppImage-packed game

Post by alberto_lara »

Hi there, so I'm using this function:

Code: Select all

utils.readTextFile = function (path)
  local f = assert(io.open(path, "rb"))
  local content = f:read("*all")
  f:close()
  return content
end
and this works when I run the game in "dev" mode, but it fails when I try to run the game after I packed it inside the AppImage file (following the wiki instructions). This makes sense to me somehow but, what would be the right way to fix it? I see love.filesystem has a bunch of useful methods to get paths, but Idk if something will work for my case.

This is the error I get, and it makes sense since (I guess) it's looking for the assets folder at the same level as the AppImage file is?

Image
Last edited by alberto_lara on Tue Nov 08, 2022 4:43 pm, edited 1 time in total.
MrFariator
Party member
Posts: 512
Joined: Wed Oct 05, 2016 11:53 am

Re: Using io.open() inside AppImage-packed game

Post by MrFariator »

At a quick glance, I found this post by zorg about io.* library's shortcomings, and I imagine you're experiencing some of these issues using io.open can bring about in a packed game. Essentially, it might be looking at a wrong place (if the filepath is otherwise correct), and as such doesn't find the file you're looking for. Might be better if you just use love.filesystem.read instead.

I tried to use some of io.* functions in the past, and I couldn't get them to comfortably work with love2d for my purposes.
User avatar
alberto_lara
Party member
Posts: 372
Joined: Wed Oct 30, 2013 8:59 pm

Re: Using io.open() inside AppImage-packed game

Post by alberto_lara »

For some reason I thought love.filesystem was only for those user directories outside of the game code, but it can also be used to read/write inside your own game root directory, right? if so, yeah, maybe I'm just using IO carelessly
User avatar
alberto_lara
Party member
Posts: 372
Joined: Wed Oct 30, 2013 8:59 pm

Re: Using io.open() inside AppImage-packed game

Post by alberto_lara »

Alright, this works! I just did:

Code: Select all

utils.readAsLuaObj = function (path)
  local content = love.filesystem.read(path)
  return loadstring(content)()
end
where path is in the same level as main.lua as

Code: Select all

assets/somefilder.../file
Thanks!
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: [SOLVED] Using io.open() inside AppImage-packed game

Post by zorg »

love.filesystem (in 11.4 and earlier) is sandboxed, yes, but to both where your main.lua is (whether zipped or not), and also to your project's save directory.

You can still get around that limitation in certain ways though (ffi, or using libraries that already do that for you, like nativefs or my own love-fml; both does different things), but for most purposes, those two places are enough.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 56 guests