Skip to content

ReFreezed/LuaHotLoader

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 

LuaHotLoader

LuaHotLoader is a Lua library for hot-loading files, including modules. Works with LuaFileSystem or LÖVE 0.10+.

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

Documentation

Help

Got a question? If the documentation doesn't have the answer, look if someone has asked the question in the issue tracker, or create a new issue.