项目作者: benwiley4000

项目描述 :
Converts PICO-8 extended Lua syntax to standard Lua syntax
高级语言: Lua
项目地址: git://github.com/benwiley4000/pico8-to-lua.git
创建时间: 2019-05-25T22:59:11Z
项目社区:https://github.com/benwiley4000/pico8-to-lua

开源协议:zlib License

下载


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:

    1. $ luarocks install pico8-to-lua

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

    1. $ git clone https://github.com/benwiley4000/pico8-to-lua.git
    2. $ 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:

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

You can generate a standard Lua version with the command:

  1. $ pico8-to-lua input.lua

You should see this output:

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

You can also use a .p8 file as input…

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

…which will output transformed p8 file contents:

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

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

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

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

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

Or you can pipe into another program:

  1. $ 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:

  1. $ cat input.lua | pico8-to-lua - > output.lua
  1. $ curl https://someurl.com/mycart.p8 | pico8-to-lua - --lua-only | luacheck -