Skip to content

Data Types

SamaLang inherits all data types from Lua. Since SamaLang transpiles directly to Lua, every Lua data type is available.

SamaLang uses floating-point numbers (double precision) for all numeric values.

Terminal window
ada umur = 25
ada tinggi = 170.5
ada negatif = -10
tulis(umur)
tulis(tinggi)

Strings are sequences of characters enclosed in double quotes.

Terminal window
ada nama = "SamaLang"
ada sapa = "Halo, Dunia!"
tulis(nama)
tulis(sapa)

String concatenation uses the .. operator:

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

SamaLang has two boolean values: tutu (true) and siong (false).

Terminal window
ada aktif = tutu
ada kosong = siong
lamen aktif tres
tulis("Aktif!")
jure_mo

The nda_isi keyword represents the absence of a value (equivalent to Lua’s nil).

Terminal window
ada data = nda_isi
lamen data == nda_isi tres
tulis("Tidak ada data")
jure_mo

Tables are SamaLang’s primary data structure. They can be used as arrays, dictionaries, or objects.

Terminal window
-- Array
ada buah = {"apel", "mangga", "jeruk"}
tulis(buah[1]) -- Output: apel
-- Dictionary
ada mahasiswa = {
nama = "Ahmad",
umur = 20,
jurusan = "Teknik"
}
tulis(mahasiswa.nama)

See Tables for more details.

Use the type() function to check a value’s type:

Terminal window
ada x = 42
tulis(type(x)) -- Output: number
ada s = "hello"
tulis(type(s)) -- Output: string
Type Example Lua Equivalent
Number 42, 3.14 number
String "text" string
Boolean tutu, siong boolean
Nil nda_isi nil
Table {1, 2, 3} table
Function fungsi ... jure_mo function