Using fswatch to detect updated files
Posted: Thu Jul 23, 2020 2:21 am
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
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