Skip to content
/ m Public

A module for creating hot-reloadable modules in Defold

License

Notifications You must be signed in to change notification settings

wistpotion/m

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hero

A module for creating hot-reloadable modules in Defold

Intro

A problem encountered when using hot reloading in defold is that modules are not reimported by scripts and modules not reloaded. See hot reloading modules to see why this happens and how it's fixed.

Installation

To use this, add it Defold as a library dependency. Open your game.project file and in the dependencies field under project add: https://github.com/wistpotion/m/archive/refs/tags/1.0.zip, or add a different release.

Usage

Using m is very simple. When you declare a module with this format:

local M = {}

function M.potato()
  return "potato"
end

return M

You simply replace the empty table in the start with m(...). ... is a variable that points to the path to the file (for example main.potato) when use in the top scope of the file. The new, hot reloadable module becomes:

local m = require "m.m"

local M = m(...)

function M.potato()
  return "potato"
end

return M

Pitfalls

Just because the module is reloaded doesn't mean code is rerun. Scripts functions like init are not rerun upon reload. See the reload function for a way to deal with that.

About

A module for creating hot-reloadable modules in Defold

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages