|
1 | 1 | --[[============================================================ |
2 | 2 | --= |
3 | | ---= LuaHotLoader v1.2-dev - file hot-loading library |
| 3 | +--= LuaHotLoader v1.3 - file hot-loading library |
4 | 4 | --= by Marcus 'ReFreezed' Thunström |
5 | 5 | --= |
6 | 6 | --= License: MIT (see below) |
|
104 | 104 |
|
105 | 105 |
|
106 | 106 | 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.", |
109 | 109 | _URL = "http://refreezed.com/luahotloader/", |
110 | 110 | _LICENSE = [[ |
111 | 111 | MIT License |
|
277 | 277 |
|
278 | 278 | -- chunk = loadLuaFile( path ) |
279 | 279 | -- 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 |
281 | 288 |
|
282 | 289 |
|
283 | 290 |
|
@@ -397,12 +404,26 @@ local function loadModule(level, moduleName, protected) |
397 | 404 | local main_chunk, err = loadLuaFile(getModuleFilePath(incLevel(level), moduleName)) |
398 | 405 | local module |
399 | 406 |
|
| 407 | + if not main_chunk then |
| 408 | + err = err:gsub("\n$", "") |
| 409 | + end |
| 410 | + |
400 | 411 | 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 |
402 | 416 |
|
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 |
406 | 427 |
|
407 | 428 | else |
408 | 429 | if not main_chunk then error(err, incLevel(level)) end |
|
0 commit comments