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.
const hour = 60 * 60;
Becomes:
local hour = 3600
Requires a modern version of TSTL. Tested on TSTL >= 1.22.0.
- 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
- Add
tstl-simple-const-unroller
totstl.luaPlugins
intsconfig.json
{
"tstl": {
"luaPlugins": [
+ { "name": "tstl-simple-const-unroller" }
],
}
}
CC0