-- 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.
-- To accomplish this, we need to override the default behavior of dofile and some other things.
localLiveReload={}
localoldDofile=dofile
---Overwritten dofile to execute a lua script from disk and cirumvent any caching.
---Noita for some reason caches script files (Or loads them into its virtual filesystem)(Or caches compiled bytecode), so reloading script files from disk does not work without this.
---
---This is not fully conform the the standard lua implementation, but so isn't Noita's implementation.
---@param path string
---@return any result
---@return string|nil err
functiondofile(path)---TODO: Consider moving dofile into compatibility.lua
localfunc,err=loadfile(path)
ifnotfuncthenreturnnil,errend
localstatus,res=pcall(func)
ifnotstatusthenreturnnil,resend
returnres,nil
end
---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 and namespaces.
---
---Just put this into your `OnWorldPreUpdate` or `OnWorldPostUpdate` callback: