Pico-8 REPL/Interpreter

Published 2023-06-12


A REPL (Read-Eval-Print Loop) for pico-8, in pico-8!

Supports executing all lua & pico-8 statements. (if statements, for loops, functions - you name it)

While my code does its own parsing and execution of the statements, any functions you call are the real pico-8 functions.

Code can be typed in, pasted in, or dropped in from .lua files.

Alternatively, carts saved in .p8.rom format (save mycart.p8.rom in pico-8) can be dropped to the REPL to automatically run them.

Type expressions like 1+3/5 or sqrt(-2) to see the expected results. (Well - perhaps unexpected to some in the case of the sqrt)

Type statements or programs like the one below to do whatever you wish. (That one prints all global functions)

Computations that produce lots of results are automatically paged, computations that do nothing indefinitely can be interrupted via escape (escape works in BBS or SPLORE only)

The special variable "_" is set to the value of the last expression you've executed.

The special variable "_env" is set to the globals table (it's similar to lua's/pico-8's _ENV - which is also supported but requires ctrl+L to type)

Pico-8's globals are not disturbed and are the same as in a blank Pico-8 cart.

You can type "\i=0" to disable all text that "interrupts" the code while its executing, letting the code use up the entire screen. This also disables output paging, but pressing escape to stop execution still works.

The main point of it is that I made it, everything else is up to you.

But for example, you can easily take a look at whatever Pico version happens to be running in the BBS, and see how it differs from your own.

No. All this allows you to do is to write and execute some code.

You can't edit sprites/sfx/etc/etc, or export, or import, etc etc etc.

Hopefully that's limited enough to avoid running afoul of any legal concerns.

As said, all evaluation other than execution of global functions is implemented by me and may have bugs (feel free to report those), or subtle inconsistencies with real pico8/lua behaviour.

No bugs or missing features are currently known.

Easy - just use Ctrl+V to paste and Ctrl+X/C to cut/copy.

Well - cut/copy is currently a bit janky on the BBS - you have to press it twice to get it on the clipboard.

You can also drag & drop a text file to the cart to copy its contents.

You can take any cart, use pico-8 to convert it to .p8.rom format (e.g. save mycart.p8.rom) and drag & drop it into the cart to run it immediately.

The cart runs without resetting the system, so odd effects may occur if you run multiple carts without resetting (e.g. via \rst).

If you press escape, you can resume the cart via \cont (or restart - without reset - via '\run')

(Note: .p8 and .p8.png files are not supported - just .p8.rom)

There are some special \-prefixed identifiers which act like special variables:

As well as some special \-prefixed functions:

And even some special \-prefixed commands (identifiers which perform an action when accessed):

And some shortcuts:

Oh, and a puzzle game based on this interpreter can be found HERE.

Since the comments in the source code took too many characters and had to be stripped out, the original source code, with the comments, is available here:

Commented Source Code

Just in case the link goes down, it's also available here, though unfortunately without syntax highlighting: