From 8a5e2639d349402ad66d838ed45a124b53c35b7e Mon Sep 17 00:00:00 2001 From: Dania Rifki Date: Sat, 7 Feb 2026 18:40:56 +0800 Subject: Format docs with prettier Also adjust custom.css a little --- doc/docs/id-id/doc/advanced/do.md | 3 + doc/docs/id-id/doc/advanced/line-decorators.md | 3 + doc/docs/id-id/doc/advanced/macro.md | 9 + doc/docs/id-id/doc/advanced/module.md | 8 + doc/docs/id-id/doc/advanced/try.md | 2 + doc/docs/id-id/doc/assignment/assignment.md | 9 + .../doc/assignment/destructuring-assignment.md | 11 + doc/docs/id-id/doc/assignment/if-assignment.md | 5 + ...ng-clause-controlling-destructive-assignment.md | 3 + .../id-id/doc/assignment/varargs-assignment.md | 1 + doc/docs/id-id/doc/control-flow/conditionals.md | 7 + doc/docs/id-id/doc/control-flow/continue.md | 2 + doc/docs/id-id/doc/control-flow/for-loop.md | 6 + doc/docs/id-id/doc/control-flow/switch.md | 11 + doc/docs/id-id/doc/control-flow/while-loop.md | 3 + .../id-id/doc/data-structures/comprehensions.md | 16 ++ .../id-id/doc/data-structures/table-literals.md | 9 + doc/docs/id-id/doc/functions/backcalls.md | 4 + doc/docs/id-id/doc/functions/function-literals.md | 27 +- doc/docs/id-id/doc/functions/function-stubs.md | 1 + doc/docs/id-id/doc/getting-started/usage.md | 100 +++---- doc/docs/id-id/doc/language-basics/attributes.md | 3 + doc/docs/id-id/doc/language-basics/comment.md | 1 + doc/docs/id-id/doc/language-basics/literals.md | 5 + doc/docs/id-id/doc/language-basics/operator.md | 15 + doc/docs/id-id/doc/language-basics/whitespace.md | 2 + .../doc/objects/object-oriented-programming.md | 22 ++ doc/docs/id-id/doc/objects/with-statement.md | 6 + .../id-id/doc/reference/the-yuescript-library.md | 317 ++++++++++++--------- doc/docs/id-id/try/index.md | 1 + 30 files changed, 422 insertions(+), 190 deletions(-) (limited to 'doc/docs/id-id') diff --git a/doc/docs/id-id/doc/advanced/do.md b/doc/docs/id-id/doc/advanced/do.md index ebbd2e2..ac75531 100644 --- a/doc/docs/id-id/doc/advanced/do.md +++ b/doc/docs/id-id/doc/advanced/do.md @@ -8,6 +8,7 @@ do print var print var -- nil di sini ``` + ```yue @@ -31,6 +32,7 @@ counter = do print counter! print counter! ``` + ```yue @@ -53,6 +55,7 @@ tbl = { 1234 } ``` + ```yue diff --git a/doc/docs/id-id/doc/advanced/line-decorators.md b/doc/docs/id-id/doc/advanced/line-decorators.md index e90e205..d968b1f 100644 --- a/doc/docs/id-id/doc/advanced/line-decorators.md +++ b/doc/docs/id-id/doc/advanced/line-decorators.md @@ -5,6 +5,7 @@ Untuk kemudahan, loop for dan pernyataan if dapat diterapkan pada pernyataan tun ```yuescript print "hello world" if name == "Rob" ``` + ```yue @@ -18,6 +19,7 @@ Dan dengan loop dasar: ```yuescript print "item: ", item for item in *items ``` + ```yue @@ -33,6 +35,7 @@ game\update! while game\isRunning! reader\parse_line! until reader\eof! ``` + ```yue diff --git a/doc/docs/id-id/doc/advanced/macro.md b/doc/docs/id-id/doc/advanced/macro.md index ce0bafa..d33ec5b 100644 --- a/doc/docs/id-id/doc/advanced/macro.md +++ b/doc/docs/id-id/doc/advanced/macro.md @@ -32,6 +32,7 @@ macro and = (...) -> "#{ table.concat {...}, ' and ' }" if $and f1!, f2!, f3! print "OK" ``` + ```yue @@ -68,6 +69,7 @@ if $and f1!, f2!, f3! ## Menyisipkan Kode Mentah Fungsi macro bisa mengembalikan string YueScript atau tabel konfigurasi yang berisi kode Lua. + ```yuescript macro yueFunc = (var) -> "local #{var} = ->" $yueFunc funcA @@ -93,6 +95,7 @@ if cond then end ]==] ``` + ```yue @@ -126,6 +129,7 @@ end ## Export Macro Fungsi macro dapat diekspor dari modul dan diimpor di modul lain. Anda harus menaruh fungsi macro export dalam satu file agar dapat digunakan, dan hanya definisi macro, impor macro, dan ekspansi macro yang boleh ada di modul export macro. + ```yuescript -- file: utils.yue export macro map = (items, action) -> "[#{action} for _ in *#{items}]" @@ -140,6 +144,7 @@ import "utils" as { } [1, 2, 3] |> $map(_ * 2) |> $filter(_ > 4) |> $each print _ ``` + ```yue @@ -165,10 +170,12 @@ import "utils" as { ## Macro Bawaan Ada beberapa macro bawaan tetapi Anda bisa menimpanya dengan mendeklarasikan macro dengan nama yang sama. + ```yuescript print $FILE -- mendapatkan string nama modul saat ini print $LINE -- mendapatkan angka 2 ``` + ```yue @@ -235,6 +242,7 @@ macro printNumAndStr = (num `Num, str `String) -> | $printNumAndStr 123, "hello" ``` + ```yue @@ -259,6 +267,7 @@ macro printNumAndStr = (num, str) -> $printNumAndStr 123, "hello" ``` + ```yue diff --git a/doc/docs/id-id/doc/advanced/module.md b/doc/docs/id-id/doc/advanced/module.md index dd97a32..103e3f6 100644 --- a/doc/docs/id-id/doc/advanced/module.md +++ b/doc/docs/id-id/doc/advanced/module.md @@ -28,6 +28,7 @@ do import "lpeg" as :C, :Ct, :Cmt import "export" as {one, two, Something:{umm:{ch}}} ``` + ```yue @@ -67,6 +68,7 @@ do import table.concat print concat ["a", tostring 1] ``` + ```yue @@ -98,6 +100,7 @@ do print FLAG FLAG = 123 ``` + ```yue @@ -140,6 +143,7 @@ export y = -> export class Something umm: "cool" ``` + ```yue @@ -166,6 +170,7 @@ Melakukan export bernama dengan destrukturisasi. export :loadstring, to_lua: tolua = yue export {itemA: {:fieldA = 'default'}} = tb ``` + ```yue @@ -182,6 +187,7 @@ export.itemA = tb export. = items export["a-b-c"] = 123 ``` + ```yue @@ -208,6 +214,7 @@ else export with tmp j = 2000 ``` + ```yue @@ -234,6 +241,7 @@ export default -> print "hello" 123 ``` + ```yue diff --git a/doc/docs/id-id/doc/advanced/try.md b/doc/docs/id-id/doc/advanced/try.md index 6607451..4e63004 100644 --- a/doc/docs/id-id/doc/advanced/try.md +++ b/doc/docs/id-id/doc/advanced/try.md @@ -29,6 +29,7 @@ catch err print yue.traceback err print result ``` + ```yue @@ -82,6 +83,7 @@ catch e print e e ``` + ```yue diff --git a/doc/docs/id-id/doc/assignment/assignment.md b/doc/docs/id-id/doc/assignment/assignment.md index d9fd45d..34e18fd 100644 --- a/doc/docs/id-id/doc/assignment/assignment.md +++ b/doc/docs/id-id/doc/assignment/assignment.md @@ -7,6 +7,7 @@ hello = "world" a, b, c = 1, 2, 3 hello = 123 -- menggunakan variabel yang sudah ada ``` + ```yue @@ -20,6 +21,7 @@ hello = 123 -- menggunakan variabel yang sudah ada ## Pembaruan Nilai Anda dapat melakukan assignment pembaruan dengan banyak operator biner. + ```yuescript x = 1 x += 1 @@ -30,6 +32,7 @@ x %= 10 s ..= "world" -- akan menambah local baru jika variabel local belum ada arg or= "default value" ``` + ```yue @@ -48,10 +51,12 @@ arg or= "default value" ## Assignment Berantai Anda bisa melakukan assignment berantai untuk menetapkan beberapa item ke nilai yang sama. + ```yuescript a = b = c = d = e = 0 x = y = z = f! ``` + ```yue @@ -62,6 +67,7 @@ x = y = z = f! ## Local Eksplisit + ```yuescript do local a = 1 @@ -78,6 +84,7 @@ do a = 1 B = 2 ``` + ```yue @@ -100,6 +107,7 @@ do ## Global Eksplisit + ```yuescript do global a = 1 @@ -116,6 +124,7 @@ do B = 2 local Temp = "a local value" ``` + ```yue diff --git a/doc/docs/id-id/doc/assignment/destructuring-assignment.md b/doc/docs/id-id/doc/assignment/destructuring-assignment.md index ba591fd..b9956a8 100644 --- a/doc/docs/id-id/doc/assignment/destructuring-assignment.md +++ b/doc/docs/id-id/doc/assignment/destructuring-assignment.md @@ -12,6 +12,7 @@ thing = [1, 2] [a, b] = thing print a, b ``` + ```yue @@ -37,6 +38,7 @@ print hello, the_day :day = obj -- OK untuk destrukturisasi sederhana tanpa kurung ``` + ```yue @@ -68,6 +70,7 @@ obj2 = { {numbers: [first, second], properties: {color: color}} = obj2 print first, second, color ``` + ```yue @@ -95,6 +98,7 @@ Jika pernyataan destrukturisasi kompleks, Anda bisa memecahnya ke beberapa baris } } = obj2 ``` + ```yue @@ -113,6 +117,7 @@ Umumnya mengekstrak nilai dari tabel lalu menugaskannya ke variabel local dengan ```yuescript {:concat, :insert} = table ``` + ```yue @@ -126,6 +131,7 @@ Ini secara efektif sama seperti import, tetapi kita dapat mengganti nama field y ```yuescript {:mix, :max, random: rand} = math ``` + ```yue @@ -139,6 +145,7 @@ Anda bisa menulis nilai default saat destrukturisasi seperti: ```yuescript {:name = "nameless", :job = "jobless"} = person ``` + ```yue @@ -152,6 +159,7 @@ Anda dapat menggunakan `_` sebagai placeholder saat destrukturisasi list: ```yuescript [_, two, _, four] = items ``` + ```yue @@ -171,6 +179,7 @@ print first -- prints: first print bulk -- prints: {"second", "third", "fourth"} print last -- prints: last ``` + ```yue @@ -195,6 +204,7 @@ Operator spread dapat digunakan pada posisi berbeda untuk menangkap rentang yang -- Tangkap semuanya kecuali elemen tengah [first, ..._, last] = orders ``` + ```yue @@ -223,6 +233,7 @@ tuples = [ for [left, right] in *tuples print left, right ``` + ```yue diff --git a/doc/docs/id-id/doc/assignment/if-assignment.md b/doc/docs/id-id/doc/assignment/if-assignment.md index b30d0d9..e212859 100644 --- a/doc/docs/id-id/doc/assignment/if-assignment.md +++ b/doc/docs/id-id/doc/assignment/if-assignment.md @@ -6,6 +6,7 @@ Blok `if` dan `elseif` dapat menerima assignment sebagai ganti ekspresi kondisio if user := database.find_user "moon" print user.name ``` + ```yue @@ -23,6 +24,7 @@ elseif world := os.getenv "world" else print "nothing :(" ``` + ```yue @@ -37,11 +39,13 @@ else Assignment if dengan beberapa nilai return. Hanya nilai pertama yang dicek, nilai lainnya tetap berada dalam scope. + ```yuescript if success, result := pcall -> "get result without problems" print result -- variabel result berada dalam scope print "OK" ``` + ```yue @@ -61,6 +65,7 @@ while byte := stream\read_one! -- lakukan sesuatu dengan byte print byte ``` + ```yue diff --git a/doc/docs/id-id/doc/assignment/the-using-clause-controlling-destructive-assignment.md b/doc/docs/id-id/doc/assignment/the-using-clause-controlling-destructive-assignment.md index 6953138..6e47f0c 100644 --- a/doc/docs/id-id/doc/assignment/the-using-clause-controlling-destructive-assignment.md +++ b/doc/docs/id-id/doc/assignment/the-using-clause-controlling-destructive-assignment.md @@ -17,6 +17,7 @@ my_func! print i -- akan mencetak 0 ``` + ```yue @@ -52,6 +53,7 @@ my_func = (using nil) -> my_func! print i -- mencetak 100, i tidak terpengaruh ``` + ```yue @@ -80,6 +82,7 @@ my_func = (add using k, i) -> my_func(22) print i, k -- ini telah diperbarui ``` + ```yue diff --git a/doc/docs/id-id/doc/assignment/varargs-assignment.md b/doc/docs/id-id/doc/assignment/varargs-assignment.md index f24652f..9c5c8a3 100644 --- a/doc/docs/id-id/doc/assignment/varargs-assignment.md +++ b/doc/docs/id-id/doc/assignment/varargs-assignment.md @@ -10,6 +10,7 @@ count = select '#', ... first = select 1, ... print ok, count, first ``` + ```yue diff --git a/doc/docs/id-id/doc/control-flow/conditionals.md b/doc/docs/id-id/doc/control-flow/conditionals.md index 4f08b16..861eae6 100644 --- a/doc/docs/id-id/doc/control-flow/conditionals.md +++ b/doc/docs/id-id/doc/control-flow/conditionals.md @@ -7,6 +7,7 @@ if have_coins else print "Tidak ada koin" ``` + ```yue @@ -25,6 +26,7 @@ Sintaks pendek untuk pernyataan tunggal juga bisa digunakan: have_coins = false if have_coins then print "Dapat koin" else print "Tidak ada koin" ``` + ```yue @@ -40,6 +42,7 @@ Karena pernyataan if dapat digunakan sebagai ekspresi, ini juga bisa ditulis seb have_coins = false print if have_coins then "Dapat koin" else "Tidak ada koin" ``` + ```yue @@ -65,6 +68,7 @@ else print message -- prints: Saya sangat tinggi ``` + ```yue @@ -90,6 +94,7 @@ Kebalikan dari if adalah unless: unless os.date("%A") == "Monday" print "hari ini bukan Senin!" ``` + ```yue @@ -102,6 +107,7 @@ unless os.date("%A") == "Monday" ```yuescript print "Kamu beruntung!" unless math.random! > 0.1 ``` + ```yue @@ -123,6 +129,7 @@ if a in [1, 3, 5, 7] if a in list print "memeriksa apakah `a` ada di dalam daftar" ``` + ```yue diff --git a/doc/docs/id-id/doc/control-flow/continue.md b/doc/docs/id-id/doc/control-flow/continue.md index 3d7a68c..798a44b 100644 --- a/doc/docs/id-id/doc/control-flow/continue.md +++ b/doc/docs/id-id/doc/control-flow/continue.md @@ -9,6 +9,7 @@ while i < 10 continue if i % 2 == 0 print i ``` + ```yue @@ -29,6 +30,7 @@ odds = for x in *my_numbers continue if x % 2 == 1 x ``` + ```yue diff --git a/doc/docs/id-id/doc/control-flow/for-loop.md b/doc/docs/id-id/doc/control-flow/for-loop.md index 91ba22e..65386f7 100644 --- a/doc/docs/id-id/doc/control-flow/for-loop.md +++ b/doc/docs/id-id/doc/control-flow/for-loop.md @@ -12,6 +12,7 @@ for k = 1, 15, 2 -- an optional step provided for key, value in pairs object print key, value ``` + ```yue @@ -33,6 +34,7 @@ Operator slicing dan **\*** dapat digunakan, seperti pada comprehension: for item in *items[2, 4] print item ``` + ```yue @@ -49,6 +51,7 @@ for item in *items do print item for j = 1, 10, 3 do print j ``` + ```yue @@ -70,6 +73,7 @@ doubled_evens = for i = 1, 20 else i ``` + ```yue @@ -90,6 +94,7 @@ Contohnya, untuk menemukan angka pertama yang lebih besar dari 10: first_large = for n in *numbers break n if n > 10 ``` + ```yue @@ -112,6 +117,7 @@ func_b = -> return for i = 1, 10 do i print func_a! -- prints nil print func_b! -- prints table object ``` + ```yue diff --git a/doc/docs/id-id/doc/control-flow/switch.md b/doc/docs/id-id/doc/control-flow/switch.md index ced4748..1b7b86e 100644 --- a/doc/docs/id-id/doc/control-flow/switch.md +++ b/doc/docs/id-id/doc/control-flow/switch.md @@ -11,6 +11,7 @@ switch name := "Dan" else print "I don't know about you with name #{name}" ``` + ```yue @@ -39,6 +40,7 @@ next_number = switch b else error "can't count that high!" ``` + ```yue @@ -62,6 +64,7 @@ msg = switch math.random(1, 5) when 2 then "you are almost lucky" else "not so lucky" ``` + ```yue @@ -87,6 +90,7 @@ switch math.random(1, 5) when 1 else print "not so lucky" ``` + ```yue @@ -124,6 +128,7 @@ for item in *items when :width, :height print "size #{width}, #{height}" ``` + ```yue @@ -154,6 +159,7 @@ switch item when {pos: {:x = 50, :y = 200}} print "Vec2 #{x}, #{y}" -- table destructuring will still pass ``` + ```yue @@ -181,6 +187,7 @@ switch tb when [1, 2, b = 3] -- b has a default value print "1, 2, #{b}" ``` + ```yue @@ -206,6 +213,7 @@ switch tb else print "invalid" ``` + ```yue @@ -231,6 +239,7 @@ switch tb else print "invalid" ``` + ```yue @@ -257,6 +266,7 @@ switch tb ] print "matched", fourth ``` + ```yue @@ -282,6 +292,7 @@ switch segments print "Resource:", resource -- prints: "logs" print "Action:", action -- prints: "view" ``` + ```yue diff --git a/doc/docs/id-id/doc/control-flow/while-loop.md b/doc/docs/id-id/doc/control-flow/while-loop.md index cd93c91..3e302cc 100644 --- a/doc/docs/id-id/doc/control-flow/while-loop.md +++ b/doc/docs/id-id/doc/control-flow/while-loop.md @@ -10,6 +10,7 @@ while i > 0 while running == true do my_function! ``` + ```yue @@ -31,6 +32,7 @@ until i == 0 until running == false do my_function! ``` + ```yue @@ -56,6 +58,7 @@ repeat i -= 1 until i == 0 ``` + ```yue diff --git a/doc/docs/id-id/doc/data-structures/comprehensions.md b/doc/docs/id-id/doc/data-structures/comprehensions.md index 3a2a9ff..c5a8f7b 100644 --- a/doc/docs/id-id/doc/data-structures/comprehensions.md +++ b/doc/docs/id-id/doc/data-structures/comprehensions.md @@ -10,6 +10,7 @@ Berikut membuat salinan tabel `items` tetapi semua nilainya digandakan. items = [ 1, 2, 3, 4 ] doubled = [item * 2 for i, item in ipairs items] ``` + ```yue @@ -24,6 +25,7 @@ Item yang disertakan dalam tabel baru bisa dibatasi dengan klausa `when`: ```yuescript slice = [item for i, item in ipairs items when i > 1 and i < 3] ``` + ```yue @@ -37,6 +39,7 @@ Karena umum untuk mengiterasi nilai dari tabel berindeks numerik, operator **\** ```yuescript doubled = [item * 2 for item in *items] ``` + ```yue @@ -55,6 +58,7 @@ data = flat = [...v for k,v in pairs data] -- flat sekarang [1, 2, 3, 4, 5, 6] ``` + ```yue @@ -79,6 +83,7 @@ y_coords = [9, 2, 3] points = [ [x, y] for x in *x_coords \ for y in *y_coords] ``` + ```yue @@ -96,6 +101,7 @@ Perulangan for numerik juga bisa digunakan dalam komprehensi: ```yuescript evens = [i for i = 1, 100 when i % 2 == 0] ``` + ```yue @@ -119,6 +125,7 @@ thing = { thing_copy = {k, v for k, v in pairs thing} ``` + ```yue @@ -136,6 +143,7 @@ thing_copy = {k, v for k, v in pairs thing} ```yuescript no_color = {k, v for k, v in pairs thing when k != "color"} ``` + ```yue @@ -150,6 +158,7 @@ Operator **\*** juga didukung. Di sini kita membuat tabel lookup akar kuadrat un numbers = [1, 2, 3, 4] sqrts = {i, math.sqrt i for i in *numbers} ``` + ```yue @@ -167,6 +176,7 @@ Dalam contoh ini kita mengonversi array pasangan menjadi tabel di mana item pert tuples = [ ["hello", "world"], ["foo", "bar"]] tbl = {unpack tuple for tuple in *tuples} ``` + ```yue @@ -185,6 +195,7 @@ Di sini kita bisa menetapkan batas minimum dan maksimum, mengambil semua item de ```yuescript slice = [item for item in *items[1, 5]] ``` + ```yue @@ -198,6 +209,7 @@ Salah satu argumen slice boleh dikosongkan untuk menggunakan default yang masuk ```yuescript slice = [item for item in *items[2,]] ``` + ```yue @@ -211,6 +223,7 @@ Jika batas minimum dikosongkan, defaultnya adalah 1. Di sini kita hanya memberik ```yuescript slice = [item for item in *items[,,2]] ``` + ```yue @@ -225,6 +238,7 @@ Batas minimum dan maksimum bisa bernilai negatif, yang berarti batas dihitung da -- ambil 4 item terakhir slice = [item for item in *items[-4,-1]] ``` + ```yue @@ -239,6 +253,7 @@ Ukuran langkah juga bisa negatif, yang berarti item diambil dalam urutan terbali ```yuescript reverse_slice = [item for item in *items[-1,1,-1]] ``` + ```yue @@ -258,6 +273,7 @@ sub_list = items[2, 4] -- ambil 4 item terakhir last_four_items = items[-4, -1] ``` + ```yue diff --git a/doc/docs/id-id/doc/data-structures/table-literals.md b/doc/docs/id-id/doc/data-structures/table-literals.md index df32f1c..c190f00 100644 --- a/doc/docs/id-id/doc/data-structures/table-literals.md +++ b/doc/docs/id-id/doc/data-structures/table-literals.md @@ -5,6 +5,7 @@ Seperti di Lua, tabel dibatasi dengan kurung kurawal. ```yuescript some_values = [1, 2, 3, 4] ``` + ```yue @@ -22,6 +23,7 @@ some_values = { ["favorite food"]: "rice" } ``` + ```yue @@ -42,6 +44,7 @@ profile = shoe_size: 13, favorite_foods: ["ice cream", "donuts"] ``` + ```yue @@ -63,6 +66,7 @@ values = { occupation: "crime fighting" } ``` + ```yue @@ -83,6 +87,7 @@ my_function dance: "Tango", partner: "none" y = type: "dog", legs: 4, tails: 1 ``` + ```yue @@ -101,6 +106,7 @@ tbl = { end: "hunger" } ``` + ```yue @@ -121,6 +127,7 @@ person = { :hair, :height, shoe_size: 40 } print_table :hair, :height ``` + ```yue @@ -141,6 +148,7 @@ t = { "hello world": true } ``` + ```yue @@ -158,6 +166,7 @@ Tabel Lua memiliki bagian array dan bagian hash, tetapi terkadang Anda ingin mem some_values = [1, 2, 3, 4] list_with_one_element = [1, ] ``` + ```yue diff --git a/doc/docs/id-id/doc/functions/backcalls.md b/doc/docs/id-id/doc/functions/backcalls.md index 8d542ee..9de64c3 100644 --- a/doc/docs/id-id/doc/functions/backcalls.md +++ b/doc/docs/id-id/doc/functions/backcalls.md @@ -6,6 +6,7 @@ Backcall digunakan untuk meratakan callback yang bersarang. Backcall didefinisik x <- f print "hello" .. x ``` + ```yue @@ -21,6 +22,7 @@ Fungsi panah tebal juga tersedia. <= f print @value ``` + ```yue @@ -36,6 +38,7 @@ Anda dapat menentukan placeholder untuk posisi fungsi backcall sebagai parameter (x) <- map _, [1, 2, 3] x * 2 ``` + ```yue @@ -55,6 +58,7 @@ result, msg = do check info print result, msg ``` + ```yue diff --git a/doc/docs/id-id/doc/functions/function-literals.md b/doc/docs/id-id/doc/functions/function-literals.md index 589a26d..67ae158 100644 --- a/doc/docs/id-id/doc/functions/function-literals.md +++ b/doc/docs/id-id/doc/functions/function-literals.md @@ -6,6 +6,7 @@ Semua fungsi dibuat menggunakan ekspresi fungsi. Fungsi sederhana ditandai denga my_function = -> my_function() -- memanggil fungsi kosong ``` + ```yue @@ -24,6 +25,7 @@ func_b = -> value = 100 print "The value:", value ``` + ```yue @@ -42,6 +44,7 @@ Jika fungsi tidak memiliki argumen, ia dapat dipanggil menggunakan operator `!`, func_a! func_b() ``` + ```yue @@ -56,6 +59,7 @@ Fungsi dengan argumen dapat dibuat dengan menaruh daftar nama argumen dalam tand ```yuescript sum = (x, y) -> print "sum", x + y ``` + ```yue @@ -72,6 +76,7 @@ print sum 10, 20 a b c "a", "b", "c" ``` + ```yue @@ -88,6 +93,7 @@ Untuk menghindari ambiguitas saat memanggil fungsi, tanda kurung juga bisa digun ```yuescript print "x:", sum(10, 20), "y:", sum(30, 40) ``` + ```yue @@ -104,6 +110,7 @@ Fungsi akan memaksa pernyataan terakhir di badannya menjadi pernyataan return, i sum = (x, y) -> x + y print "The sum is ", sum 10, 20 ``` + ```yue @@ -118,6 +125,7 @@ Dan jika Anda perlu return secara eksplisit, Anda bisa menggunakan kata kunci `r ```yuescript sum = (x, y) -> return x + y ``` + ```yue @@ -132,6 +140,7 @@ Seperti di Lua, fungsi dapat mengembalikan beberapa nilai. Pernyataan terakhir h mystery = (x, y) -> x + y, x - y a, b = mystery 10, 20 ``` + ```yue @@ -148,6 +157,7 @@ Karena sudah menjadi idiom di Lua untuk mengirim objek sebagai argumen pertama s ```yuescript func = (num) => @value + num ``` + ```yue @@ -165,6 +175,7 @@ my_function = (name = "something", height = 100) -> print "Hello I am", name print "My height is", height ``` + ```yue @@ -181,6 +192,7 @@ Ekspresi nilai default argumen dievaluasi di dalam badan fungsi sesuai urutan de some_args = (x = 100, y = x + 1000) -> print x + y ``` + ```yue @@ -202,6 +214,7 @@ b = x-10 c = x -y d = x- z ``` + ```yue @@ -223,6 +236,7 @@ Ketika ada spasi setelah variabel dan literal string, pemanggilan fungsi bertind x = func"hello" + 100 y = func "hello" + 100 ``` + ```yue @@ -247,6 +261,7 @@ cool_func 1, 2, 5, 6, 7, 8 ``` + ```yue @@ -269,6 +284,7 @@ my_func 5, 6, 7, 9, 1, 2, 5, 4 ``` + ```yue @@ -289,6 +305,7 @@ x = [ 8, 9, 10 ] ``` + ```yue @@ -309,6 +326,7 @@ y = [ my_func 1, 2, 3, 5, 6, 7 ] ``` + ```yue @@ -335,6 +353,7 @@ if func 1, 2, 3, print "hello" print "I am inside if" ``` + ```yue @@ -357,9 +376,9 @@ if func 1, 2, 3, YueScript kini mendukung destrukturisasi parameter fungsi ketika argumen berupa objek. Dua bentuk destrukturisasi literal tabel tersedia: -* **Literal berkurung kurawal/parameter objek**, memungkinkan nilai default opsional ketika field hilang (misalnya, `{:a, :b}`, `{a: a1 = 123}`). +- **Literal berkurung kurawal/parameter objek**, memungkinkan nilai default opsional ketika field hilang (misalnya, `{:a, :b}`, `{a: a1 = 123}`). -* **Sintaks tabel sederhana tanpa pembungkus**, dimulai dengan urutan key-value atau binding singkat dan berlanjut sampai ekspresi lain menghentikannya (misalnya, `:a, b: b1, :c`). Bentuk ini mengekstrak beberapa field dari objek yang sama. +- **Sintaks tabel sederhana tanpa pembungkus**, dimulai dengan urutan key-value atau binding singkat dan berlanjut sampai ekspresi lain menghentikannya (misalnya, `:a, b: b1, :c`). Bentuk ini mengekstrak beberapa field dari objek yang sama. ```yuescript f1 = (:a, :b, :c) -> @@ -373,6 +392,7 @@ f2 = ({a: a1 = 123, :b = 'abc'}, c = {}) -> arg1 = {a: 0} f2 arg1, arg2 ``` + ```yue @@ -402,6 +422,7 @@ findFirstEven = (list): nil -> if sub % 2 == 0 return sub ``` + ```yue @@ -426,6 +447,7 @@ findFirstEven = (list) -> return sub nil ``` + ```yue @@ -467,6 +489,7 @@ process = (...args) -> process 1, nil, 3, nil, 5 ``` + ```yue diff --git a/doc/docs/id-id/doc/functions/function-stubs.md b/doc/docs/id-id/doc/functions/function-stubs.md index 57ed5c1..87dfd73 100644 --- a/doc/docs/id-id/doc/functions/function-stubs.md +++ b/doc/docs/id-id/doc/functions/function-stubs.md @@ -24,6 +24,7 @@ run_callback my_object.write -- memungkinkan kita membundel objek ke fungsi baru run_callback my_object\write ``` + ```yue diff --git a/doc/docs/id-id/doc/getting-started/usage.md b/doc/docs/id-id/doc/getting-started/usage.md index 85cad07..a9523f7 100644 --- a/doc/docs/id-id/doc/getting-started/usage.md +++ b/doc/docs/id-id/doc/getting-started/usage.md @@ -4,49 +4,51 @@ Gunakan modul YueScript di Lua: -* **Kasus 1** - - Require "your_yuescript_entry.yue" di Lua. - ```Lua - require("yue")("your_yuescript_entry") - ``` - Dan kode ini tetap bekerja ketika Anda mengompilasi "your_yuescript_entry.yue" menjadi "your_yuescript_entry.lua" di path yang sama. Pada file YueScript lainnya cukup gunakan **require** atau **import** biasa. Nomor baris pada pesan error juga akan ditangani dengan benar. - -* **Kasus 2** - - Require modul YueScript dan tulis ulang pesan secara manual. - - ```lua - local yue = require("yue") - yue.insert_loader() - local success, result = xpcall(function() - return require("yuescript_module_name") - end, function(err) - return yue.traceback(err) - end) - ``` - -* **Kasus 3** - - Gunakan fungsi kompiler YueScript di Lua. - - ```lua - local yue = require("yue") - local codes, err, globals = yue.to_lua([[ - f = -> - print "hello world" - f! - ]],{ - implicit_return_root = true, - reserve_line_number = true, - lint_global = true, - space_over_tab = false, - options = { - target = "5.4", - path = "/script" - } - }) - ``` +- **Kasus 1** + + Require "your_yuescript_entry.yue" di Lua. + + ```Lua + require("yue")("your_yuescript_entry") + ``` + + Dan kode ini tetap bekerja ketika Anda mengompilasi "your_yuescript_entry.yue" menjadi "your_yuescript_entry.lua" di path yang sama. Pada file YueScript lainnya cukup gunakan **require** atau **import** biasa. Nomor baris pada pesan error juga akan ditangani dengan benar. + +- **Kasus 2** + + Require modul YueScript dan tulis ulang pesan secara manual. + + ```lua + local yue = require("yue") + yue.insert_loader() + local success, result = xpcall(function() + return require("yuescript_module_name") + end, function(err) + return yue.traceback(err) + end) + ``` + +- **Kasus 3** + + Gunakan fungsi kompiler YueScript di Lua. + + ```lua + local yue = require("yue") + local codes, err, globals = yue.to_lua([[ + f = -> + print "hello world" + f! + ]],{ + implicit_return_root = true, + reserve_line_number = true, + lint_global = true, + space_over_tab = false, + options = { + target = "5.4", + path = "/script" + } + }) + ``` ## Tool YueScript @@ -99,14 +101,14 @@ Opsi: Gunakan kasus: -Kompilasi semua file YueScript dengan ekstensi **.yue** secara rekursif di bawah path saat ini: **yue .** +Kompilasi semua file YueScript dengan ekstensi **.yue** secara rekursif di bawah path saat ini: **yue .** -Kompilasi dan simpan hasil ke path target: **yue -t /target/path/ .** +Kompilasi dan simpan hasil ke path target: **yue -t /target/path/ .** -Kompilasi dan pertahankan info debug: **yue -l .** +Kompilasi dan pertahankan info debug: **yue -l .** -Kompilasi dan hasilkan kode yang diminisasi: **yue -m .** +Kompilasi dan hasilkan kode yang diminisasi: **yue -m .** -Eksekusi kode mentah: **yue -e 'print 123'** +Eksekusi kode mentah: **yue -e 'print 123'** -Eksekusi file YueScript: **yue -e main.yue** +Eksekusi file YueScript: **yue -e main.yue** diff --git a/doc/docs/id-id/doc/language-basics/attributes.md b/doc/docs/id-id/doc/language-basics/attributes.md index 5b92947..20b7c9c 100644 --- a/doc/docs/id-id/doc/language-basics/attributes.md +++ b/doc/docs/id-id/doc/language-basics/attributes.md @@ -6,6 +6,7 @@ Dukungan sintaks untuk atribut Lua 5.4. Anda juga masih bisa menggunakan deklara const a = 123 close _ = : -> print "Out of scope." ``` + ```yue @@ -21,6 +22,7 @@ Anda dapat melakukan destrukturisasi dengan variabel yang diberi atribut sebagai const {:a, :b, c, d} = tb -- a = 1 ``` + ```yue @@ -36,6 +38,7 @@ Anda juga bisa mendeklarasikan variabel global sebagai `const`. global const Constant = 123 -- Constant = 1 ``` + ```yue diff --git a/doc/docs/id-id/doc/language-basics/comment.md b/doc/docs/id-id/doc/language-basics/comment.md index 99f7b51..058c66b 100644 --- a/doc/docs/id-id/doc/language-basics/comment.md +++ b/doc/docs/id-id/doc/language-basics/comment.md @@ -12,6 +12,7 @@ Tidak masalah. func --[[port]] 3000, --[[ip]] "192.168.1.1" ``` + ```yue diff --git a/doc/docs/id-id/doc/language-basics/literals.md b/doc/docs/id-id/doc/language-basics/literals.md index c17c310..93a547b 100644 --- a/doc/docs/id-id/doc/language-basics/literals.md +++ b/doc/docs/id-id/doc/language-basics/literals.md @@ -12,6 +12,7 @@ some_string = "Here is a string -- Interpolasi string hanya tersedia pada string dengan tanda kutip ganda. print "I am #{math.random! * 100}% sure." ``` + ```yue @@ -34,6 +35,7 @@ integer = 1_000_000 hex = 0xEF_BB_BF binary = 0B10011 ``` + ```yue @@ -55,6 +57,7 @@ str = | - item1 - #{expr} ``` + ```yue @@ -78,6 +81,7 @@ fn = -> bar: baz return str ``` + ```yue @@ -99,6 +103,7 @@ str = | path: "C:\Program Files\App" note: 'He said: "#{Hello}!"' ``` + ```yue diff --git a/doc/docs/id-id/doc/language-basics/operator.md b/doc/docs/id-id/doc/language-basics/operator.md index f3fe092..6e0030a 100644 --- a/doc/docs/id-id/doc/language-basics/operator.md +++ b/doc/docs/id-id/doc/language-basics/operator.md @@ -6,6 +6,7 @@ Semua operator biner dan unari Lua tersedia. Selain itu **!=** adalah alias untu tb\func! if tb ~= nil tb::func! if tb != nil ``` + ```yue @@ -27,6 +28,7 @@ a = 5 print 1 <= a <= 10 -- output: true ``` + ```yue @@ -64,6 +66,7 @@ print v(1) > v(2) <= v(3) false ]] ``` + ```yue @@ -101,6 +104,7 @@ Operator **[] =** digunakan untuk menambahkan nilai ke tabel. tab = [] tab[] = "Value" ``` + ```yue @@ -118,6 +122,7 @@ tbB = [4, 5, 6] tbA[] = ...tbB -- tbA sekarang [1, 2, 3, 4, 5, 6] ``` + ```yue @@ -149,6 +154,7 @@ a = {1, 2, 3, x: 1} b = {4, 5, y: 1} merge = {...a, ...b} ``` + ```yue @@ -179,6 +185,7 @@ last = data.items[#] second_last = data.items[#-1] data.items[#] = 1 ``` + ```yue @@ -212,6 +219,7 @@ print d.value close _ = : -> print "out of scope" ``` + ```yue @@ -245,6 +253,7 @@ print tb.value tb.<> = __index: {item: "hello"} print tb.item ``` + ```yue @@ -266,6 +275,7 @@ Destrukturisasi metatable dengan kunci metamethod yang dikelilingi **<>**. {item, :new, :, : getter} = tb print item, new, close, getter ``` + ```yue @@ -293,6 +303,7 @@ with? io.open "test.txt", "w" \write "hello" \close! ``` + ```yue @@ -329,6 +340,7 @@ readFile "example.txt" |> render |> print ``` + ```yue @@ -349,6 +361,7 @@ readFile "example.txt" ## Nil Coalescing Operator nil-coalescing **??** mengembalikan nilai dari operan kiri jika bukan **nil**; jika tidak, operator mengevaluasi operan kanan dan mengembalikan hasilnya. Operator **??** tidak mengevaluasi operan kanan jika operan kiri bernilai non-nil. + ```yuescript local a, b, c, d a = b ?? c ?? d @@ -356,6 +369,7 @@ func a ?? {} a ??= false ``` + ```yue @@ -413,6 +427,7 @@ tb = tb: { } ``` + ```yue diff --git a/doc/docs/id-id/doc/language-basics/whitespace.md b/doc/docs/id-id/doc/language-basics/whitespace.md index bdc124e..486bcaa 100644 --- a/doc/docs/id-id/doc/language-basics/whitespace.md +++ b/doc/docs/id-id/doc/language-basics/whitespace.md @@ -9,6 +9,7 @@ Sebuah pernyataan biasanya berakhir pada pergantian baris. Anda juga bisa memaka ```yuescript a = 1; b = 2; print a + b ``` + ```yue @@ -29,6 +30,7 @@ Rx.Observable \map (value) -> value .. '!' \subscribe print ``` + ```yue diff --git a/doc/docs/id-id/doc/objects/object-oriented-programming.md b/doc/docs/id-id/doc/objects/object-oriented-programming.md index 96c19d7..7d5d420 100644 --- a/doc/docs/id-id/doc/objects/object-oriented-programming.md +++ b/doc/docs/id-id/doc/objects/object-oriented-programming.md @@ -15,6 +15,7 @@ class Inventory else @items[name] = 1 ``` + ```yue @@ -46,6 +47,7 @@ inv = Inventory! inv\add_item "t-shirt" inv\add_item "pants" ``` + ```yue @@ -77,6 +79,7 @@ b\give_item "shirt" -- akan mencetak pants dan shirt print item for item in *a.clothes ``` + ```yue @@ -104,6 +107,7 @@ class Person new: => @clothes = [] ``` + ```yue @@ -125,6 +129,7 @@ class BackPack extends Inventory if #@items > size then error "backpack is full" super name ``` + ```yue @@ -151,6 +156,7 @@ class Shelf -- akan mencetak: Shelf was inherited by Cupboard class Cupboard extends Shelf ``` + ```yue @@ -189,6 +195,7 @@ class MyClass extends ParentClass -- super sebagai nilai sama dengan kelas induk: assert super == ParentClass ``` + ```yue @@ -217,6 +224,7 @@ assert b.__class == BackPack print BackPack.size -- mencetak 10 ``` + ```yue @@ -247,6 +255,7 @@ Nama kelas saat dideklarasikan disimpan sebagai string di field `__name` pada ob ```yuescript print BackPack.__name -- mencetak Backpack ``` + ```yue @@ -272,6 +281,7 @@ Things\some_func! -- variabel kelas tidak terlihat pada instance assert Things().some_func == nil ``` + ```yue @@ -300,6 +310,7 @@ Counter! print Counter.count -- mencetak 2 ``` + ```yue @@ -322,6 +333,7 @@ Semantik pemanggilan `@@` mirip dengan `@`. Memanggil nama `@@` akan meneruskan ```yuescript @@hello 1,2,3,4 ``` + ```yue @@ -340,6 +352,7 @@ Berikut cara alternatif untuk membuat variabel kelas dibandingkan yang dijelaska class Things @class_var = "hello world" ``` + ```yue @@ -361,6 +374,7 @@ class MoreThings some_method: => log "hello world: " .. secret ``` + ```yue @@ -384,6 +398,7 @@ Jika digunakan sendirian, keduanya adalah alias untuk `self` dan `self.__class`. assert @ == self assert @@ == self.__class ``` + ```yue @@ -398,6 +413,7 @@ Contohnya, cara cepat untuk membuat instance baru dari kelas yang sama dari meth ```yuescript some_instance_method = (...) => @@ ... ``` + ```yue @@ -423,6 +439,7 @@ class Something @@biz = biz @@baz = baz ``` + ```yue @@ -448,6 +465,7 @@ new = (@fieldA, @fieldB) => @ obj = new {}, 123, "abc" print obj ``` + ```yue @@ -467,6 +485,7 @@ x = class Bucket drops: 0 add_drop: => @drops += 1 ``` + ```yue @@ -487,6 +506,7 @@ BigBucket = class extends Bucket assert Bucket.__name == "BigBucket" ``` + ```yue @@ -503,6 +523,7 @@ Anda bahkan bisa menghilangkan badan kelas, artinya Anda bisa menulis kelas anon ```yuescript x = class ``` + ```yue @@ -532,6 +553,7 @@ y\func! assert y.__class.__parent ~= X -- X bukan parent dari Y ``` + ```yue diff --git a/doc/docs/id-id/doc/objects/with-statement.md b/doc/docs/id-id/doc/objects/with-statement.md index 3c0a8a5..96a3efd 100644 --- a/doc/docs/id-id/doc/objects/with-statement.md +++ b/doc/docs/id-id/doc/objects/with-statement.md @@ -15,6 +15,7 @@ with Person! \save! print .name ``` + ```yue @@ -33,6 +34,7 @@ Pernyataan `with` juga bisa digunakan sebagai ekspresi yang mengembalikan nilai file = with File "favorite_foods.txt" \set_encoding "utf8" ``` + ```yue @@ -52,6 +54,7 @@ create_person = (name, relatives) -> me = create_person "Leaf", [dad, mother, sister] ``` + ```yue @@ -74,6 +77,7 @@ with str := "Hello" print "original:", str print "upper:", \upper! ``` + ```yue @@ -95,6 +99,7 @@ with tb ["key-name"] = value [] = "abc" -- menambahkan ke "tb" ``` + ```yue @@ -115,6 +120,7 @@ with tb with? obj print obj.name ``` + ```yue diff --git a/doc/docs/id-id/doc/reference/the-yuescript-library.md b/doc/docs/id-id/doc/reference/the-yuescript-library.md index 0a398a5..3adfe63 100644 --- a/doc/docs/id-id/doc/reference/the-yuescript-library.md +++ b/doc/docs/id-id/doc/reference/the-yuescript-library.md @@ -17,6 +17,7 @@ Pustaka bahasa YueScript. Versi YueScript. **Signature:** + ```lua version: string ``` @@ -30,6 +31,7 @@ version: string Pemisah file untuk platform saat ini. **Signature:** + ```lua dirsep: string ``` @@ -43,6 +45,7 @@ dirsep: string Cache kode modul yang telah dikompilasi. **Signature:** + ```lua yue_compiled: {string: string} ``` @@ -56,6 +59,7 @@ yue_compiled: {string: string} Fungsi kompilasi YueScript. Mengompilasi kode YueScript menjadi kode Lua. **Signature:** + ```lua to_lua: function(code: string, config?: Config): --[[codes]] string | nil, @@ -65,17 +69,17 @@ to_lua: function(code: string, config?: Config): **Parameter:** -| Parameter | Tipe | Deskripsi | -| --- | --- | --- | -| code | string | Kode YueScript. | -| config | Config | [Opsional] Opsi kompiler. | +| Parameter | Tipe | Deskripsi | +| --------- | ------ | ------------------------- | +| code | string | Kode YueScript. | +| config | Config | [Opsional] Opsi kompiler. | **Return:** -| Tipe Return | Deskripsi | -| --- | --- | -| string \| nil | Kode Lua hasil kompilasi, atau nil jika kompilasi gagal. | -| string \| nil | Pesan error, atau nil jika kompilasi berhasil. | +| Tipe Return | Deskripsi | +| ----------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- | +| string \| nil | Kode Lua hasil kompilasi, atau nil jika kompilasi gagal. | +| string \| nil | Pesan error, atau nil jika kompilasi berhasil. | | {{string, integer, integer}} \| nil | Variabel global yang muncul dalam kode (dengan nama, baris, dan kolom), atau nil jika opsi kompiler `lint_global` bernilai false. | ### file_exist @@ -87,21 +91,22 @@ to_lua: function(code: string, config?: Config): Fungsi untuk memeriksa keberadaan file sumber. Dapat ditimpa untuk menyesuaikan perilaku. **Signature:** + ```lua file_exist: function(filename: string): boolean ``` **Parameter:** -| Parameter | Tipe | Deskripsi | -| --- | --- | --- | -| filename | string | Nama file. | +| Parameter | Tipe | Deskripsi | +| --------- | ------ | ---------- | +| filename | string | Nama file. | **Return:** -| Tipe Return | Deskripsi | -| --- | --- | -| boolean | Apakah file ada. | +| Tipe Return | Deskripsi | +| ----------- | ---------------- | +| boolean | Apakah file ada. | ### read_file @@ -112,21 +117,22 @@ file_exist: function(filename: string): boolean Fungsi untuk membaca file sumber. Dapat ditimpa untuk menyesuaikan perilaku. **Signature:** + ```lua read_file: function(filename: string): string ``` **Parameter:** -| Parameter | Tipe | Deskripsi | -| --- | --- | --- | -| filename | string | Nama file. | +| Parameter | Tipe | Deskripsi | +| --------- | ------ | ---------- | +| filename | string | Nama file. | **Return:** | Tipe Return | Deskripsi | -| --- | --- | -| string | Isi file. | +| ----------- | --------- | +| string | Isi file. | ### insert_loader @@ -137,21 +143,22 @@ read_file: function(filename: string): string Menyisipkan loader YueScript ke package loaders (searchers). **Signature:** + ```lua insert_loader: function(pos?: integer): boolean ``` **Parameter:** -| Parameter | Tipe | Deskripsi | -| --- | --- | --- | -| pos | integer | [Opsional] Posisi untuk menyisipkan loader. Default adalah 3. | +| Parameter | Tipe | Deskripsi | +| --------- | ------- | ------------------------------------------------------------- | +| pos | integer | [Opsional] Posisi untuk menyisipkan loader. Default adalah 3. | **Return:** -| Tipe Return | Deskripsi | -| --- | --- | -| boolean | Apakah loader berhasil disisipkan. Akan gagal jika loader sudah disisipkan. | +| Tipe Return | Deskripsi | +| ----------- | --------------------------------------------------------------------------- | +| boolean | Apakah loader berhasil disisipkan. Akan gagal jika loader sudah disisipkan. | ### remove_loader @@ -162,15 +169,16 @@ insert_loader: function(pos?: integer): boolean Menghapus loader YueScript dari package loaders (searchers). **Signature:** + ```lua remove_loader: function(): boolean ``` **Return:** -| Tipe Return | Deskripsi | -| --- | --- | -| boolean | Apakah loader berhasil dihapus. Akan gagal jika loader belum disisipkan. | +| Tipe Return | Deskripsi | +| ----------- | ------------------------------------------------------------------------ | +| boolean | Apakah loader berhasil dihapus. Akan gagal jika loader belum disisipkan. | ### loadstring @@ -181,6 +189,7 @@ remove_loader: function(): boolean Memuat kode YueScript dari string menjadi fungsi. **Signature:** + ```lua loadstring: function(input: string, chunkname: string, env: table, config?: Config): --[[loaded function]] nil | function(...: any): (any...), @@ -189,19 +198,19 @@ loadstring: function(input: string, chunkname: string, env: table, config?: Conf **Parameter:** -| Parameter | Tipe | Deskripsi | -| --- | --- | --- | -| input | string | Kode YueScript. | -| chunkname | string | Nama chunk kode. | -| env | table | Tabel environment. | -| config | Config | [Opsional] Opsi kompiler. | +| Parameter | Tipe | Deskripsi | +| --------- | ------ | ------------------------- | +| input | string | Kode YueScript. | +| chunkname | string | Nama chunk kode. | +| env | table | Tabel environment. | +| config | Config | [Opsional] Opsi kompiler. | **Return:** -| Tipe Return | Deskripsi | -| --- | --- | +| Tipe Return | Deskripsi | +| --------------- | ------------------------------------------------- | | function \| nil | Fungsi yang dimuat, atau nil jika pemuatan gagal. | -| string \| nil | Pesan error, atau nil jika pemuatan berhasil. | +| string \| nil | Pesan error, atau nil jika pemuatan berhasil. | ### loadstring @@ -212,6 +221,7 @@ loadstring: function(input: string, chunkname: string, env: table, config?: Conf Memuat kode YueScript dari string menjadi fungsi. **Signature:** + ```lua loadstring: function(input: string, chunkname: string, config?: Config): --[[loaded function]] nil | function(...: any): (any...), @@ -220,18 +230,18 @@ loadstring: function(input: string, chunkname: string, config?: Config): **Parameter:** -| Parameter | Tipe | Deskripsi | -| --- | --- | --- | -| input | string | Kode YueScript. | -| chunkname | string | Nama chunk kode. | -| config | Config | [Opsional] Opsi kompiler. | +| Parameter | Tipe | Deskripsi | +| --------- | ------ | ------------------------- | +| input | string | Kode YueScript. | +| chunkname | string | Nama chunk kode. | +| config | Config | [Opsional] Opsi kompiler. | **Return:** -| Tipe Return | Deskripsi | -| --- | --- | +| Tipe Return | Deskripsi | +| --------------- | ------------------------------------------------- | | function \| nil | Fungsi yang dimuat, atau nil jika pemuatan gagal. | -| string \| nil | Pesan error, atau nil jika pemuatan berhasil. | +| string \| nil | Pesan error, atau nil jika pemuatan berhasil. | ### loadstring @@ -242,6 +252,7 @@ loadstring: function(input: string, chunkname: string, config?: Config): Memuat kode YueScript dari string menjadi fungsi. **Signature:** + ```lua loadstring: function(input: string, config?: Config): --[[loaded function]] nil | function(...: any): (any...), @@ -250,17 +261,17 @@ loadstring: function(input: string, config?: Config): **Parameter:** -| Parameter | Tipe | Deskripsi | -| --- | --- | --- | -| input | string | Kode YueScript. | -| config | Config | [Opsional] Opsi kompiler. | +| Parameter | Tipe | Deskripsi | +| --------- | ------ | ------------------------- | +| input | string | Kode YueScript. | +| config | Config | [Opsional] Opsi kompiler. | **Return:** -| Tipe Return | Deskripsi | -| --- | --- | +| Tipe Return | Deskripsi | +| --------------- | ------------------------------------------------- | | function \| nil | Fungsi yang dimuat, atau nil jika pemuatan gagal. | -| string \| nil | Pesan error, atau nil jika pemuatan berhasil. | +| string \| nil | Pesan error, atau nil jika pemuatan berhasil. | ### loadfile @@ -271,6 +282,7 @@ loadstring: function(input: string, config?: Config): Memuat kode YueScript dari file menjadi fungsi. **Signature:** + ```lua loadfile: function(filename: string, env: table, config?: Config): nil | function(...: any): (any...), @@ -279,18 +291,18 @@ loadfile: function(filename: string, env: table, config?: Config): **Parameter:** -| Parameter | Tipe | Deskripsi | -| --- | --- | --- | -| filename | string | Nama file. | -| env | table | Tabel environment. | -| config | Config | [Opsional] Opsi kompiler. | +| Parameter | Tipe | Deskripsi | +| --------- | ------ | ------------------------- | +| filename | string | Nama file. | +| env | table | Tabel environment. | +| config | Config | [Opsional] Opsi kompiler. | **Return:** -| Tipe Return | Deskripsi | -| --- | --- | +| Tipe Return | Deskripsi | +| --------------- | ------------------------------------------------- | | function \| nil | Fungsi yang dimuat, atau nil jika pemuatan gagal. | -| string \| nil | Pesan error, atau nil jika pemuatan berhasil. | +| string \| nil | Pesan error, atau nil jika pemuatan berhasil. | ### loadfile @@ -301,6 +313,7 @@ loadfile: function(filename: string, env: table, config?: Config): Memuat kode YueScript dari file menjadi fungsi. **Signature:** + ```lua loadfile: function(filename: string, config?: Config): nil | function(...: any): (any...), @@ -309,17 +322,17 @@ loadfile: function(filename: string, config?: Config): **Parameter:** -| Parameter | Tipe | Deskripsi | -| --- | --- | --- | -| filename | string | Nama file. | -| config | Config | [Opsional] Opsi kompiler. | +| Parameter | Tipe | Deskripsi | +| --------- | ------ | ------------------------- | +| filename | string | Nama file. | +| config | Config | [Opsional] Opsi kompiler. | **Return:** -| Tipe Return | Deskripsi | -| --- | --- | +| Tipe Return | Deskripsi | +| --------------- | ------------------------------------------------- | | function \| nil | Fungsi yang dimuat, atau nil jika pemuatan gagal. | -| string \| nil | Pesan error, atau nil jika pemuatan berhasil. | +| string \| nil | Pesan error, atau nil jika pemuatan berhasil. | ### dofile @@ -330,23 +343,24 @@ loadfile: function(filename: string, config?: Config): Memuat kode YueScript dari file menjadi fungsi dan mengeksekusinya. **Signature:** + ```lua dofile: function(filename: string, env: table, config?: Config): any... ``` **Parameter:** -| Parameter | Tipe | Deskripsi | -| --- | --- | --- | -| filename | string | Nama file. | -| env | table | Tabel environment. | -| config | Config | [Opsional] Opsi kompiler. | +| Parameter | Tipe | Deskripsi | +| --------- | ------ | ------------------------- | +| filename | string | Nama file. | +| env | table | Tabel environment. | +| config | Config | [Opsional] Opsi kompiler. | **Return:** -| Tipe Return | Deskripsi | -| --- | --- | -| any... | Nilai return dari fungsi yang dimuat. | +| Tipe Return | Deskripsi | +| ----------- | ------------------------------------- | +| any... | Nilai return dari fungsi yang dimuat. | ### dofile @@ -357,22 +371,23 @@ dofile: function(filename: string, env: table, config?: Config): any... Memuat kode YueScript dari file menjadi fungsi dan mengeksekusinya. **Signature:** + ```lua dofile: function(filename: string, config?: Config): any... ``` **Parameter:** -| Parameter | Tipe | Deskripsi | -| --- | --- | --- | -| filename | string | Nama file. | -| config | Config | [Opsional] Opsi kompiler. | +| Parameter | Tipe | Deskripsi | +| --------- | ------ | ------------------------- | +| filename | string | Nama file. | +| config | Config | [Opsional] Opsi kompiler. | **Return:** -| Tipe Return | Deskripsi | -| --- | --- | -| any... | Nilai return dari fungsi yang dimuat. | +| Tipe Return | Deskripsi | +| ----------- | ------------------------------------- | +| any... | Nilai return dari fungsi yang dimuat. | ### find_modulepath @@ -383,21 +398,22 @@ dofile: function(filename: string, config?: Config): any... Menguraikan nama modul YueScript menjadi path file. **Signature:** + ```lua find_modulepath: function(name: string): string ``` **Parameter:** -| Parameter | Tipe | Deskripsi | -| --- | --- | --- | -| name | string | Nama modul. | +| Parameter | Tipe | Deskripsi | +| --------- | ------ | ----------- | +| name | string | Nama modul. | **Return:** -| Tipe Return | Deskripsi | -| --- | --- | -| string | Path file. | +| Tipe Return | Deskripsi | +| ----------- | ---------- | +| string | Path file. | ### pcall @@ -410,21 +426,22 @@ Menangkap error apa pun dan mengembalikan kode status beserta hasil atau objek e Menulis ulang nomor baris error ke nomor baris asli di kode YueScript saat error terjadi. **Signature:** + ```lua pcall: function(f: function, ...: any): boolean, any... ``` **Parameter:** -| Parameter | Tipe | Deskripsi | -| --- | --- | --- | -| f | function | Fungsi yang akan dipanggil. | -| ... | any | Argumen yang diteruskan ke fungsi. | +| Parameter | Tipe | Deskripsi | +| --------- | -------- | ---------------------------------- | +| f | function | Fungsi yang akan dipanggil. | +| ... | any | Argumen yang diteruskan ke fungsi. | **Return:** -| Tipe Return | Deskripsi | -| --- | --- | +| Tipe Return | Deskripsi | +| ------------ | ---------------------------------------------- | | boolean, ... | Kode status dan hasil fungsi atau objek error. | ### require @@ -437,21 +454,22 @@ Memuat modul tertentu. Bisa berupa modul Lua atau modul YueScript. Menulis ulang nomor baris error ke nomor baris asli di kode YueScript jika modul adalah modul YueScript dan pemuatan gagal. **Signature:** + ```lua require: function(name: string): any... ``` **Parameter:** -| Parameter | Tipe | Deskripsi | -| --- | --- | --- | -| modname | string | Nama modul yang akan dimuat. | +| Parameter | Tipe | Deskripsi | +| --------- | ------ | ---------------------------- | +| modname | string | Nama modul yang akan dimuat. | **Return:** -| Tipe Return | Deskripsi | -| --- | --- | -| any | Nilai yang disimpan di package.loaded[modname] jika modul sudah dimuat. Jika belum, mencoba mencari loader dan mengembalikan nilai akhir package.loaded[modname] serta data loader sebagai hasil kedua. | +| Tipe Return | Deskripsi | +| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| any | Nilai yang disimpan di package.loaded[modname] jika modul sudah dimuat. Jika belum, mencoba mencari loader dan mengembalikan nilai akhir package.loaded[modname] serta data loader sebagai hasil kedua. | ### p @@ -462,15 +480,16 @@ require: function(name: string): any... Memeriksa struktur nilai yang diteruskan dan mencetak representasi string. **Signature:** + ```lua p: function(...: any) ``` **Parameter:** -| Parameter | Tipe | Deskripsi | -| --- | --- | --- | -| ... | any | Nilai yang akan diperiksa. | +| Parameter | Tipe | Deskripsi | +| --------- | ---- | -------------------------- | +| ... | any | Nilai yang akan diperiksa. | ### options @@ -481,6 +500,7 @@ p: function(...: any) Opsi kompiler saat ini. **Signature:** + ```lua options: Config.Options ``` @@ -494,21 +514,22 @@ options: Config.Options Fungsi traceback yang menulis ulang nomor baris stack trace ke nomor baris asli di kode YueScript. **Signature:** + ```lua traceback: function(message: string): string ``` **Parameter:** -| Parameter | Tipe | Deskripsi | -| --- | --- | --- | -| message | string | Pesan traceback. | +| Parameter | Tipe | Deskripsi | +| --------- | ------ | ---------------- | +| message | string | Pesan traceback. | **Return:** -| Tipe Return | Deskripsi | -| --- | --- | -| string | Pesan traceback yang telah ditulis ulang. | +| Tipe Return | Deskripsi | +| ----------- | ----------------------------------------- | +| string | Pesan traceback yang telah ditulis ulang. | ### is_ast @@ -519,22 +540,23 @@ traceback: function(message: string): string Memeriksa apakah kode cocok dengan AST yang ditentukan. **Signature:** + ```lua is_ast: function(astName: string, code: string): boolean ``` **Parameter:** -| Parameter | Tipe | Deskripsi | -| --- | --- | --- | -| astName | string | Nama AST. | -| code | string | Kode. | +| Parameter | Tipe | Deskripsi | +| --------- | ------ | --------- | +| astName | string | Nama AST. | +| code | string | Kode. | **Return:** -| Tipe Return | Deskripsi | -| --- | --- | -| boolean | Apakah kode cocok dengan AST. | +| Tipe Return | Deskripsi | +| ----------- | ----------------------------- | +| boolean | Apakah kode cocok dengan AST. | ### AST @@ -545,6 +567,7 @@ is_ast: function(astName: string, code: string): boolean Definisi tipe AST dengan nama, baris, kolom, dan sub-node. **Signature:** + ```lua type AST = {string, integer, integer, any} ``` @@ -558,6 +581,7 @@ type AST = {string, integer, integer, any} Mengonversi kode menjadi AST. **Signature:** + ```lua to_ast: function(code: string, flattenLevel?: number, astName?: string, reserveComment?: boolean): --[[AST]] AST | nil, @@ -566,18 +590,18 @@ to_ast: function(code: string, flattenLevel?: number, astName?: string, reserveC **Parameter:** -| Parameter | Tipe | Deskripsi | -| --- | --- | --- | -| code | string | Kode. | -| flattenLevel | integer | [Opsional] Tingkat perataan. Semakin tinggi berarti semakin rata. Default 0. Maksimum 2. | -| astName | string | [Opsional] Nama AST. Default "File". | -| reserveComment | boolean | [Opsional] Apakah akan mempertahankan komentar asli. Default false. | +| Parameter | Tipe | Deskripsi | +| -------------- | ------- | ---------------------------------------------------------------------------------------- | +| code | string | Kode. | +| flattenLevel | integer | [Opsional] Tingkat perataan. Semakin tinggi berarti semakin rata. Default 0. Maksimum 2. | +| astName | string | [Opsional] Nama AST. Default "File". | +| reserveComment | boolean | [Opsional] Apakah akan mempertahankan komentar asli. Default false. | **Return:** -| Tipe Return | Deskripsi | -| --- | --- | -| AST \| nil | AST, atau nil jika konversi gagal. | +| Tipe Return | Deskripsi | +| ------------- | --------------------------------------------- | +| AST \| nil | AST, atau nil jika konversi gagal. | | string \| nil | Pesan error, atau nil jika konversi berhasil. | ### format @@ -589,25 +613,26 @@ to_ast: function(code: string, flattenLevel?: number, astName?: string, reserveC Memformat kode YueScript. **Signature:** + ```lua format: function(code: string, tabSize?: number, reserveComment?: boolean): string ``` **Parameter:** -| Parameter | Tipe | Deskripsi | -| --- | --- | --- | -| code | string | Kode. | -| tabSize | integer | [Opsional] Ukuran tab. Default 4. | +| Parameter | Tipe | Deskripsi | +| -------------- | ------- | ------------------------------------------------------------- | +| code | string | Kode. | +| tabSize | integer | [Opsional] Ukuran tab. Default 4. | | reserveComment | boolean | [Opsional] Apakah mempertahankan komentar asli. Default true. | **Return:** -| Tipe Return | Deskripsi | -| --- | --- | -| string | Kode yang telah diformat. | +| Tipe Return | Deskripsi | +| ----------- | ------------------------- | +| string | Kode yang telah diformat. | -### __call +### \_\_call **Tipe:** Metamethod. @@ -617,21 +642,22 @@ Me-require modul YueScript. Menulis ulang nomor baris error ke nomor baris asli di kode YueScript saat pemuatan gagal. **Signature:** + ```lua metamethod __call: function(self: yue, module: string): any... ``` **Parameter:** -| Parameter | Tipe | Deskripsi | -| --- | --- | --- | -| module | string | Nama modul. | +| Parameter | Tipe | Deskripsi | +| --------- | ------ | ----------- | +| module | string | Nama modul. | **Return:** -| Tipe Return | Deskripsi | -| --- | --- | -| any | Nilai modul. | +| Tipe Return | Deskripsi | +| ----------- | ------------ | +| any | Nilai modul. | ## Config @@ -648,6 +674,7 @@ Opsi kompilasi kompiler. Apakah kompiler harus mengumpulkan variabel global yang muncul dalam kode. **Signature:** + ```lua lint_global: boolean ``` @@ -661,6 +688,7 @@ lint_global: boolean Apakah kompiler harus melakukan return implisit untuk blok kode root. **Signature:** + ```lua implicit_return_root: boolean ``` @@ -674,6 +702,7 @@ implicit_return_root: boolean Apakah kompiler harus mempertahankan nomor baris asli di kode hasil kompilasi. **Signature:** + ```lua reserve_line_number: boolean ``` @@ -687,6 +716,7 @@ reserve_line_number: boolean Apakah kompiler harus mempertahankan komentar asli di kode hasil kompilasi. **Signature:** + ```lua reserve_comment: boolean ``` @@ -700,6 +730,7 @@ reserve_comment: boolean Apakah kompiler harus menggunakan karakter spasi alih-alih tab di kode hasil kompilasi. **Signature:** + ```lua space_over_tab: boolean ``` @@ -713,6 +744,7 @@ space_over_tab: boolean Apakah kompiler harus memperlakukan kode yang akan dikompilasi sebagai modul yang sama dengan modul yang sedang dikompilasi. Untuk penggunaan internal saja. **Signature:** + ```lua same_module: boolean ``` @@ -726,6 +758,7 @@ same_module: boolean Apakah pesan error kompiler harus menyertakan offset nomor baris. Untuk penggunaan internal saja. **Signature:** + ```lua line_offset: integer ``` @@ -739,6 +772,7 @@ line_offset: integer Enumerasi versi Lua target. **Signature:** + ```lua enum LuaTarget "5.1" @@ -758,6 +792,7 @@ end Opsi tambahan untuk diteruskan ke fungsi kompilasi. **Signature:** + ```lua options: Options ``` @@ -777,6 +812,7 @@ Definisi opsi kompiler tambahan. Versi Lua target untuk kompilasi. **Signature:** + ```lua target: LuaTarget ``` @@ -790,6 +826,7 @@ target: LuaTarget Path pencarian modul tambahan. **Signature:** + ```lua path: string ``` @@ -803,6 +840,7 @@ path: string Apakah akan menampilkan variabel local dalam pesan error traceback. Default false. **Signature:** + ```lua dump_locals: boolean ``` @@ -816,6 +854,7 @@ dump_locals: boolean Apakah akan menyederhanakan pesan error. Default true. **Signature:** + ```lua simplified: boolean ``` diff --git a/doc/docs/id-id/try/index.md b/doc/docs/id-id/try/index.md index c31dc1c..c5127e2 100755 --- a/doc/docs/id-id/try/index.md +++ b/doc/docs/id-id/try/index.md @@ -5,6 +5,7 @@ next: false --- # Kompiler Online YueScript + --- Coba YueScript di browser dengan WASM. -- cgit v1.2.3-55-g6feb