Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wistpotion/m
A module for creating hot-reloadable modules in Defold
https://github.com/wistpotion/m
Last synced: 4 months ago
JSON representation
A module for creating hot-reloadable modules in Defold
- Host: GitHub
- URL: https://github.com/wistpotion/m
- Owner: wistpotion
- License: cc0-1.0
- Created: 2022-11-11T10:15:00.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2022-11-11T20:45:05.000Z (about 2 years ago)
- Last Synced: 2024-02-06T22:44:14.193Z (12 months ago)
- Language: Lua
- Homepage:
- Size: 6.27 MB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-defold - m - reloadable modules. (Libraries / Programming Language)
README
![hero](https://github.com/wistpotion/m/blob/main/hero.png)
A module for creating hot-reloadable modules in Defold
## Intro
A problem encountered when using [hot reloading in defold](https://defold.com/manuals/hot-reload/) is that modules are not reimported by scripts and modules not reloaded. See [hot reloading modules](https://defold.com/manuals/modules/#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:
```lua
local M = {}function M.potato()
return "potato"
endreturn 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:
```lua
local m = require "m.m"local M = m(...)
function M.potato()
return "potato"
endreturn 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](https://defold.com/manuals/hot-reload/#the-on_reload-function) for a way to deal with that.