crush/README.md

113 lines
3.8 KiB
Markdown
Raw Normal View History

crush
=====
2022-08-15 11:01:51 +02:00
**crush** - The uncomplicated LÖVE external module system.
**crush** is a minimalistic dependency-less package system for the LÖVE engine.
It provides a structured approach to retrieve external libraries for your game project.
2022-08-15 18:54:20 +02:00
## Why?
Lua knows some excellent dependency management system,
like [LuaRocks](https://luarocks.org).
2022-08-15 18:54:20 +02:00
Though, they are not optimal for a game project, where:
* External libraries should be packed along with the game for distribution.
* Packages are often small, and their code should be readily hackable by developers (package versions are not tremendously important).
* Depending on a complex package manager is undesireable.
2022-08-15 18:54:20 +02:00
LÖVE games have limited ways to manage external libraries:
2022-08-15 18:54:20 +02:00
1. Manually, directly copying external libraries in the game source tree.
2022-08-15 18:54:20 +02:00
* Pulling latest changes in the library requires more copy-pasting.
* Harder to use libraries if they depend on other libraries themselves.
2022-08-15 18:54:20 +02:00
2. Using a package manager during development, and carefully
pack external libraries with the game manually upon distribution.
2022-08-15 18:54:20 +02:00
* Adds a non-trivial step to distribution phase.
* Many existing LÖVE libraries have no support for package managers.
2022-08-15 18:54:20 +02:00
**crush** provides an alternative to this.
2022-08-15 18:54:20 +02:00
## How to use it?
To use **crush** follow these steps:
1. Copy the latest `crush.lua` into your project's root folder.
2. Create a `.lovedeps` file in the same directory, here you will list every dependency (more in the next section).
3. With `crush.lua` and `.lovedeps` in place, you can populate or refresh project dependencies by running:
2022-08-15 18:54:20 +02:00
```sh
lua crush.lua
```
**crush** will fetch the project's dependencies recursively, cloning them inside a `lib` subdirectory.
2022-08-15 18:54:20 +02:00
Thus you may use them comfortably in your code with a trivial `require()`, like this:
2022-08-15 18:54:20 +02:00
```lua
local serialize = require 'lib.serialize'
```
Meaning that **crush** flattens all dependencies inside the `lib` folder.
This implies that common dependencies across different packages must be named and accessed consistently in the source code.
A reasonable limitation given **crush** use-case.
2022-08-15 18:54:20 +02:00
## The .lovedeps file
The `.lovedeps` file is a regular Lua text file, containing a table where every entry specifies a dependency:
```lua
2022-08-15 19:20:48 +02:00
['dependency-name'] = "git-url"
2022-08-15 18:54:20 +02:00
```
For example:
```lua
{
-- Fetch lib/serialize from https://git.doublefourteen.io/lua/df-serialize
serialize = "https://git.doublefourteen.io/lua/df-serialize",
-- Fetch lib/gear from https://git.doublefourteen.io/lua/gear
gear = "https://git.doublefourteen.io/lua/gear"
}
```
## Philosophy
**crush** is somewhat opinionated and tied to its intended use-case.
It obeys the following general rules:
`MUST`:
* Be Self-contained, only a single Lua file: `crush.lua`.
* Must only depend on Lua, LÖVE and `git`, expected to be available on any LÖVE developer machine.
* Do one thing: fetch the dependencies listed in the `.lovedeps` file.
* Be simple and predictable, integrating **crush** into a LÖVE game must be as intuitive as possible.
* Be hackable, its code must be reasonably trivial, understandable and adaptable.
* Enforce one way to do things, encouraging consistency.
`MUST NOT`:
* Give in to feature creep.
2022-08-15 19:10:28 +02:00
* Provide a centralized repository.
2022-08-15 18:54:20 +02:00
* Be completely general, its scope is limited to the average LÖVE game or library.
* Be entirely safe, there is no demand for checksum or strict versioning in **crush** use case.
`SHOULD NOT`:
* Break compatibility with older `.lovedeps` files.
If this does not meet your requirements, code should still be sufficiently hackable to
provide some room for customization.
2022-08-15 18:54:20 +02:00
## Similar projects
* [LÖVERocks](https://github.com/Alloyed/loverocks) is a more involved project with the ambition to bring LuaRocks features to LÖVE.
## License
See [LICENSE](LICENSE) for license information.