Skip to content

4. Operations and symbols

Felice D'Angelo edited this page Apr 9, 2023 · 3 revisions

This page lists all operators and symbols available in Clue.

Arithmetic

  • + Addition
  • - Subtraction
  • * Multiplication
  • / Division
  • /_ Floor division
  • % Modulo
  • ^ Exponentiation

These operators remain unchanged from Lua except floor division.

Comparison

  • == Equals
  • != Not equals
  • < Less than
  • > Greater than
  • <= Less than or equals
  • >= Greater than or equals

Only the not equals operator changed: != must be used instead of ~=

Boolean

  • && Lua's and keyword
  • || Lua's or keyword
  • ! Lua's not keyword

Lua's keywords are replaced by symbols, but they work exactly the same.

Ternary

While ternary is possible in Lua with condition and x or y it is not identical to C's ternary (if condition is true but x is nil or false it will return y).

Clue adds ? and : that replicate true ternary when compiled (if condition is true x will be returned no matter what).

local a = x ? y : z;

This code will be compiled to:

local _t0;      
if x then       
    _t0 = y;
else
    _t0 = z;
end
local a = _t0;

Altering

  • = Redefine
  • += Increase
  • -= Decrease
  • *= Multiply
  • /= Divide
  • ^= Exponentiate
  • ..= Concatenate
  • %= Module
  • &&= Define if itself is true
  • ||= Define if itself is false
  • ??= Define if itself is nil

All of these except = were added by Clue, click here for more info about them.

Bitwise

  • & AND
  • | OR
  • ^^ XOR
  • ~ NOT
  • << Left shift
  • >> Right shift

When compiling Clue will assume the version of Lua you're compiling to supports bitwise operations and uses the same symbols that Clue uses.

If you're using LuaJIT you can use the -jitbit flag to make Clue load the bit library and use it for bitwise operations.

You can choose the name of the variable that stores the bit library, and you will be able to use the library yourself with the same variable.

(For example, to name the variable bit: --jitbit=bit)

Indexing

  • . String-keys indexing
  • [] Normal indexing
  • :: Method indexing
  • ?. Conditional . indexing
  • ?[] Conditional [] indexing
  • ?:: Conditional :: indexing

Clue adds conditional indexing and replaces : with ::.

Misc

  • = Define
  • # Length
  • ; End of expression
  • ... Variable amount of function arguments
  • $ Pseudo variable

Deprecated

  • ?> PGet, removed entirely (b2.0.86)
  • ?= Replaced by &&= (3.0.0)
  • := Replaced by ||= (3.0.0)
Clone this wiki locally