Skip to content
This repository has been archived by the owner on Dec 8, 2023. It is now read-only.

TypeScriptToLua plugin that performs constant folding for simple numeric expressions

License

Notifications You must be signed in to change notification settings

thinknathan/tstl-simple-const-unroller

Repository files navigation

tstl-simple-const-unroller

TypeScriptToLua plugin that performs constant folding for simple numeric expressions:

  • Addition (+)
  • Subtraction (-)
  • Multiplication (*)
  • Division (/)
  • Modulo (%)
  • Exponentiation (**)

All parts of the expression must be numeric literals.

Redundancy warning: Your target Lua runtime may already perform constant folding.

Example

const hour = 60 * 60;

Becomes:

local hour = 3600

Installation

Requires a modern version of TSTL. Tested on TSTL >= 1.22.0.

  1. Install this plugin
yarn add git+https://git@github.com/thinknathan/tstl-simple-const-unroller.git#^1.0.0 -D
# or
npm install git+https://git@github.com/thinknathan/tstl-simple-const-unroller.git#^1.0.0 --save-dev
  1. Add tstl-simple-const-unroller to tstl.luaPlugins in tsconfig.json
{
	"tstl": {
		"luaPlugins": [
+			{ "name": "tstl-simple-const-unroller" }
		],
	}
}

License

CC0