Using fswatch to detect updated files

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
gilzoide
Prole
Posts: 5
Joined: Fri Jun 19, 2020 2:19 am

Using fswatch to detect updated files

Post by gilzoide »

Hi everyone!
I'd like to share with you an easy and effective way of detecting updated files in a project, so you could hot reload them, for example.

The idea is to have an external program monitoring the filesystem and have your game just listening for when an update really occurs, no need for tracking file stats with love.filesystem.getInfo(), polling or anything like this. This only works if you have the program available for execution in your PATH, a one-time setup. Reloading assets will probably only be useful while developing the game and no crashes occur if the command fails, so even if the setup is off, it is not much of a problem.

I'm using the awesome fswatch (https://github.com/emcrisostomo/fswatch) because it works on all major platforms, is really simple to call and uses the operating system native monitors by default.

The example code is in this gist, is short and all explained in comments.
Feel free to use, comment, ask questions and all =D

All the best,

gilzoide
Post Reply

Who is online

Users browsing this forum: Amazon [Bot] and 4 guests