fileWatchRoutine.lua 397 B

1234567891011121314
  1. local lfs = require("lfs")
  2. -- coroutine that watches files and calls the callback if they change
  3. return function(filename, callback)
  4. lastUpdated = -1 --lfs.attributes(filename).modification
  5. while(true) do
  6. local newTime = lfs.attributes(filename).modification
  7. if(newTime > lastUpdated) then
  8. callback(filename)
  9. lastUpdated = newTime
  10. end
  11. coroutine.yield()
  12. end
  13. end