Conciseness techniques - arbuxsrc/replicube-techniques GitHub Wiki

Operator precedence

Ref: https://www.lua.org/pil/3.5.html

Understanding operator precedence in the complex formula will help remove brackets.

Operator precedence is:

  • ^
  • not - (unary)
  • * /
  • ..
  • < > <= >= ~= ==
  • and
  • or

so the following:

return x == 0 or (y==3 and z>4)

is the same as the script below. This is because and runs with a higher precedence than or, but saves you 1 size for the bracket removal.

return x == 0 or y==3 and z>4

Checking if any of x, y, z are on the centreline

The simple way, readable way:

if x==0 or y==0 or z==0 then return 1 end -- code size 16

As 0 times anything is 0 and the centre line is at 0

return x*y*z==0 -- code size 8
⚠️ **GitHub.com Fallback** ⚠️