Skip to content

Commit 21e6c13

Browse files
committed
Fixed module reloading. Sigh...
1 parent 356db30 commit 21e6c13

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

hotLoader.lua

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
--[[============================================================
22
--=
3-
--= LuaHotLoader v1.2-dev - file hot-loading library
3+
--= LuaHotLoader v1.3 - file hot-loading library
44
--= by Marcus 'ReFreezed' Thunström
55
--=
66
--= License: MIT (see below)
@@ -104,8 +104,8 @@
104104

105105

106106
local hotLoader = {
107-
_VERSION = "LuaHotLoader 1.2.0-dev",
108-
_DESCRIPTION = "File hot-loading library",
107+
_VERSION = "LuaHotLoader 1.3.0",
108+
_DESCRIPTION = "File hot-loading library.",
109109
_URL = "http://refreezed.com/luahotloader/",
110110
_LICENSE = [[
111111
MIT License
@@ -277,7 +277,14 @@ end
277277

278278
-- chunk = loadLuaFile( path )
279279
-- Returns nil and a message on error.
280-
local loadLuaFile = love and love.filesystem.load or loadfile
280+
local loadLuaFile
281+
= love and function(path)
282+
local ok, chunkOrErr1, err2 = pcall(love.filesystem.load, path) -- LÖVE, you're drunk.
283+
if not ok then return nil, chunkOrErr1 end
284+
if not chunkOrErr1 then return nil, err2 end
285+
return chunkOrErr1
286+
end
287+
or loadfile
281288

282289

283290

@@ -397,12 +404,26 @@ local function loadModule(level, moduleName, protected)
397404
local main_chunk, err = loadLuaFile(getModuleFilePath(incLevel(level), moduleName))
398405
local module
399406

407+
if not main_chunk then
408+
err = err:gsub("\n$", "")
409+
end
410+
400411
if protected then
401-
if not main_chunk then logError(err) ; return nil end
412+
if not main_chunk then
413+
io.stderr:write(err, "\n")
414+
return nil
415+
end
402416

403-
local ok, moduleOrErr = pcall(main_chunk, moduleName)
404-
if not ok then logError(tostring(moduleOrErr)) ; return nil end
405-
module = moduleOrErr
417+
if not xpcall(
418+
function()
419+
module = main_chunk(moduleName)
420+
end,
421+
function(err)
422+
io.stderr:write(debug.traceback(tostring(err), 2), "\n")
423+
end
424+
) then
425+
return nil
426+
end
406427

407428
else
408429
if not main_chunk then error(err, incLevel(level)) end

0 commit comments

Comments
 (0)