LoveFS

Showcase your libraries, tools and other projects that help your fellow love users.
linux-man
Citizen
Posts: 67
Joined: Thu Apr 28, 2011 4:51 pm

LoveFS

Post by linux-man » Fri Jun 08, 2012 5:02 pm

File Systems are the most boring subject I can find, but, since I started a game editor in love (yet to come) I had some revolutionary ideas like loading images from somewhere...
Please try the demo. It's working on Linux and Windows 7. I don't have a Mac (don't even know how is love._os for Mac), but since it's soooo BSD I'm trying the Linux code. Hope it works.
Generally, I'm using terminal commands to do everything.

Updated 2016/11/07
Compatibility with Love 0.10.2
Changes:
ffi calls
Gspot GUI Demo
Source:https://github.com/linux-man/lovefs

Updated 2014/11/05
Compatibility with Love 0.9.1
Changes:
LoveFrames-0.9.8.1 (modified)
lovefs-demo.love
Version 0.8 for Love 0.9.1
(152.49 KiB) Downloaded 449 times
Updated 2014/01/17
New version for Love 0.9
Changes:
LoveFrames-0.9.7-1 (modified)
If on Windows drives can't be obtained, a default list of drive letters is returned (from A: to J:)
lovefs-demo.love
Version 0.8 for Love 0.9
(132.93 KiB) Downloaded 407 times
fs.jpg
fs.jpg (69.07 KiB) Viewed 8731 times
Windows users will have to see a lot of terminals flashing (there's no other way, at least until Love is builded with LuaFileSystem).

For those interested:

To start, (look at the demo code)

fs = lovefs(dir[string]) -- if no dir is given, start on UserDirectory

---------------------------------------- lovefs.lua -------------------------------------------------

fs.current -- Current Directory [string] (don't change it, use fs:cd(dir))

fs.drives, fs.dirs, fs.files, fs.all -- drives (detected at start), directories and files in current dir [tables].

(internal) function fs:loadCp(codepage[string]) -- Load terminal codepage. Use only for testing. Return FALSE if codepage is not supported.

Supported codepages: '737', '775', '850', '852', '855', '866', '8859-1', '8859-2', '8859-4', '8859-5', '8859-7', '8859-15', '8859-16', 'KOI8-R', 'KOI8-U'

Note: Windows 473 and Linux UTF-8 don't need translation. If Windows codepage is not supported, non-ascii chars are changed to '?'. It should work because files are opened using 8.3 names.

(internal) function fs:toUtf8(str[string]) -- return string translated to utf-8

(internal) function fs:toCp(str[string]) -- return string translated to current codepage

(internal) function fs:path8p3(dir[string], all[boolean]) -- return Windows path in 8.3 format

(internal) function fs:run(command[string]) -- Execute command on console

function fs:setParam(param[string]) -- Used by :cd() to populate fs.dirs and fs.files. Useful to apply filters like '*.jpg'

function fs:ls(param[string], dir[string]) -- return file list (table and string). Alias: fs:dir(param, dir). if dir is NIL, uses fs.current.

function fs:lsDrives() -- return drives (table)

function fs:lsDirs(param[string], dir[string]) -- return directories (table and string) Ex: tb_dirs, str_dirs = fs:lsDirs()

function fs:lsFiles(param[string], dir[string]) -- return files (table and string)

function fs:exists(name[string], dir[string]) -- return TRUE if exists.

function fs:isDirectory(name[string], dir[string]) -- return TRUE if directory.

function fs:isFile(name[string], dir[string]) return TRUE if is file.

function fs:cd(dir[string]) -- Change directory. Populate fs.dirs, fs.files and fs.all with the new directory contents. Files list use filter defined in fs:setParam.

Note: if dir is NIL current directory is used

function fs:up() -- same as fs:cd:('..')

(internal) function fs:copy(source[string], dest[string]) -- copy file

function fs:loadImage(source[string]) -- return image. If no source, uses fs.SelectedFile. Attention: This function NILs fs.selectedFile.

function fs:loadSource(source[string]) --return sound. If no source, uses fs.SelectedFile. Attention: This function NILs fs.selectedFile.

function fs:loadFont(size[int], source[string]) --return font. If no source, uses fs.SelectedFile. Attention: This function NILs fs.selectedFile.

function fs:saveImage(img, dest[string]) -- Need Canvas support. Return FALSE on failure. . If no source, uses fs.SelectedFile. Attention: This function NILs fs.selectedFile.

---------------------------------------- dialogs.lua ------------------------------------------------
Load and Save Dialogs using LoveFrames (modified)

dialog = loadDialog(lovefs, filters[table])

dialog = saveDialog(lovefs, filters[table])

Example:

fs = lovefs()
dialog = loadDialog(fs, {'All | *.*', 'Images | *.jpg *.bmp *.png'})

On close with OK, the path of the chosen file is stored at fs.selectedFile.
'|' is optional. You can write only the masks.
Last edited by linux-man on Mon Nov 07, 2016 11:21 pm, edited 12 times in total.

User avatar
josefnpat
Inner party member
Posts: 955
Joined: Wed Oct 05, 2011 1:36 am
Location: your basement
Contact:

Re: LoveFS

Post by josefnpat » Fri Jun 08, 2012 5:09 pm

For the load file screen, consider taking a list of filetypess, and having a dropdown for selecting file type that you want to show (including "All Files").

It might mediate the awkward "filter and params" section.

Much like this:
Image
You'll notice this design shows up all the time :)

Nice job!
Missing Sentinel Software | Twitter

FORCIBLY IGNORED.
<leafo> when in doubt delete all of your code
<bartbes> git rm -r *
<bartbes> git commit -m "Fixed all bugs"
<bartbes> git push

User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: LoveFS

Post by Roland_Yonaba » Fri Jun 08, 2012 5:57 pm

linux-man wrote: On Windows I'm getting UTF-8 crashes with non-windows characters, although on terminal the text looks ok. Lovers, what's the problem with printing unicode?
Me cyaan run it, man, same crash me got! (Win7 Ultimate (x32) :x

linux-man
Citizen
Posts: 67
Joined: Thu Apr 28, 2011 4:51 pm

Re: LoveFS

Post by linux-man » Fri Jun 08, 2012 7:05 pm

josefnpat wrote:For the load file screen, consider taking a list of filetypess, and having a dropdown for selecting file type that you want to show (including "All Files").
Consider that LoveFS is a low level library: functions to change directory, list files and folders and test it's existence. The demo looks so awesome thanks to Nicolai's Loveframes. If I can get a stable and multi-platform code I intent to offer a load and save frame to Nicolai. :)
josefnpat wrote:Me cyaan run it, man, same crash me got! (Win7 Ultimate (x32)
I expected that :( and probably Chineses don't have a chance. Well, you can always change to Linux :megagrin: or wait until Love support Unicode on Windows.
I'll post a console-only demo. Ugly but I must confirm where's the problem. My guess: the problem is on love.graphics.print.

User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: LoveFS

Post by Roland_Yonaba » Fri Jun 08, 2012 7:27 pm

linux-man wrote: I expected that :( and probably Chineses don't have a chance. Well, you can always change to Linux :megagrin: or wait until Love support Unicode on Windows.
I'll post a console-only demo. Ugly but I must confirm where's the problem. My guess: the problem is on love.graphics.print.
Totally right, the error raises inside columnlist-row.lua file, on a printing task.
I'll check that, right now kinda busy.
Anyway, nice job, I'll be testing your Konsöl demo.

User avatar
Nikolai Resokav
Party member
Posts: 140
Joined: Wed Apr 28, 2010 12:51 am
Location: United States

Re: LoveFS

Post by Nikolai Resokav » Fri Jun 08, 2012 8:43 pm

Pretty cool! It's awesome that you used my library too!

linux-man
Citizen
Posts: 67
Joined: Thu Apr 28, 2011 4:51 pm

Re: LoveFS

Post by linux-man » Sat Jun 09, 2012 10:05 am

Nikolai Resokav wrote:Pretty cool! It's awesome that you used my library too!
Your library is awesome!

Did some more research and I'm convinced that the problem is in the encoding/decoding of the console output. Although, love 0.8 handle unicode, it don't play well with other codepage. So, if on your console CHCP return 437 your good to go! I'm starting to analyse others.

Roland: Can you tell me what's your console codepage? I guess I can deal with 850 and 860 and maybe Cyrillic but don't know about others.

coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: LoveFS

Post by coffee » Sat Jun 09, 2012 10:17 am

In OSX

Code: Select all

[0x0-0x82082].org.love2d.love[1571]	Error: [string "lovefs.lua"]:107: 'popen' not supported
[0x0-0x82082].org.love2d.love[1571]	stack traceback:
[0x0-0x82082].org.love2d.love[1571]		[C]: in function 'popen'
[0x0-0x82082].org.love2d.love[1571]		[string "lovefs.lua"]:107: in function 'cd'
[0x0-0x82082].org.love2d.love[1571]		[string "lovefs.lua"]:125: in function 'lovefs'
[0x0-0x82082].org.love2d.love[1571]		[string "main.lua"]:22: in function 'load'
[0x0-0x82082].org.love2d.love[1571]		[string "boot.lua"]:1: in function <[string "boot.lua"]:1>
[0x0-0x82082].org.love2d.love[1571]		[C]: in function 'xpcall'

User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: LoveFS

Post by Boolsheet » Sat Jun 09, 2012 10:51 am

The unicode problem is a Lua on Windows issue. On Linux (and OS X most likely too), the ASCII compatibility advantage of UTF-8 shows through. They didn't need to change the functions that use 8-bit encoded strings, but Windows uses UTF-16 and has 2 versions for every function. Lua does not target Windows' UTF-16 and only does ASCII.

Edit: Oh. It seems I didn't understand your problem correctly. I guess it defaults to a certain codepage like you already found out. Windows does have a UTF-8 codepage, but I'm not sure how you could set it in this case.
Shallow indentations.

linux-man
Citizen
Posts: 67
Joined: Thu Apr 28, 2011 4:51 pm

Re: LoveFS

Post by linux-man » Sat Jun 09, 2012 11:17 am

coffee wrote:In OSX

Code: Select all

[0x0-0x82082].org.love2d.love[1571]	Error: [string "lovefs.lua"]:107: 'popen' not supported
[0x0-0x82082].org.love2d.love[1571]	stack traceback:
[0x0-0x82082].org.love2d.love[1571]		[C]: in function 'popen'
[0x0-0x82082].org.love2d.love[1571]		[string "lovefs.lua"]:107: in function 'cd'
[0x0-0x82082].org.love2d.love[1571]		[string "lovefs.lua"]:125: in function 'lovefs'
[0x0-0x82082].org.love2d.love[1571]		[string "main.lua"]:22: in function 'load'
[0x0-0x82082].org.love2d.love[1571]		[string "boot.lua"]:1: in function <[string "boot.lua"]:1>
[0x0-0x82082].org.love2d.love[1571]		[C]: in function 'xpcall'
That's a reall issue: it seems that the Mac build don't include io.popen. Why? I'll try to find other way. Can you use os.execute?
Boolsheet wrote:Windows does have a UTF-8 codepage, but I'm not sure how you could set it in this case.
You can't without a hack over a hack over a... at least in console. Apparently, chcp 65001 should be an utf-8 mode. It crash my console.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests