Data Types
SamaLang inherits all data types from Lua. Since SamaLang transpiles directly to Lua, every Lua data type is available.
Numbers
Section titled “Numbers”SamaLang uses floating-point numbers (double precision) for all numeric values.
ada umur = 25ada tinggi = 170.5ada negatif = -10
tulis(umur)tulis(tinggi)Strings
Section titled “Strings”Strings are sequences of characters enclosed in double quotes.
ada nama = "SamaLang"ada sapa = "Halo, Dunia!"
tulis(nama)tulis(sapa)String concatenation uses the .. operator:
ada nama = "Sama"ada bahasa = "Lang"ada gabung = nama .. bahasa
tulis(gabung) -- Output: SamaLangBooleans
Section titled “Booleans”SamaLang has two boolean values: tutu (true) and siong (false).
ada aktif = tutuada kosong = siong
lamen aktif tres tulis("Aktif!")jure_moThe nda_isi keyword represents the absence of a value (equivalent to Lua’s nil).
ada data = nda_isi
lamen data == nda_isi tres tulis("Tidak ada data")jure_moTables
Section titled “Tables”Tables are SamaLang’s primary data structure. They can be used as arrays, dictionaries, or objects.
-- Arrayada buah = {"apel", "mangga", "jeruk"}tulis(buah[1]) -- Output: apel
-- Dictionaryada mahasiswa = { nama = "Ahmad", umur = 20, jurusan = "Teknik"}
tulis(mahasiswa.nama)See Tables for more details.
Type Checking
Section titled “Type Checking”Use the type() function to check a value’s type:
ada x = 42tulis(type(x)) -- Output: number
ada s = "hello"tulis(type(s)) -- Output: stringSummary
Section titled “Summary”| 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 |