A small module which automatically hotswaps changed Lua files in a running LÖVE project.
Drop the lurker.lua and
lume.lua files into an
existing project and add the following line inside the love.update()
function:
require("lurker").update()
Lurker will automatically detect changed files and hotswap them into the running project.
To more easily make use of additional functionality, the lurker module can be set to a variable when it is required into the project:
lurker = require "lurker"
As opposed to using the lurker.update()
function -- such to avoid the
overhead of repeatedly polling for file changes -- you can instead opt to
trigger a scan of the directory by calling lurker.scan()
manually. If the
scan detects any changes a hotswap is performed.
lurker.preswap
can be set to a function. This function is called before a
hotswap occurs and is passed the name of the file which will be swapped.
lurker.preswap = function(f) print("File " .. f .. " swapping...") end
lurker.postswap
can be set to a function. This function is called after a
hotswap occurs and is passed the name of the file which was swapped.
lurker.postswap = function(f) print("File " .. f .. " was swapped") end
lurker.prescan
can be set to a function. This function is called before a
scan occurs.
lurker.prescan = function() print("Scanning for changes...") end
lurker.postscan
can be set to a function. This function is called after a
scan occurs and is passed all the changed files.
lurker.prescan = function(f) print("Scan found and swapped " .. lume.count(f) .. "changes.") end
lurker.crashhook
can be set to a function. This function is called whenever
f11 is hit during the crash screen. This could be used to trigger any error
reporting behavior in the application without replacing the onerror event.
Dictates whether lurker should run in protected mode; this is true
by
default. If protected mode is disabled then LÖVE's usual error screen is used
when an error occurs in a LÖVE callback function; if it is enabled then
lurker's error state (which continues watching for file changes and can resume
execution) is used. Changes to this variable should be made before any calls to
lurker.update() are made.
Dictates what should happen if lurker tries to load a file which contains a
syntax error. If it is false
then lurker's error screen is shown until the
syntax error is fixed; if it is true
the error message is printed to the
console and the program continues. lurker.quiet is false
by default.
The interval in seconds for how often the scan of the directory is performed.
This is .5
by default.
The directory which is scanned for changes. This is .
(The project's root) by
default.