/fennel-pico-8-example

An example of building pico 8 games with the fennel programming language

Primary LanguageLuaThe UnlicenseUnlicense

Fennel PICO-8

An example Fennel project for targeting PICO-8.

Setup

Symlink the projects games directory to the PICO-8 carts directory. In my case on OSX this would be:

ln -s ~/projects/fennel-pico-8-example/games '~/Library/Application Support/pico-8/carts/games'

Install Lua:

brew install lua

This project vendors Fennel as a git submodule.

The fennel directory is there, but empty. You must run the following commands to initialise your local configuration file, and to fetch all the data from that project:

git submodule init
git submodule update

Build the fennel script and make it executable:

cd fennel
make
chmod +x fennel
cd ..

Compiling Fennel game code to Lua

make

Load the code in PICO-8

Launch PICO-8 then at the PICO-8 prompt:

load games/squashy.p8

Run the code in PICO-8

At the PICO-8 prompt:

run

Tips & Tricks

View limits

Because we are using #includes and an external editor the token, chars and compressed limits won't display properly. In order to view their correct values type info at the PICO-8 prompt.

What counts to token limit?

One of the stricter limits PICO-8 places on its carts' code is that they must contain no more than 8192 tokens.

A token is one of:

  • A literal value, such as nil, false, true, any number (e.g. 123, 0xff.ff, -3, ~1e4), or any string (of any size).
  • A variable or operator
  • An opening bracket ([{
  • A keyword, with the exception of end and local

In particular, the following are not counted as tokens:

  • The comma ,, semicolon ;, period ., colon :, and double-colon ::
  • Closing brackets )]}
  • The end and local keywords
  • The unary minus - and complement ~ operators when applied on a numeric literal

The important one for code generated by fennel is that local does not count to the token limit.

Macros

By defining things as a macro they don't exist at run time unless used. This means macros don't contribute to your token limit unless used.

However, because macros expand into code, macros can use up more tokens than functions if called multiple times.

Useful links