Skip to content

Lua library for hot-loading files, including modules. Works with LuaFileSystem or LÖVE.

License

Notifications You must be signed in to change notification settings

ReFreezed/LuaHotLoader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.