diff options
23 files changed, 1735 insertions, 13 deletions
diff --git a/doc/docs/.vitepress/config.mts b/doc/docs/.vitepress/config.mts index 635d087..872791c 100644 --- a/doc/docs/.vitepress/config.mts +++ b/doc/docs/.vitepress/config.mts | |||
| @@ -55,6 +55,7 @@ const sidebarText = { | |||
| 55 | whileLoop: "While-Schleife", | 55 | whileLoop: "While-Schleife", |
| 56 | continueStatement: "Continue-Anweisung", | 56 | continueStatement: "Continue-Anweisung", |
| 57 | conditionals: "Bedingungen", | 57 | conditionals: "Bedingungen", |
| 58 | gotoStatement: "Goto und Labels", | ||
| 58 | lineDecorators: "Zeilen-Dekoratoren", | 59 | lineDecorators: "Zeilen-Dekoratoren", |
| 59 | switch: "Switch", | 60 | switch: "Switch", |
| 60 | objectOrientedProgramming: "Objektorientierte Programmierung", | 61 | objectOrientedProgramming: "Objektorientierte Programmierung", |
| @@ -89,6 +90,7 @@ const sidebarText = { | |||
| 89 | whileLoop: "While Loop", | 90 | whileLoop: "While Loop", |
| 90 | continueStatement: "Continue Statement", | 91 | continueStatement: "Continue Statement", |
| 91 | conditionals: "Conditionals", | 92 | conditionals: "Conditionals", |
| 93 | gotoStatement: "Goto and Labels", | ||
| 92 | lineDecorators: "Line Decorators", | 94 | lineDecorators: "Line Decorators", |
| 93 | switch: "Switch", | 95 | switch: "Switch", |
| 94 | objectOrientedProgramming: "Object Oriented Programming", | 96 | objectOrientedProgramming: "Object Oriented Programming", |
| @@ -123,6 +125,7 @@ const sidebarText = { | |||
| 123 | whileLoop: "Perulangan While", | 125 | whileLoop: "Perulangan While", |
| 124 | continueStatement: "Pernyataan Lanjutkan", | 126 | continueStatement: "Pernyataan Lanjutkan", |
| 125 | conditionals: "Percabangan", | 127 | conditionals: "Percabangan", |
| 128 | gotoStatement: "Goto dan Label", | ||
| 126 | lineDecorators: "Dekorator Baris", | 129 | lineDecorators: "Dekorator Baris", |
| 127 | switch: "Switch", | 130 | switch: "Switch", |
| 128 | objectOrientedProgramming: "Pemrograman Berorientasi Objek", | 131 | objectOrientedProgramming: "Pemrograman Berorientasi Objek", |
| @@ -157,6 +160,7 @@ const sidebarText = { | |||
| 157 | whileLoop: "Laço while", | 160 | whileLoop: "Laço while", |
| 158 | continueStatement: "Instrução continue", | 161 | continueStatement: "Instrução continue", |
| 159 | conditionals: "Condicionais", | 162 | conditionals: "Condicionais", |
| 163 | gotoStatement: "Goto e Rótulos", | ||
| 160 | lineDecorators: "Decoradores de linha", | 164 | lineDecorators: "Decoradores de linha", |
| 161 | switch: "Switch", | 165 | switch: "Switch", |
| 162 | objectOrientedProgramming: "Programação orientada a objetos", | 166 | objectOrientedProgramming: "Programação orientada a objetos", |
| @@ -191,6 +195,7 @@ const sidebarText = { | |||
| 191 | whileLoop: "while 循环", | 195 | whileLoop: "while 循环", |
| 192 | continueStatement: "continue 语句", | 196 | continueStatement: "continue 语句", |
| 193 | conditionals: "条件语句", | 197 | conditionals: "条件语句", |
| 198 | gotoStatement: "goto 语句与标签", | ||
| 194 | lineDecorators: "代码行修饰符", | 199 | lineDecorators: "代码行修饰符", |
| 195 | switch: "switch 语句", | 200 | switch: "switch 语句", |
| 196 | objectOrientedProgramming: "面向对象编程", | 201 | objectOrientedProgramming: "面向对象编程", |
| @@ -363,6 +368,10 @@ function createSidebar(basePath: string, locale: SidebarLocale) { | |||
| 363 | text: text.continueStatement, | 368 | text: text.continueStatement, |
| 364 | link: `${basePath}/control-flow/continue`, | 369 | link: `${basePath}/control-flow/continue`, |
| 365 | }, | 370 | }, |
| 371 | { | ||
| 372 | text: text.gotoStatement, | ||
| 373 | link: `${basePath}/control-flow/goto`, | ||
| 374 | }, | ||
| 366 | { text: text.switch, link: `${basePath}/control-flow/switch` }, | 375 | { text: text.switch, link: `${basePath}/control-flow/switch` }, |
| 367 | ], | 376 | ], |
| 368 | }, | 377 | }, |
diff --git a/doc/docs/de/doc/control-flow/conditionals.md b/doc/docs/de/doc/control-flow/conditionals.md index 56663d1..0d2574d 100644 --- a/doc/docs/de/doc/control-flow/conditionals.md +++ b/doc/docs/de/doc/control-flow/conditionals.md | |||
| @@ -143,3 +143,61 @@ if a in list | |||
| 143 | ``` | 143 | ``` |
| 144 | 144 | ||
| 145 | </YueDisplay> | 145 | </YueDisplay> |
| 146 | |||
| 147 | Der `in`-Operator kann auch mit Tabellen verwendet werden und unterstützt die Variante `not in` für Verneinungen: | ||
| 148 | |||
| 149 | ```yuescript | ||
| 150 | has = "foo" in {"bar", "foo"} | ||
| 151 | |||
| 152 | if a in {1, 2, 3} | ||
| 153 | print "a ist in der Tabelle" | ||
| 154 | |||
| 155 | not_exist = item not in list | ||
| 156 | |||
| 157 | check = -> value not in table | ||
| 158 | ``` | ||
| 159 | |||
| 160 | <YueDisplay> | ||
| 161 | |||
| 162 | ```yue | ||
| 163 | has = "foo" in {"bar", "foo"} | ||
| 164 | |||
| 165 | if a in {1, 2, 3} | ||
| 166 | print "a ist in der Tabelle" | ||
| 167 | |||
| 168 | not_exist = item not in list | ||
| 169 | |||
| 170 | check = -> value not in table | ||
| 171 | ``` | ||
| 172 | |||
| 173 | </YueDisplay> | ||
| 174 | |||
| 175 | Eine Ein-Element-Liste oder Tabelle prüft auf Gleichheit mit diesem Element: | ||
| 176 | |||
| 177 | ```yuescript | ||
| 178 | -- [1,] prüft, ob wert == 1 | ||
| 179 | c = a in [1,] | ||
| 180 | |||
| 181 | -- {1} prüft auch, ob wert == 1 | ||
| 182 | c = a in {1} | ||
| 183 | |||
| 184 | -- Ohne Komma ist [1] ein Indexzugriff (tb[1]) | ||
| 185 | with tb | ||
| 186 | c = a in [1] | ||
| 187 | ``` | ||
| 188 | |||
| 189 | <YueDisplay> | ||
| 190 | |||
| 191 | ```yue | ||
| 192 | -- [1,] prüft, ob wert == 1 | ||
| 193 | c = a in [1,] | ||
| 194 | |||
| 195 | -- {1} prüft auch, ob wert == 1 | ||
| 196 | c = a in {1} | ||
| 197 | |||
| 198 | -- Ohne Komma ist [1] ein Indexzugriff (tb[1]) | ||
| 199 | with tb | ||
| 200 | c = a in [1] | ||
| 201 | ``` | ||
| 202 | |||
| 203 | </YueDisplay> | ||
diff --git a/doc/docs/de/doc/control-flow/goto.md b/doc/docs/de/doc/control-flow/goto.md new file mode 100644 index 0000000..0e2a415 --- /dev/null +++ b/doc/docs/de/doc/control-flow/goto.md | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | # Goto | ||
| 2 | |||
| 3 | YueScript unterstützt die goto-Anweisung und die Label-Syntax zur Steuerung des Programmflusses, wobei die gleichen Regeln wie bei Luas goto-Anweisung gelten. **Hinweis:** Die goto-Anweisung erfordert Lua 5.2 oder höher. Beim Kompilieren zu Lua 5.1 führt die Verwendung der goto-Syntax zu einem Kompilierfehler. | ||
| 4 | |||
| 5 | Ein Label wird mit doppelten Doppelpunkten definiert: | ||
| 6 | |||
| 7 | ```yuescript | ||
| 8 | ::start:: | ||
| 9 | ::done:: | ||
| 10 | ::mein_label:: | ||
| 11 | ``` | ||
| 12 | |||
| 13 | <YueDisplay> | ||
| 14 | |||
| 15 | ```yue | ||
| 16 | ::start:: | ||
| 17 | ::done:: | ||
| 18 | ::mein_label:: | ||
| 19 | ``` | ||
| 20 | |||
| 21 | </YueDisplay> | ||
| 22 | |||
| 23 | Die goto-Anweisung springt zu einem angegebenen Label: | ||
| 24 | |||
| 25 | ```yuescript | ||
| 26 | a = 0 | ||
| 27 | ::start:: | ||
| 28 | a += 1 | ||
| 29 | goto done if a == 5 | ||
| 30 | goto start | ||
| 31 | ::done:: | ||
| 32 | print "a ist jetzt 5" | ||
| 33 | ``` | ||
| 34 | |||
| 35 | <YueDisplay> | ||
| 36 | |||
| 37 | ```yue | ||
| 38 | a = 0 | ||
| 39 | ::start:: | ||
| 40 | a += 1 | ||
| 41 | goto done if a == 5 | ||
| 42 | goto start | ||
| 43 | ::done:: | ||
| 44 | print "a ist jetzt 5" | ||
| 45 | ``` | ||
| 46 | |||
| 47 | </YueDisplay> | ||
| 48 | |||
| 49 | Die goto-Anweisung ist nützlich, um aus tief verschachtelten Schleifen zu springen: | ||
| 50 | |||
| 51 | ```yuescript | ||
| 52 | for z = 1, 10 | ||
| 53 | for y = 1, 10 do for x = 1, 10 | ||
| 54 | if x^2 + y^2 == z^2 | ||
| 55 | print 'Pythagoreisches Tripel gefunden:', x, y, z | ||
| 56 | goto ok | ||
| 57 | ::ok:: | ||
| 58 | ``` | ||
| 59 | |||
| 60 | <YueDisplay> | ||
| 61 | |||
| 62 | ```yue | ||
| 63 | for z = 1, 10 | ||
| 64 | for y = 1, 10 do for x = 1, 10 | ||
| 65 | if x^2 + y^2 == z^2 | ||
| 66 | print 'Pythagoreisches Tripel gefunden:', x, y, z | ||
| 67 | goto ok | ||
| 68 | ::ok:: | ||
| 69 | ``` | ||
| 70 | |||
| 71 | </YueDisplay> | ||
| 72 | |||
| 73 | Sie können auch Labels verwenden, um zu einer bestimmten Schleifenebene zu springen: | ||
| 74 | |||
| 75 | ```yuescript | ||
| 76 | for z = 1, 10 | ||
| 77 | for y = 1, 10 | ||
| 78 | for x = 1, 10 | ||
| 79 | if x^2 + y^2 == z^2 | ||
| 80 | print 'Pythagoreisches Tripel gefunden:', x, y, z | ||
| 81 | print 'versuche nächstes z...' | ||
| 82 | goto zcontinue | ||
| 83 | ::zcontinue:: | ||
| 84 | ``` | ||
| 85 | |||
| 86 | <YueDisplay> | ||
| 87 | |||
| 88 | ```yue | ||
| 89 | for z = 1, 10 | ||
| 90 | for y = 1, 10 | ||
| 91 | for x = 1, 10 | ||
| 92 | if x^2 + y^2 == z^2 | ||
| 93 | print 'Pythagoreisches Tripel gefunden:', x, y, z | ||
| 94 | print 'versuche nächstes z...' | ||
| 95 | goto zcontinue | ||
| 96 | ::zcontinue:: | ||
| 97 | ``` | ||
| 98 | |||
| 99 | </YueDisplay> | ||
| 100 | |||
| 101 | ## Hinweise | ||
| 102 | |||
| 103 | - Labels müssen innerhalb ihres Geltungsbereichs eindeutig sein | ||
| 104 | - goto kann zu Labels auf derselben oder äußeren Geltungsbereichsebenen springen | ||
| 105 | - goto kann nicht in innere Geltungsbereiche springen (wie in Blöcke oder Schleifen) | ||
| 106 | - Verwenden Sie goto sparsam, da es den Code schwieriger zu lesen und zu warten machen kann | ||
diff --git a/doc/docs/doc/control-flow/conditionals.md b/doc/docs/doc/control-flow/conditionals.md index 1bcc838..ca29fda 100644 --- a/doc/docs/doc/control-flow/conditionals.md +++ b/doc/docs/doc/control-flow/conditionals.md | |||
| @@ -143,3 +143,61 @@ if a in list | |||
| 143 | ``` | 143 | ``` |
| 144 | 144 | ||
| 145 | </YueDisplay> | 145 | </YueDisplay> |
| 146 | |||
| 147 | The `in` operator can also be used with tables and supports the `not in` variant for negation: | ||
| 148 | |||
| 149 | ```yuescript | ||
| 150 | has = "foo" in {"bar", "foo"} | ||
| 151 | |||
| 152 | if a in {1, 2, 3} | ||
| 153 | print "a is in the table" | ||
| 154 | |||
| 155 | not_exist = item not in list | ||
| 156 | |||
| 157 | check = -> value not in table | ||
| 158 | ``` | ||
| 159 | |||
| 160 | <YueDisplay> | ||
| 161 | |||
| 162 | ```yue | ||
| 163 | has = "foo" in {"bar", "foo"} | ||
| 164 | |||
| 165 | if a in {1, 2, 3} | ||
| 166 | print "a is in the table" | ||
| 167 | |||
| 168 | not_exist = item not in list | ||
| 169 | |||
| 170 | check = -> value not in table | ||
| 171 | ``` | ||
| 172 | |||
| 173 | </YueDisplay> | ||
| 174 | |||
| 175 | A single-element list or table checks for equality with that element: | ||
| 176 | |||
| 177 | ```yuescript | ||
| 178 | -- [1,] checks if value == 1 | ||
| 179 | c = a in [1,] | ||
| 180 | |||
| 181 | -- {1} also checks if value == 1 | ||
| 182 | c = a in {1} | ||
| 183 | |||
| 184 | -- Without comma, [1] is indexing (tb[1]) | ||
| 185 | with tb | ||
| 186 | c = a in [1] | ||
| 187 | ``` | ||
| 188 | |||
| 189 | <YueDisplay> | ||
| 190 | |||
| 191 | ```yue | ||
| 192 | -- [1,] checks if value == 1 | ||
| 193 | c = a in [1,] | ||
| 194 | |||
| 195 | -- {1} also checks if value == 1 | ||
| 196 | c = a in {1} | ||
| 197 | |||
| 198 | -- Without comma, [1] is indexing (tb[1]) | ||
| 199 | with tb | ||
| 200 | c = a in [1] | ||
| 201 | ``` | ||
| 202 | |||
| 203 | </YueDisplay> | ||
diff --git a/doc/docs/doc/control-flow/goto.md b/doc/docs/doc/control-flow/goto.md new file mode 100644 index 0000000..00227ba --- /dev/null +++ b/doc/docs/doc/control-flow/goto.md | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | # Goto | ||
| 2 | |||
| 3 | YueScript supports goto statement and label syntax for controlling program flow, following the same rules as Lua's goto statement. **Note:** The goto statement requires Lua 5.2 or higher. When compiling to Lua 5.1, using goto syntax will result in a compilation error. | ||
| 4 | |||
| 5 | A label is defined using double colons: | ||
| 6 | |||
| 7 | ```yuescript | ||
| 8 | ::start:: | ||
| 9 | ::done:: | ||
| 10 | ::my_label:: | ||
| 11 | ``` | ||
| 12 | |||
| 13 | <YueDisplay> | ||
| 14 | |||
| 15 | ```yue | ||
| 16 | ::start:: | ||
| 17 | ::done:: | ||
| 18 | ::my_label:: | ||
| 19 | ``` | ||
| 20 | |||
| 21 | </YueDisplay> | ||
| 22 | |||
| 23 | The goto statement jumps to a specified label: | ||
| 24 | |||
| 25 | ```yuescript | ||
| 26 | a = 0 | ||
| 27 | ::start:: | ||
| 28 | a += 1 | ||
| 29 | goto done if a == 5 | ||
| 30 | goto start | ||
| 31 | ::done:: | ||
| 32 | print "a is now 5" | ||
| 33 | ``` | ||
| 34 | |||
| 35 | <YueDisplay> | ||
| 36 | |||
| 37 | ```yue | ||
| 38 | a = 0 | ||
| 39 | ::start:: | ||
| 40 | a += 1 | ||
| 41 | goto done if a == 5 | ||
| 42 | goto start | ||
| 43 | ::done:: | ||
| 44 | print "a is now 5" | ||
| 45 | ``` | ||
| 46 | |||
| 47 | </YueDisplay> | ||
| 48 | |||
| 49 | The goto statement is useful for breaking out of deeply nested loops: | ||
| 50 | |||
| 51 | ```yuescript | ||
| 52 | for z = 1, 10 | ||
| 53 | for y = 1, 10 do for x = 1, 10 | ||
| 54 | if x^2 + y^2 == z^2 | ||
| 55 | print 'found a Pythagorean triple:', x, y, z | ||
| 56 | goto ok | ||
| 57 | ::ok:: | ||
| 58 | ``` | ||
| 59 | |||
| 60 | <YueDisplay> | ||
| 61 | |||
| 62 | ```yue | ||
| 63 | for z = 1, 10 | ||
| 64 | for y = 1, 10 do for x = 1, 10 | ||
| 65 | if x^2 + y^2 == z^2 | ||
| 66 | print 'found a Pythagorean triple:', x, y, z | ||
| 67 | goto ok | ||
| 68 | ::ok:: | ||
| 69 | ``` | ||
| 70 | |||
| 71 | </YueDisplay> | ||
| 72 | |||
| 73 | You can also use labels to jump to a specific loop level: | ||
| 74 | |||
| 75 | ```yuescript | ||
| 76 | for z = 1, 10 | ||
| 77 | for y = 1, 10 | ||
| 78 | for x = 1, 10 | ||
| 79 | if x^2 + y^2 == z^2 | ||
| 80 | print 'found a Pythagorean triple:', x, y, z | ||
| 81 | print 'now trying next z...' | ||
| 82 | goto zcontinue | ||
| 83 | ::zcontinue:: | ||
| 84 | ``` | ||
| 85 | |||
| 86 | <YueDisplay> | ||
| 87 | |||
| 88 | ```yue | ||
| 89 | for z = 1, 10 | ||
| 90 | for y = 1, 10 | ||
| 91 | for x = 1, 10 | ||
| 92 | if x^2 + y^2 == z^2 | ||
| 93 | print 'found a Pythagorean triple:', x, y, z | ||
| 94 | print 'now trying next z...' | ||
| 95 | goto zcontinue | ||
| 96 | ::zcontinue:: | ||
| 97 | ``` | ||
| 98 | |||
| 99 | </YueDisplay> | ||
| 100 | |||
| 101 | ## Notes | ||
| 102 | |||
| 103 | - Labels must be unique within their scope | ||
| 104 | - goto can jump to labels at the same or outer scope levels | ||
| 105 | - goto cannot jump into inner scopes (like inside blocks or loops) | ||
| 106 | - Use goto sparingly, as it can make code harder to read and maintain | ||
diff --git a/doc/docs/id-id/doc/control-flow/conditionals.md b/doc/docs/id-id/doc/control-flow/conditionals.md index 861eae6..db67a79 100644 --- a/doc/docs/id-id/doc/control-flow/conditionals.md +++ b/doc/docs/id-id/doc/control-flow/conditionals.md | |||
| @@ -143,3 +143,61 @@ if a in list | |||
| 143 | ``` | 143 | ``` |
| 144 | 144 | ||
| 145 | </YueDisplay> | 145 | </YueDisplay> |
| 146 | |||
| 147 | Operator `in` juga dapat digunakan dengan tabel dan mendukung varian `not in` untuk negasi: | ||
| 148 | |||
| 149 | ```yuescript | ||
| 150 | has = "foo" in {"bar", "foo"} | ||
| 151 | |||
| 152 | if a in {1, 2, 3} | ||
| 153 | print "a ada di dalam tabel" | ||
| 154 | |||
| 155 | not_exist = item not in list | ||
| 156 | |||
| 157 | check = -> value not in table | ||
| 158 | ``` | ||
| 159 | |||
| 160 | <YueDisplay> | ||
| 161 | |||
| 162 | ```yue | ||
| 163 | has = "foo" in {"bar", "foo"} | ||
| 164 | |||
| 165 | if a in {1, 2, 3} | ||
| 166 | print "a ada di dalam tabel" | ||
| 167 | |||
| 168 | not_exist = item not in list | ||
| 169 | |||
| 170 | check = -> value not in table | ||
| 171 | ``` | ||
| 172 | |||
| 173 | </YueDisplay> | ||
| 174 | |||
| 175 | Daftar atau tabel dengan satu elemen memeriksa kesamaan dengan elemen tersebut: | ||
| 176 | |||
| 177 | ```yuescript | ||
| 178 | -- [1,] memeriksa apakah nilai == 1 | ||
| 179 | c = a in [1,] | ||
| 180 | |||
| 181 | -- {1} juga memeriksa apakah nilai == 1 | ||
| 182 | c = a in {1} | ||
| 183 | |||
| 184 | -- Tanpa koma, [1] adalah akses indeks (tb[1]) | ||
| 185 | with tb | ||
| 186 | c = a in [1] | ||
| 187 | ``` | ||
| 188 | |||
| 189 | <YueDisplay> | ||
| 190 | |||
| 191 | ```yue | ||
| 192 | -- [1,] memeriksa apakah nilai == 1 | ||
| 193 | c = a in [1,] | ||
| 194 | |||
| 195 | -- {1} juga memeriksa apakah nilai == 1 | ||
| 196 | c = a in {1} | ||
| 197 | |||
| 198 | -- Tanpa koma, [1] adalah akses indeks (tb[1]) | ||
| 199 | with tb | ||
| 200 | c = a in [1] | ||
| 201 | ``` | ||
| 202 | |||
| 203 | </YueDisplay> | ||
diff --git a/doc/docs/id-id/doc/control-flow/goto.md b/doc/docs/id-id/doc/control-flow/goto.md new file mode 100644 index 0000000..f387f0d --- /dev/null +++ b/doc/docs/id-id/doc/control-flow/goto.md | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | # Goto | ||
| 2 | |||
| 3 | YueScript mendukung pernyataan goto dan sintaks label untuk mengontrol alur program, mengikuti aturan yang sama dengan pernyataan goto Lua. **Catatan:** Pernyataan goto memerlukan Lua 5.2 atau lebih tinggi. Saat mengompilasi ke Lua 5.1, penggunaan sintaks goto akan menyebabkan galat kompilasi. | ||
| 4 | |||
| 5 | Label didefinisikan menggunakan dua titik dua: | ||
| 6 | |||
| 7 | ```yuescript | ||
| 8 | ::mulai:: | ||
| 9 | ::selesai:: | ||
| 10 | ::label_saya:: | ||
| 11 | ``` | ||
| 12 | |||
| 13 | <YueDisplay> | ||
| 14 | |||
| 15 | ```yue | ||
| 16 | ::mulai:: | ||
| 17 | ::selesai:: | ||
| 18 | ::label_saya:: | ||
| 19 | ``` | ||
| 20 | |||
| 21 | </YueDisplay> | ||
| 22 | |||
| 23 | Pernyataan goto melompat ke label yang ditentukan: | ||
| 24 | |||
| 25 | ```yuescript | ||
| 26 | a = 0 | ||
| 27 | ::mulai:: | ||
| 28 | a += 1 | ||
| 29 | goto selesai if a == 5 | ||
| 30 | goto mulai | ||
| 31 | ::selesai:: | ||
| 32 | print "a sekarang 5" | ||
| 33 | ``` | ||
| 34 | |||
| 35 | <YueDisplay> | ||
| 36 | |||
| 37 | ```yue | ||
| 38 | a = 0 | ||
| 39 | ::mulai:: | ||
| 40 | a += 1 | ||
| 41 | goto selesai if a == 5 | ||
| 42 | goto mulai | ||
| 43 | ::selesai:: | ||
| 44 | print "a sekarang 5" | ||
| 45 | ``` | ||
| 46 | |||
| 47 | </YueDisplay> | ||
| 48 | |||
| 49 | Pernyataan goto berguna untuk keluar dari loop yang bersarang dalam: | ||
| 50 | |||
| 51 | ```yuescript | ||
| 52 | for z = 1, 10 | ||
| 53 | for y = 1, 10 do for x = 1, 10 | ||
| 54 | if x^2 + y^2 == z^2 | ||
| 55 | print 'tripel Pythagorean ditemukan:', x, y, z | ||
| 56 | goto ok | ||
| 57 | ::ok:: | ||
| 58 | ``` | ||
| 59 | |||
| 60 | <YueDisplay> | ||
| 61 | |||
| 62 | ```yue | ||
| 63 | for z = 1, 10 | ||
| 64 | for y = 1, 10 do for x = 1, 10 | ||
| 65 | if x^2 + y^2 == z^2 | ||
| 66 | print 'tripel Pythagorean ditemukan:', x, y, z | ||
| 67 | goto ok | ||
| 68 | ::ok:: | ||
| 69 | ``` | ||
| 70 | |||
| 71 | </YueDisplay> | ||
| 72 | |||
| 73 | Anda juga dapat menggunakan label untuk melompat ke tingkat loop tertentu: | ||
| 74 | |||
| 75 | ```yuescript | ||
| 76 | for z = 1, 10 | ||
| 77 | for y = 1, 10 | ||
| 78 | for x = 1, 10 | ||
| 79 | if x^2 + y^2 == z^2 | ||
| 80 | print 'tripel Pythagorean ditemukan:', x, y, z | ||
| 81 | print 'mencoba z berikutnya...' | ||
| 82 | goto zcontinue | ||
| 83 | ::zcontinue:: | ||
| 84 | ``` | ||
| 85 | |||
| 86 | <YueDisplay> | ||
| 87 | |||
| 88 | ```yue | ||
| 89 | for z = 1, 10 | ||
| 90 | for y = 1, 10 | ||
| 91 | for x = 1, 10 | ||
| 92 | if x^2 + y^2 == z^2 | ||
| 93 | print 'tripel Pythagorean ditemukan:', x, y, z | ||
| 94 | print 'mencoba z berikutnya...' | ||
| 95 | goto zcontinue | ||
| 96 | ::zcontinue:: | ||
| 97 | ``` | ||
| 98 | |||
| 99 | </YueDisplay> | ||
| 100 | |||
| 101 | ## Catatan | ||
| 102 | |||
| 103 | - Label harus unik dalam cakupannya | ||
| 104 | - goto dapat melompat ke label pada tingkat cakupan yang sama atau luar | ||
| 105 | - goto tidak dapat melompat ke cakupan dalam (seperti di dalam blok atau loop) | ||
| 106 | - Gunakan goto dengan hemat, karena dapat membuat kode lebih sulit dibaca dan dipelihara | ||
diff --git a/doc/docs/pt-br/doc/control-flow/conditionals.md b/doc/docs/pt-br/doc/control-flow/conditionals.md index bc12d4e..ce32d89 100644 --- a/doc/docs/pt-br/doc/control-flow/conditionals.md +++ b/doc/docs/pt-br/doc/control-flow/conditionals.md | |||
| @@ -143,3 +143,61 @@ if a in list | |||
| 143 | ``` | 143 | ``` |
| 144 | 144 | ||
| 145 | </YueDisplay> | 145 | </YueDisplay> |
| 146 | |||
| 147 | O operador `in` também pode ser usado com tabelas e suporta a variante `not in` para negação: | ||
| 148 | |||
| 149 | ```yuescript | ||
| 150 | has = "foo" in {"bar", "foo"} | ||
| 151 | |||
| 152 | if a in {1, 2, 3} | ||
| 153 | print "a está na tabela" | ||
| 154 | |||
| 155 | not_exist = item not in list | ||
| 156 | |||
| 157 | check = -> value not in table | ||
| 158 | ``` | ||
| 159 | |||
| 160 | <YueDisplay> | ||
| 161 | |||
| 162 | ```yue | ||
| 163 | has = "foo" in {"bar", "foo"} | ||
| 164 | |||
| 165 | if a in {1, 2, 3} | ||
| 166 | print "a está na tabela" | ||
| 167 | |||
| 168 | not_exist = item not in list | ||
| 169 | |||
| 170 | check = -> value not in table | ||
| 171 | ``` | ||
| 172 | |||
| 173 | </YueDisplay> | ||
| 174 | |||
| 175 | Uma lista ou tabela de único elemento verifica igualdade com esse elemento: | ||
| 176 | |||
| 177 | ```yuescript | ||
| 178 | -- [1,] verifica se valor == 1 | ||
| 179 | c = a in [1,] | ||
| 180 | |||
| 181 | -- {1} também verifica se valor == 1 | ||
| 182 | c = a in {1} | ||
| 183 | |||
| 184 | -- Sem vírgula, [1] é acesso por índice (tb[1]) | ||
| 185 | with tb | ||
| 186 | c = a in [1] | ||
| 187 | ``` | ||
| 188 | |||
| 189 | <YueDisplay> | ||
| 190 | |||
| 191 | ```yue | ||
| 192 | -- [1,] verifica se valor == 1 | ||
| 193 | c = a in [1,] | ||
| 194 | |||
| 195 | -- {1} também verifica se valor == 1 | ||
| 196 | c = a in {1} | ||
| 197 | |||
| 198 | -- Sem vírgula, [1] é acesso por índice (tb[1]) | ||
| 199 | with tb | ||
| 200 | c = a in [1] | ||
| 201 | ``` | ||
| 202 | |||
| 203 | </YueDisplay> | ||
diff --git a/doc/docs/pt-br/doc/control-flow/goto.md b/doc/docs/pt-br/doc/control-flow/goto.md new file mode 100644 index 0000000..f4c85f4 --- /dev/null +++ b/doc/docs/pt-br/doc/control-flow/goto.md | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | # Goto | ||
| 2 | |||
| 3 | YueScript suporta a instrução goto e a sintaxe de rótulos para controlar o fluxo do programa, seguindo as mesmas regras da instrução goto do Lua. **Nota:** A instrução goto requer Lua 5.2 ou superior. Ao compilar para Lua 5.1, o uso da sintaxe goto resultará em um erro de compilação. | ||
| 4 | |||
| 5 | Um rótulo é definido usando dois pontos duplos: | ||
| 6 | |||
| 7 | ```yuescript | ||
| 8 | ::inicio:: | ||
| 9 | ::fim:: | ||
| 10 | ::meu_rotulo:: | ||
| 11 | ``` | ||
| 12 | |||
| 13 | <YueDisplay> | ||
| 14 | |||
| 15 | ```yue | ||
| 16 | ::inicio:: | ||
| 17 | ::fim:: | ||
| 18 | ::meu_rotulo:: | ||
| 19 | ``` | ||
| 20 | |||
| 21 | </YueDisplay> | ||
| 22 | |||
| 23 | A instrução goto salta para um rótulo especificado: | ||
| 24 | |||
| 25 | ```yuescript | ||
| 26 | a = 0 | ||
| 27 | ::inicio:: | ||
| 28 | a += 1 | ||
| 29 | goto fim if a == 5 | ||
| 30 | goto inicio | ||
| 31 | ::fim:: | ||
| 32 | print "a agora é 5" | ||
| 33 | ``` | ||
| 34 | |||
| 35 | <YueDisplay> | ||
| 36 | |||
| 37 | ```yue | ||
| 38 | a = 0 | ||
| 39 | ::inicio:: | ||
| 40 | a += 1 | ||
| 41 | goto fim if a == 5 | ||
| 42 | goto inicio | ||
| 43 | ::fim:: | ||
| 44 | print "a agora é 5" | ||
| 45 | ``` | ||
| 46 | |||
| 47 | </YueDisplay> | ||
| 48 | |||
| 49 | A instrução goto é útil para sair de laços profundamente aninhados: | ||
| 50 | |||
| 51 | ```yuescript | ||
| 52 | for z = 1, 10 | ||
| 53 | for y = 1, 10 do for x = 1, 10 | ||
| 54 | if x^2 + y^2 == z^2 | ||
| 55 | print 'triplo pitagórico encontrado:', x, y, z | ||
| 56 | goto ok | ||
| 57 | ::ok:: | ||
| 58 | ``` | ||
| 59 | |||
| 60 | <YueDisplay> | ||
| 61 | |||
| 62 | ```yue | ||
| 63 | for z = 1, 10 | ||
| 64 | for y = 1, 10 do for x = 1, 10 | ||
| 65 | if x^2 + y^2 == z^2 | ||
| 66 | print 'triplo pitagórico encontrado:', x, y, z | ||
| 67 | goto ok | ||
| 68 | ::ok:: | ||
| 69 | ``` | ||
| 70 | |||
| 71 | </YueDisplay> | ||
| 72 | |||
| 73 | Você também pode usar rótulos para pular para um nível específico de laço: | ||
| 74 | |||
| 75 | ```yuescript | ||
| 76 | for z = 1, 10 | ||
| 77 | for y = 1, 10 | ||
| 78 | for x = 1, 10 | ||
| 79 | if x^2 + y^2 == z^2 | ||
| 80 | print 'triplo pitagórico encontrado:', x, y, z | ||
| 81 | print 'tentando próximo z...' | ||
| 82 | goto zcontinue | ||
| 83 | ::zcontinue:: | ||
| 84 | ``` | ||
| 85 | |||
| 86 | <YueDisplay> | ||
| 87 | |||
| 88 | ```yue | ||
| 89 | for z = 1, 10 | ||
| 90 | for y = 1, 10 | ||
| 91 | for x = 1, 10 | ||
| 92 | if x^2 + y^2 == z^2 | ||
| 93 | print 'triplo pitagórico encontrado:', x, y, z | ||
| 94 | print 'tentando próximo z...' | ||
| 95 | goto zcontinue | ||
| 96 | ::zcontinue:: | ||
| 97 | ``` | ||
| 98 | |||
| 99 | </YueDisplay> | ||
| 100 | |||
| 101 | ## Notas | ||
| 102 | |||
| 103 | - Rótulos devem ser únicos dentro de seu escopo | ||
| 104 | - goto pode pular para rótulos nos mesmos níveis de escopo ou externos | ||
| 105 | - goto não pode pular para escopos internos (como dentro de blocos ou laços) | ||
| 106 | - Use goto com moderação, pois pode tornar o código mais difícil de ler e manter | ||
diff --git a/doc/docs/zh/doc/control-flow/conditionals.md b/doc/docs/zh/doc/control-flow/conditionals.md index 3a4d5d1..f8d2851 100644 --- a/doc/docs/zh/doc/control-flow/conditionals.md +++ b/doc/docs/zh/doc/control-flow/conditionals.md | |||
| @@ -143,3 +143,61 @@ if a in list | |||
| 143 | ``` | 143 | ``` |
| 144 | 144 | ||
| 145 | </YueDisplay> | 145 | </YueDisplay> |
| 146 | |||
| 147 | `in` 运算符也可以用于表,并支持 `not in` 变体来进行否定检查: | ||
| 148 | |||
| 149 | ```yuescript | ||
| 150 | has = "foo" in {"bar", "foo"} | ||
| 151 | |||
| 152 | if a in {1, 2, 3} | ||
| 153 | print "a 在表中" | ||
| 154 | |||
| 155 | not_exist = item not in list | ||
| 156 | |||
| 157 | check = -> value not in table | ||
| 158 | ``` | ||
| 159 | |||
| 160 | <YueDisplay> | ||
| 161 | |||
| 162 | ```yue | ||
| 163 | has = "foo" in {"bar", "foo"} | ||
| 164 | |||
| 165 | if a in {1, 2, 3} | ||
| 166 | print "a 在表中" | ||
| 167 | |||
| 168 | not_exist = item not in list | ||
| 169 | |||
| 170 | check = -> value not in table | ||
| 171 | ``` | ||
| 172 | |||
| 173 | </YueDisplay> | ||
| 174 | |||
| 175 | 单元素列表或表会检查与该元素的相等性: | ||
| 176 | |||
| 177 | ```yuescript | ||
| 178 | -- [1,] 检查 value == 1 | ||
| 179 | c = a in [1,] | ||
| 180 | |||
| 181 | -- {1} 也是检查 value == 1 | ||
| 182 | c = a in {1} | ||
| 183 | |||
| 184 | -- 没有逗号,[1] 是索引访问(tb[1]) | ||
| 185 | with tb | ||
| 186 | c = a in [1] | ||
| 187 | ``` | ||
| 188 | |||
| 189 | <YueDisplay> | ||
| 190 | |||
| 191 | ```yue | ||
| 192 | -- [1,] 检查 value == 1 | ||
| 193 | c = a in [1,] | ||
| 194 | |||
| 195 | -- {1} 也是检查 value == 1 | ||
| 196 | c = a in {1} | ||
| 197 | |||
| 198 | -- 没有逗号,[1] 是索引访问(tb[1]) | ||
| 199 | with tb | ||
| 200 | c = a in [1] | ||
| 201 | ``` | ||
| 202 | |||
| 203 | </YueDisplay> | ||
diff --git a/doc/docs/zh/doc/control-flow/goto.md b/doc/docs/zh/doc/control-flow/goto.md new file mode 100644 index 0000000..6d1cc89 --- /dev/null +++ b/doc/docs/zh/doc/control-flow/goto.md | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | # Goto | ||
| 2 | |||
| 3 | YueScript 支持 goto 语句和标签语法来控制程序流程,该语法遵循与 Lua 的 goto 语句相同的规则。**注意:** goto 语句需要 Lua 5.2 或更高版本。当编译目标是 Lua 5.1 时,使用 goto 语法将导致编译错误。 | ||
| 4 | |||
| 5 | 标签使用双冒号定义: | ||
| 6 | |||
| 7 | ```yuescript | ||
| 8 | ::开始:: | ||
| 9 | ::结束:: | ||
| 10 | ::我的标签:: | ||
| 11 | ``` | ||
| 12 | |||
| 13 | <YueDisplay> | ||
| 14 | |||
| 15 | ```yue | ||
| 16 | ::开始:: | ||
| 17 | ::结束:: | ||
| 18 | ::我的标签:: | ||
| 19 | ``` | ||
| 20 | |||
| 21 | </YueDisplay> | ||
| 22 | |||
| 23 | goto 语句可以跳转到指定的标签: | ||
| 24 | |||
| 25 | ```yuescript | ||
| 26 | a = 0 | ||
| 27 | ::开始:: | ||
| 28 | a += 1 | ||
| 29 | goto 结束 if a == 5 | ||
| 30 | goto 开始 | ||
| 31 | ::结束:: | ||
| 32 | print "a 现在是 5" | ||
| 33 | ``` | ||
| 34 | |||
| 35 | <YueDisplay> | ||
| 36 | |||
| 37 | ```yue | ||
| 38 | a = 0 | ||
| 39 | ::开始:: | ||
| 40 | a += 1 | ||
| 41 | goto 结束 if a == 5 | ||
| 42 | goto 开始 | ||
| 43 | ::结束:: | ||
| 44 | print "a 现在是 5" | ||
| 45 | ``` | ||
| 46 | |||
| 47 | </YueDisplay> | ||
| 48 | |||
| 49 | goto 语句对于跳出深层嵌套循环非常有用: | ||
| 50 | |||
| 51 | ```yuescript | ||
| 52 | for z = 1, 10 | ||
| 53 | for y = 1, 10 do for x = 1, 10 | ||
| 54 | if x^2 + y^2 == z^2 | ||
| 55 | print '找到勾股数:', x, y, z | ||
| 56 | goto 完成 | ||
| 57 | ::完成:: | ||
| 58 | ``` | ||
| 59 | |||
| 60 | <YueDisplay> | ||
| 61 | |||
| 62 | ```yue | ||
| 63 | for z = 1, 10 | ||
| 64 | for y = 1, 10 do for x = 1, 10 | ||
| 65 | if x^2 + y^2 == z^2 | ||
| 66 | print '找到勾股数:', x, y, z | ||
| 67 | goto 完成 | ||
| 68 | ::完成:: | ||
| 69 | ``` | ||
| 70 | |||
| 71 | </YueDisplay> | ||
| 72 | |||
| 73 | 你也可以使用标签跳转到特定的循环层级: | ||
| 74 | |||
| 75 | ```yuescript | ||
| 76 | for z = 1, 10 | ||
| 77 | for y = 1, 10 | ||
| 78 | for x = 1, 10 | ||
| 79 | if x^2 + y^2 == z^2 | ||
| 80 | print '找到勾股数:', x, y, z | ||
| 81 | print '尝试下一个 z...' | ||
| 82 | goto 继续z | ||
| 83 | ::继续z:: | ||
| 84 | ``` | ||
| 85 | |||
| 86 | <YueDisplay> | ||
| 87 | |||
| 88 | ```yue | ||
| 89 | for z = 1, 10 | ||
| 90 | for y = 1, 10 | ||
| 91 | for x = 1, 10 | ||
| 92 | if x^2 + y^2 == z^2 | ||
| 93 | print '找到勾股数:', x, y, z | ||
| 94 | print '尝试下一个 z...' | ||
| 95 | goto 继续z | ||
| 96 | ::继续z:: | ||
| 97 | ``` | ||
| 98 | |||
| 99 | </YueDisplay> | ||
| 100 | |||
| 101 | ## 注意事项 | ||
| 102 | |||
| 103 | - 标签在其作用域内必须唯一 | ||
| 104 | - goto 可以跳转到相同或外层作用域级别的标签 | ||
| 105 | - goto 不能跳转到内层作用域(如代码块或循环内部) | ||
| 106 | - 谨慎使用 goto,因为它会使代码更难阅读和维护 | ||
diff --git a/doc/yue-de.md b/doc/yue-de.md index 9149231..1a13a47 100644 --- a/doc/yue-de.md +++ b/doc/yue-de.md | |||
| @@ -2779,6 +2779,64 @@ if a in list | |||
| 2779 | 2779 | ||
| 2780 | </YueDisplay> | 2780 | </YueDisplay> |
| 2781 | 2781 | ||
| 2782 | Der `in`-Operator kann auch mit Tabellen verwendet werden und unterstützt die Variante `not in` für Verneinungen: | ||
| 2783 | |||
| 2784 | ```yuescript | ||
| 2785 | has = "foo" in {"bar", "foo"} | ||
| 2786 | |||
| 2787 | if a in {1, 2, 3} | ||
| 2788 | print "a ist in der Tabelle" | ||
| 2789 | |||
| 2790 | not_exist = item not in list | ||
| 2791 | |||
| 2792 | check = -> value not in table | ||
| 2793 | ``` | ||
| 2794 | |||
| 2795 | <YueDisplay> | ||
| 2796 | |||
| 2797 | ```yue | ||
| 2798 | has = "foo" in {"bar", "foo"} | ||
| 2799 | |||
| 2800 | if a in {1, 2, 3} | ||
| 2801 | print "a ist in der Tabelle" | ||
| 2802 | |||
| 2803 | not_exist = item not in list | ||
| 2804 | |||
| 2805 | check = -> value not in table | ||
| 2806 | ``` | ||
| 2807 | |||
| 2808 | </YueDisplay> | ||
| 2809 | |||
| 2810 | Eine Ein-Element-Liste oder Tabelle prüft auf Gleichheit mit diesem Element: | ||
| 2811 | |||
| 2812 | ```yuescript | ||
| 2813 | -- [1,] prüft, ob wert == 1 | ||
| 2814 | c = a in [1,] | ||
| 2815 | |||
| 2816 | -- {1} prüft auch, ob wert == 1 | ||
| 2817 | c = a in {1} | ||
| 2818 | |||
| 2819 | -- Ohne Komma ist [1] ein Indexzugriff (tb[1]) | ||
| 2820 | with tb | ||
| 2821 | c = a in [1] | ||
| 2822 | ``` | ||
| 2823 | |||
| 2824 | <YueDisplay> | ||
| 2825 | |||
| 2826 | ```yue | ||
| 2827 | -- [1,] prüft, ob wert == 1 | ||
| 2828 | c = a in [1,] | ||
| 2829 | |||
| 2830 | -- {1} prüft auch, ob wert == 1 | ||
| 2831 | c = a in {1} | ||
| 2832 | |||
| 2833 | -- Ohne Komma ist [1] ein Indexzugriff (tb[1]) | ||
| 2834 | with tb | ||
| 2835 | c = a in [1] | ||
| 2836 | ``` | ||
| 2837 | |||
| 2838 | </YueDisplay> | ||
| 2839 | |||
| 2782 | # For-Schleife | 2840 | # For-Schleife |
| 2783 | 2841 | ||
| 2784 | Es gibt zwei Formen der `for`-Schleife, genau wie in Lua: eine numerische und eine generische. | 2842 | Es gibt zwei Formen der `for`-Schleife, genau wie in Lua: eine numerische und eine generische. |
diff --git a/doc/yue-en.md b/doc/yue-en.md index a3d98d3..3f8546a 100644 --- a/doc/yue-en.md +++ b/doc/yue-en.md | |||
| @@ -2780,6 +2780,64 @@ if a in list | |||
| 2780 | 2780 | ||
| 2781 | </YueDisplay> | 2781 | </YueDisplay> |
| 2782 | 2782 | ||
| 2783 | The `in` operator can also be used with tables and supports the `not in` variant for negation: | ||
| 2784 | |||
| 2785 | ```yuescript | ||
| 2786 | has = "foo" in {"bar", "foo"} | ||
| 2787 | |||
| 2788 | if a in {1, 2, 3} | ||
| 2789 | print "a is in the table" | ||
| 2790 | |||
| 2791 | not_exist = item not in list | ||
| 2792 | |||
| 2793 | check = -> value not in table | ||
| 2794 | ``` | ||
| 2795 | |||
| 2796 | <YueDisplay> | ||
| 2797 | |||
| 2798 | ```yue | ||
| 2799 | has = "foo" in {"bar", "foo"} | ||
| 2800 | |||
| 2801 | if a in {1, 2, 3} | ||
| 2802 | print "a is in the table" | ||
| 2803 | |||
| 2804 | not_exist = item not in list | ||
| 2805 | |||
| 2806 | check = -> value not in table | ||
| 2807 | ``` | ||
| 2808 | |||
| 2809 | </YueDisplay> | ||
| 2810 | |||
| 2811 | A single-element list or table checks for equality with that element: | ||
| 2812 | |||
| 2813 | ```yuescript | ||
| 2814 | -- [1,] checks if value == 1 | ||
| 2815 | c = a in [1,] | ||
| 2816 | |||
| 2817 | -- {1} also checks if value == 1 | ||
| 2818 | c = a in {1} | ||
| 2819 | |||
| 2820 | -- Without comma, [1] is indexing (tb[1]) | ||
| 2821 | with tb | ||
| 2822 | c = a in [1] | ||
| 2823 | ``` | ||
| 2824 | |||
| 2825 | <YueDisplay> | ||
| 2826 | |||
| 2827 | ```yue | ||
| 2828 | -- [1,] checks if value == 1 | ||
| 2829 | c = a in [1,] | ||
| 2830 | |||
| 2831 | -- {1} also checks if value == 1 | ||
| 2832 | c = a in {1} | ||
| 2833 | |||
| 2834 | -- Without comma, [1] is indexing (tb[1]) | ||
| 2835 | with tb | ||
| 2836 | c = a in [1] | ||
| 2837 | ``` | ||
| 2838 | |||
| 2839 | </YueDisplay> | ||
| 2840 | |||
| 2783 | # For Loop | 2841 | # For Loop |
| 2784 | 2842 | ||
| 2785 | There are two for loop forms, just like in Lua. A numeric one and a generic one: | 2843 | There are two for loop forms, just like in Lua. A numeric one and a generic one: |
diff --git a/doc/yue-id-id.md b/doc/yue-id-id.md index 365ee32..ca90d85 100644 --- a/doc/yue-id-id.md +++ b/doc/yue-id-id.md | |||
| @@ -2778,6 +2778,64 @@ if a in list | |||
| 2778 | 2778 | ||
| 2779 | </YueDisplay> | 2779 | </YueDisplay> |
| 2780 | 2780 | ||
| 2781 | Operator `in` juga dapat digunakan dengan tabel dan mendukung varian `not in` untuk negasi: | ||
| 2782 | |||
| 2783 | ```yuescript | ||
| 2784 | has = "foo" in {"bar", "foo"} | ||
| 2785 | |||
| 2786 | if a in {1, 2, 3} | ||
| 2787 | print "a ada di dalam tabel" | ||
| 2788 | |||
| 2789 | not_exist = item not in list | ||
| 2790 | |||
| 2791 | check = -> value not in table | ||
| 2792 | ``` | ||
| 2793 | |||
| 2794 | <YueDisplay> | ||
| 2795 | |||
| 2796 | ```yue | ||
| 2797 | has = "foo" in {"bar", "foo"} | ||
| 2798 | |||
| 2799 | if a in {1, 2, 3} | ||
| 2800 | print "a ada di dalam tabel" | ||
| 2801 | |||
| 2802 | not_exist = item not in list | ||
| 2803 | |||
| 2804 | check = -> value not in table | ||
| 2805 | ``` | ||
| 2806 | |||
| 2807 | </YueDisplay> | ||
| 2808 | |||
| 2809 | Daftar atau tabel dengan satu elemen memeriksa kesamaan dengan elemen tersebut: | ||
| 2810 | |||
| 2811 | ```yuescript | ||
| 2812 | -- [1,] memeriksa apakah nilai == 1 | ||
| 2813 | c = a in [1,] | ||
| 2814 | |||
| 2815 | -- {1} juga memeriksa apakah nilai == 1 | ||
| 2816 | c = a in {1} | ||
| 2817 | |||
| 2818 | -- Tanpa koma, [1] adalah akses indeks (tb[1]) | ||
| 2819 | with tb | ||
| 2820 | c = a in [1] | ||
| 2821 | ``` | ||
| 2822 | |||
| 2823 | <YueDisplay> | ||
| 2824 | |||
| 2825 | ```yue | ||
| 2826 | -- [1,] memeriksa apakah nilai == 1 | ||
| 2827 | c = a in [1,] | ||
| 2828 | |||
| 2829 | -- {1} juga memeriksa apakah nilai == 1 | ||
| 2830 | c = a in {1} | ||
| 2831 | |||
| 2832 | -- Tanpa koma, [1] adalah akses indeks (tb[1]) | ||
| 2833 | with tb | ||
| 2834 | c = a in [1] | ||
| 2835 | ``` | ||
| 2836 | |||
| 2837 | </YueDisplay> | ||
| 2838 | |||
| 2781 | # Perulangan For | 2839 | # Perulangan For |
| 2782 | 2840 | ||
| 2783 | Ada dua bentuk perulangan for, seperti di Lua. Satu numerik dan satu generik: | 2841 | Ada dua bentuk perulangan for, seperti di Lua. Satu numerik dan satu generik: |
diff --git a/doc/yue-pt-br.md b/doc/yue-pt-br.md index ad0521a..7bab231 100644 --- a/doc/yue-pt-br.md +++ b/doc/yue-pt-br.md | |||
| @@ -2777,6 +2777,64 @@ if a in list | |||
| 2777 | 2777 | ||
| 2778 | </YueDisplay> | 2778 | </YueDisplay> |
| 2779 | 2779 | ||
| 2780 | O operador `in` também pode ser usado com tabelas e suporta a variante `not in` para negação: | ||
| 2781 | |||
| 2782 | ```yuescript | ||
| 2783 | has = "foo" in {"bar", "foo"} | ||
| 2784 | |||
| 2785 | if a in {1, 2, 3} | ||
| 2786 | print "a está na tabela" | ||
| 2787 | |||
| 2788 | not_exist = item not in list | ||
| 2789 | |||
| 2790 | check = -> value not in table | ||
| 2791 | ``` | ||
| 2792 | |||
| 2793 | <YueDisplay> | ||
| 2794 | |||
| 2795 | ```yue | ||
| 2796 | has = "foo" in {"bar", "foo"} | ||
| 2797 | |||
| 2798 | if a in {1, 2, 3} | ||
| 2799 | print "a está na tabela" | ||
| 2800 | |||
| 2801 | not_exist = item not in list | ||
| 2802 | |||
| 2803 | check = -> value not in table | ||
| 2804 | ``` | ||
| 2805 | |||
| 2806 | </YueDisplay> | ||
| 2807 | |||
| 2808 | Uma lista ou tabela de único elemento verifica igualdade com esse elemento: | ||
| 2809 | |||
| 2810 | ```yuescript | ||
| 2811 | -- [1,] verifica se valor == 1 | ||
| 2812 | c = a in [1,] | ||
| 2813 | |||
| 2814 | -- {1} também verifica se valor == 1 | ||
| 2815 | c = a in {1} | ||
| 2816 | |||
| 2817 | -- Sem vírgula, [1] é acesso por índice (tb[1]) | ||
| 2818 | with tb | ||
| 2819 | c = a in [1] | ||
| 2820 | ``` | ||
| 2821 | |||
| 2822 | <YueDisplay> | ||
| 2823 | |||
| 2824 | ```yue | ||
| 2825 | -- [1,] verifica se valor == 1 | ||
| 2826 | c = a in [1,] | ||
| 2827 | |||
| 2828 | -- {1} também verifica se valor == 1 | ||
| 2829 | c = a in {1} | ||
| 2830 | |||
| 2831 | -- Sem vírgula, [1] é acesso por índice (tb[1]) | ||
| 2832 | with tb | ||
| 2833 | c = a in [1] | ||
| 2834 | ``` | ||
| 2835 | |||
| 2836 | </YueDisplay> | ||
| 2837 | |||
| 2780 | # Loop For | 2838 | # Loop For |
| 2781 | 2839 | ||
| 2782 | Existem duas formas de loop for, assim como no Lua. Uma numérica e uma genérica: | 2840 | Existem duas formas de loop for, assim como no Lua. Uma numérica e uma genérica: |
diff --git a/doc/yue-zh.md b/doc/yue-zh.md index d026fc2..93e21d8 100644 --- a/doc/yue-zh.md +++ b/doc/yue-zh.md | |||
| @@ -2770,6 +2770,64 @@ if a in list | |||
| 2770 | 2770 | ||
| 2771 | </YueDisplay> | 2771 | </YueDisplay> |
| 2772 | 2772 | ||
| 2773 | `in` 运算符也可以用于表,并支持 `not in` 变体来进行否定检查: | ||
| 2774 | |||
| 2775 | ```yuescript | ||
| 2776 | has = "foo" in {"bar", "foo"} | ||
| 2777 | |||
| 2778 | if a in {1, 2, 3} | ||
| 2779 | print "a 在表中" | ||
| 2780 | |||
| 2781 | not_exist = item not in list | ||
| 2782 | |||
| 2783 | check = -> value not in table | ||
| 2784 | ``` | ||
| 2785 | |||
| 2786 | <YueDisplay> | ||
| 2787 | |||
| 2788 | ```yue | ||
| 2789 | has = "foo" in {"bar", "foo"} | ||
| 2790 | |||
| 2791 | if a in {1, 2, 3} | ||
| 2792 | print "a 在表中" | ||
| 2793 | |||
| 2794 | not_exist = item not in list | ||
| 2795 | |||
| 2796 | check = -> value not in table | ||
| 2797 | ``` | ||
| 2798 | |||
| 2799 | </YueDisplay> | ||
| 2800 | |||
| 2801 | 单元素列表或表会检查与该元素的相等性: | ||
| 2802 | |||
| 2803 | ```yuescript | ||
| 2804 | -- [1,] 检查 value == 1 | ||
| 2805 | c = a in [1,] | ||
| 2806 | |||
| 2807 | -- {1} 也是检查 value == 1 | ||
| 2808 | c = a in {1} | ||
| 2809 | |||
| 2810 | -- 没有逗号,[1] 是索引访问(tb[1]) | ||
| 2811 | with tb | ||
| 2812 | c = a in [1] | ||
| 2813 | ``` | ||
| 2814 | |||
| 2815 | <YueDisplay> | ||
| 2816 | |||
| 2817 | ```yue | ||
| 2818 | -- [1,] 检查 value == 1 | ||
| 2819 | c = a in [1,] | ||
| 2820 | |||
| 2821 | -- {1} 也是检查 value == 1 | ||
| 2822 | c = a in {1} | ||
| 2823 | |||
| 2824 | -- 没有逗号,[1] 是索引访问(tb[1]) | ||
| 2825 | with tb | ||
| 2826 | c = a in [1] | ||
| 2827 | ``` | ||
| 2828 | |||
| 2829 | </YueDisplay> | ||
| 2830 | |||
| 2773 | # for 循环 | 2831 | # for 循环 |
| 2774 | 2832 | ||
| 2775 |   Lua 中有两种 for 循环形式,数字型和通用型: | 2833 |   Lua 中有两种 for 循环形式,数字型和通用型: |
| @@ -58,22 +58,29 @@ endif | |||
| 58 | LINK_FLAGS += -L $(SRC_PATH)/3rdParty/lua -llua -ldl | 58 | LINK_FLAGS += -L $(SRC_PATH)/3rdParty/lua -llua -ldl |
| 59 | endif | 59 | endif |
| 60 | 60 | ||
| 61 | # Detect PRoot environment (e.g., PRoot-Distro) | ||
| 62 | # PRoot can be detected by checking uname -v or /proc/version for "PRoot" | ||
| 63 | IS_PROOT := $(shell uname -v 2>/dev/null | grep -q "PRoot" && echo yes || cat /proc/version 2>/dev/null | grep -q "PRoot" && echo yes) | ||
| 64 | |||
| 61 | # Detect Android Termux environment | 65 | # Detect Android Termux environment |
| 62 | # Termux typically has ANDROID_ROOT environment variable set and PREFIX points to Termux directory | 66 | # Termux typically has ANDROID_ROOT environment variable set and PREFIX points to Termux directory |
| 67 | # Note: PRoot environments may have ANDROID_ROOT set but are not Termux | ||
| 63 | IS_TERMUX := false | 68 | IS_TERMUX := false |
| 64 | ANDROID_ROOT_VAR := $(shell echo $$ANDROID_ROOT) | 69 | ifeq ($(IS_PROOT),) |
| 65 | PREFIX_VAR := $(shell echo $$PREFIX) | 70 | ANDROID_ROOT_VAR := $(shell echo $$ANDROID_ROOT) |
| 66 | ifneq ($(ANDROID_ROOT_VAR),) | 71 | PREFIX_VAR := $(shell echo $$PREFIX) |
| 67 | # Check if PREFIX environment variable points to Termux directory | 72 | ifneq ($(ANDROID_ROOT_VAR),) |
| 68 | ifneq ($(PREFIX_VAR),) | 73 | # Check if PREFIX environment variable points to Termux directory |
| 69 | ifneq ($(findstring com.termux,$(PREFIX_VAR)),) | 74 | ifneq ($(PREFIX_VAR),) |
| 70 | IS_TERMUX := true | 75 | ifneq ($(findstring com.termux,$(PREFIX_VAR)),) |
| 76 | IS_TERMUX := true | ||
| 77 | endif | ||
| 71 | endif | 78 | endif |
| 72 | endif | 79 | # Alternative check: verify if Termux installation path exists |
| 73 | # Alternative check: verify if Termux installation path exists | 80 | ifeq ($(IS_TERMUX),false) |
| 74 | ifeq ($(IS_TERMUX),false) | 81 | ifneq ($(shell test -d /data/data/com.termux/files/usr && echo yes),) |
| 75 | ifneq ($(shell test -d /data/data/com.termux/files/usr && echo yes),) | 82 | IS_TERMUX := true |
| 76 | IS_TERMUX := true | 83 | endif |
| 77 | endif | 84 | endif |
| 78 | endif | 85 | endif |
| 79 | endif | 86 | endif |
| @@ -82,10 +89,14 @@ endif | |||
| 82 | ifeq ($(IS_TERMUX),true) | 89 | ifeq ($(IS_TERMUX),true) |
| 83 | ifeq ($(NO_WATCHER),) | 90 | ifeq ($(NO_WATCHER),) |
| 84 | NO_WATCHER := true | 91 | NO_WATCHER := true |
| 85 | $(info Detected Android Termux environment, automatically setting NO_WATCHER=true) | 92 | TERMUX_DETECTED := true |
| 86 | endif | 93 | endif |
| 87 | endif | 94 | endif |
| 88 | 95 | ||
| 96 | ifdef TERMUX_DETECTED | ||
| 97 | $(info Detected Android Termux environment, automatically setting NO_WATCHER=true) | ||
| 98 | endif | ||
| 99 | |||
| 89 | ifeq ($(NO_WATCHER),true) | 100 | ifeq ($(NO_WATCHER),true) |
| 90 | COMPILE_FLAGS += -DYUE_NO_WATCHER | 101 | COMPILE_FLAGS += -DYUE_NO_WATCHER |
| 91 | endif | 102 | endif |
diff --git a/spec/outputs/codes_from_doc_de.lua b/spec/outputs/codes_from_doc_de.lua index 4c9ba1d..385dbae 100644 --- a/spec/outputs/codes_from_doc_de.lua +++ b/spec/outputs/codes_from_doc_de.lua | |||
| @@ -2966,6 +2966,65 @@ if (function() | |||
| 2966 | end)() then | 2966 | end)() then |
| 2967 | print("Prüfen, ob `a` in einer Liste ist") | 2967 | print("Prüfen, ob `a` in einer Liste ist") |
| 2968 | end | 2968 | end |
| 2969 | local has | ||
| 2970 | do | ||
| 2971 | local _val_0 = "foo" | ||
| 2972 | has = "bar" == _val_0 or "foo" == _val_0 | ||
| 2973 | end | ||
| 2974 | if (function() | ||
| 2975 | local _val_0 = a | ||
| 2976 | return 1 == _val_0 or 2 == _val_0 or 3 == _val_0 | ||
| 2977 | end)() then | ||
| 2978 | print("a ist in der Tabelle") | ||
| 2979 | end | ||
| 2980 | local not_exist | ||
| 2981 | do | ||
| 2982 | local _check_0 = list | ||
| 2983 | local _val_0 = item | ||
| 2984 | local _find_0 = false | ||
| 2985 | for _index_0 = 1, #_check_0 do | ||
| 2986 | local _item_0 = _check_0[_index_0] | ||
| 2987 | if _item_0 == _val_0 then | ||
| 2988 | _find_0 = true | ||
| 2989 | break | ||
| 2990 | end | ||
| 2991 | end | ||
| 2992 | not_exist = not _find_0 | ||
| 2993 | end | ||
| 2994 | local check | ||
| 2995 | check = function() | ||
| 2996 | local _check_0 = table | ||
| 2997 | local _val_0 = value | ||
| 2998 | for _index_0 = 1, #_check_0 do | ||
| 2999 | if _check_0[_index_0] == _val_0 then | ||
| 3000 | return false | ||
| 3001 | end | ||
| 3002 | end | ||
| 3003 | return true | ||
| 3004 | end | ||
| 3005 | local c | ||
| 3006 | do | ||
| 3007 | local _val_0 = a | ||
| 3008 | c = 1 == _val_0 | ||
| 3009 | end | ||
| 3010 | do | ||
| 3011 | local _val_0 = a | ||
| 3012 | c = 1 == _val_0 | ||
| 3013 | end | ||
| 3014 | local _with_0 = tb | ||
| 3015 | do | ||
| 3016 | local _check_0 = _with_0[1] | ||
| 3017 | local _val_0 = a | ||
| 3018 | local _find_0 = false | ||
| 3019 | for _index_0 = 1, #_check_0 do | ||
| 3020 | local _item_0 = _check_0[_index_0] | ||
| 3021 | if _item_0 == _val_0 then | ||
| 3022 | _find_0 = true | ||
| 3023 | break | ||
| 3024 | end | ||
| 3025 | end | ||
| 3026 | c = _find_0 | ||
| 3027 | end | ||
| 2969 | local have_coins = false | 3028 | local have_coins = false |
| 2970 | if have_coins then | 3029 | if have_coins then |
| 2971 | print("Münzen erhalten") | 3030 | print("Münzen erhalten") |
| @@ -3022,6 +3081,65 @@ if (function() | |||
| 3022 | end)() then | 3081 | end)() then |
| 3023 | print("Prüfen, ob `a` in einer Liste ist") | 3082 | print("Prüfen, ob `a` in einer Liste ist") |
| 3024 | end | 3083 | end |
| 3084 | local has | ||
| 3085 | do | ||
| 3086 | local _val_0 = "foo" | ||
| 3087 | has = "bar" == _val_0 or "foo" == _val_0 | ||
| 3088 | end | ||
| 3089 | if (function() | ||
| 3090 | local _val_0 = a | ||
| 3091 | return 1 == _val_0 or 2 == _val_0 or 3 == _val_0 | ||
| 3092 | end)() then | ||
| 3093 | print("a ist in der Tabelle") | ||
| 3094 | end | ||
| 3095 | local not_exist | ||
| 3096 | do | ||
| 3097 | local _check_0 = list | ||
| 3098 | local _val_0 = item | ||
| 3099 | local _find_0 = false | ||
| 3100 | for _index_0 = 1, #_check_0 do | ||
| 3101 | local _item_0 = _check_0[_index_0] | ||
| 3102 | if _item_0 == _val_0 then | ||
| 3103 | _find_0 = true | ||
| 3104 | break | ||
| 3105 | end | ||
| 3106 | end | ||
| 3107 | not_exist = not _find_0 | ||
| 3108 | end | ||
| 3109 | local check | ||
| 3110 | check = function() | ||
| 3111 | local _check_0 = table | ||
| 3112 | local _val_0 = value | ||
| 3113 | for _index_0 = 1, #_check_0 do | ||
| 3114 | if _check_0[_index_0] == _val_0 then | ||
| 3115 | return false | ||
| 3116 | end | ||
| 3117 | end | ||
| 3118 | return true | ||
| 3119 | end | ||
| 3120 | local c | ||
| 3121 | do | ||
| 3122 | local _val_0 = a | ||
| 3123 | c = 1 == _val_0 | ||
| 3124 | end | ||
| 3125 | do | ||
| 3126 | local _val_0 = a | ||
| 3127 | c = 1 == _val_0 | ||
| 3128 | end | ||
| 3129 | local _with_0 = tb | ||
| 3130 | do | ||
| 3131 | local _check_0 = _with_0[1] | ||
| 3132 | local _val_0 = a | ||
| 3133 | local _find_0 = false | ||
| 3134 | for _index_0 = 1, #_check_0 do | ||
| 3135 | local _item_0 = _check_0[_index_0] | ||
| 3136 | if _item_0 == _val_0 then | ||
| 3137 | _find_0 = true | ||
| 3138 | break | ||
| 3139 | end | ||
| 3140 | end | ||
| 3141 | c = _find_0 | ||
| 3142 | end | ||
| 3025 | for i = 10, 20 do | 3143 | for i = 10, 20 do |
| 3026 | print(i) | 3144 | print(i) |
| 3027 | end | 3145 | end |
diff --git a/spec/outputs/codes_from_doc_en.lua b/spec/outputs/codes_from_doc_en.lua index 6d822e1..2d9c8cf 100644 --- a/spec/outputs/codes_from_doc_en.lua +++ b/spec/outputs/codes_from_doc_en.lua | |||
| @@ -2966,6 +2966,65 @@ if (function() | |||
| 2966 | end)() then | 2966 | end)() then |
| 2967 | print("checking if `a` is in a list") | 2967 | print("checking if `a` is in a list") |
| 2968 | end | 2968 | end |
| 2969 | local has | ||
| 2970 | do | ||
| 2971 | local _val_0 = "foo" | ||
| 2972 | has = "bar" == _val_0 or "foo" == _val_0 | ||
| 2973 | end | ||
| 2974 | if (function() | ||
| 2975 | local _val_0 = a | ||
| 2976 | return 1 == _val_0 or 2 == _val_0 or 3 == _val_0 | ||
| 2977 | end)() then | ||
| 2978 | print("a is in the table") | ||
| 2979 | end | ||
| 2980 | local not_exist | ||
| 2981 | do | ||
| 2982 | local _check_0 = list | ||
| 2983 | local _val_0 = item | ||
| 2984 | local _find_0 = false | ||
| 2985 | for _index_0 = 1, #_check_0 do | ||
| 2986 | local _item_0 = _check_0[_index_0] | ||
| 2987 | if _item_0 == _val_0 then | ||
| 2988 | _find_0 = true | ||
| 2989 | break | ||
| 2990 | end | ||
| 2991 | end | ||
| 2992 | not_exist = not _find_0 | ||
| 2993 | end | ||
| 2994 | local check | ||
| 2995 | check = function() | ||
| 2996 | local _check_0 = table | ||
| 2997 | local _val_0 = value | ||
| 2998 | for _index_0 = 1, #_check_0 do | ||
| 2999 | if _check_0[_index_0] == _val_0 then | ||
| 3000 | return false | ||
| 3001 | end | ||
| 3002 | end | ||
| 3003 | return true | ||
| 3004 | end | ||
| 3005 | local c | ||
| 3006 | do | ||
| 3007 | local _val_0 = a | ||
| 3008 | c = 1 == _val_0 | ||
| 3009 | end | ||
| 3010 | do | ||
| 3011 | local _val_0 = a | ||
| 3012 | c = 1 == _val_0 | ||
| 3013 | end | ||
| 3014 | local _with_0 = tb | ||
| 3015 | do | ||
| 3016 | local _check_0 = _with_0[1] | ||
| 3017 | local _val_0 = a | ||
| 3018 | local _find_0 = false | ||
| 3019 | for _index_0 = 1, #_check_0 do | ||
| 3020 | local _item_0 = _check_0[_index_0] | ||
| 3021 | if _item_0 == _val_0 then | ||
| 3022 | _find_0 = true | ||
| 3023 | break | ||
| 3024 | end | ||
| 3025 | end | ||
| 3026 | c = _find_0 | ||
| 3027 | end | ||
| 2969 | local have_coins = false | 3028 | local have_coins = false |
| 2970 | if have_coins then | 3029 | if have_coins then |
| 2971 | print("Got coins") | 3030 | print("Got coins") |
| @@ -3022,6 +3081,65 @@ if (function() | |||
| 3022 | end)() then | 3081 | end)() then |
| 3023 | print("checking if `a` is in a list") | 3082 | print("checking if `a` is in a list") |
| 3024 | end | 3083 | end |
| 3084 | local has | ||
| 3085 | do | ||
| 3086 | local _val_0 = "foo" | ||
| 3087 | has = "bar" == _val_0 or "foo" == _val_0 | ||
| 3088 | end | ||
| 3089 | if (function() | ||
| 3090 | local _val_0 = a | ||
| 3091 | return 1 == _val_0 or 2 == _val_0 or 3 == _val_0 | ||
| 3092 | end)() then | ||
| 3093 | print("a is in the table") | ||
| 3094 | end | ||
| 3095 | local not_exist | ||
| 3096 | do | ||
| 3097 | local _check_0 = list | ||
| 3098 | local _val_0 = item | ||
| 3099 | local _find_0 = false | ||
| 3100 | for _index_0 = 1, #_check_0 do | ||
| 3101 | local _item_0 = _check_0[_index_0] | ||
| 3102 | if _item_0 == _val_0 then | ||
| 3103 | _find_0 = true | ||
| 3104 | break | ||
| 3105 | end | ||
| 3106 | end | ||
| 3107 | not_exist = not _find_0 | ||
| 3108 | end | ||
| 3109 | local check | ||
| 3110 | check = function() | ||
| 3111 | local _check_0 = table | ||
| 3112 | local _val_0 = value | ||
| 3113 | for _index_0 = 1, #_check_0 do | ||
| 3114 | if _check_0[_index_0] == _val_0 then | ||
| 3115 | return false | ||
| 3116 | end | ||
| 3117 | end | ||
| 3118 | return true | ||
| 3119 | end | ||
| 3120 | local c | ||
| 3121 | do | ||
| 3122 | local _val_0 = a | ||
| 3123 | c = 1 == _val_0 | ||
| 3124 | end | ||
| 3125 | do | ||
| 3126 | local _val_0 = a | ||
| 3127 | c = 1 == _val_0 | ||
| 3128 | end | ||
| 3129 | local _with_0 = tb | ||
| 3130 | do | ||
| 3131 | local _check_0 = _with_0[1] | ||
| 3132 | local _val_0 = a | ||
| 3133 | local _find_0 = false | ||
| 3134 | for _index_0 = 1, #_check_0 do | ||
| 3135 | local _item_0 = _check_0[_index_0] | ||
| 3136 | if _item_0 == _val_0 then | ||
| 3137 | _find_0 = true | ||
| 3138 | break | ||
| 3139 | end | ||
| 3140 | end | ||
| 3141 | c = _find_0 | ||
| 3142 | end | ||
| 3025 | for i = 10, 20 do | 3143 | for i = 10, 20 do |
| 3026 | print(i) | 3144 | print(i) |
| 3027 | end | 3145 | end |
diff --git a/spec/outputs/codes_from_doc_id-id.lua b/spec/outputs/codes_from_doc_id-id.lua index 4026240..7af01b7 100644 --- a/spec/outputs/codes_from_doc_id-id.lua +++ b/spec/outputs/codes_from_doc_id-id.lua | |||
| @@ -2966,6 +2966,65 @@ if (function() | |||
| 2966 | end)() then | 2966 | end)() then |
| 2967 | print("memeriksa apakah `a` ada di dalam daftar") | 2967 | print("memeriksa apakah `a` ada di dalam daftar") |
| 2968 | end | 2968 | end |
| 2969 | local has | ||
| 2970 | do | ||
| 2971 | local _val_0 = "foo" | ||
| 2972 | has = "bar" == _val_0 or "foo" == _val_0 | ||
| 2973 | end | ||
| 2974 | if (function() | ||
| 2975 | local _val_0 = a | ||
| 2976 | return 1 == _val_0 or 2 == _val_0 or 3 == _val_0 | ||
| 2977 | end)() then | ||
| 2978 | print("a ada di dalam tabel") | ||
| 2979 | end | ||
| 2980 | local not_exist | ||
| 2981 | do | ||
| 2982 | local _check_0 = list | ||
| 2983 | local _val_0 = item | ||
| 2984 | local _find_0 = false | ||
| 2985 | for _index_0 = 1, #_check_0 do | ||
| 2986 | local _item_0 = _check_0[_index_0] | ||
| 2987 | if _item_0 == _val_0 then | ||
| 2988 | _find_0 = true | ||
| 2989 | break | ||
| 2990 | end | ||
| 2991 | end | ||
| 2992 | not_exist = not _find_0 | ||
| 2993 | end | ||
| 2994 | local check | ||
| 2995 | check = function() | ||
| 2996 | local _check_0 = table | ||
| 2997 | local _val_0 = value | ||
| 2998 | for _index_0 = 1, #_check_0 do | ||
| 2999 | if _check_0[_index_0] == _val_0 then | ||
| 3000 | return false | ||
| 3001 | end | ||
| 3002 | end | ||
| 3003 | return true | ||
| 3004 | end | ||
| 3005 | local c | ||
| 3006 | do | ||
| 3007 | local _val_0 = a | ||
| 3008 | c = 1 == _val_0 | ||
| 3009 | end | ||
| 3010 | do | ||
| 3011 | local _val_0 = a | ||
| 3012 | c = 1 == _val_0 | ||
| 3013 | end | ||
| 3014 | local _with_0 = tb | ||
| 3015 | do | ||
| 3016 | local _check_0 = _with_0[1] | ||
| 3017 | local _val_0 = a | ||
| 3018 | local _find_0 = false | ||
| 3019 | for _index_0 = 1, #_check_0 do | ||
| 3020 | local _item_0 = _check_0[_index_0] | ||
| 3021 | if _item_0 == _val_0 then | ||
| 3022 | _find_0 = true | ||
| 3023 | break | ||
| 3024 | end | ||
| 3025 | end | ||
| 3026 | c = _find_0 | ||
| 3027 | end | ||
| 2969 | local have_coins = false | 3028 | local have_coins = false |
| 2970 | if have_coins then | 3029 | if have_coins then |
| 2971 | print("Dapat koin") | 3030 | print("Dapat koin") |
| @@ -3022,6 +3081,65 @@ if (function() | |||
| 3022 | end)() then | 3081 | end)() then |
| 3023 | print("memeriksa apakah `a` ada di dalam daftar") | 3082 | print("memeriksa apakah `a` ada di dalam daftar") |
| 3024 | end | 3083 | end |
| 3084 | local has | ||
| 3085 | do | ||
| 3086 | local _val_0 = "foo" | ||
| 3087 | has = "bar" == _val_0 or "foo" == _val_0 | ||
| 3088 | end | ||
| 3089 | if (function() | ||
| 3090 | local _val_0 = a | ||
| 3091 | return 1 == _val_0 or 2 == _val_0 or 3 == _val_0 | ||
| 3092 | end)() then | ||
| 3093 | print("a ada di dalam tabel") | ||
| 3094 | end | ||
| 3095 | local not_exist | ||
| 3096 | do | ||
| 3097 | local _check_0 = list | ||
| 3098 | local _val_0 = item | ||
| 3099 | local _find_0 = false | ||
| 3100 | for _index_0 = 1, #_check_0 do | ||
| 3101 | local _item_0 = _check_0[_index_0] | ||
| 3102 | if _item_0 == _val_0 then | ||
| 3103 | _find_0 = true | ||
| 3104 | break | ||
| 3105 | end | ||
| 3106 | end | ||
| 3107 | not_exist = not _find_0 | ||
| 3108 | end | ||
| 3109 | local check | ||
| 3110 | check = function() | ||
| 3111 | local _check_0 = table | ||
| 3112 | local _val_0 = value | ||
| 3113 | for _index_0 = 1, #_check_0 do | ||
| 3114 | if _check_0[_index_0] == _val_0 then | ||
| 3115 | return false | ||
| 3116 | end | ||
| 3117 | end | ||
| 3118 | return true | ||
| 3119 | end | ||
| 3120 | local c | ||
| 3121 | do | ||
| 3122 | local _val_0 = a | ||
| 3123 | c = 1 == _val_0 | ||
| 3124 | end | ||
| 3125 | do | ||
| 3126 | local _val_0 = a | ||
| 3127 | c = 1 == _val_0 | ||
| 3128 | end | ||
| 3129 | local _with_0 = tb | ||
| 3130 | do | ||
| 3131 | local _check_0 = _with_0[1] | ||
| 3132 | local _val_0 = a | ||
| 3133 | local _find_0 = false | ||
| 3134 | for _index_0 = 1, #_check_0 do | ||
| 3135 | local _item_0 = _check_0[_index_0] | ||
| 3136 | if _item_0 == _val_0 then | ||
| 3137 | _find_0 = true | ||
| 3138 | break | ||
| 3139 | end | ||
| 3140 | end | ||
| 3141 | c = _find_0 | ||
| 3142 | end | ||
| 3025 | for i = 10, 20 do | 3143 | for i = 10, 20 do |
| 3026 | print(i) | 3144 | print(i) |
| 3027 | end | 3145 | end |
diff --git a/spec/outputs/codes_from_doc_pt-br.lua b/spec/outputs/codes_from_doc_pt-br.lua index 0d0c76f..dfe0108 100644 --- a/spec/outputs/codes_from_doc_pt-br.lua +++ b/spec/outputs/codes_from_doc_pt-br.lua | |||
| @@ -2966,6 +2966,65 @@ if (function() | |||
| 2966 | end)() then | 2966 | end)() then |
| 2967 | print("verificando se `a` está na lista") | 2967 | print("verificando se `a` está na lista") |
| 2968 | end | 2968 | end |
| 2969 | local has | ||
| 2970 | do | ||
| 2971 | local _val_0 = "foo" | ||
| 2972 | has = "bar" == _val_0 or "foo" == _val_0 | ||
| 2973 | end | ||
| 2974 | if (function() | ||
| 2975 | local _val_0 = a | ||
| 2976 | return 1 == _val_0 or 2 == _val_0 or 3 == _val_0 | ||
| 2977 | end)() then | ||
| 2978 | print("a está na tabela") | ||
| 2979 | end | ||
| 2980 | local not_exist | ||
| 2981 | do | ||
| 2982 | local _check_0 = list | ||
| 2983 | local _val_0 = item | ||
| 2984 | local _find_0 = false | ||
| 2985 | for _index_0 = 1, #_check_0 do | ||
| 2986 | local _item_0 = _check_0[_index_0] | ||
| 2987 | if _item_0 == _val_0 then | ||
| 2988 | _find_0 = true | ||
| 2989 | break | ||
| 2990 | end | ||
| 2991 | end | ||
| 2992 | not_exist = not _find_0 | ||
| 2993 | end | ||
| 2994 | local check | ||
| 2995 | check = function() | ||
| 2996 | local _check_0 = table | ||
| 2997 | local _val_0 = value | ||
| 2998 | for _index_0 = 1, #_check_0 do | ||
| 2999 | if _check_0[_index_0] == _val_0 then | ||
| 3000 | return false | ||
| 3001 | end | ||
| 3002 | end | ||
| 3003 | return true | ||
| 3004 | end | ||
| 3005 | local c | ||
| 3006 | do | ||
| 3007 | local _val_0 = a | ||
| 3008 | c = 1 == _val_0 | ||
| 3009 | end | ||
| 3010 | do | ||
| 3011 | local _val_0 = a | ||
| 3012 | c = 1 == _val_0 | ||
| 3013 | end | ||
| 3014 | local _with_0 = tb | ||
| 3015 | do | ||
| 3016 | local _check_0 = _with_0[1] | ||
| 3017 | local _val_0 = a | ||
| 3018 | local _find_0 = false | ||
| 3019 | for _index_0 = 1, #_check_0 do | ||
| 3020 | local _item_0 = _check_0[_index_0] | ||
| 3021 | if _item_0 == _val_0 then | ||
| 3022 | _find_0 = true | ||
| 3023 | break | ||
| 3024 | end | ||
| 3025 | end | ||
| 3026 | c = _find_0 | ||
| 3027 | end | ||
| 2969 | local have_coins = false | 3028 | local have_coins = false |
| 2970 | if have_coins then | 3029 | if have_coins then |
| 2971 | print("Tem moedas") | 3030 | print("Tem moedas") |
| @@ -3022,6 +3081,65 @@ if (function() | |||
| 3022 | end)() then | 3081 | end)() then |
| 3023 | print("verificando se `a` está na lista") | 3082 | print("verificando se `a` está na lista") |
| 3024 | end | 3083 | end |
| 3084 | local has | ||
| 3085 | do | ||
| 3086 | local _val_0 = "foo" | ||
| 3087 | has = "bar" == _val_0 or "foo" == _val_0 | ||
| 3088 | end | ||
| 3089 | if (function() | ||
| 3090 | local _val_0 = a | ||
| 3091 | return 1 == _val_0 or 2 == _val_0 or 3 == _val_0 | ||
| 3092 | end)() then | ||
| 3093 | print("a está na tabela") | ||
| 3094 | end | ||
| 3095 | local not_exist | ||
| 3096 | do | ||
| 3097 | local _check_0 = list | ||
| 3098 | local _val_0 = item | ||
| 3099 | local _find_0 = false | ||
| 3100 | for _index_0 = 1, #_check_0 do | ||
| 3101 | local _item_0 = _check_0[_index_0] | ||
| 3102 | if _item_0 == _val_0 then | ||
| 3103 | _find_0 = true | ||
| 3104 | break | ||
| 3105 | end | ||
| 3106 | end | ||
| 3107 | not_exist = not _find_0 | ||
| 3108 | end | ||
| 3109 | local check | ||
| 3110 | check = function() | ||
| 3111 | local _check_0 = table | ||
| 3112 | local _val_0 = value | ||
| 3113 | for _index_0 = 1, #_check_0 do | ||
| 3114 | if _check_0[_index_0] == _val_0 then | ||
| 3115 | return false | ||
| 3116 | end | ||
| 3117 | end | ||
| 3118 | return true | ||
| 3119 | end | ||
| 3120 | local c | ||
| 3121 | do | ||
| 3122 | local _val_0 = a | ||
| 3123 | c = 1 == _val_0 | ||
| 3124 | end | ||
| 3125 | do | ||
| 3126 | local _val_0 = a | ||
| 3127 | c = 1 == _val_0 | ||
| 3128 | end | ||
| 3129 | local _with_0 = tb | ||
| 3130 | do | ||
| 3131 | local _check_0 = _with_0[1] | ||
| 3132 | local _val_0 = a | ||
| 3133 | local _find_0 = false | ||
| 3134 | for _index_0 = 1, #_check_0 do | ||
| 3135 | local _item_0 = _check_0[_index_0] | ||
| 3136 | if _item_0 == _val_0 then | ||
| 3137 | _find_0 = true | ||
| 3138 | break | ||
| 3139 | end | ||
| 3140 | end | ||
| 3141 | c = _find_0 | ||
| 3142 | end | ||
| 3025 | for i = 10, 20 do | 3143 | for i = 10, 20 do |
| 3026 | print(i) | 3144 | print(i) |
| 3027 | end | 3145 | end |
diff --git a/spec/outputs/codes_from_doc_zh.lua b/spec/outputs/codes_from_doc_zh.lua index c847841..6db4a43 100644 --- a/spec/outputs/codes_from_doc_zh.lua +++ b/spec/outputs/codes_from_doc_zh.lua | |||
| @@ -2966,6 +2966,65 @@ if (function() | |||
| 2966 | end)() then | 2966 | end)() then |
| 2967 | print("检查`a`是否在列表中") | 2967 | print("检查`a`是否在列表中") |
| 2968 | end | 2968 | end |
| 2969 | local has | ||
| 2970 | do | ||
| 2971 | local _val_0 = "foo" | ||
| 2972 | has = "bar" == _val_0 or "foo" == _val_0 | ||
| 2973 | end | ||
| 2974 | if (function() | ||
| 2975 | local _val_0 = a | ||
| 2976 | return 1 == _val_0 or 2 == _val_0 or 3 == _val_0 | ||
| 2977 | end)() then | ||
| 2978 | print("a 在表中") | ||
| 2979 | end | ||
| 2980 | local not_exist | ||
| 2981 | do | ||
| 2982 | local _check_0 = list | ||
| 2983 | local _val_0 = item | ||
| 2984 | local _find_0 = false | ||
| 2985 | for _index_0 = 1, #_check_0 do | ||
| 2986 | local _item_0 = _check_0[_index_0] | ||
| 2987 | if _item_0 == _val_0 then | ||
| 2988 | _find_0 = true | ||
| 2989 | break | ||
| 2990 | end | ||
| 2991 | end | ||
| 2992 | not_exist = not _find_0 | ||
| 2993 | end | ||
| 2994 | local check | ||
| 2995 | check = function() | ||
| 2996 | local _check_0 = table | ||
| 2997 | local _val_0 = value | ||
| 2998 | for _index_0 = 1, #_check_0 do | ||
| 2999 | if _check_0[_index_0] == _val_0 then | ||
| 3000 | return false | ||
| 3001 | end | ||
| 3002 | end | ||
| 3003 | return true | ||
| 3004 | end | ||
| 3005 | local c | ||
| 3006 | do | ||
| 3007 | local _val_0 = a | ||
| 3008 | c = 1 == _val_0 | ||
| 3009 | end | ||
| 3010 | do | ||
| 3011 | local _val_0 = a | ||
| 3012 | c = 1 == _val_0 | ||
| 3013 | end | ||
| 3014 | local _with_0 = tb | ||
| 3015 | do | ||
| 3016 | local _check_0 = _with_0[1] | ||
| 3017 | local _val_0 = a | ||
| 3018 | local _find_0 = false | ||
| 3019 | for _index_0 = 1, #_check_0 do | ||
| 3020 | local _item_0 = _check_0[_index_0] | ||
| 3021 | if _item_0 == _val_0 then | ||
| 3022 | _find_0 = true | ||
| 3023 | break | ||
| 3024 | end | ||
| 3025 | end | ||
| 3026 | c = _find_0 | ||
| 3027 | end | ||
| 2969 | local have_coins = false | 3028 | local have_coins = false |
| 2970 | if have_coins then | 3029 | if have_coins then |
| 2971 | print("有硬币") | 3030 | print("有硬币") |
| @@ -3022,6 +3081,65 @@ if (function() | |||
| 3022 | end)() then | 3081 | end)() then |
| 3023 | print("检查`a`是否在列表中") | 3082 | print("检查`a`是否在列表中") |
| 3024 | end | 3083 | end |
| 3084 | local has | ||
| 3085 | do | ||
| 3086 | local _val_0 = "foo" | ||
| 3087 | has = "bar" == _val_0 or "foo" == _val_0 | ||
| 3088 | end | ||
| 3089 | if (function() | ||
| 3090 | local _val_0 = a | ||
| 3091 | return 1 == _val_0 or 2 == _val_0 or 3 == _val_0 | ||
| 3092 | end)() then | ||
| 3093 | print("a 在表中") | ||
| 3094 | end | ||
| 3095 | local not_exist | ||
| 3096 | do | ||
| 3097 | local _check_0 = list | ||
| 3098 | local _val_0 = item | ||
| 3099 | local _find_0 = false | ||
| 3100 | for _index_0 = 1, #_check_0 do | ||
| 3101 | local _item_0 = _check_0[_index_0] | ||
| 3102 | if _item_0 == _val_0 then | ||
| 3103 | _find_0 = true | ||
| 3104 | break | ||
| 3105 | end | ||
| 3106 | end | ||
| 3107 | not_exist = not _find_0 | ||
| 3108 | end | ||
| 3109 | local check | ||
| 3110 | check = function() | ||
| 3111 | local _check_0 = table | ||
| 3112 | local _val_0 = value | ||
| 3113 | for _index_0 = 1, #_check_0 do | ||
| 3114 | if _check_0[_index_0] == _val_0 then | ||
| 3115 | return false | ||
| 3116 | end | ||
| 3117 | end | ||
| 3118 | return true | ||
| 3119 | end | ||
| 3120 | local c | ||
| 3121 | do | ||
| 3122 | local _val_0 = a | ||
| 3123 | c = 1 == _val_0 | ||
| 3124 | end | ||
| 3125 | do | ||
| 3126 | local _val_0 = a | ||
| 3127 | c = 1 == _val_0 | ||
| 3128 | end | ||
| 3129 | local _with_0 = tb | ||
| 3130 | do | ||
| 3131 | local _check_0 = _with_0[1] | ||
| 3132 | local _val_0 = a | ||
| 3133 | local _find_0 = false | ||
| 3134 | for _index_0 = 1, #_check_0 do | ||
| 3135 | local _item_0 = _check_0[_index_0] | ||
| 3136 | if _item_0 == _val_0 then | ||
| 3137 | _find_0 = true | ||
| 3138 | break | ||
| 3139 | end | ||
| 3140 | end | ||
| 3141 | c = _find_0 | ||
| 3142 | end | ||
| 3025 | for i = 10, 20 do | 3143 | for i = 10, 20 do |
| 3026 | print(i) | 3144 | print(i) |
| 3027 | end | 3145 | end |
diff --git a/src/yue.cpp b/src/yue.cpp index a30075d..0493205 100644 --- a/src/yue.cpp +++ b/src/yue.cpp | |||
| @@ -264,7 +264,9 @@ static std::string compileFile(const fs::path& file, yue::YueConfig conf, const | |||
| 264 | return "Failed to read file: "s + srcFile.string() + '\n'; | 264 | return "Failed to read file: "s + srcFile.string() + '\n'; |
| 265 | } | 265 | } |
| 266 | } | 266 | } |
| 267 | #endif // YUE_NO_WATCHER | ||
| 267 | 268 | ||
| 269 | #ifndef YUE_NO_WATCHER | ||
| 268 | class UpdateListener : public efsw::FileWatchListener { | 270 | class UpdateListener : public efsw::FileWatchListener { |
| 269 | public: | 271 | public: |
| 270 | void handleFileAction(efsw::WatchID, const std::string& dir, const std::string& filename, efsw::Action action, std::string) override { | 272 | void handleFileAction(efsw::WatchID, const std::string& dir, const std::string& filename, efsw::Action action, std::string) override { |
