JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 8
  • Score
    100M100P100Q45793F
  • License MIT

A javascript to PICO-8 LUA converter

Package Exports

  • @jspicl/core
  • @jspicl/core/pic8-api.d.ts
  • @jspicl/core/types

Readme

@jspicl/core

The transpiler library that converts JavaScript to PICO-8 Lua. Use this to build custom tools, integrate into existing pipelines, or when you need fine-grained control over transpilation.

Most users should use @jspicl/cli - it handles bundling, transpiling, and cartridge generation in one step.

Installation

npm install @jspicl/core

Usage

import {jspicl} from "@jspicl/core";

const javascript = `
function _init() {
  x = 64;
  y = 64;
}

function _update() {
  if (btn(0)) x -= 1;
  if (btn(1)) x += 1;
}

function _draw() {
  cls();
  circfill(x, y, 4, 8);
}
`;

const result = jspicl(javascript);
console.log(result.code);

Output:

function _init()
  x = 64
  y = 64
end

function _update()
  if btn(0) then
    x -= 1
  end
  if btn(1) then
    x += 1
  end
end

function _draw()
  cls()
  circfill(x, y, 4, 8)
end

Advanced Usage

Extend or replace transpilation behavior with custom mappers:

const result = jspicl(javascript, {
  customMappers: {
    // Replace how while loops are transpiled
    WhileStatement: ({body, test}, {transpile}) =>
      `while ${transpile(test)} do\n${transpile(body)}\nend`
  }
});

Documentation

Visit jspicl.github.io for the full API reference and customization guides.