Page 2 of 2
Re: Loading files from an choosable user folder
Posted: Thu Jul 16, 2015 7:51 am
by Calandriel
it's working! Thank you guys, you're awesome, Now I can make my .love version! Soon I'll show my project and start a website to sell my games, I have a lot of ideas, and I want to make all my games with Java and LÖVE versions, to keep it portable and easier to everyone to play!
Re: Loading files from an choosable user folder
Posted: Fri Jul 17, 2015 6:33 pm
by Calandriel
I have another doubt, I heard that I shouldn't use love.filesystem and i/o library together, it is true?
Re: Loading files from an choosable user folder
Posted: Sat Jul 18, 2015 10:13 am
by Linkpy
You can use love.filesystem and Lua's IO library. But, you shouldn't use these two library together. Example :
You have a function "readFile" which takes a file handle (love.filesystem.newFile / io.open). I don't recommend this. So, you should do two function : "readFileLove" for love.filesystem.newFile and "readLoveIO" for io.open. But, don't use IO for Love's datatype (sound, image, etc).
Re: Loading files from an choosable user folder
Posted: Sat Jul 18, 2015 11:31 am
by Calandriel
So, you should do two function : "readFileLove" for love.filesystem.newFile and "readLoveIO" for io.open.
Yeah right. I'm having a lot of problem working with that ffi thing and love.filesystem. But I am getting somewhere. Ill Just try to go deeper inside the luajit pages to get more knowledge. For example, if I use filesystem to enumerate files using the ffi function to set write dir, it doesnt works. I have to use PHYSFS own function to do this. But I can use love.filesystem.write as well, wich is curious... thought that I'd had to rewrite using ffi all the filesystem functions that I could need, and that scared me
By the way, LuaJIT isn't portable? They say using it would make me lose my "portability"
Re: Loading files from an choosable user folder
Posted: Sat Jul 18, 2015 2:44 pm
by Linkpy
love.filesystem.getDirectoryItems which doesn't work ? Strange. Maybe this function uses another PHYSFS function.
LuaJIT is portable if you write code for each OSes. But, in this case -with Love2D- you don't need to do a code part for each OSes because all the libraries you use are already included in the global name space (not Lua's global name space, the program's global name space !), so you don't need to load each library. But, if you use ffi.cdef in the quick-and-dirty way, you could have some portability issues due to C data type across different platform. So, I recommend you to use C headers directly (one day I found a LuaJIT module which do the preprocessor stage, I can't remember the name
). Firstly, with a line of code you will be able to have all functions (for example, all PHYSFS functions), and also have correct data type for the current host system. If you want to try to make a C preprocessor, you can try. It's not very complex. The problem may come from the "#include" command, which is NEEDED
Another thing. You can do your stuff in another way. You can also bind all file-related function for each OS (which is not very complicated, but which can be veryyyy long if you don't use a C preprocessor). You will be able to open file, enumerate directories, etc directly, and without modifying Love2D's stuff (which can be good !). But, this need to be done in two step : The first is the direct binding (POSIX API, Windows API). The second step is the warping of OS APIs. For example, create an Lua class "File" which will use correct data type and functions for each OS. So, when you will need to use this class, you haven't got to care about "I'm on windows ? Or on Linux ?". But, this way is much longer than the way you currently use and can be a very good Love2D library for other user in the same case.
PS: I failed... It was : "readFileLove" for love.filesystem.newFile and "readFileIO" for io.open. And not "readLoveIO"
Re: Loading files from an choosable user folder
Posted: Mon Jul 20, 2015 4:25 pm
by Muzz
love.filesystem.getDirectoryItems
Does work. I'm using it with the FFI code.
Code: Select all
if love.filesystem.isDirectory("ImageMasks/") then
self.previews,success = love.filesystem.getDirectoryItems("ImageMasks/")
end
Your mistake probably is somewhere else and not in ffi. If you upload the .love i can take a look.
Re: Loading files from an choosable user folder
Posted: Mon Jul 20, 2015 11:04 pm
by Calandriel
Oh, sorry I commited a mistake. It works, but I am looking for something which works in any place I want, not just inside the write, search or appdata directory. What means ffi.PHYSFS_enumerate files. The big problem to me is that I'm not familiarized with C so, I keep trying to pass a char* as a string an things like that. I really suck at this.
Re: Loading files from an choosable user folder
Posted: Tue Jul 21, 2015 8:12 am
by Muzz
Btw this is why i said it's not recommended to use FFI to do it. Honestly from the sound of it, everything you want to do you can do in a single folder. It's not too much to ask your users to drag a package into the game folder.
Just leave the code i gave you working, and then try and work within the paramaters of it imo.