1.17. Complier directives

Quirrel has a way to for flexibly customize language features.

This allows to smoothly change compiler, while keeping backward compatibility if needed.



let function foo() {
  if (123)

Prefix directive with ‘default:’ to apply it to entire VM, otherwise directive applies to clojure in where it is declared.

1.18. List of Complier directives

1.18.1. Strict booleans


Force booleans in conditional expressions, raise an error on non-boolean types.

Non-boolean in conditional expressions can lead to errors. Because all programming languages with such feature behave differently, for example Python treats empty arrays and strings as false, but JS doesn’t; PHP convert logical expression to Boolean, etc. Another reason is that due to dynamic nature of Quirrel those who read code can’t know what exactly author meant with it.

if (some_var) //somevar can be null, 0, 0.0 or object


local foo = a() || b() && c //what author means? What will be foo?

1.18.2. Implicit bool expressions


Original Squirrel 3.1 behavior (treat boolean false, null, 0 and 0.0 as false, all other values as true)

1.18.3. Disable access to root table via ::


Forbids use of :: operator for the current unit Using root table is dangerous (as all global vairables)

1.18.4. Enable access to root table via ::


Allows use of :: operator for the current unit

1.18.5. Disable implicit string concatenation


Throws error on string concatenation with +. It is slower for multple strings, use concat or join instead. It is also not safe and can cause errors, as + is supposed to be at least Associative operation, and usually Commutative too. But + for string concatenation is not associative, e.g.


let a = 1
let b = 2
let c = "3"
(a + b) + c != a + (b + c) // "33" != "123"

This actually happens especially on reduce of arrays and alike.

1.18.6. Enable plus string concatenation


Allow using plus operator ‘+’ to concatenate strings.

1.18.7. #strict


Enable all extra checks/restrictions

1.18.8. #relaxed


Disable all extra checks/restrictions