33 lines
1.5 KiB
Markdown
33 lines
1.5 KiB
Markdown
# L5 in Fennel template
|
|
|
|
[Repo](https://codeberg.org/durian/l5-fennel-template.git)
|
|
|
|
A minimalist template for using [L5](https://github.com/L5lua/L5) within [Fennel](https://fennel-lang.org/).
|
|
|
|
[L5](https://l5lua.org/) is built on top of [LÖVE](https://www.love2d.org/), and it provides a Processing API for Lua. It's meant for interactive artwork on the computer, aimed at artists, designers, and anyone that wants a flexible way to prototype art, games, toys, and other software experiments in code.
|
|
|
|
To use it in Fennel, we can use the [Absolutely Minimal Fennel Setup for Love2D](https://sr.ht/~benthor/absolutely-minimal-love2d-fennel/) template for `main.lua`, but modify it to add the `allowedGlobals=false` option for L5 to work properly. We do this because L5 sets global variables that we want to allow and `allowedGlobals=false` disables that check.
|
|
|
|
```fennel
|
|
fennel = require("fennel")
|
|
debug.traceback = fennel.traceback
|
|
table.insert(package.loaders,
|
|
function(filename)
|
|
if love.filesystem.getInfo(filename) then
|
|
return function(...)
|
|
return fennel.eval(love.filesystem.read(filename), {env=_G, filename=filename, allowedGlobals=false}, ...), filename
|
|
end
|
|
end
|
|
end)
|
|
|
|
require("main.fnl")
|
|
```
|
|
|
|
Inside `main.fnl`, the other thing that we need to do is to expose the functions that L5 expects:
|
|
|
|
```fennel
|
|
(set _G.setup setup)
|
|
(set _G.draw draw)
|
|
```
|
|
|
|
Now you can simply run `love .` in the root of your project directory and you should be good to go!
|