noita-mapcap/files/libraries/noita-api/live-reload.lua
David Vogel 403167b366 Fix compatibility stuff
- Make dofile more conform to standard lua
- Move dofile from live-reload.lua to compatibility.lua
- Let dofile and require throw errors on script errors
- Fix bug in recursion detection
- Remove Noita's dofile annotation
- Fix some EmmyLua annotations
- Improve print replacement
2022-07-30 00:32:11 +02:00

30 lines
987 B
Lua

-- Copyright (c) 2022 David Vogel
--
-- This software is released under the MIT License.
-- https://opensource.org/licenses/MIT
-- Allows Noita mods to reload themselves every now and then.
-- This helps dramatically with development, as we don't have to restart Noita for every change.
local LiveReload = {}
---Reloads the mod's init file in the given interval in frames.
---For reloading to work correctly, the mod has to be structured in a special way.
---Like the usage of require, namespaces, correct error handling, ...
---
---Just put this into your `OnWorldPreUpdate` or `OnWorldPostUpdate` callback:
---
--- LiveReload:Reload("mods/your-mod/", 60) -- The trailing path separator is needed!
---@param modPath string
---@param interval integer
function LiveReload:Reload(modPath, interval)
interval = interval or 60
self.Counter = (self.Counter or 0) + 1
if self.Counter < interval then return end
self.Counter = nil
dofile(modPath .. "init.lua")
end
return LiveReload