Skip to content

Operators

SamaLang supports all Lua operators. Since the transpiler only replaces keywords, operators work exactly as they do in Lua.

Operator Description Example
+ Addition 3 + 25
- Subtraction 10 - 46
* Multiplication 5 * 315
/ Division 10 / 33.333...
% Modulo 10 % 31
^ Exponent 2 ^ 38
Terminal window
ada hasil = (10 + 5) * 2
tulis(hasil) -- Output: 30
ada sisa = 17 % 5
tulis(sisa) -- Output: 2
Operator Description
== Equal to
~= Not equal to
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
Terminal window
ada umur = 20
lamen umur >= 18 tres
tulis("Dewasa")
jure_mo
Operator Description Lua Equivalent
no Logical NOT not
dan Logical AND and
atau Logical OR or
Terminal window
ada x = tutu
ada y = siong
-- no (NOT)
lamen no y tres
tulis("y adalah siong") -- This runs
jure_mo
-- dan (AND)
lamen x dan y tres
tulis("Keduanya benar") -- This does NOT run
jure_mo
-- atau (OR)
lamen x atau y tres
tulis("Salah satu benar") -- This runs
jure_mo

Use .. to join strings together:

Terminal window
ada nama = "Sama"
ada versi = "Lang"
ada gabung = nama .. versi
tulis(gabung) -- Output: SamaLang

Use # to get the length of a string or table:

Terminal window
ada teks = "SamaLang"
tulis(#teks) -- Output: 8
ada buah = {"apel", "mangga", "jeruk"}
tulis(#buah) -- Output: 3

From highest to lowest precedence:

  1. ^ (exponent)
  2. #, unary -, no (NOT)
  3. *, /, %
  4. +, -
  5. .. (concatenation)
  6. <, >, <=, >=, ~=, ==
  7. dan
  8. atau