is it possible for a thread to use love.filesystem?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
is it possible for a thread to use love.filesystem?
is it possible for a thread to use love.filesystem?
- 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?
Code: Select all
require('love.filesystem')
Help us help you: attach a .love.
Re: is it possible for a thread to use love.filesystem?
yeah, it doesn't work (using 0.9.0)
Re: is it possible for a thread to use love.filesystem?
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.
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.
Re: is it possible for a thread to use love.filesystem?
(using löve 0.9.0 luajit version)
my code:
main.lua code
thread.lua
my code:
main.lua code
Code: Select all
thread = love.thread.newThread("thread.lua")
thread:start()
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)
Re: is it possible for a thread to use love.filesystem?
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.
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?
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
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.
Re: is it possible for a thread to use love.filesystem?
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?
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.
Re: is it possible for a thread to use love.filesystem?
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.
Re: is it possible for a thread to use love.filesystem?
nevermind, it works now, thanks for your help guys
Who is online
Users browsing this forum: Google [Bot] and 223 guests