is it possible for a thread to use love.filesystem?

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
jjmafiae
Party member
Posts: 1331
Joined: Tue Jul 24, 2012 8:22 am

is it possible for a thread to use love.filesystem?

Post by jjmafiae »

is it possible for a thread to use love.filesystem?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: is it possible for a thread to use love.filesystem?

Post by Robin »

Code: Select all

require('love.filesystem')
Have you tried it?
Help us help you: attach a .love.
jjmafiae
Party member
Posts: 1331
Joined: Tue Jul 24, 2012 8:22 am

Re: is it possible for a thread to use love.filesystem?

Post by jjmafiae »

yeah, it doesn't work :( (using 0.9.0)
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: is it possible for a thread to use love.filesystem?

Post by Boolsheet »

Well, then provide your code or some testcase so we can test it ourselves. If you only say "it doesn't work" then my answer to that is "works for me".

Also, as a general warning: assume nothing is thread-safe (unless stated otherwise). While PhsysicsFS might have been built thread-safe, the LÖVE code calling to it may not be. It is possible that it will work without issues, depending on what you do.
Attachments
filesystem_thread_test.love
(508 Bytes) Downloaded 114 times
Shallow indentations.
jjmafiae
Party member
Posts: 1331
Joined: Tue Jul 24, 2012 8:22 am

Re: is it possible for a thread to use love.filesystem?

Post by jjmafiae »

(using löve 0.9.0 luajit version)

my code:

main.lua code

Code: Select all

thread = love.thread.newThread("thread.lua")
thread:start()
thread.lua

Code: Select all

	require("love.filesystem")
	http = require 'socket.http'
	
	
    local data1, r, e = http.request('http://geggames.com/test.txt')
    -- Ensure the file was donwnloaded properly
    assert(r == 200 and data1,
      ('Could not download file: %s')
        :format(host:match('/([^/]+)$')))
	
	love.filesystem.newFile("test.txt")
	love.filesystem.write("test.txt", data1)
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: is it possible for a thread to use love.filesystem?

Post by Boolsheet »

Yes, that works. A few things though.

You don't need to call [wiki]love.filesystem.newFile[/wiki] before you use [wiki]love.filesystem.write[/wiki]. [wiki]love.filesystem.write[/wiki] is more or less a short version of this.

Code: Select all

function love.filesystem.write(filename, data)
   local file = love.filesystem.newFile(filename)
   file:open("w")
   file:write(data)
   file:close()
end
Not exactly like that of course, but you get the idea.

I'm assuming the variable host is the url you pass in to the request function.

Have you checked with [wiki]Thread:getError[/wiki] if you made a mistake somwhere?
Shallow indentations.
jjmafiae
Party member
Posts: 1331
Joined: Tue Jul 24, 2012 8:22 am

Re: is it possible for a thread to use love.filesystem?

Post by jjmafiae »

it returns nil

it can make empty files but it doesn't work when i use the data downloaded from the internet :/

does luasocket work in threads?
Last edited by jjmafiae on Fri Nov 22, 2013 4:48 pm, edited 1 time in total.
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: is it possible for a thread to use love.filesystem?

Post by Boolsheet »

Yes, it returns nil until there's an error. Keep calling it until the thread has ended. If it's still nil, then we know it's not a Lua error in your code.
Shallow indentations.
jjmafiae
Party member
Posts: 1331
Joined: Tue Jul 24, 2012 8:22 am

Re: is it possible for a thread to use love.filesystem?

Post by jjmafiae »

nevermind, it works now, thanks for your help guys :D
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 223 guests