This repository has been archived on 2025-08-04. You can view files and clone it, but cannot push or open issues or pull requests.
rhaj/rhai_engine/rhaibook/engine/precedence.md
2025-04-03 09:18:05 +02:00

1.9 KiB

Operator Precedence

{{#include ../links.md}}

All operators in Rhai has a precedence indicating how tightly they bind.

A higher precedence binds more tightly than a lower precedence, so * and / binds before + and - etc.

When registering a custom operator, the operator's precedence must also be provided.

The following precedence table shows the built-in precedence of standard Rhai operators:

Category Operators Binding Precedence (0-255)
Logic and bit masks ||, |, ^ left 30
Logic and bit masks &&, & left 60
Comparisons ==, != left 90
Containment [in] left 110
Comparisons >, >=, <, <= left 130
Null-coalesce ?? left 135
Ranges .., ..= left 140
Arithmetic +, - left 150
Arithmetic *, /, % left 180
Arithmetic ** right 190
Bit-shifts <<, >> left 210
Unary operators +, -, ! right highest
Object field access ., ?. right highest