« ReFreezed.com
LuaHotLoader

This is the official website for LuaHotLoader - a Lua library for hot-loading files and modules.

The library is a single Lua file. It works with LuaFileSystem or LÖVE. MIT license.

Download the latest stable release here or, if you're cloning the repository, checkout the last commit with a version tag.

Basic usage

With LuaFileSystem

local hotLoader = require("hotLoader")
local duckPath  = "duck.jpg"

-- Program loop.
local lastTime = os.clock()

while true do
	local currentTime = os.clock()

	-- Allow the library to reload module and resource files that have been updated.
	hotLoader.update(currentTime-lastTime)

	-- Show if debug mode is enabled.
	local settings = hotLoader.require("appSettings")
	if settings.enableDebug then
		print("DEBUG")
	end

	-- Show size of duck image.
	local duckData = hotLoader.load(duckPath)
	print("Duck is "..(#duckData).." bytes")

	lastTime = currentTime
end

In LÖVE

local hotLoader = require("hotLoader")
local player = {
	x = 100, y = 50,
	imagePath = "player.png",
}

function love.load()
	-- Tell the library to load .png files using love.graphics.newImage().
	hotLoader.setLoader("png", love.graphics.newImage)

	-- Note: The library automatically adds common loaders in LÖVE, including
	-- for .png files. You can call hotLoader.removeAllLoaders() to undo this.
end

function love.update(dt)
	-- Allow the library to reload module and resource files that have been updated.
	hotLoader.update(dt)
end

function love.draw()
	-- Show if debug mode is enabled.
	local settings = hotLoader.require("gameSettings")
	if settings.enableDebug then
		love.graphics.print("DEBUG", 5, 5)
	end

	-- Draw player image.
	local playerImage = hotLoader.load(player.imagePath)
	love.graphics.draw(playerImage, player.x, player.y)
end