Loading files from an choosable user folder
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Calandriel
- Prole
- Posts: 39
- Joined: Wed Apr 22, 2015 9:00 am
Re: Loading files from an choosable user folder
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!
If violence is not solving all your problems, You're simply not using enough of it.
Twitter: https://twitter.com/Calandriell Some news about wtf I'm doing.
Tumblr:https://www.tumblr.com/blog/calandriell I use to draw some random stuff.
Twitter: https://twitter.com/Calandriell Some news about wtf I'm doing.
Tumblr:https://www.tumblr.com/blog/calandriell I use to draw some random stuff.
- Calandriel
- Prole
- Posts: 39
- Joined: Wed Apr 22, 2015 9:00 am
Re: Loading files from an choosable user folder
I have another doubt, I heard that I shouldn't use love.filesystem and i/o library together, it is true?
If violence is not solving all your problems, You're simply not using enough of it.
Twitter: https://twitter.com/Calandriell Some news about wtf I'm doing.
Tumblr:https://www.tumblr.com/blog/calandriell I use to draw some random stuff.
Twitter: https://twitter.com/Calandriell Some news about wtf I'm doing.
Tumblr:https://www.tumblr.com/blog/calandriell I use to draw some random stuff.
Re: Loading files from an choosable user folder
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).
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).
Founder of NeoShadow Studio. Currently working on the project "Sirami".
github / linkpy
github / linkpy
- Calandriel
- Prole
- Posts: 39
- Joined: Wed Apr 22, 2015 9:00 am
Re: Loading files from an choosable user folder
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"So, you should do two function : "readFileLove" for love.filesystem.newFile and "readLoveIO" for io.open.
If violence is not solving all your problems, You're simply not using enough of it.
Twitter: https://twitter.com/Calandriell Some news about wtf I'm doing.
Tumblr:https://www.tumblr.com/blog/calandriell I use to draw some random stuff.
Twitter: https://twitter.com/Calandriell Some news about wtf I'm doing.
Tumblr:https://www.tumblr.com/blog/calandriell I use to draw some random stuff.
Re: Loading files from an choosable user folder
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"
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"
Founder of NeoShadow Studio. Currently working on the project "Sirami".
github / linkpy
github / linkpy
Re: Loading files from an choosable user folder
love.filesystem.getDirectoryItems
Does work. I'm using it with the FFI code.
Your mistake probably is somewhere else and not in ffi. If you upload the .love i can take a look.
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
- Calandriel
- Prole
- Posts: 39
- Joined: Wed Apr 22, 2015 9:00 am
Re: Loading files from an choosable user folder
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.
Last edited by Calandriel on Wed Jul 22, 2015 8:56 am, edited 1 time in total.
If violence is not solving all your problems, You're simply not using enough of it.
Twitter: https://twitter.com/Calandriell Some news about wtf I'm doing.
Tumblr:https://www.tumblr.com/blog/calandriell I use to draw some random stuff.
Twitter: https://twitter.com/Calandriell Some news about wtf I'm doing.
Tumblr:https://www.tumblr.com/blog/calandriell I use to draw some random stuff.
Re: Loading files from an choosable user folder
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.
Just leave the code i gave you working, and then try and work within the paramaters of it imo.
Who is online
Users browsing this forum: No registered users and 11 guests