Skip to content
Converts PICO-8 extended Lua syntax to standard Lua syntax
Lua Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.luarocks
.gitignore
LICENSE
README.md
luarocks
pico8-to-lua-0.1.0-1.rockspec
pico8-to-lua.lua

README.md

pico8-to-lua

A command-line utility written in Lua that converts the PICO-8 variety of extended Lua syntax to standard Lua syntax.

It's a thin wrapper around the internal syntax converter from PICOLOVE.

Reasons you might find this useful:

  • You want to run a tool built for Lua on your code, and the tool won't recognize it because you're using special PICO-8 syntax
  • You want better syntax highlighting support in your text editor
  • You want to extract a function you wrote for PICO-8 and use it in a different Lua program

You might also try...

While I was working on this project, picotool was updated to support a --pure-lua argument to its listlua command, which will do roughly the same thing as this!

Installation

  1. Install Lua for your operating system. This doesn't come with PICO-8, which has its own Lua compiler, so you'll need to install Lua separately.

  2. You can either:

    a. Install with LuaRocks:

    $ luarocks install pico8-to-lua

    b. Clone the repository from GitHub and enter the project directory:

    $ git clone https://github.com/benwiley4000/pico8-to-lua.git
    $ cd pico-to-lua/

Usage

NOTE: All the examples assume you have installed pico-to-lua globally, but if you're using it from inside the cloned directory, you can replace all instances of pico8-to-lua with ./pico8-to-lua.lua (or lua pico8-to-lua.lua for non-UNIX environments) in the commands that you run.

Assuming you have an input Lua file that looks like this:

-- input.lua
function next_even_number(num)
 if (num % 2 != 0) num += 1
 return num
end

You can generate a standard Lua version with the command:

$ pico8-to-lua input.lua

You should see this output:

function next_even_number(num)
 if num % 2 ~= 0 then num = num +  1 end
 return num
end

You can also use a .p8 file as input...

pico-8 cartridge // http://www.pico-8.com
version 16
__lua__
function _init()
 local num = 0b10
 if (num+1==0b11) print('yes!')
end
$ pico8-to-lua input.p8

...which will output transformed p8 file contents:

pico-8 cartridge // http://www.pico-8.com
version 16
__lua__
function _init()
 local num = 0x2
 if num+1==0x3 then print('yes!') end
end

If you only want the lua output, you can pass the --lua-only flag when the input is a p8 file:

$ pico8-to-lua input.p8 --lua-only
function _init()
 local num = 0x2
 if num+1==0x3 then print('yes!') end
end

If you're in a UNIX environment, you can pipe the output directly to a file:

$ pico8-to-lua input.lua > output.lua
$ pico8-to-lua input.p8 > output.p8

Or you can pipe into another program:

$ pico8-to-lua input.p8 --lua-only | luacheck -

You can even pipe output from another program into this one by passing - as the filename argument:

$ cat input.lua | pico8-to-lua - > output.lua
$ curl https://someurl.com/mycart.p8 | pico8-to-lua - --lua-only | luacheck -
You can’t perform that action at this time.