Operators
SamaLang supports all Lua operators. Since the transpiler only replaces keywords, operators work exactly as they do in Lua.
Arithmetic Operators
Section titled “Arithmetic Operators”| Operator | Description | Example |
|---|---|---|
+ |
Addition | 3 + 2 → 5 |
- |
Subtraction | 10 - 4 → 6 |
* |
Multiplication | 5 * 3 → 15 |
/ |
Division | 10 / 3 → 3.333... |
% |
Modulo | 10 % 3 → 1 |
^ |
Exponent | 2 ^ 3 → 8 |
ada hasil = (10 + 5) * 2tulis(hasil) -- Output: 30
ada sisa = 17 % 5tulis(sisa) -- Output: 2Comparison Operators
Section titled “Comparison Operators”| Operator | Description |
|---|---|
== |
Equal to |
~= |
Not equal to |
> |
Greater than |
< |
Less than |
>= |
Greater than or equal |
<= |
Less than or equal |
ada umur = 20
lamen umur >= 18 tres tulis("Dewasa")jure_moLogical Operators
Section titled “Logical Operators”| Operator | Description | Lua Equivalent |
|---|---|---|
no |
Logical NOT | not |
dan |
Logical AND | and |
atau |
Logical OR | or |
ada x = tutuada y = siong
-- no (NOT)lamen no y tres tulis("y adalah siong") -- This runsjure_mo
-- dan (AND)lamen x dan y tres tulis("Keduanya benar") -- This does NOT runjure_mo
-- atau (OR)lamen x atau y tres tulis("Salah satu benar") -- This runsjure_moString Concatenation
Section titled “String Concatenation”Use .. to join strings together:
ada nama = "Sama"ada versi = "Lang"ada gabung = nama .. versitulis(gabung) -- Output: SamaLangLength Operator
Section titled “Length Operator”Use # to get the length of a string or table:
ada teks = "SamaLang"tulis(#teks) -- Output: 8
ada buah = {"apel", "mangga", "jeruk"}tulis(#buah) -- Output: 3Operator Precedence
Section titled “Operator Precedence”From highest to lowest precedence:
^(exponent)#, unary-,no(NOT)*,/,%+,-..(concatenation)<,>,<=,>=,~=,==danatau