Hot Module Replacement
Hot Module Replacement (HMR) allows you to see changes in your game without a full restart.
Enable HMR
Section titled “Enable HMR”In your kaledis.toml, add:
experimental_hmr = trueHow it Works
Section titled “How it Works”When you save a file, Kaledis:
- Transpiles the changed file.
- Sends the new code to the running game.
- The game’s HMR handler re-executes the module and attempts to update references.
Writing HMR-friendly Code
Section titled “Writing HMR-friendly Code”For HMR to work best, avoid side effects at the top level of your modules.
Bad:
-- player.luaulocal hp = 100 -- This resets to 100 on every reload!
return { getHp = function() return hp end}Good:
-- player.luaureturn { hp = 100, -- Store state in the returned table or a central state manager getHp = function(self) return self.hp end}Limitations
Section titled “Limitations”- Global State: Changes to global variables usually don’t persist or might behave unpredictably.
- Upvalues: Local variables in closures might not update as expected.
- Love Callbacks: Changing
love.loadwon’t re-run it.