How I change directory with love.filesystem
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
How I change directory with love.filesystem
Hi there everyone I was new I LOVE I was trying to a filesystem that write file in Lua for entities and ingame propertys I want that I save my file in different dictionary not on main LOVE dictionary
Re: How I change directory with love.filesystem
Good day and welcome!
Sadly, Love2d has some unpleasant restrictions about working with files aside from default savegame directory.
This is caused by some cross-platform features and some security reasons.
With love.filesystem you can only change the name of save directory with love.filesystem.setIdentity but not the full path to it:
But there are few ways to get around it:
Sadly, Love2d has some unpleasant restrictions about working with files aside from default savegame directory.
This is caused by some cross-platform features and some security reasons.
With love.filesystem you can only change the name of save directory with love.filesystem.setIdentity but not the full path to it:
Code: Select all
love.filesystem.setIdentity("my_lovely_game_saves")
- You can use Lua functions to write to a file, not the Love ones. But keep in mind that Lua's functions for working with files are not the best and reliable ones.
Code: Select all
local file = io.open("D:\\example.txt", "w+") file:write("Hello from Lua!") file:close()
- You can write a file in Love directory and then move it anywhere you want with os Lua functions.
Code: Select all
love.filesystem.write("example.txt", "Hello from Love!") local src_path = love.filesystem.getSaveDirectory() .. "/example.txt" local dst_path = "D:\\example.txt" os.rename(src_path, dst_path)
- You can do something in C (or potentially some other language) using Lua JIT FFI. Maybe (not sure this will work anywhere, but works for me):
Code: Select all
local ffi = require("ffi") ffi.cdef([[ typedef struct FILE FILE; FILE* fopen(const char *filename, const char *mode); int fprintf(FILE* stream, const char* format, ...); int fclose(FILE* stream); ]]) local file = ffi.C.fopen("D:\\example.txt", "w") ffi.C.fprintf(file, "Hello from C FFI !") ffi.C.fclose(file)
- You can use NativeFS library that mostly replicates Love's filesystem, but without restrictions to file paths:https://github.com/EngineerSmith/nativefs
- zorg
- Party member
- Posts: 3468
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: How I change directory with love.filesystem
You can also wait for 12.0 to relax the restrictions a bit.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Who is online
Users browsing this forum: Google [Bot] and 2 guests