Skip to content

Hot Module Replacement

Hot Module Replacement (HMR) allows you to see changes in your game without a full restart.

In your kaledis.toml, add:

experimental_hmr = true

When you save a file, Kaledis:

  1. Transpiles the changed file.
  2. Sends the new code to the running game.
  3. The game’s HMR handler re-executes the module and attempts to update references.

For HMR to work best, avoid side effects at the top level of your modules.

Bad:

-- player.luau
local hp = 100 -- This resets to 100 on every reload!
return {
getHp = function() return hp end
}

Good:

-- player.luau
return {
hp = 100, -- Store state in the returned table or a central state manager
getHp = function(self) return self.hp end
}
  • 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.load won’t re-run it.