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.

Example

#default:strict

let function foo() {
  #relaxed-bool
  if (123)
    print("bar")
}

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

#strict-bool

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

or

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

1.18.2. Implicit bool expressions

#relaxed-bool

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 ::

#forbid-root-table

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 ::

#allow-root-table

Allows use of :: operator for the current unit

1.18.5. Disable implicit string concatenation

#no-plus-concat

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.

Example:

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-plus-concat

Allow using plus operator ‘+’ to concatenate strings.

1.18.7. #strict

#strict

Enable all extra checks/restrictions

1.18.8. #relaxed

#relaxed

Disable all extra checks/restrictions