Log In  

I was working on this a while ago and haven’t found much time for it lately, but I thought it could be interesting to some people. It is a fork of Lua that implements the PICO-8 dialect.


If you know how to embed Lua somewhere, then there are chances that you can embed PICO-8 compatible Lua instead! I use it for an unfinished toy emulator project.


  • short if syntax (on one line)
  • short print syntax (? at the beginning of a line)
  • compound assignment operators: += /= etc.
  • C style not equal operator: !=
  • C++ style comments with //
  • fixed-point arithmetic with overflows, infinity etc.
  • the PICO-8 math library (shr, atan2, flr etc.)
  • binary literals: 0b1001001.10010
  • works in Windows and Linux, and probably in OS X too


The usual approach to the language extensions is through code parsing and patching. For instance, replacing all occurrences of <something>+=<blah> with <something>=<something>+(<blah>). This is what PICO-8 itself does, which is why it still has the occasional weird parsing issues (you can write x=0y=1 but not x+=0y=1). My approach is to implement these extensions in the Lua parser instead, which is elegant, more robust, and gives better error reporting.


It’s on GitHub: https://github.com/samhocevar/z8lua


Here is a z8lua session in my terminal; you can see familiar PICO-8 syntax in here:

P#54527 2018-07-30 07:38 ( Edited 2018-07-30 11:38)

FYI, z8lua now supports features from upcoming PICO-8 0.1.12d:

  • support for full 8-bit character set (Japanese and extra punctuation)
  • new ord() and chr() functions
  • new ^= and ..= operators
  • short while syntax on a single line: while(foo()) bar()

Also there is experimental support for Lua persistence using Eris, allowing for memory snapshots and advanced debugging.

P#73217 2020-02-18 22:49
:: Felice


I'd considered doing something broadly similar, but I can never find the energy these days.

Which version of Lua is backing this? I'm wondering how hard it'd be to diff your version with the base version and try applying the edits to the current Lua, just for the sake of having these extensions on regular Lua.

P#73219 2020-02-19 02:22 ( Edited 2020-02-19 02:23)
:: sparr

@samhocevar dare I ask where you got your list of 12d features?

P#73221 2020-02-19 03:45

@Felice it’s based on Lua 5.2 (same as PICO-8); not sure what you mean by “regular Lua” but I consider that regular Lua 🙂 My goal is to emulate PICO-8 so that’s what made sense. Targeting Lua 5.3 might be possible but it’s a very different language, especially in the way it handles numbers, which would make the implementation of fixed-point arithmetic very tricky.

You can see a list of changes against upstream Lua on Github; I tried to split them by feature and one should be able to cherry-pick them.

@sparr I just look at the BBS and Twitter; @zep teases a lot 😄 here are a few pointers:

P#73222 2020-02-19 07:29 ( Edited 2020-02-19 07:31)

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2020-04-09 11:43 | 0.036s | 2097k | Q:27