Skip to content

Instantly share code, notes, and snippets.

@hazzard993
Created May 28, 2019 06:40
Show Gist options
  • Save hazzard993/810632c1fc5b5cfa6a94e3ef36ad69da to your computer and use it in GitHub Desktop.
Save hazzard993/810632c1fc5b5cfa6a94e3ef36ad69da to your computer and use it in GitHub Desktop.

PICO-8 Transformer

  • Disallows LuaLibs
  • Disallows classes
  • Disallows iifes if (x = 0)
  • Disallows non-tuple return methods

for loops

tstl-anti-boilerplate

Can be used briefly to weed out any code that unexpectedly generates tables, functions or extra boilerplate code.

Useful for code that may be executed many times.

function x() {}             // -> function x() end          ✔ Lua equivilent
x = x + 1;                  // -> x = x + 1                 ✔ Lua equivilent
func();                     // -> func()                    ✔ Lua equivilent
x = {}                      // -> x = {}                    ✔ Lua equivilent
x += 1;                     // -> x = x + 1                 ✔ Same logic
x++;                        // -> x = x + 1                 ✔ Same logic
[x] = [0];                  // -> x = 0                     ✔ Different way but same logic
[[x]] = [[x]];              // -> ____ = {{x}} ...          ❌ This destructure requires a table
[x, y] = tuple();           // -> x, y = tuple()            ✔ Tuple return destructure
x = array();                // -> x = { array() }           ❌ This assignment requires a table
[x, y] = array();           // -> ____ = array() ...        ❌ Non-tuple-return destructure
y = x++;                    // -> y = (function() ...end)   ❌ This assignment requires an iife
x = x = x + 1;              // -> x = (function() ... end)  ❌ This assignment requires an iife
class Player {}             // -> [Class Construction]      ❌ No classes
for (...)                   // -> varies                    ❌ No complex for-loop iteration
switch (...)                // -> switch ...                ❌ There is no Lua equivilent for this
x instanceof y              // -> __TS__InstanceOf...       ❌ There is no Lua equivilent for this

tstl-native-control-statements

Only transforms control statements that have a Lua equivilent.

Transformation Kinds

Shorthand - Transforms to Lua equivilent code without using an extra table, function or statement. Minor Workaround - Transforms to Lua equivilent code using multiple statements but no tables or functions. Major Workaround - Transforms to Lua equivilent code that uses functions, tables and as many statements as it wants.

for (let i = 0; i < 6; i++) {}  // -> for i=0, 6, 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment