diff options
| author | Li Jin <dragon-fly@qq.com> | 2026-02-06 11:54:32 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2026-02-06 11:54:32 +0800 |
| commit | 1f83d504bc344ffd3c8b4120b3865fd6c11a9e2d (patch) | |
| tree | 1d5c39eadcbe086d2a592ac76c8f1d288adfbe9d /doc | |
| parent | aa3ecc7badfb39cb9167fb95c9a678257c1d9954 (diff) | |
| download | yuescript-1f83d504bc344ffd3c8b4120b3865fd6c11a9e2d.tar.gz yuescript-1f83d504bc344ffd3c8b4120b3865fd6c11a9e2d.tar.bz2 yuescript-1f83d504bc344ffd3c8b4120b3865fd6c11a9e2d.zip | |
Updated docs.v0.32.9
Diffstat (limited to 'doc')
104 files changed, 3077 insertions, 3145 deletions
diff --git a/doc/docs/de/doc/advanced/do.md b/doc/docs/de/doc/advanced/do.md index 4990d6f..6f81f9d 100644 --- a/doc/docs/de/doc/advanced/do.md +++ b/doc/docs/de/doc/advanced/do.md | |||
| @@ -1,25 +1,25 @@ | |||
| 1 | # Do | 1 | # Do |
| 2 | 2 | ||
| 3 | When used as a statement, do works just like it does in Lua. | 3 | Als Statement verhält sich `do` wie in Lua. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | do | 6 | do |
| 7 | var = "hello" | 7 | var = "hallo" |
| 8 | print var | 8 | print var |
| 9 | print var -- nil here | 9 | print var -- nil hier |
| 10 | ``` | 10 | ``` |
| 11 | <YueDisplay> | 11 | <YueDisplay> |
| 12 | 12 | ||
| 13 | ```yue | 13 | ```yue |
| 14 | do | 14 | do |
| 15 | var = "hello" | 15 | var = "hallo" |
| 16 | print var | 16 | print var |
| 17 | print var -- nil here | 17 | print var -- nil hier |
| 18 | ``` | 18 | ``` |
| 19 | 19 | ||
| 20 | </YueDisplay> | 20 | </YueDisplay> |
| 21 | 21 | ||
| 22 | YueScript's **do** can also be used an expression . Allowing you to combine multiple lines into one. The result of the do expression is the last statement in its body. | 22 | YueScripts **do** kann auch als Ausdruck verwendet werden. So kannst du mehrere Zeilen in einem Ausdruck kombinieren. Das Ergebnis des `do`-Ausdrucks ist die letzte Anweisung im Block. |
| 23 | 23 | ||
| 24 | ```yuescript | 24 | ```yuescript |
| 25 | counter = do | 25 | counter = do |
| @@ -49,7 +49,7 @@ print counter! | |||
| 49 | ```yuescript | 49 | ```yuescript |
| 50 | tbl = { | 50 | tbl = { |
| 51 | key: do | 51 | key: do |
| 52 | print "assigning key!" | 52 | print "Schlüssel wird zugewiesen!" |
| 53 | 1234 | 53 | 1234 |
| 54 | } | 54 | } |
| 55 | ``` | 55 | ``` |
| @@ -58,7 +58,7 @@ tbl = { | |||
| 58 | ```yue | 58 | ```yue |
| 59 | tbl = { | 59 | tbl = { |
| 60 | key: do | 60 | key: do |
| 61 | print "assigning key!" | 61 | print "Schlüssel wird zugewiesen!" |
| 62 | 1234 | 62 | 1234 |
| 63 | } | 63 | } |
| 64 | ``` | 64 | ``` |
diff --git a/doc/docs/de/doc/advanced/line-decorators.md b/doc/docs/de/doc/advanced/line-decorators.md index 292bc77..dd26925 100644 --- a/doc/docs/de/doc/advanced/line-decorators.md +++ b/doc/docs/de/doc/advanced/line-decorators.md | |||
| @@ -1,32 +1,32 @@ | |||
| 1 | # Line Decorators | 1 | # Line-Decorators |
| 2 | 2 | ||
| 3 | For convenience, the for loop and if statement can be applied to single statements at the end of the line: | 3 | Zur Vereinfachung können `for`-Schleifen und `if`-Anweisungen auf einzelne Anweisungen am Zeilenende angewendet werden: |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | print "hello world" if name == "Rob" | 6 | print "Hallo Welt" if name == "Rob" |
| 7 | ``` | 7 | ``` |
| 8 | <YueDisplay> | 8 | <YueDisplay> |
| 9 | 9 | ||
| 10 | ```yue | 10 | ```yue |
| 11 | print "hello world" if name == "Rob" | 11 | print "Hallo Welt" if name == "Rob" |
| 12 | ``` | 12 | ``` |
| 13 | 13 | ||
| 14 | </YueDisplay> | 14 | </YueDisplay> |
| 15 | 15 | ||
| 16 | And with basic loops: | 16 | Und mit einfachen Schleifen: |
| 17 | 17 | ||
| 18 | ```yuescript | 18 | ```yuescript |
| 19 | print "item: ", item for item in *items | 19 | print "Element: ", item for item in *items |
| 20 | ``` | 20 | ``` |
| 21 | <YueDisplay> | 21 | <YueDisplay> |
| 22 | 22 | ||
| 23 | ```yue | 23 | ```yue |
| 24 | print "item: ", item for item in *items | 24 | print "Element: ", item for item in *items |
| 25 | ``` | 25 | ``` |
| 26 | 26 | ||
| 27 | </YueDisplay> | 27 | </YueDisplay> |
| 28 | 28 | ||
| 29 | And with while loops: | 29 | Und mit `while`-Schleifen: |
| 30 | 30 | ||
| 31 | ```yuescript | 31 | ```yuescript |
| 32 | game\update! while game\isRunning! | 32 | game\update! while game\isRunning! |
diff --git a/doc/docs/de/doc/advanced/macro.md b/doc/docs/de/doc/advanced/macro.md index 6d194c3..a3e155a 100644 --- a/doc/docs/de/doc/advanced/macro.md +++ b/doc/docs/de/doc/advanced/macro.md | |||
| @@ -1,14 +1,14 @@ | |||
| 1 | # Macro | 1 | # Makros |
| 2 | 2 | ||
| 3 | ## Common Usage | 3 | ## Häufige Verwendung |
| 4 | 4 | ||
| 5 | Macro function is used for evaluating a string in the compile time and insert the generated codes into final compilation. | 5 | Makrofunktionen werden verwendet, um zur Compile-Zeit einen String auszuwerten und den generierten Code in die finale Kompilierung einzufügen. |
| 6 | 6 | ||
| 7 | ```yuescript | 7 | ```yuescript |
| 8 | macro PI2 = -> math.pi * 2 | 8 | macro PI2 = -> math.pi * 2 |
| 9 | area = $PI2 * 5 | 9 | area = $PI2 * 5 |
| 10 | 10 | ||
| 11 | macro HELLO = -> "'hello world'" | 11 | macro HELLO = -> "'Hallo Welt'" |
| 12 | print $HELLO | 12 | print $HELLO |
| 13 | 13 | ||
| 14 | macro config = (debugging) -> | 14 | macro config = (debugging) -> |
| @@ -27,7 +27,7 @@ $asserts item ~= nil | |||
| 27 | $config false | 27 | $config false |
| 28 | value = $assert item | 28 | value = $assert item |
| 29 | 29 | ||
| 30 | -- the passed expressions are treated as strings | 30 | -- übergebene Ausdrücke werden als Strings behandelt |
| 31 | macro and = (...) -> "#{ table.concat {...}, ' and ' }" | 31 | macro and = (...) -> "#{ table.concat {...}, ' and ' }" |
| 32 | if $and f1!, f2!, f3! | 32 | if $and f1!, f2!, f3! |
| 33 | print "OK" | 33 | print "OK" |
| @@ -38,7 +38,7 @@ if $and f1!, f2!, f3! | |||
| 38 | macro PI2 = -> math.pi * 2 | 38 | macro PI2 = -> math.pi * 2 |
| 39 | area = $PI2 * 5 | 39 | area = $PI2 * 5 |
| 40 | 40 | ||
| 41 | macro HELLO = -> "'hello world'" | 41 | macro HELLO = -> "'Hallo Welt'" |
| 42 | print $HELLO | 42 | print $HELLO |
| 43 | 43 | ||
| 44 | macro config = (debugging) -> | 44 | macro config = (debugging) -> |
| @@ -57,7 +57,7 @@ $asserts item ~= nil | |||
| 57 | $config false | 57 | $config false |
| 58 | value = $assert item | 58 | value = $assert item |
| 59 | 59 | ||
| 60 | -- the passed expressions are treated as strings | 60 | -- übergebene Ausdrücke werden als Strings behandelt |
| 61 | macro and = (...) -> "#{ table.concat {...}, ' and ' }" | 61 | macro and = (...) -> "#{ table.concat {...}, ' and ' }" |
| 62 | if $and f1!, f2!, f3! | 62 | if $and f1!, f2!, f3! |
| 63 | print "OK" | 63 | print "OK" |
| @@ -65,31 +65,32 @@ if $and f1!, f2!, f3! | |||
| 65 | 65 | ||
| 66 | </YueDisplay> | 66 | </YueDisplay> |
| 67 | 67 | ||
| 68 | ## Insert Raw Codes | 68 | ## Rohcode einfügen |
| 69 | |||
| 70 | Eine Makrofunktion kann entweder einen YueScript-String oder eine Konfigurationstabelle mit Lua-Code zurückgeben. | ||
| 69 | 71 | ||
| 70 | A macro function can either return a YueScript string or a config table containing Lua codes. | ||
| 71 | ```yuescript | 72 | ```yuescript |
| 72 | macro yueFunc = (var) -> "local #{var} = ->" | 73 | macro yueFunc = (var) -> "local #{var} = ->" |
| 73 | $yueFunc funcA | 74 | $yueFunc funcA |
| 74 | funcA = -> "fail to assign to the Yue macro defined variable" | 75 | funcA = -> "Zuweisung an die vom Yue-Makro definierte Variable schlägt fehl" |
| 75 | 76 | ||
| 76 | macro luaFunc = (var) -> { | 77 | macro luaFunc = (var) -> { |
| 77 | code: "local function #{var}() end" | 78 | code: "local function #{var}() end" |
| 78 | type: "lua" | 79 | type: "lua" |
| 79 | } | 80 | } |
| 80 | $luaFunc funcB | 81 | $luaFunc funcB |
| 81 | funcB = -> "fail to assign to the Lua macro defined variable" | 82 | funcB = -> "Zuweisung an die vom Lua-Makro definierte Variable schlägt fehl" |
| 82 | 83 | ||
| 83 | macro lua = (code) -> { | 84 | macro lua = (code) -> { |
| 84 | :code | 85 | :code |
| 85 | type: "lua" | 86 | type: "lua" |
| 86 | } | 87 | } |
| 87 | 88 | ||
| 88 | -- the raw string leading and ending symbols are auto trimed | 89 | -- führende und abschließende Symbole des Raw-Strings werden automatisch getrimmt |
| 89 | $lua[==[ | 90 | $lua[==[ |
| 90 | -- raw Lua codes insertion | 91 | -- Einfügen von rohem Lua-Code |
| 91 | if cond then | 92 | if cond then |
| 92 | print("output") | 93 | print("Ausgabe") |
| 93 | end | 94 | end |
| 94 | ]==] | 95 | ]==] |
| 95 | ``` | 96 | ``` |
| @@ -98,63 +99,64 @@ end | |||
| 98 | ```yue | 99 | ```yue |
| 99 | macro yueFunc = (var) -> "local #{var} = ->" | 100 | macro yueFunc = (var) -> "local #{var} = ->" |
| 100 | $yueFunc funcA | 101 | $yueFunc funcA |
| 101 | funcA = -> "fail to assign to the Yue macro defined variable" | 102 | funcA = -> "Zuweisung an die vom Yue-Makro definierte Variable schlägt fehl" |
| 102 | 103 | ||
| 103 | macro luaFunc = (var) -> { | 104 | macro luaFunc = (var) -> { |
| 104 | code: "local function #{var}() end" | 105 | code: "local function #{var}() end" |
| 105 | type: "lua" | 106 | type: "lua" |
| 106 | } | 107 | } |
| 107 | $luaFunc funcB | 108 | $luaFunc funcB |
| 108 | funcB = -> "fail to assign to the Lua macro defined variable" | 109 | funcB = -> "Zuweisung an die vom Lua-Makro definierte Variable schlägt fehl" |
| 109 | 110 | ||
| 110 | macro lua = (code) -> { | 111 | macro lua = (code) -> { |
| 111 | :code | 112 | :code |
| 112 | type: "lua" | 113 | type: "lua" |
| 113 | } | 114 | } |
| 114 | 115 | ||
| 115 | -- the raw string leading and ending symbols are auto trimed | 116 | -- führende und abschließende Symbole des Raw-Strings werden automatisch getrimmt |
| 116 | $lua[==[ | 117 | $lua[==[ |
| 117 | -- raw Lua codes insertion | 118 | -- Einfügen von rohem Lua-Code |
| 118 | if cond then | 119 | if cond then |
| 119 | print("output") | 120 | print("Ausgabe") |
| 120 | end | 121 | end |
| 121 | ]==] | 122 | ]==] |
| 122 | ``` | 123 | ``` |
| 123 | 124 | ||
| 124 | </YueDisplay> | 125 | </YueDisplay> |
| 125 | 126 | ||
| 126 | ## Export Macro | 127 | ## Makros exportieren |
| 128 | |||
| 129 | Makrofunktionen können aus einem Modul exportiert und in ein anderes Modul importiert werden. Exportierte Makros müssen in einer einzelnen Datei liegen, und im Export-Modul dürfen nur Makrodefinitionen, Makro-Imports und Makro-Expansionen stehen. | ||
| 127 | 130 | ||
| 128 | Macro functions can be exported from a module and get imported in another module. You have to put export macro functions in a single file to be used, and only macro definition, macro importing and macro expansion in place can be put into the macro exporting module. | ||
| 129 | ```yuescript | 131 | ```yuescript |
| 130 | -- file: utils.yue | 132 | -- Datei: utils.yue |
| 131 | export macro map = (items, action) -> "[#{action} for _ in *#{items}]" | 133 | export macro map = (items, action) -> "[#{action} for _ in *#{items}]" |
| 132 | export macro filter = (items, action) -> "[_ for _ in *#{items} when #{action}]" | 134 | export macro filter = (items, action) -> "[_ for _ in *#{items} when #{action}]" |
| 133 | export macro foreach = (items, action) -> "for _ in *#{items} | 135 | export macro foreach = (items, action) -> "for _ in *#{items} |
| 134 | #{action}" | 136 | #{action}" |
| 135 | 137 | ||
| 136 | -- file main.yue | 138 | -- Datei main.yue |
| 137 | import "utils" as { | 139 | import "utils" as { |
| 138 | $, -- symbol to import all macros | 140 | $, -- Symbol zum Importieren aller Makros |
| 139 | $foreach: $each -- rename macro $foreach to $each | 141 | $foreach: $each -- Makro $foreach in $each umbenennen |
| 140 | } | 142 | } |
| 141 | [1, 2, 3] |> $map(_ * 2) |> $filter(_ > 4) |> $each print _ | 143 | [1, 2, 3] |> $map(_ * 2) |> $filter(_ > 4) |> $each print _ |
| 142 | ``` | 144 | ``` |
| 143 | <YueDisplay> | 145 | <YueDisplay> |
| 144 | 146 | ||
| 145 | ```yue | 147 | ```yue |
| 146 | -- file: utils.yue | 148 | -- Datei: utils.yue |
| 147 | export macro map = (items, action) -> "[#{action} for _ in *#{items}]" | 149 | export macro map = (items, action) -> "[#{action} for _ in *#{items}]" |
| 148 | export macro filter = (items, action) -> "[_ for _ in *#{items} when #{action}]" | 150 | export macro filter = (items, action) -> "[_ for _ in *#{items} when #{action}]" |
| 149 | export macro foreach = (items, action) -> "for _ in *#{items} | 151 | export macro foreach = (items, action) -> "for _ in *#{items} |
| 150 | #{action}" | 152 | #{action}" |
| 151 | 153 | ||
| 152 | -- file main.yue | 154 | -- Datei main.yue |
| 153 | -- import function is not available in browser, try it in a real environment | 155 | -- Import-Funktion im Browser nicht verfügbar, in echter Umgebung testen |
| 154 | --[[ | 156 | --[[ |
| 155 | import "utils" as { | 157 | import "utils" as { |
| 156 | $, -- symbol to import all macros | 158 | $, -- Symbol zum Importieren aller Makros |
| 157 | $foreach: $each -- rename macro $foreach to $each | 159 | $foreach: $each -- Makro $foreach in $each umbenennen |
| 158 | } | 160 | } |
| 159 | [1, 2, 3] |> $map(_ * 2) |> $filter(_ > 4) |> $each print _ | 161 | [1, 2, 3] |> $map(_ * 2) |> $filter(_ > 4) |> $each print _ |
| 160 | ]] | 162 | ]] |
| @@ -162,32 +164,33 @@ import "utils" as { | |||
| 162 | 164 | ||
| 163 | </YueDisplay> | 165 | </YueDisplay> |
| 164 | 166 | ||
| 165 | ## Builtin Macro | 167 | ## Eingebaute Makros |
| 168 | |||
| 169 | Es gibt einige eingebaute Makros, aber du kannst sie überschreiben, indem du Makros mit denselben Namen deklarierst. | ||
| 166 | 170 | ||
| 167 | There are some builtin macros but you can override them by declaring macros with the same names. | ||
| 168 | ```yuescript | 171 | ```yuescript |
| 169 | print $FILE -- get string of current module name | 172 | print $FILE -- String des aktuellen Modulnamens |
| 170 | print $LINE -- get number 2 | 173 | print $LINE -- gibt 2 aus |
| 171 | ``` | 174 | ``` |
| 172 | <YueDisplay> | 175 | <YueDisplay> |
| 173 | 176 | ||
| 174 | ```yue | 177 | ```yue |
| 175 | print $FILE -- get string of current module name | 178 | print $FILE -- String des aktuellen Modulnamens |
| 176 | print $LINE -- get number 2 | 179 | print $LINE -- gibt 2 aus |
| 177 | ``` | 180 | ``` |
| 178 | 181 | ||
| 179 | </YueDisplay> | 182 | </YueDisplay> |
| 180 | 183 | ||
| 181 | ## Generating Macros with Macros | 184 | ## Makros mit Makros erzeugen |
| 182 | 185 | ||
| 183 | In YueScript, macro functions allow you to generate code at compile time. By nesting macro functions, you can create more complex generation patterns. This feature enables you to define a macro function that generates another macro function, allowing for more dynamic code generation. | 186 | In YueScript erlauben Makrofunktionen Codegenerierung zur Compile-Zeit. Durch das Verschachteln von Makrofunktionen kannst du komplexere Generierungsmuster erzeugen. Damit kannst du eine Makrofunktion definieren, die eine andere Makrofunktion erzeugt. |
| 184 | 187 | ||
| 185 | ```yuescript | 188 | ```yuescript |
| 186 | macro Enum = (...) -> | 189 | macro Enum = (...) -> |
| 187 | items = {...} | 190 | items = {...} |
| 188 | itemSet = {item, true for item in *items} | 191 | itemSet = {item, true for item in *items} |
| 189 | (item) -> | 192 | (item) -> |
| 190 | error "got \"#{item}\", expecting one of #{table.concat items, ', '}" unless itemSet[item] | 193 | error "erhalten: \"#{item}\", erwartet eines von #{table.concat items, ', '}" unless itemSet[item] |
| 191 | "\"#{item}\"" | 194 | "\"#{item}\"" |
| 192 | 195 | ||
| 193 | macro BodyType = $Enum( | 196 | macro BodyType = $Enum( |
| @@ -196,8 +199,8 @@ macro BodyType = $Enum( | |||
| 196 | Kinematic | 199 | Kinematic |
| 197 | ) | 200 | ) |
| 198 | 201 | ||
| 199 | print "Valid enum type:", $BodyType Static | 202 | print "Gültiger Enum-Typ:", $BodyType Static |
| 200 | -- print "Compilation error with enum type:", $BodyType Unknown | 203 | -- print "Kompilierungsfehler bei Enum-Typ:", $BodyType Unknown |
| 201 | ``` | 204 | ``` |
| 202 | 205 | ||
| 203 | <YueDisplay> | 206 | <YueDisplay> |
| @@ -207,7 +210,7 @@ macro Enum = (...) -> | |||
| 207 | items = {...} | 210 | items = {...} |
| 208 | itemSet = {item, true for item in *items} | 211 | itemSet = {item, true for item in *items} |
| 209 | (item) -> | 212 | (item) -> |
| 210 | error "got \"#{item}\", expecting one of #{table.concat items, ', '}" unless itemSet[item] | 213 | error "erhalten: \"#{item}\", erwartet eines von #{table.concat items, ', '}" unless itemSet[item] |
| 211 | "\"#{item}\"" | 214 | "\"#{item}\"" |
| 212 | 215 | ||
| 213 | macro BodyType = $Enum( | 216 | macro BodyType = $Enum( |
| @@ -216,15 +219,15 @@ macro BodyType = $Enum( | |||
| 216 | Kinematic | 219 | Kinematic |
| 217 | ) | 220 | ) |
| 218 | 221 | ||
| 219 | print "Valid enum type:", $BodyType Static | 222 | print "Gültiger Enum-Typ:", $BodyType Static |
| 220 | -- print "Compilation error with enum type:", $BodyType Unknown | 223 | -- print "Kompilierungsfehler bei Enum-Typ:", $BodyType Unknown |
| 221 | ``` | 224 | ``` |
| 222 | 225 | ||
| 223 | </YueDisplay> | 226 | </YueDisplay> |
| 224 | 227 | ||
| 225 | ## Argument Validation | 228 | ## Argument-Validierung |
| 226 | 229 | ||
| 227 | You can declare the expected AST node types in the argument list, and check whether the incoming macro arguments meet the expectations at compile time. | 230 | Du kannst erwartete AST-Knotentypen in der Argumentliste deklarieren und zur Compile-Zeit prüfen, ob die übergebenen Makroargumente den Erwartungen entsprechen. |
| 228 | 231 | ||
| 229 | ```yuescript | 232 | ```yuescript |
| 230 | macro printNumAndStr = (num `Num, str `String) -> | | 233 | macro printNumAndStr = (num `Num, str `String) -> | |
| @@ -233,7 +236,7 @@ macro printNumAndStr = (num `Num, str `String) -> | | |||
| 233 | #{str} | 236 | #{str} |
| 234 | ) | 237 | ) |
| 235 | 238 | ||
| 236 | $printNumAndStr 123, "hello" | 239 | $printNumAndStr 123, "hallo" |
| 237 | ``` | 240 | ``` |
| 238 | <YueDisplay> | 241 | <YueDisplay> |
| 239 | 242 | ||
| @@ -244,32 +247,32 @@ macro printNumAndStr = (num `Num, str `String) -> | | |||
| 244 | #{str} | 247 | #{str} |
| 245 | ) | 248 | ) |
| 246 | 249 | ||
| 247 | $printNumAndStr 123, "hello" | 250 | $printNumAndStr 123, "hallo" |
| 248 | ``` | 251 | ``` |
| 249 | 252 | ||
| 250 | </YueDisplay> | 253 | </YueDisplay> |
| 251 | 254 | ||
| 252 | If you need more flexible argument checking, you can use the built-in `$is_ast` macro function to manually check at the appropriate place. | 255 | Wenn du flexiblere Argumentprüfungen brauchst, kannst du das eingebaute Makro `$is_ast` verwenden, um manuell an der passenden Stelle zu prüfen. |
| 253 | 256 | ||
| 254 | ```yuescript | 257 | ```yuescript |
| 255 | macro printNumAndStr = (num, str) -> | 258 | macro printNumAndStr = (num, str) -> |
| 256 | error "expected Num as first argument" unless $is_ast Num, num | 259 | error "als erstes Argument Num erwartet" unless $is_ast Num, num |
| 257 | error "expected String as second argument" unless $is_ast String, str | 260 | error "als zweites Argument String erwartet" unless $is_ast String, str |
| 258 | "print(#{num}, #{str})" | 261 | "print(#{num}, #{str})" |
| 259 | 262 | ||
| 260 | $printNumAndStr 123, "hello" | 263 | $printNumAndStr 123, "hallo" |
| 261 | ``` | 264 | ``` |
| 262 | <YueDisplay> | 265 | <YueDisplay> |
| 263 | 266 | ||
| 264 | ```yue | 267 | ```yue |
| 265 | macro printNumAndStr = (num, str) -> | 268 | macro printNumAndStr = (num, str) -> |
| 266 | error "expected Num as first argument" unless $is_ast Num, num | 269 | error "als erstes Argument Num erwartet" unless $is_ast Num, num |
| 267 | error "expected String as second argument" unless $is_ast String, str | 270 | error "als zweites Argument String erwartet" unless $is_ast String, str |
| 268 | "print(#{num}, #{str})" | 271 | "print(#{num}, #{str})" |
| 269 | 272 | ||
| 270 | $printNumAndStr 123, "hello" | 273 | $printNumAndStr 123, "hallo" |
| 271 | ``` | 274 | ``` |
| 272 | 275 | ||
| 273 | </YueDisplay> | 276 | </YueDisplay> |
| 274 | 277 | ||
| 275 | For more details about available AST nodes, please refer to the uppercased definitions in [yue_parser.cpp](https://github.com/IppClub/YueScript/blob/main/src/yuescript/yue_parser.cpp). | 278 | Weitere Details zu verfügbaren AST-Knoten findest du in den großgeschriebenen Definitionen in `yue_parser.cpp`. |
diff --git a/doc/docs/de/doc/advanced/module.md b/doc/docs/de/doc/advanced/module.md index c955092..bdc5d86 100644 --- a/doc/docs/de/doc/advanced/module.md +++ b/doc/docs/de/doc/advanced/module.md | |||
| @@ -2,27 +2,27 @@ | |||
| 2 | 2 | ||
| 3 | ## Import | 3 | ## Import |
| 4 | 4 | ||
| 5 | The import statement is a syntax sugar for requiring a module or help extracting items from an imported module. The imported items are const by default. | 5 | Die `import`-Anweisung ist syntaktischer Zucker für `require` und hilft beim Extrahieren von Einträgen aus importierten Modulen. Importierte Elemente sind standardmäßig `const`. |
| 6 | 6 | ||
| 7 | ```yuescript | 7 | ```yuescript |
| 8 | -- used as table destructuring | 8 | -- als Tabellen-Destrukturierung |
| 9 | do | 9 | do |
| 10 | import insert, concat from table | 10 | import insert, concat from table |
| 11 | -- report error when assigning to insert, concat | 11 | -- Fehler beim Zuweisen zu insert, concat |
| 12 | import C, Ct, Cmt from require "lpeg" | 12 | import C, Ct, Cmt from require "lpeg" |
| 13 | -- shortcut for implicit requiring | 13 | -- Kurzform für implizites Require |
| 14 | import x, y, z from 'mymodule' | 14 | import x, y, z from 'mymodule' |
| 15 | -- import with Python style | 15 | -- Import im Python-Stil |
| 16 | from 'module' import a, b, c | 16 | from 'module' import a, b, c |
| 17 | 17 | ||
| 18 | -- shortcut for requring a module | 18 | -- Kurzform zum Laden eines Moduls |
| 19 | do | 19 | do |
| 20 | import 'module' | 20 | import 'module' |
| 21 | import 'module_x' | 21 | import 'module_x' |
| 22 | import "d-a-s-h-e-s" | 22 | import "d-a-s-h-e-s" |
| 23 | import "module.part" | 23 | import "module.part" |
| 24 | 24 | ||
| 25 | -- requring module with aliasing or table destructuring | 25 | -- Modul mit Alias oder Tabellen-Destrukturierung laden |
| 26 | do | 26 | do |
| 27 | import "player" as PlayerModule | 27 | import "player" as PlayerModule |
| 28 | import "lpeg" as :C, :Ct, :Cmt | 28 | import "lpeg" as :C, :Ct, :Cmt |
| @@ -31,24 +31,24 @@ do | |||
| 31 | <YueDisplay> | 31 | <YueDisplay> |
| 32 | 32 | ||
| 33 | ```yue | 33 | ```yue |
| 34 | -- used as table destructuring | 34 | -- als Tabellen-Destrukturierung |
| 35 | do | 35 | do |
| 36 | import insert, concat from table | 36 | import insert, concat from table |
| 37 | -- report error when assigning to insert, concat | 37 | -- Fehler beim Zuweisen zu insert, concat |
| 38 | import C, Ct, Cmt from require "lpeg" | 38 | import C, Ct, Cmt from require "lpeg" |
| 39 | -- shortcut for implicit requiring | 39 | -- Kurzform für implizites Require |
| 40 | import x, y, z from 'mymodule' | 40 | import x, y, z from 'mymodule' |
| 41 | -- import with Python style | 41 | -- Import im Python-Stil |
| 42 | from 'module' import a, b, c | 42 | from 'module' import a, b, c |
| 43 | 43 | ||
| 44 | -- shortcut for requring a module | 44 | -- Kurzform zum Laden eines Moduls |
| 45 | do | 45 | do |
| 46 | import 'module' | 46 | import 'module' |
| 47 | import 'module_x' | 47 | import 'module_x' |
| 48 | import "d-a-s-h-e-s" | 48 | import "d-a-s-h-e-s" |
| 49 | import "module.part" | 49 | import "module.part" |
| 50 | 50 | ||
| 51 | -- requring module with aliasing or table destructuring | 51 | -- Modul mit Alias oder Tabellen-Destrukturierung laden |
| 52 | do | 52 | do |
| 53 | import "player" as PlayerModule | 53 | import "player" as PlayerModule |
| 54 | import "lpeg" as :C, :Ct, :Cmt | 54 | import "lpeg" as :C, :Ct, :Cmt |
| @@ -57,9 +57,9 @@ do | |||
| 57 | 57 | ||
| 58 | </YueDisplay> | 58 | </YueDisplay> |
| 59 | 59 | ||
| 60 | ## Import Global | 60 | ## Import von Globals |
| 61 | 61 | ||
| 62 | You can import specific globals into local variables with `import`. When importing a chain of global variable accessings, the last field will be assigned to the local variable. | 62 | Du kannst mit `import` bestimmte Globals in lokale Variablen importieren. Wenn du eine Kette von Globalzugriffen importierst, wird das letzte Feld der lokalen Variable zugewiesen. |
| 63 | 63 | ||
| 64 | ```yuescript | 64 | ```yuescript |
| 65 | do | 65 | do |
| @@ -78,21 +78,21 @@ do | |||
| 78 | 78 | ||
| 79 | </YueDisplay> | 79 | </YueDisplay> |
| 80 | 80 | ||
| 81 | ### Automatic Global Variable Import | 81 | ### Automatischer Global-Import |
| 82 | 82 | ||
| 83 | You can place `import global` at the top of a block to automatically import all names that have not been explicitly declared or assigned in the current scope as globals. These implicit imports are treated as local consts that reference the corresponding globals at the position of the statement. | 83 | Du kannst `import global` am Anfang eines Blocks platzieren, um automatisch alle Namen zu importieren, die im aktuellen Scope nicht explizit deklariert oder zugewiesen sind. Diese impliziten Importe werden als lokale `const` behandelt, die an die entsprechenden Globals zum Zeitpunkt der Anweisung gebunden sind. |
| 84 | 84 | ||
| 85 | Names that are explicitly declared as globals in the same scope will not be imported, so you can still assign to them. | 85 | Namen, die im selben Scope explizit als `global` deklariert werden, werden nicht importiert, sodass du sie weiterhin zuweisen kannst. |
| 86 | 86 | ||
| 87 | ```yuescript | 87 | ```yuescript |
| 88 | do | 88 | do |
| 89 | import global | 89 | import global |
| 90 | print "hello" | 90 | print "hallo" |
| 91 | math.random 3 | 91 | math.random 3 |
| 92 | -- print = nil -- error: imported globals are const | 92 | -- print = nil -- Fehler: importierte Globals sind const |
| 93 | 93 | ||
| 94 | do | 94 | do |
| 95 | -- explicit global variable will not be imported | 95 | -- explizite globale Variable wird nicht importiert |
| 96 | import global | 96 | import global |
| 97 | global FLAG | 97 | global FLAG |
| 98 | print FLAG | 98 | print FLAG |
| @@ -103,12 +103,12 @@ do | |||
| 103 | ```yue | 103 | ```yue |
| 104 | do | 104 | do |
| 105 | import global | 105 | import global |
| 106 | print "hello" | 106 | print "hallo" |
| 107 | math.random 3 | 107 | math.random 3 |
| 108 | -- print = nil -- error: imported globals are const | 108 | -- print = nil -- Fehler: importierte Globals sind const |
| 109 | 109 | ||
| 110 | do | 110 | do |
| 111 | -- explicit global variable will not be imported | 111 | -- explizite globale Variable wird nicht importiert |
| 112 | import global | 112 | import global |
| 113 | global FLAG | 113 | global FLAG |
| 114 | print FLAG | 114 | print FLAG |
| @@ -119,15 +119,15 @@ do | |||
| 119 | 119 | ||
| 120 | ## Export | 120 | ## Export |
| 121 | 121 | ||
| 122 | The export statement offers a concise way to define modules. | 122 | Die `export`-Anweisung bietet eine knappe Möglichkeit, Module zu definieren. |
| 123 | 123 | ||
| 124 | ### Named Export | 124 | ### Benannter Export |
| 125 | 125 | ||
| 126 | Named export will define a local variable as well as adding a field in the exported table. | 126 | Benannter Export definiert eine lokale Variable und fügt ein Feld in die exportierte Tabelle ein. |
| 127 | 127 | ||
| 128 | ```yuescript | 128 | ```yuescript |
| 129 | export a, b, c = 1, 2, 3 | 129 | export a, b, c = 1, 2, 3 |
| 130 | export cool = "cat" | 130 | export cool = "Katze" |
| 131 | 131 | ||
| 132 | export What = if this | 132 | export What = if this |
| 133 | "abc" | 133 | "abc" |
| @@ -144,7 +144,7 @@ export class Something | |||
| 144 | 144 | ||
| 145 | ```yue | 145 | ```yue |
| 146 | export a, b, c = 1, 2, 3 | 146 | export a, b, c = 1, 2, 3 |
| 147 | export cool = "cat" | 147 | export cool = "Katze" |
| 148 | 148 | ||
| 149 | export What = if this | 149 | export What = if this |
| 150 | "abc" | 150 | "abc" |
| @@ -160,7 +160,7 @@ export class Something | |||
| 160 | 160 | ||
| 161 | </YueDisplay> | 161 | </YueDisplay> |
| 162 | 162 | ||
| 163 | Doing named export with destructuring. | 163 | Benannter Export mit Destructuring. |
| 164 | 164 | ||
| 165 | ```yuescript | 165 | ```yuescript |
| 166 | export :loadstring, to_lua: tolua = yue | 166 | export :loadstring, to_lua: tolua = yue |
| @@ -175,7 +175,7 @@ export {itemA: {:fieldA = 'default'}} = tb | |||
| 175 | 175 | ||
| 176 | </YueDisplay> | 176 | </YueDisplay> |
| 177 | 177 | ||
| 178 | Export named items from module without creating local variables. | 178 | Benannte Elemente aus dem Modul exportieren, ohne lokale Variablen zu erstellen. |
| 179 | 179 | ||
| 180 | ```yuescript | 180 | ```yuescript |
| 181 | export.itemA = tb | 181 | export.itemA = tb |
| @@ -192,9 +192,9 @@ export["a-b-c"] = 123 | |||
| 192 | 192 | ||
| 193 | </YueDisplay> | 193 | </YueDisplay> |
| 194 | 194 | ||
| 195 | ### Unnamed Export | 195 | ### Unbenannter Export |
| 196 | 196 | ||
| 197 | Unnamed export will add the target item into the array part of the exported table. | 197 | Unbenannter Export fügt das Ziel-Element in den Array-Teil der exportierten Tabelle ein. |
| 198 | 198 | ||
| 199 | ```yuescript | 199 | ```yuescript |
| 200 | d, e, f = 3, 2, 1 | 200 | d, e, f = 3, 2, 1 |
| @@ -225,20 +225,20 @@ export with tmp | |||
| 225 | 225 | ||
| 226 | </YueDisplay> | 226 | </YueDisplay> |
| 227 | 227 | ||
| 228 | ### Default Export | 228 | ### Default-Export |
| 229 | 229 | ||
| 230 | Using the **default** keyword in export statement to replace the exported table with any thing. | 230 | Mit dem Schlüsselwort **default** in einer `export`-Anweisung wird die exportierte Tabelle durch ein beliebiges Objekt ersetzt. |
| 231 | 231 | ||
| 232 | ```yuescript | 232 | ```yuescript |
| 233 | export default -> | 233 | export default -> |
| 234 | print "hello" | 234 | print "hallo" |
| 235 | 123 | 235 | 123 |
| 236 | ``` | 236 | ``` |
| 237 | <YueDisplay> | 237 | <YueDisplay> |
| 238 | 238 | ||
| 239 | ```yue | 239 | ```yue |
| 240 | export default -> | 240 | export default -> |
| 241 | print "hello" | 241 | print "hallo" |
| 242 | 123 | 242 | 123 |
| 243 | ``` | 243 | ``` |
| 244 | 244 | ||
diff --git a/doc/docs/de/doc/advanced/try.md b/doc/docs/de/doc/advanced/try.md index 23c7877..4550e92 100644 --- a/doc/docs/de/doc/advanced/try.md +++ b/doc/docs/de/doc/advanced/try.md | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | # Try | 1 | # Try |
| 2 | 2 | ||
| 3 | The syntax for Lua error handling in a common form. | 3 | Die Syntax für Fehlerbehandlung in Lua in einer gängigen Form. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | try | 6 | try |
| @@ -20,10 +20,10 @@ catch err | |||
| 20 | success, result = try func 1, 2, 3 | 20 | success, result = try func 1, 2, 3 |
| 21 | 21 | ||
| 22 | try | 22 | try |
| 23 | print "trying" | 23 | print "Versuche" |
| 24 | func 1, 2, 3 | 24 | func 1, 2, 3 |
| 25 | 25 | ||
| 26 | -- working with if assignment pattern | 26 | -- Verwendung mit if-Zuweisungsmuster |
| 27 | if success, result := try func 1, 2, 3 | 27 | if success, result := try func 1, 2, 3 |
| 28 | catch err | 28 | catch err |
| 29 | print yue.traceback err | 29 | print yue.traceback err |
| @@ -49,10 +49,10 @@ catch err | |||
| 49 | success, result = try func 1, 2, 3 | 49 | success, result = try func 1, 2, 3 |
| 50 | 50 | ||
| 51 | try | 51 | try |
| 52 | print "trying" | 52 | print "Versuche" |
| 53 | func 1, 2, 3 | 53 | func 1, 2, 3 |
| 54 | 54 | ||
| 55 | -- working with if assignment pattern | 55 | -- Verwendung mit if-Zuweisungsmuster |
| 56 | if success, result := try func 1, 2, 3 | 56 | if success, result := try func 1, 2, 3 |
| 57 | catch err | 57 | catch err |
| 58 | print yue.traceback err | 58 | print yue.traceback err |
| @@ -63,18 +63,18 @@ catch err | |||
| 63 | 63 | ||
| 64 | ## Try? | 64 | ## Try? |
| 65 | 65 | ||
| 66 | `try?` is a simplified use for error handling syntax that omit the boolean status from the `try` statement, and it will return the result from the try block when success, return nil instead of error object otherwise. | 66 | `try?` ist eine vereinfachte Fehlerbehandlungs-Syntax, die den booleschen Status aus dem `try`-Statement weglässt. Bei Erfolg gibt sie das Ergebnis des `try`-Blocks zurück, ansonsten `nil` statt eines Fehlerobjekts. |
| 67 | 67 | ||
| 68 | ```yuescript | 68 | ```yuescript |
| 69 | a, b, c = try? func! | 69 | a, b, c = try? func! |
| 70 | 70 | ||
| 71 | -- with nil coalescing operator | 71 | -- mit Nil-Verschmelzungs-Operator |
| 72 | a = (try? func!) ?? "default" | 72 | a = (try? func!) ?? "Standardwert" |
| 73 | 73 | ||
| 74 | -- as function argument | 74 | -- als Funktionsargument |
| 75 | f try? func! | 75 | f try? func! |
| 76 | 76 | ||
| 77 | -- with catch block | 77 | -- mit catch-Block |
| 78 | f try? | 78 | f try? |
| 79 | print 123 | 79 | print 123 |
| 80 | func! | 80 | func! |
| @@ -87,13 +87,13 @@ catch e | |||
| 87 | ```yue | 87 | ```yue |
| 88 | a, b, c = try? func! | 88 | a, b, c = try? func! |
| 89 | 89 | ||
| 90 | -- with nil coalescing operator | 90 | -- mit Nil-Verschmelzungs-Operator |
| 91 | a = (try? func!) ?? "default" | 91 | a = (try? func!) ?? "Standardwert" |
| 92 | 92 | ||
| 93 | -- as function argument | 93 | -- als Funktionsargument |
| 94 | f try? func! | 94 | f try? func! |
| 95 | 95 | ||
| 96 | -- with catch block | 96 | -- mit catch-Block |
| 97 | f try? | 97 | f try? |
| 98 | print 123 | 98 | print 123 |
| 99 | func! | 99 | func! |
diff --git a/doc/docs/de/doc/assignment/assignment.md b/doc/docs/de/doc/assignment/assignment.md index 4dac6f4..b74501f 100644 --- a/doc/docs/de/doc/assignment/assignment.md +++ b/doc/docs/de/doc/assignment/assignment.md | |||
| @@ -1,25 +1,26 @@ | |||
| 1 | # Assignment | 1 | # Zuweisung |
| 2 | 2 | ||
| 3 | The variable is dynamic typed and is defined as local by default. But you can change the scope of declaration by **local** and **global** statement. | 3 | Variablen sind dynamisch typisiert und standardmäßig `local`. Du kannst den Geltungsbereich mit den Statements **local** und **global** ändern. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | hello = "world" | 6 | hello = "world" |
| 7 | a, b, c = 1, 2, 3 | 7 | a, b, c = 1, 2, 3 |
| 8 | hello = 123 -- uses the existing variable | 8 | hello = 123 -- nutzt die bestehende Variable |
| 9 | ``` | 9 | ``` |
| 10 | <YueDisplay> | 10 | <YueDisplay> |
| 11 | 11 | ||
| 12 | ```yue | 12 | ```yue |
| 13 | hello = "world" | 13 | hello = "world" |
| 14 | a, b, c = 1, 2, 3 | 14 | a, b, c = 1, 2, 3 |
| 15 | hello = 123 -- uses the existing variable | 15 | hello = 123 -- nutzt die bestehende Variable |
| 16 | ``` | 16 | ``` |
| 17 | 17 | ||
| 18 | </YueDisplay> | 18 | </YueDisplay> |
| 19 | 19 | ||
| 20 | ## Perform Update | 20 | ## Update-Zuweisung |
| 21 | |||
| 22 | Du kannst Update-Zuweisungen mit vielen binären Operatoren durchführen. | ||
| 21 | 23 | ||
| 22 | You can perform update assignment with many binary operators. | ||
| 23 | ```yuescript | 24 | ```yuescript |
| 24 | x = 1 | 25 | x = 1 |
| 25 | x += 1 | 26 | x += 1 |
| @@ -27,7 +28,7 @@ x -= 1 | |||
| 27 | x *= 10 | 28 | x *= 10 |
| 28 | x /= 10 | 29 | x /= 10 |
| 29 | x %= 10 | 30 | x %= 10 |
| 30 | s ..= "world" -- will add a new local if local variable is not exist | 31 | s ..= "world" -- legt eine neue lokale Variable an, wenn sie nicht existiert |
| 31 | arg or= "default value" | 32 | arg or= "default value" |
| 32 | ``` | 33 | ``` |
| 33 | <YueDisplay> | 34 | <YueDisplay> |
| @@ -39,15 +40,16 @@ x -= 1 | |||
| 39 | x *= 10 | 40 | x *= 10 |
| 40 | x /= 10 | 41 | x /= 10 |
| 41 | x %= 10 | 42 | x %= 10 |
| 42 | s ..= "world" -- will add a new local if local variable is not exist | 43 | s ..= "world" -- legt eine neue lokale Variable an, wenn sie nicht existiert |
| 43 | arg or= "default value" | 44 | arg or= "default value" |
| 44 | ``` | 45 | ``` |
| 45 | 46 | ||
| 46 | </YueDisplay> | 47 | </YueDisplay> |
| 47 | 48 | ||
| 48 | ## Chaining Assignment | 49 | ## Verkettete Zuweisung |
| 50 | |||
| 51 | Mit verketteten Zuweisungen kannst du mehrere Variablen auf denselben Wert setzen. | ||
| 49 | 52 | ||
| 50 | You can do chaining assignment to assign multiple items to hold the same value. | ||
| 51 | ```yuescript | 53 | ```yuescript |
| 52 | a = b = c = d = e = 0 | 54 | a = b = c = d = e = 0 |
| 53 | x = y = z = f! | 55 | x = y = z = f! |
| @@ -61,7 +63,8 @@ x = y = z = f! | |||
| 61 | 63 | ||
| 62 | </YueDisplay> | 64 | </YueDisplay> |
| 63 | 65 | ||
| 64 | ## Explicit Locals | 66 | ## Explizite Locals |
| 67 | |||
| 65 | ```yuescript | 68 | ```yuescript |
| 66 | do | 69 | do |
| 67 | local a = 1 | 70 | local a = 1 |
| @@ -99,7 +102,8 @@ do | |||
| 99 | 102 | ||
| 100 | </YueDisplay> | 103 | </YueDisplay> |
| 101 | 104 | ||
| 102 | ## Explicit Globals | 105 | ## Explizite Globals |
| 106 | |||
| 103 | ```yuescript | 107 | ```yuescript |
| 104 | do | 108 | do |
| 105 | global a = 1 | 109 | global a = 1 |
diff --git a/doc/docs/de/doc/assignment/destructuring-assignment.md b/doc/docs/de/doc/assignment/destructuring-assignment.md index e7b8046..0a08e22 100644 --- a/doc/docs/de/doc/assignment/destructuring-assignment.md +++ b/doc/docs/de/doc/assignment/destructuring-assignment.md | |||
| @@ -1,10 +1,10 @@ | |||
| 1 | # Destructuring Assignment | 1 | # Destructuring-Zuweisung |
| 2 | 2 | ||
| 3 | Destructuring assignment is a way to quickly extract values from a table by their name or position in array based tables. | 3 | Destructuring-Zuweisung ist eine Möglichkeit, schnell Werte aus einer Tabelle nach Name oder Position in array-basierten Tabellen zu extrahieren. |
| 4 | 4 | ||
| 5 | Typically when you see a table literal, {1,2,3}, it is on the right hand side of an assignment because it is a value. Destructuring assignment swaps the role of the table literal, and puts it on the left hand side of an assign statement. | 5 | Normalerweise steht ein Tabellenliteral wie `{1,2,3}` auf der rechten Seite einer Zuweisung, weil es ein Wert ist. Destructuring-Zuweisung tauscht die Rolle des Tabellenliterals und setzt es auf die linke Seite der Zuweisung. |
| 6 | 6 | ||
| 7 | This is best explained with examples. Here is how you would unpack the first two values from a table: | 7 | Am besten lässt sich das mit Beispielen erklären. So entpackst du die ersten zwei Werte einer Tabelle: |
| 8 | 8 | ||
| 9 | ```yuescript | 9 | ```yuescript |
| 10 | thing = [1, 2] | 10 | thing = [1, 2] |
| @@ -23,44 +23,44 @@ print a, b | |||
| 23 | 23 | ||
| 24 | </YueDisplay> | 24 | </YueDisplay> |
| 25 | 25 | ||
| 26 | In the destructuring table literal, the key represents the key to read from the right hand side, and the value represents the name the read value will be assigned to. | 26 | Im Destructuring-Tabellenliteral repräsentiert der Schlüssel den zu lesenden Schlüssel der rechten Seite, und der Wert ist der Name, dem der gelesene Wert zugewiesen wird. |
| 27 | 27 | ||
| 28 | ```yuescript | 28 | ```yuescript |
| 29 | obj = { | 29 | obj = { |
| 30 | hello: "world" | 30 | hello: "Welt" |
| 31 | day: "tuesday" | 31 | day: "Dienstag" |
| 32 | length: 20 | 32 | length: 20 |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | {hello: hello, day: the_day} = obj | 35 | {hello: hello, day: the_day} = obj |
| 36 | print hello, the_day | 36 | print hello, the_day |
| 37 | 37 | ||
| 38 | :day = obj -- OK to do simple destructuring without braces | 38 | :day = obj -- einfache Destructuring-Zuweisung ohne Klammern ist ok |
| 39 | ``` | 39 | ``` |
| 40 | <YueDisplay> | 40 | <YueDisplay> |
| 41 | 41 | ||
| 42 | ```yue | 42 | ```yue |
| 43 | obj = { | 43 | obj = { |
| 44 | hello: "world" | 44 | hello: "Welt" |
| 45 | day: "tuesday" | 45 | day: "Dienstag" |
| 46 | length: 20 | 46 | length: 20 |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | {hello: hello, day: the_day} = obj | 49 | {hello: hello, day: the_day} = obj |
| 50 | print hello, the_day | 50 | print hello, the_day |
| 51 | 51 | ||
| 52 | :day = obj -- OK to do simple destructuring without braces | 52 | :day = obj -- einfache Destructuring-Zuweisung ohne Klammern ist ok |
| 53 | ``` | 53 | ``` |
| 54 | 54 | ||
| 55 | </YueDisplay> | 55 | </YueDisplay> |
| 56 | 56 | ||
| 57 | This also works with nested data structures as well: | 57 | Das funktioniert auch mit verschachtelten Datenstrukturen: |
| 58 | 58 | ||
| 59 | ```yuescript | 59 | ```yuescript |
| 60 | obj2 = { | 60 | obj2 = { |
| 61 | numbers: [1, 2, 3, 4] | 61 | numbers: [1, 2, 3, 4] |
| 62 | properties: { | 62 | properties: { |
| 63 | color: "green" | 63 | color: "grün" |
| 64 | height: 13.5 | 64 | height: 13.5 |
| 65 | } | 65 | } |
| 66 | } | 66 | } |
| @@ -74,7 +74,7 @@ print first, second, color | |||
| 74 | obj2 = { | 74 | obj2 = { |
| 75 | numbers: [1, 2, 3, 4] | 75 | numbers: [1, 2, 3, 4] |
| 76 | properties: { | 76 | properties: { |
| 77 | color: "green" | 77 | color: "grün" |
| 78 | height: 13.5 | 78 | height: 13.5 |
| 79 | } | 79 | } |
| 80 | } | 80 | } |
| @@ -85,7 +85,7 @@ print first, second, color | |||
| 85 | 85 | ||
| 86 | </YueDisplay> | 86 | </YueDisplay> |
| 87 | 87 | ||
| 88 | If the destructuring statement is complicated, feel free to spread it out over a few lines. A slightly more complicated example: | 88 | Wenn die Destructuring-Anweisung kompliziert ist, kannst du sie gerne auf mehrere Zeilen verteilen. Ein etwas komplexeres Beispiel: |
| 89 | 89 | ||
| 90 | ```yuescript | 90 | ```yuescript |
| 91 | { | 91 | { |
| @@ -108,7 +108,7 @@ If the destructuring statement is complicated, feel free to spread it out over a | |||
| 108 | 108 | ||
| 109 | </YueDisplay> | 109 | </YueDisplay> |
| 110 | 110 | ||
| 111 | It's common to extract values from at table and assign them the local variables that have the same name as the key. In order to avoid repetition we can use the **:** prefix operator: | 111 | Es ist üblich, Werte aus einer Tabelle zu extrahieren und ihnen lokale Variablen mit demselben Namen wie der Schlüssel zuzuweisen. Um Wiederholungen zu vermeiden, kannst du den Präfix-Operator **:** verwenden: |
| 112 | 112 | ||
| 113 | ```yuescript | 113 | ```yuescript |
| 114 | {:concat, :insert} = table | 114 | {:concat, :insert} = table |
| @@ -121,7 +121,7 @@ It's common to extract values from at table and assign them the local variables | |||
| 121 | 121 | ||
| 122 | </YueDisplay> | 122 | </YueDisplay> |
| 123 | 123 | ||
| 124 | This is effectively the same as import, but we can rename fields we want to extract by mixing the syntax: | 124 | Das ist effektiv dasselbe wie `import`, aber du kannst Felder umbenennen, indem du die Syntax mischst: |
| 125 | 125 | ||
| 126 | ```yuescript | 126 | ```yuescript |
| 127 | {:mix, :max, random: rand} = math | 127 | {:mix, :max, random: rand} = math |
| @@ -134,20 +134,20 @@ This is effectively the same as import, but we can rename fields we want to extr | |||
| 134 | 134 | ||
| 135 | </YueDisplay> | 135 | </YueDisplay> |
| 136 | 136 | ||
| 137 | You can write default values while doing destructuring like: | 137 | Du kannst Standardwerte beim Destructuring angeben, z. B.: |
| 138 | 138 | ||
| 139 | ```yuescript | 139 | ```yuescript |
| 140 | {:name = "nameless", :job = "jobless"} = person | 140 | {:name = "namenlos", :job = "arbeitlos"} = person |
| 141 | ``` | 141 | ``` |
| 142 | <YueDisplay> | 142 | <YueDisplay> |
| 143 | 143 | ||
| 144 | ```yue | 144 | ```yue |
| 145 | {:name = "nameless", :job = "jobless"} = person | 145 | {:name = "namenlos", :job = "arbeitlos"} = person |
| 146 | ``` | 146 | ``` |
| 147 | 147 | ||
| 148 | </YueDisplay> | 148 | </YueDisplay> |
| 149 | 149 | ||
| 150 | You can use `_` as placeholder when doing a list destructuring: | 150 | Du kannst `_` als Platzhalter verwenden, wenn du eine Listen-Destructuring-Zuweisung machst: |
| 151 | 151 | ||
| 152 | ```yuescript | 152 | ```yuescript |
| 153 | [_, two, _, four] = items | 153 | [_, two, _, four] = items |
| @@ -160,64 +160,64 @@ You can use `_` as placeholder when doing a list destructuring: | |||
| 160 | 160 | ||
| 161 | </YueDisplay> | 161 | </YueDisplay> |
| 162 | 162 | ||
| 163 | ## Range Destructuring | 163 | ## Bereichs-Destructuring |
| 164 | 164 | ||
| 165 | You can use the spread operator `...` in list destructuring to capture a range of values. This is useful when you want to extract specific elements from the beginning and end of a list while collecting the rest in between. | 165 | Du kannst den Spread-Operator `...` in Listen-Destructuring verwenden, um einen Wertebereich zu erfassen. Das ist nützlich, wenn du bestimmte Elemente am Anfang und Ende einer Liste extrahieren und den Rest dazwischen sammeln willst. |
| 166 | 166 | ||
| 167 | ```yuescript | 167 | ```yuescript |
| 168 | orders = ["first", "second", "third", "fourth", "last"] | 168 | orders = ["erster", "zweiter", "dritter", "vierter", "letzter"] |
| 169 | [first, ...bulk, last] = orders | 169 | [first, ...bulk, last] = orders |
| 170 | print first -- prints: first | 170 | print first -- gibt aus: erster |
| 171 | print bulk -- prints: {"second", "third", "fourth"} | 171 | print bulk -- gibt aus: {"zweiter", "dritter", "vierter"} |
| 172 | print last -- prints: last | 172 | print last -- gibt aus: letzter |
| 173 | ``` | 173 | ``` |
| 174 | <YueDisplay> | 174 | <YueDisplay> |
| 175 | 175 | ||
| 176 | ```yue | 176 | ```yue |
| 177 | orders = ["first", "second", "third", "fourth", "last"] | 177 | orders = ["erster", "zweiter", "dritter", "vierter", "letzter"] |
| 178 | [first, ...bulk, last] = orders | 178 | [first, ...bulk, last] = orders |
| 179 | print first -- prints: first | 179 | print first -- gibt aus: erster |
| 180 | print bulk -- prints: {"second", "third", "fourth"} | 180 | print bulk -- gibt aus: {"zweiter", "dritter", "vierter"} |
| 181 | print last -- prints: last | 181 | print last -- gibt aus: letzter |
| 182 | ``` | 182 | ``` |
| 183 | 183 | ||
| 184 | </YueDisplay> | 184 | </YueDisplay> |
| 185 | 185 | ||
| 186 | The spread operator can be used in different positions to capture different ranges, and you can use `_` as a placeholder for the values you don't want to capture: | 186 | Der Spread-Operator kann an unterschiedlichen Positionen verwendet werden, um unterschiedliche Bereiche zu erfassen, und du kannst `_` als Platzhalter für Werte verwenden, die du nicht erfassen willst: |
| 187 | 187 | ||
| 188 | ```yuescript | 188 | ```yuescript |
| 189 | -- Capture everything after first element | 189 | -- Alles nach dem ersten Element erfassen |
| 190 | [first, ...rest] = orders | 190 | [first, ...rest] = orders |
| 191 | 191 | ||
| 192 | -- Capture everything before last element | 192 | -- Alles vor dem letzten Element erfassen |
| 193 | [...start, last] = orders | 193 | [...start, last] = orders |
| 194 | 194 | ||
| 195 | -- Capture things except the middle elements | 195 | -- Alles außer den mittleren Elementen erfassen |
| 196 | [first, ..._, last] = orders | 196 | [first, ..._, last] = orders |
| 197 | ``` | 197 | ``` |
| 198 | <YueDisplay> | 198 | <YueDisplay> |
| 199 | 199 | ||
| 200 | ```yue | 200 | ```yue |
| 201 | -- Capture everything after first element | 201 | -- Alles nach dem ersten Element erfassen |
| 202 | [first, ...rest] = orders | 202 | [first, ...rest] = orders |
| 203 | 203 | ||
| 204 | -- Capture everything before last element | 204 | -- Alles vor dem letzten Element erfassen |
| 205 | [...start, last] = orders | 205 | [...start, last] = orders |
| 206 | 206 | ||
| 207 | -- Capture things except the middle elements | 207 | -- Alles außer den mittleren Elementen erfassen |
| 208 | [first, ..._, last] = orders | 208 | [first, ..._, last] = orders |
| 209 | ``` | 209 | ``` |
| 210 | 210 | ||
| 211 | </YueDisplay> | 211 | </YueDisplay> |
| 212 | 212 | ||
| 213 | ## Destructuring In Other Places | 213 | ## Destructuring an anderen Stellen |
| 214 | 214 | ||
| 215 | Destructuring can also show up in places where an assignment implicitly takes place. An example of this is a for loop: | 215 | Destructuring kann auch an Stellen vorkommen, an denen eine Zuweisung implizit erfolgt. Ein Beispiel ist eine `for`-Schleife: |
| 216 | 216 | ||
| 217 | ```yuescript | 217 | ```yuescript |
| 218 | tuples = [ | 218 | tuples = [ |
| 219 | ["hello", "world"] | 219 | ["hallo", "Welt"] |
| 220 | ["egg", "head"] | 220 | ["Ei", "Kopf"] |
| 221 | ] | 221 | ] |
| 222 | 222 | ||
| 223 | for [left, right] in *tuples | 223 | for [left, right] in *tuples |
| @@ -227,8 +227,8 @@ for [left, right] in *tuples | |||
| 227 | 227 | ||
| 228 | ```yue | 228 | ```yue |
| 229 | tuples = [ | 229 | tuples = [ |
| 230 | ["hello", "world"] | 230 | ["hallo", "Welt"] |
| 231 | ["egg", "head"] | 231 | ["Ei", "Kopf"] |
| 232 | ] | 232 | ] |
| 233 | 233 | ||
| 234 | for [left, right] in *tuples | 234 | for [left, right] in *tuples |
| @@ -237,4 +237,4 @@ for [left, right] in *tuples | |||
| 237 | 237 | ||
| 238 | </YueDisplay> | 238 | </YueDisplay> |
| 239 | 239 | ||
| 240 | We know each element in the array table is a two item tuple, so we can unpack it directly in the names clause of the for statement using a destructure. | 240 | Wir wissen, dass jedes Element der Array-Tabelle ein 2er-Tupel ist, daher können wir es direkt in der Namensliste der `for`-Anweisung mittels Destructuring entpacken. |
diff --git a/doc/docs/de/doc/assignment/if-assignment.md b/doc/docs/de/doc/assignment/if-assignment.md index 02984e8..884a8d2 100644 --- a/doc/docs/de/doc/assignment/if-assignment.md +++ b/doc/docs/de/doc/assignment/if-assignment.md | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | # If Assignment | 1 | # If-Zuweisung |
| 2 | 2 | ||
| 3 | `if` and `elseif` blocks can take an assignment in place of a conditional expression. Upon evaluating the conditional, the assignment will take place and the value that was assigned to will be used as the conditional expression. The assigned variable is only in scope for the body of the conditional, meaning it is never available if the value is not truthy. And you have to use "the walrus operator" `:=` instead of `=` to do assignment. | 3 | `if`- und `elseif`-Blöcke können eine Zuweisung anstelle eines Bedingungsausdrucks enthalten. Beim Auswerten der Bedingung findet die Zuweisung statt, und der zugewiesene Wert wird als Bedingung verwendet. Die zugewiesene Variable ist nur im Geltungsbereich des Bedingungsblocks verfügbar, d. h. sie ist nicht verfügbar, wenn der Wert nicht truthy ist. Für die Zuweisung musst du den "Walrus-Operator" `:=` statt `=` verwenden. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | if user := database.find_user "moon" | 6 | if user := database.find_user "moon" |
| @@ -17,55 +17,56 @@ if user := database.find_user "moon" | |||
| 17 | 17 | ||
| 18 | ```yuescript | 18 | ```yuescript |
| 19 | if hello := os.getenv "hello" | 19 | if hello := os.getenv "hello" |
| 20 | print "You have hello", hello | 20 | print "Du hast hello", hello |
| 21 | elseif world := os.getenv "world" | 21 | elseif world := os.getenv "world" |
| 22 | print "you have world", world | 22 | print "Du hast world", world |
| 23 | else | 23 | else |
| 24 | print "nothing :(" | 24 | print "nichts :(" |
| 25 | ``` | 25 | ``` |
| 26 | <YueDisplay> | 26 | <YueDisplay> |
| 27 | 27 | ||
| 28 | ```yue | 28 | ```yue |
| 29 | if hello := os.getenv "hello" | 29 | if hello := os.getenv "hello" |
| 30 | print "You have hello", hello | 30 | print "Du hast hello", hello |
| 31 | elseif world := os.getenv "world" | 31 | elseif world := os.getenv "world" |
| 32 | print "you have world", world | 32 | print "Du hast world", world |
| 33 | else | 33 | else |
| 34 | print "nothing :(" | 34 | print "nichts :(" |
| 35 | ``` | 35 | ``` |
| 36 | 36 | ||
| 37 | </YueDisplay> | 37 | </YueDisplay> |
| 38 | 38 | ||
| 39 | If assignment with multiple return values. Only the first value is getting checked, other values are scoped. | 39 | If-Zuweisung mit mehreren Rückgabewerten. Nur der erste Wert wird geprüft, andere Werte bleiben im Scope. |
| 40 | |||
| 40 | ```yuescript | 41 | ```yuescript |
| 41 | if success, result := pcall -> "get result without problems" | 42 | if success, result := pcall -> "Ergebnis ohne Probleme erhalten" |
| 42 | print result -- variable result is scoped | 43 | print result -- Variable result ist im Scope |
| 43 | print "OK" | 44 | print "OK" |
| 44 | ``` | 45 | ``` |
| 45 | <YueDisplay> | 46 | <YueDisplay> |
| 46 | 47 | ||
| 47 | ```yue | 48 | ```yue |
| 48 | if success, result := pcall -> "get result without problems" | 49 | if success, result := pcall -> "Ergebnis ohne Probleme erhalten" |
| 49 | print result -- variable result is scoped | 50 | print result -- Variable result ist im Scope |
| 50 | print "OK" | 51 | print "OK" |
| 51 | ``` | 52 | ``` |
| 52 | 53 | ||
| 53 | </YueDisplay> | 54 | </YueDisplay> |
| 54 | 55 | ||
| 55 | ## While Assignment | 56 | ## While-Zuweisung |
| 56 | 57 | ||
| 57 | You can also use if assignment in a while loop to get the value as the loop condition. | 58 | Du kannst if-Zuweisung auch in einer while-Schleife verwenden, um den Wert als Schleifenbedingung zu nutzen. |
| 58 | 59 | ||
| 59 | ```yuescript | 60 | ```yuescript |
| 60 | while byte := stream\read_one! | 61 | while byte := stream\read_one! |
| 61 | -- do something with the byte | 62 | -- mit dem Byte etwas anfangen |
| 62 | print byte | 63 | print byte |
| 63 | ``` | 64 | ``` |
| 64 | <YueDisplay> | 65 | <YueDisplay> |
| 65 | 66 | ||
| 66 | ```yue | 67 | ```yue |
| 67 | while byte := stream\read_one! | 68 | while byte := stream\read_one! |
| 68 | -- do something with the byte | 69 | -- mit dem Byte etwas anfangen |
| 69 | print byte | 70 | print byte |
| 70 | ``` | 71 | ``` |
| 71 | 72 | ||
diff --git a/doc/docs/de/doc/assignment/the-using-clause-controlling-destructive-assignment.md b/doc/docs/de/doc/assignment/the-using-clause-controlling-destructive-assignment.md index fb9b740..63bf016 100644 --- a/doc/docs/de/doc/assignment/the-using-clause-controlling-destructive-assignment.md +++ b/doc/docs/de/doc/assignment/the-using-clause-controlling-destructive-assignment.md | |||
| @@ -1,11 +1,11 @@ | |||
| 1 | # The Using Clause; Controlling Destructive Assignment | 1 | # Die Using-Klausel: Destruktive Zuweisung kontrollieren |
| 2 | 2 | ||
| 3 | While lexical scoping can be a great help in reducing the complexity of the code we write, things can get unwieldy as the code size increases. Consider the following snippet: | 3 | Lexikalisches Scoping kann die Komplexität des Codes stark reduzieren, aber mit wachsendem Codeumfang kann es unübersichtlich werden. Betrachte folgendes Beispiel: |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | i = 100 | 6 | i = 100 |
| 7 | 7 | ||
| 8 | -- many lines of code... | 8 | -- viele Zeilen Code... |
| 9 | 9 | ||
| 10 | my_func = -> | 10 | my_func = -> |
| 11 | i = 10 | 11 | i = 10 |
| @@ -15,14 +15,14 @@ my_func = -> | |||
| 15 | 15 | ||
| 16 | my_func! | 16 | my_func! |
| 17 | 17 | ||
| 18 | print i -- will print 0 | 18 | print i -- wird 0 ausgeben |
| 19 | ``` | 19 | ``` |
| 20 | <YueDisplay> | 20 | <YueDisplay> |
| 21 | 21 | ||
| 22 | ```yue | 22 | ```yue |
| 23 | i = 100 | 23 | i = 100 |
| 24 | 24 | ||
| 25 | -- many lines of code... | 25 | -- viele Zeilen Code... |
| 26 | 26 | ||
| 27 | my_func = -> | 27 | my_func = -> |
| 28 | i = 10 | 28 | i = 10 |
| @@ -32,25 +32,25 @@ my_func = -> | |||
| 32 | 32 | ||
| 33 | my_func! | 33 | my_func! |
| 34 | 34 | ||
| 35 | print i -- will print 0 | 35 | print i -- wird 0 ausgeben |
| 36 | ``` | 36 | ``` |
| 37 | 37 | ||
| 38 | </YueDisplay> | 38 | </YueDisplay> |
| 39 | 39 | ||
| 40 | In my_func, we've overwritten the value of i mistakenly. In this example it is quite obvious, but consider a large, or foreign code base where it isn't clear what names have already been declared. | 40 | In `my_func` haben wir den Wert von `i` versehentlich überschrieben. In diesem Beispiel ist es offensichtlich, aber in einer großen oder fremden Codebasis ist oft nicht klar, welche Namen bereits deklariert wurden. |
| 41 | 41 | ||
| 42 | It would be helpful to say which variables from the enclosing scope we intend on change, in order to prevent us from changing others by accident. | 42 | Es wäre hilfreich, anzugeben, welche Variablen aus dem umschließenden Scope wir verändern wollen, um versehentliche Änderungen zu vermeiden. |
| 43 | 43 | ||
| 44 | The using keyword lets us do that. using nil makes sure that no closed variables are overwritten in assignment. The using clause is placed after the argument list in a function, or in place of it if there are no arguments. | 44 | Das Schlüsselwort `using` ermöglicht das. `using nil` stellt sicher, dass keine geschlossenen Variablen bei Zuweisungen überschrieben werden. Die `using`-Klausel steht nach der Argumentliste einer Funktion oder ersetzt sie, wenn es keine Argumente gibt. |
| 45 | 45 | ||
| 46 | ```yuescript | 46 | ```yuescript |
| 47 | i = 100 | 47 | i = 100 |
| 48 | 48 | ||
| 49 | my_func = (using nil) -> | 49 | my_func = (using nil) -> |
| 50 | i = "hello" -- a new local variable is created here | 50 | i = "hello" -- hier wird eine neue lokale Variable erstellt |
| 51 | 51 | ||
| 52 | my_func! | 52 | my_func! |
| 53 | print i -- prints 100, i is unaffected | 53 | print i -- gibt 100 aus, i bleibt unverändert |
| 54 | ``` | 54 | ``` |
| 55 | <YueDisplay> | 55 | <YueDisplay> |
| 56 | 56 | ||
| @@ -58,27 +58,27 @@ print i -- prints 100, i is unaffected | |||
| 58 | i = 100 | 58 | i = 100 |
| 59 | 59 | ||
| 60 | my_func = (using nil) -> | 60 | my_func = (using nil) -> |
| 61 | i = "hello" -- a new local variable is created here | 61 | i = "hello" -- hier wird eine neue lokale Variable erstellt |
| 62 | 62 | ||
| 63 | my_func! | 63 | my_func! |
| 64 | print i -- prints 100, i is unaffected | 64 | print i -- gibt 100 aus, i bleibt unverändert |
| 65 | ``` | 65 | ``` |
| 66 | 66 | ||
| 67 | </YueDisplay> | 67 | </YueDisplay> |
| 68 | 68 | ||
| 69 | Multiple names can be separated by commas. Closure values can still be accessed, they just cant be modified: | 69 | Mehrere Namen können durch Kommas getrennt werden. Closure-Werte können weiterhin gelesen, aber nicht verändert werden: |
| 70 | 70 | ||
| 71 | ```yuescript | 71 | ```yuescript |
| 72 | tmp = 1213 | 72 | tmp = 1213 |
| 73 | i, k = 100, 50 | 73 | i, k = 100, 50 |
| 74 | 74 | ||
| 75 | my_func = (add using k, i) -> | 75 | my_func = (add using k, i) -> |
| 76 | tmp = tmp + add -- a new local tmp is created | 76 | tmp = tmp + add -- ein neues lokales tmp wird erstellt |
| 77 | i += tmp | 77 | i += tmp |
| 78 | k += tmp | 78 | k += tmp |
| 79 | 79 | ||
| 80 | my_func(22) | 80 | my_func(22) |
| 81 | print i, k -- these have been updated | 81 | print i, k -- diese wurden aktualisiert |
| 82 | ``` | 82 | ``` |
| 83 | <YueDisplay> | 83 | <YueDisplay> |
| 84 | 84 | ||
| @@ -87,12 +87,12 @@ tmp = 1213 | |||
| 87 | i, k = 100, 50 | 87 | i, k = 100, 50 |
| 88 | 88 | ||
| 89 | my_func = (add using k, i) -> | 89 | my_func = (add using k, i) -> |
| 90 | tmp = tmp + add -- a new local tmp is created | 90 | tmp = tmp + add -- ein neues lokales tmp wird erstellt |
| 91 | i += tmp | 91 | i += tmp |
| 92 | k += tmp | 92 | k += tmp |
| 93 | 93 | ||
| 94 | my_func(22) | 94 | my_func(22) |
| 95 | print i, k -- these have been updated | 95 | print i, k -- diese wurden aktualisiert |
| 96 | ``` | 96 | ``` |
| 97 | 97 | ||
| 98 | </YueDisplay> | 98 | </YueDisplay> |
diff --git a/doc/docs/de/doc/assignment/varargs-assignment.md b/doc/docs/de/doc/assignment/varargs-assignment.md index 1d66680..b211a8a 100644 --- a/doc/docs/de/doc/assignment/varargs-assignment.md +++ b/doc/docs/de/doc/assignment/varargs-assignment.md | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | # Varargs Assignment | 1 | # Varargs-Zuweisung |
| 2 | 2 | ||
| 3 | You can assign the results returned from a function to a varargs symbol `...`. And then access its content using the Lua way. | 3 | Du kannst Rückgabewerte einer Funktion dem Varargs-Symbol `...` zuweisen und dann den Inhalt auf die Lua-Weise auslesen. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | list = [1, 2, 3, 4, 5] | 6 | list = [1, 2, 3, 4, 5] |
diff --git a/doc/docs/de/doc/control-flow/conditionals.md b/doc/docs/de/doc/control-flow/conditionals.md index 5ba81cf..d20e6e3 100644 --- a/doc/docs/de/doc/control-flow/conditionals.md +++ b/doc/docs/de/doc/control-flow/conditionals.md | |||
| @@ -1,55 +1,55 @@ | |||
| 1 | # Conditionals | 1 | # Bedingungen |
| 2 | 2 | ||
| 3 | ```yuescript | 3 | ```yuescript |
| 4 | have_coins = false | 4 | have_coins = false |
| 5 | if have_coins | 5 | if have_coins |
| 6 | print "Got coins" | 6 | print "Münzen erhalten" |
| 7 | else | 7 | else |
| 8 | print "No coins" | 8 | print "Keine Münzen" |
| 9 | ``` | 9 | ``` |
| 10 | <YueDisplay> | 10 | <YueDisplay> |
| 11 | 11 | ||
| 12 | ```yue | 12 | ```yue |
| 13 | have_coins = false | 13 | have_coins = false |
| 14 | if have_coins | 14 | if have_coins |
| 15 | print "Got coins" | 15 | print "Münzen erhalten" |
| 16 | else | 16 | else |
| 17 | print "No coins" | 17 | print "Keine Münzen" |
| 18 | ``` | 18 | ``` |
| 19 | 19 | ||
| 20 | </YueDisplay> | 20 | </YueDisplay> |
| 21 | 21 | ||
| 22 | A short syntax for single statements can also be used: | 22 | Eine Kurzsyntax für einzelne Anweisungen kann ebenfalls verwendet werden: |
| 23 | 23 | ||
| 24 | ```yuescript | 24 | ```yuescript |
| 25 | have_coins = false | 25 | have_coins = false |
| 26 | if have_coins then print "Got coins" else print "No coins" | 26 | if have_coins then print "Münzen erhalten" else print "Keine Münzen" |
| 27 | ``` | 27 | ``` |
| 28 | <YueDisplay> | 28 | <YueDisplay> |
| 29 | 29 | ||
| 30 | ```yue | 30 | ```yue |
| 31 | have_coins = false | 31 | have_coins = false |
| 32 | if have_coins then print "Got coins" else print "No coins" | 32 | if have_coins then print "Münzen erhalten" else print "Keine Münzen" |
| 33 | ``` | 33 | ``` |
| 34 | 34 | ||
| 35 | </YueDisplay> | 35 | </YueDisplay> |
| 36 | 36 | ||
| 37 | Because if statements can be used as expressions, this can also be written as: | 37 | Da `if`-Anweisungen als Ausdrücke verwendet werden können, kann man das auch so schreiben: |
| 38 | 38 | ||
| 39 | ```yuescript | 39 | ```yuescript |
| 40 | have_coins = false | 40 | have_coins = false |
| 41 | print if have_coins then "Got coins" else "No coins" | 41 | print if have_coins then "Münzen erhalten" else "Keine Münzen" |
| 42 | ``` | 42 | ``` |
| 43 | <YueDisplay> | 43 | <YueDisplay> |
| 44 | 44 | ||
| 45 | ```yue | 45 | ```yue |
| 46 | have_coins = false | 46 | have_coins = false |
| 47 | print if have_coins then "Got coins" else "No coins" | 47 | print if have_coins then "Münzen erhalten" else "Keine Münzen" |
| 48 | ``` | 48 | ``` |
| 49 | 49 | ||
| 50 | </YueDisplay> | 50 | </YueDisplay> |
| 51 | 51 | ||
| 52 | Conditionals can also be used in return statements and assignments: | 52 | Bedingungen können auch in `return`-Anweisungen und Zuweisungen verwendet werden: |
| 53 | 53 | ||
| 54 | ```yuescript | 54 | ```yuescript |
| 55 | is_tall = (name) -> | 55 | is_tall = (name) -> |
| @@ -59,11 +59,11 @@ is_tall = (name) -> | |||
| 59 | false | 59 | false |
| 60 | 60 | ||
| 61 | message = if is_tall "Rob" | 61 | message = if is_tall "Rob" |
| 62 | "I am very tall" | 62 | "Ich bin sehr groß" |
| 63 | else | 63 | else |
| 64 | "I am not so tall" | 64 | "Ich bin nicht so groß" |
| 65 | 65 | ||
| 66 | print message -- prints: I am very tall | 66 | print message -- gibt aus: Ich bin sehr groß |
| 67 | ``` | 67 | ``` |
| 68 | <YueDisplay> | 68 | <YueDisplay> |
| 69 | 69 | ||
| @@ -75,26 +75,26 @@ is_tall = (name) -> | |||
| 75 | false | 75 | false |
| 76 | 76 | ||
| 77 | message = if is_tall "Rob" | 77 | message = if is_tall "Rob" |
| 78 | "I am very tall" | 78 | "Ich bin sehr groß" |
| 79 | else | 79 | else |
| 80 | "I am not so tall" | 80 | "Ich bin nicht so groß" |
| 81 | 81 | ||
| 82 | print message -- prints: I am very tall | 82 | print message -- gibt aus: Ich bin sehr groß |
| 83 | ``` | 83 | ``` |
| 84 | 84 | ||
| 85 | </YueDisplay> | 85 | </YueDisplay> |
| 86 | 86 | ||
| 87 | The opposite of if is unless: | 87 | Das Gegenteil von `if` ist `unless`: |
| 88 | 88 | ||
| 89 | ```yuescript | 89 | ```yuescript |
| 90 | unless os.date("%A") == "Monday" | 90 | unless os.date("%A") == "Monday" |
| 91 | print "it is not Monday!" | 91 | print "Es ist nicht Montag!" |
| 92 | ``` | 92 | ``` |
| 93 | <YueDisplay> | 93 | <YueDisplay> |
| 94 | 94 | ||
| 95 | ```yue | 95 | ```yue |
| 96 | unless os.date("%A") == "Monday" | 96 | unless os.date("%A") == "Monday" |
| 97 | print "it is not Monday!" | 97 | print "Es ist nicht Montag!" |
| 98 | ``` | 98 | ``` |
| 99 | 99 | ||
| 100 | </YueDisplay> | 100 | </YueDisplay> |
| @@ -110,18 +110,18 @@ print "You're lucky!" unless math.random! > 0.1 | |||
| 110 | 110 | ||
| 111 | </YueDisplay> | 111 | </YueDisplay> |
| 112 | 112 | ||
| 113 | ## In Expression | 113 | ## In-Ausdruck |
| 114 | 114 | ||
| 115 | You can write range checking code with an `in-expression`. | 115 | Mit einem `in`-Ausdruck kannst du Bereichsprüfungen schreiben. |
| 116 | 116 | ||
| 117 | ```yuescript | 117 | ```yuescript |
| 118 | a = 5 | 118 | a = 5 |
| 119 | 119 | ||
| 120 | if a in [1, 3, 5, 7] | 120 | if a in [1, 3, 5, 7] |
| 121 | print "checking equality with discrete values" | 121 | print "Gleichheitsprüfung mit diskreten Werten" |
| 122 | 122 | ||
| 123 | if a in list | 123 | if a in list |
| 124 | print "checking if `a` is in a list" | 124 | print "Prüfen, ob `a` in einer Liste ist" |
| 125 | ``` | 125 | ``` |
| 126 | <YueDisplay> | 126 | <YueDisplay> |
| 127 | 127 | ||
| @@ -129,21 +129,10 @@ if a in list | |||
| 129 | a = 5 | 129 | a = 5 |
| 130 | 130 | ||
| 131 | if a in [1, 3, 5, 7] | 131 | if a in [1, 3, 5, 7] |
| 132 | print "checking equality with discrete values" | 132 | print "Gleichheitsprüfung mit diskreten Werten" |
| 133 | 133 | ||
| 134 | if a in list | 134 | if a in list |
| 135 | print "checking if `a` is in a list" | 135 | print "Prüfen, ob `a` in einer Liste ist" |
| 136 | ``` | ||
| 137 | |||
| 138 | </YueDisplay> | ||
| 139 | |||
| 140 | ```yuescript | ||
| 141 | print "You're lucky!" unless math.random! > 0.1 | ||
| 142 | ``` | ||
| 143 | <YueDisplay> | ||
| 144 | |||
| 145 | ```yue | ||
| 146 | print "You're lucky!" unless math.random! > 0.1 | ||
| 147 | ``` | 136 | ``` |
| 148 | 137 | ||
| 149 | </YueDisplay> | 138 | </YueDisplay> |
diff --git a/doc/docs/de/doc/control-flow/continue.md b/doc/docs/de/doc/control-flow/continue.md index b000765..a6210d4 100644 --- a/doc/docs/de/doc/control-flow/continue.md +++ b/doc/docs/de/doc/control-flow/continue.md | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | # Continue | 1 | # Continue |
| 2 | 2 | ||
| 3 | A continue statement can be used to skip the current iteration in a loop. | 3 | Eine `continue`-Anweisung überspringt die aktuelle Iteration einer Schleife. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | i = 0 | 6 | i = 0 |
| @@ -21,7 +21,7 @@ while i < 10 | |||
| 21 | 21 | ||
| 22 | </YueDisplay> | 22 | </YueDisplay> |
| 23 | 23 | ||
| 24 | continue can also be used with loop expressions to prevent that iteration from accumulating into the result. This examples filters the array table into just even numbers: | 24 | `continue` kann auch mit Schleifenausdrücken verwendet werden, um zu verhindern, dass diese Iteration in das Ergebnis akkumuliert wird. Dieses Beispiel filtert die Array-Tabelle auf gerade Zahlen: |
| 25 | 25 | ||
| 26 | ```yuescript | 26 | ```yuescript |
| 27 | my_numbers = [1, 2, 3, 4, 5, 6] | 27 | my_numbers = [1, 2, 3, 4, 5, 6] |
diff --git a/doc/docs/de/doc/control-flow/for-loop.md b/doc/docs/de/doc/control-flow/for-loop.md index cabcde5..3bf63d4 100644 --- a/doc/docs/de/doc/control-flow/for-loop.md +++ b/doc/docs/de/doc/control-flow/for-loop.md | |||
| @@ -1,12 +1,12 @@ | |||
| 1 | # For Loop | 1 | # For-Schleife |
| 2 | 2 | ||
| 3 | There are two for loop forms, just like in Lua. A numeric one and a generic one: | 3 | Es gibt zwei Formen der `for`-Schleife, genau wie in Lua: eine numerische und eine generische. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | for i = 10, 20 | 6 | for i = 10, 20 |
| 7 | print i | 7 | print i |
| 8 | 8 | ||
| 9 | for k = 1, 15, 2 -- an optional step provided | 9 | for k = 1, 15, 2 -- ein optionaler Schritt |
| 10 | print k | 10 | print k |
| 11 | 11 | ||
| 12 | for key, value in pairs object | 12 | for key, value in pairs object |
| @@ -18,7 +18,7 @@ for key, value in pairs object | |||
| 18 | for i = 10, 20 | 18 | for i = 10, 20 |
| 19 | print i | 19 | print i |
| 20 | 20 | ||
| 21 | for k = 1, 15, 2 -- an optional step provided | 21 | for k = 1, 15, 2 -- ein optionaler Schritt |
| 22 | print k | 22 | print k |
| 23 | 23 | ||
| 24 | for key, value in pairs object | 24 | for key, value in pairs object |
| @@ -27,7 +27,7 @@ for key, value in pairs object | |||
| 27 | 27 | ||
| 28 | </YueDisplay> | 28 | </YueDisplay> |
| 29 | 29 | ||
| 30 | The slicing and **\*** operators can be used, just like with comprehensions: | 30 | Die Slicing- und **\***-Operatoren können verwendet werden, genau wie bei Comprehensions: |
| 31 | 31 | ||
| 32 | ```yuescript | 32 | ```yuescript |
| 33 | for item in *items[2, 4] | 33 | for item in *items[2, 4] |
| @@ -42,7 +42,7 @@ for item in *items[2, 4] | |||
| 42 | 42 | ||
| 43 | </YueDisplay> | 43 | </YueDisplay> |
| 44 | 44 | ||
| 45 | A shorter syntax is also available for all variations when the body is only a single line: | 45 | Eine kürzere Syntax ist für alle Varianten verfügbar, wenn der Rumpf nur eine Zeile hat: |
| 46 | 46 | ||
| 47 | ```yuescript | 47 | ```yuescript |
| 48 | for item in *items do print item | 48 | for item in *items do print item |
| @@ -59,9 +59,9 @@ for j = 1, 10, 3 do print j | |||
| 59 | 59 | ||
| 60 | </YueDisplay> | 60 | </YueDisplay> |
| 61 | 61 | ||
| 62 | A for loop can also be used as an expression. The last statement in the body of the for loop is coerced into an expression and appended to an accumulating array table. | 62 | Eine `for`-Schleife kann auch als Ausdruck verwendet werden. Die letzte Anweisung im Schleifenrumpf wird in einen Ausdruck umgewandelt und an eine wachsende Array-Tabelle angehängt. |
| 63 | 63 | ||
| 64 | Doubling every even number: | 64 | Alle geraden Zahlen verdoppeln: |
| 65 | 65 | ||
| 66 | ```yuescript | 66 | ```yuescript |
| 67 | doubled_evens = for i = 1, 20 | 67 | doubled_evens = for i = 1, 20 |
| @@ -82,9 +82,9 @@ doubled_evens = for i = 1, 20 | |||
| 82 | 82 | ||
| 83 | </YueDisplay> | 83 | </YueDisplay> |
| 84 | 84 | ||
| 85 | In addition, for loops support break with a return value, allowing the loop itself to be used as an expression that exits early with a meaningful result. | 85 | Zusätzlich unterstützen `for`-Schleifen `break` mit Rückgabewert, sodass die Schleife selbst als Ausdruck verwendet werden kann, der früh mit einem sinnvollen Ergebnis endet. |
| 86 | 86 | ||
| 87 | For example, to find the first number greater than 10: | 87 | Beispiel: die erste Zahl größer als 10 finden: |
| 88 | 88 | ||
| 89 | ```yuescript | 89 | ```yuescript |
| 90 | first_large = for n in *numbers | 90 | first_large = for n in *numbers |
| @@ -99,18 +99,18 @@ first_large = for n in *numbers | |||
| 99 | 99 | ||
| 100 | </YueDisplay> | 100 | </YueDisplay> |
| 101 | 101 | ||
| 102 | This break-with-value syntax enables concise and expressive search or early-exit patterns directly within loop expressions. | 102 | Diese `break`-mit-Wert-Syntax ermöglicht knappe und ausdrucksstarke Such- bzw. Early-Exit-Muster direkt in Schleifenausdrücken. |
| 103 | 103 | ||
| 104 | You can also filter values by combining the for loop expression with the continue statement. | 104 | Du kannst Werte auch filtern, indem du den `for`-Ausdruck mit `continue` kombinierst. |
| 105 | 105 | ||
| 106 | For loops at the end of a function body are not accumulated into a table for a return value (Instead the function will return nil). Either an explicit return statement can be used, or the loop can be converted into a list comprehension. | 106 | `for`-Schleifen am Ende eines Funktionsrumpfs werden nicht in eine Tabelle für einen Rückgabewert gesammelt (stattdessen gibt die Funktion `nil` zurück). Du kannst entweder explizit `return` verwenden oder die Schleife in eine Listen-Comprehension umwandeln. |
| 107 | 107 | ||
| 108 | ```yuescript | 108 | ```yuescript |
| 109 | func_a = -> for i = 1, 10 do print i | 109 | func_a = -> for i = 1, 10 do print i |
| 110 | func_b = -> return for i = 1, 10 do i | 110 | func_b = -> return for i = 1, 10 do i |
| 111 | 111 | ||
| 112 | print func_a! -- prints nil | 112 | print func_a! -- gibt nil aus |
| 113 | print func_b! -- prints table object | 113 | print func_b! -- gibt Tabellenobjekt aus |
| 114 | ``` | 114 | ``` |
| 115 | <YueDisplay> | 115 | <YueDisplay> |
| 116 | 116 | ||
| @@ -118,10 +118,10 @@ print func_b! -- prints table object | |||
| 118 | func_a = -> for i = 1, 10 do print i | 118 | func_a = -> for i = 1, 10 do print i |
| 119 | func_b = -> return for i = 1, 10 do i | 119 | func_b = -> return for i = 1, 10 do i |
| 120 | 120 | ||
| 121 | print func_a! -- prints nil | 121 | print func_a! -- gibt nil aus |
| 122 | print func_b! -- prints table object | 122 | print func_b! -- gibt Tabellenobjekt aus |
| 123 | ``` | 123 | ``` |
| 124 | 124 | ||
| 125 | </YueDisplay> | 125 | </YueDisplay> |
| 126 | 126 | ||
| 127 | This is done to avoid the needless creation of tables for functions that don't need to return the results of the loop. | 127 | Das verhindert die unnötige Erstellung von Tabellen in Funktionen, die die Ergebnisse der Schleife nicht zurückgeben müssen. |
diff --git a/doc/docs/de/doc/control-flow/switch.md b/doc/docs/de/doc/control-flow/switch.md index f503a80..81e08bd 100644 --- a/doc/docs/de/doc/control-flow/switch.md +++ b/doc/docs/de/doc/control-flow/switch.md | |||
| @@ -1,33 +1,33 @@ | |||
| 1 | # Switch | 1 | # Switch |
| 2 | 2 | ||
| 3 | The switch statement is shorthand for writing a series of if statements that check against the same value. Note that the value is only evaluated once. Like if statements, switches can have an else block to handle no matches. Comparison is done with the == operator. In switch statement, you can also use assignment expression to store temporary variable value. | 3 | Die `switch`-Anweisung ist eine Kurzform für eine Reihe von `if`-Anweisungen, die gegen denselben Wert prüfen. Der Wert wird nur einmal ausgewertet. Wie bei `if` kann `switch` einen `else`-Block haben, wenn keine Übereinstimmung gefunden wird. Verglichen wird mit dem Operator `==`. In einer `switch`-Anweisung kannst du auch eine Zuweisung verwenden, um den temporären Wert zu speichern. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | switch name := "Dan" | 6 | switch name := "Dan" |
| 7 | when "Robert" | 7 | when "Robert" |
| 8 | print "You are Robert" | 8 | print "Du bist Robert" |
| 9 | when "Dan", "Daniel" | 9 | when "Dan", "Daniel" |
| 10 | print "Your name, it's Dan" | 10 | print "Dein Name ist Dan" |
| 11 | else | 11 | else |
| 12 | print "I don't know about you with name #{name}" | 12 | print "Ich kenne dich nicht mit dem Namen #{name}" |
| 13 | ``` | 13 | ``` |
| 14 | <YueDisplay> | 14 | <YueDisplay> |
| 15 | 15 | ||
| 16 | ```yue | 16 | ```yue |
| 17 | switch name := "Dan" | 17 | switch name := "Dan" |
| 18 | when "Robert" | 18 | when "Robert" |
| 19 | print "You are Robert" | 19 | print "Du bist Robert" |
| 20 | when "Dan", "Daniel" | 20 | when "Dan", "Daniel" |
| 21 | print "Your name, it's Dan" | 21 | print "Dein Name ist Dan" |
| 22 | else | 22 | else |
| 23 | print "I don't know about you with name #{name}" | 23 | print "Ich kenne dich nicht mit dem Namen #{name}" |
| 24 | ``` | 24 | ``` |
| 25 | 25 | ||
| 26 | </YueDisplay> | 26 | </YueDisplay> |
| 27 | 27 | ||
| 28 | A switch when clause can match against multiple values by listing them out comma separated. | 28 | Eine `when`-Klausel kann mehrere Werte prüfen, indem sie kommasepariert aufgelistet werden. |
| 29 | 29 | ||
| 30 | Switches can be used as expressions as well, here we can assign the result of the switch to a variable: | 30 | `switch` kann auch als Ausdruck verwendet werden. Hier wird das Ergebnis der `switch`-Anweisung einer Variable zugewiesen: |
| 31 | 31 | ||
| 32 | ```yuescript | 32 | ```yuescript |
| 33 | b = 1 | 33 | b = 1 |
| @@ -37,7 +37,7 @@ next_number = switch b | |||
| 37 | when 2 | 37 | when 2 |
| 38 | 3 | 38 | 3 |
| 39 | else | 39 | else |
| 40 | error "can't count that high!" | 40 | error "so hoch kann ich nicht zählen!" |
| 41 | ``` | 41 | ``` |
| 42 | <YueDisplay> | 42 | <YueDisplay> |
| 43 | 43 | ||
| @@ -49,66 +49,66 @@ next_number = switch b | |||
| 49 | when 2 | 49 | when 2 |
| 50 | 3 | 50 | 3 |
| 51 | else | 51 | else |
| 52 | error "can't count that high!" | 52 | error "so hoch kann ich nicht zählen!" |
| 53 | ``` | 53 | ``` |
| 54 | 54 | ||
| 55 | </YueDisplay> | 55 | </YueDisplay> |
| 56 | 56 | ||
| 57 | We can use the then keyword to write a switch's when block on a single line. No extra keyword is needed to write the else block on a single line. | 57 | Du kannst das Schlüsselwort `then` verwenden, um einen `when`-Block in einer Zeile zu schreiben. Für den `else`-Block braucht es kein zusätzliches Schlüsselwort. |
| 58 | 58 | ||
| 59 | ```yuescript | 59 | ```yuescript |
| 60 | msg = switch math.random(1, 5) | 60 | msg = switch math.random(1, 5) |
| 61 | when 1 then "you are lucky" | 61 | when 1 then "Du hast Glück" |
| 62 | when 2 then "you are almost lucky" | 62 | when 2 then "Du hast fast Glück" |
| 63 | else "not so lucky" | 63 | else "nicht so viel Glück" |
| 64 | ``` | 64 | ``` |
| 65 | <YueDisplay> | 65 | <YueDisplay> |
| 66 | 66 | ||
| 67 | ```yue | 67 | ```yue |
| 68 | msg = switch math.random(1, 5) | 68 | msg = switch math.random(1, 5) |
| 69 | when 1 then "you are lucky" | 69 | when 1 then "Du hast Glück" |
| 70 | when 2 then "you are almost lucky" | 70 | when 2 then "Du hast fast Glück" |
| 71 | else "not so lucky" | 71 | else "nicht so viel Glück" |
| 72 | ``` | 72 | ``` |
| 73 | 73 | ||
| 74 | </YueDisplay> | 74 | </YueDisplay> |
| 75 | 75 | ||
| 76 | If you want to write code with one less indent when writing a switch statement, you can put the first when clause on the statement start line, and then all other clauses can be written with one less indent. | 76 | Wenn du eine Einrückung weniger möchtest, kannst du die erste `when`-Klausel in die Startzeile der Anweisung setzen und alle weiteren Klauseln mit einer Einrückung weniger schreiben. |
| 77 | 77 | ||
| 78 | ```yuescript | 78 | ```yuescript |
| 79 | switch math.random(1, 5) | 79 | switch math.random(1, 5) |
| 80 | when 1 | 80 | when 1 |
| 81 | print "you are lucky" -- two indents | 81 | print "Du hast Glück" -- zwei Einrückungen |
| 82 | else | 82 | else |
| 83 | print "not so lucky" | 83 | print "nicht so viel Glück" |
| 84 | 84 | ||
| 85 | switch math.random(1, 5) when 1 | 85 | switch math.random(1, 5) when 1 |
| 86 | print "you are lucky" -- one indent | 86 | print "Du hast Glück" -- eine Einrückung |
| 87 | else | 87 | else |
| 88 | print "not so lucky" | 88 | print "nicht so viel Glück" |
| 89 | ``` | 89 | ``` |
| 90 | <YueDisplay> | 90 | <YueDisplay> |
| 91 | 91 | ||
| 92 | ```yue | 92 | ```yue |
| 93 | switch math.random(1, 5) | 93 | switch math.random(1, 5) |
| 94 | when 1 | 94 | when 1 |
| 95 | print "you are lucky" -- two indents | 95 | print "Du hast Glück" -- zwei Einrückungen |
| 96 | else | 96 | else |
| 97 | print "not so lucky" | 97 | print "nicht so viel Glück" |
| 98 | 98 | ||
| 99 | switch math.random(1, 5) when 1 | 99 | switch math.random(1, 5) when 1 |
| 100 | print "you are lucky" -- one indent | 100 | print "Du hast Glück" -- eine Einrückung |
| 101 | else | 101 | else |
| 102 | print "not so lucky" | 102 | print "nicht so viel Glück" |
| 103 | ``` | 103 | ``` |
| 104 | 104 | ||
| 105 | </YueDisplay> | 105 | </YueDisplay> |
| 106 | 106 | ||
| 107 | It is worth noting the order of the case comparison expression. The case's expression is on the left hand side. This can be useful if the case's expression wants to overwrite how the comparison is done by defining an eq metamethod. | 107 | Beachte die Reihenfolge des Case-Vergleichsausdrucks. Der Case-Ausdruck steht auf der linken Seite. Das kann nützlich sein, wenn der Case-Ausdruck die Vergleichslogik über eine `__eq`-Metamethod selbst definiert. |
| 108 | 108 | ||
| 109 | ## Table Matching | 109 | ## Tabellen-Matching |
| 110 | 110 | ||
| 111 | You can do table matching in a switch when clause, if the table can be destructured by a specific structure and get non-nil values. | 111 | Du kannst in einer `switch`-`when`-Klausel Tabellen-Matching verwenden, wenn die Tabelle durch eine bestimmte Struktur destrukturiert werden kann und dabei nicht-`nil`-Werte liefert. |
| 112 | 112 | ||
| 113 | ```yuescript | 113 | ```yuescript |
| 114 | items = | 114 | items = |
| @@ -122,7 +122,7 @@ for item in *items | |||
| 122 | when :x, :y | 122 | when :x, :y |
| 123 | print "Vec2 #{x}, #{y}" | 123 | print "Vec2 #{x}, #{y}" |
| 124 | when :width, :height | 124 | when :width, :height |
| 125 | print "size #{width}, #{height}" | 125 | print "Größe #{width}, #{height}" |
| 126 | ``` | 126 | ``` |
| 127 | <YueDisplay> | 127 | <YueDisplay> |
| 128 | 128 | ||
| @@ -138,39 +138,39 @@ for item in *items | |||
| 138 | when :x, :y | 138 | when :x, :y |
| 139 | print "Vec2 #{x}, #{y}" | 139 | print "Vec2 #{x}, #{y}" |
| 140 | when :width, :height | 140 | when :width, :height |
| 141 | print "size #{width}, #{height}" | 141 | print "Größe #{width}, #{height}" |
| 142 | ``` | 142 | ``` |
| 143 | 143 | ||
| 144 | </YueDisplay> | 144 | </YueDisplay> |
| 145 | 145 | ||
| 146 | You can use default values to optionally destructure the table for some fields. | 146 | Du kannst Standardwerte verwenden, um bestimmte Felder optional zu destrukturieren. |
| 147 | 147 | ||
| 148 | ```yuescript | 148 | ```yuescript |
| 149 | item = {} | 149 | item = {} |
| 150 | 150 | ||
| 151 | {pos: {:x = 50, :y = 200}} = item -- get error: attempt to index a nil value (field 'pos') | 151 | {pos: {:x = 50, :y = 200}} = item -- Fehler: Versuch, einen nil-Wert zu indexieren (Feld 'pos') |
| 152 | 152 | ||
| 153 | switch item | 153 | switch item |
| 154 | when {pos: {:x = 50, :y = 200}} | 154 | when {pos: {:x = 50, :y = 200}} |
| 155 | print "Vec2 #{x}, #{y}" -- table destructuring will still pass | 155 | print "Vec2 #{x}, #{y}" -- Tabellen-Destrukturierung greift trotzdem |
| 156 | ``` | 156 | ``` |
| 157 | <YueDisplay> | 157 | <YueDisplay> |
| 158 | 158 | ||
| 159 | ```yue | 159 | ```yue |
| 160 | item = {} | 160 | item = {} |
| 161 | 161 | ||
| 162 | {pos: {:x = 50, :y = 200}} = item -- get error: attempt to index a nil value (field 'pos') | 162 | {pos: {:x = 50, :y = 200}} = item -- Fehler: Versuch, einen nil-Wert zu indexieren (Feld 'pos') |
| 163 | 163 | ||
| 164 | switch item | 164 | switch item |
| 165 | when {pos: {:x = 50, :y = 200}} | 165 | when {pos: {:x = 50, :y = 200}} |
| 166 | print "Vec2 #{x}, #{y}" -- table destructuring will still pass | 166 | print "Vec2 #{x}, #{y}" -- Tabellen-Destrukturierung greift trotzdem |
| 167 | ``` | 167 | ``` |
| 168 | 168 | ||
| 169 | </YueDisplay> | 169 | </YueDisplay> |
| 170 | 170 | ||
| 171 | You can also match against array elements, table fields, and even nested structures with array or table literals. | 171 | Du kannst auch gegen Array-Elemente, Tabellenfelder und sogar verschachtelte Strukturen mit Array- oder Tabellenliteralen matchen. |
| 172 | 172 | ||
| 173 | Match against array elements. | 173 | Matchen gegen Array-Elemente. |
| 174 | 174 | ||
| 175 | ```yuescript | 175 | ```yuescript |
| 176 | switch tb | 176 | switch tb |
| @@ -178,7 +178,7 @@ switch tb | |||
| 178 | print "1, 2, 3" | 178 | print "1, 2, 3" |
| 179 | when [1, b, 3] | 179 | when [1, b, 3] |
| 180 | print "1, #{b}, 3" | 180 | print "1, #{b}, 3" |
| 181 | when [1, 2, b = 3] -- b has a default value | 181 | when [1, 2, b = 3] -- b hat einen Standardwert |
| 182 | print "1, 2, #{b}" | 182 | print "1, 2, #{b}" |
| 183 | ``` | 183 | ``` |
| 184 | <YueDisplay> | 184 | <YueDisplay> |
| @@ -189,63 +189,63 @@ switch tb | |||
| 189 | print "1, 2, 3" | 189 | print "1, 2, 3" |
| 190 | when [1, b, 3] | 190 | when [1, b, 3] |
| 191 | print "1, #{b}, 3" | 191 | print "1, #{b}, 3" |
| 192 | when [1, 2, b = 3] -- b has a default value | 192 | when [1, 2, b = 3] -- b hat einen Standardwert |
| 193 | print "1, 2, #{b}" | 193 | print "1, 2, #{b}" |
| 194 | ``` | 194 | ``` |
| 195 | 195 | ||
| 196 | </YueDisplay> | 196 | </YueDisplay> |
| 197 | 197 | ||
| 198 | Match against table fields with destructuring. | 198 | Matchen gegen Tabellenfelder mit Destructuring. |
| 199 | 199 | ||
| 200 | ```yuescript | 200 | ```yuescript |
| 201 | switch tb | 201 | switch tb |
| 202 | when success: true, :result | 202 | when success: true, :result |
| 203 | print "success", result | 203 | print "Erfolg", result |
| 204 | when success: false | 204 | when success: false |
| 205 | print "failed", result | 205 | print "fehlgeschlagen", result |
| 206 | else | 206 | else |
| 207 | print "invalid" | 207 | print "ungültig" |
| 208 | ``` | 208 | ``` |
| 209 | <YueDisplay> | 209 | <YueDisplay> |
| 210 | 210 | ||
| 211 | ```yue | 211 | ```yue |
| 212 | switch tb | 212 | switch tb |
| 213 | when success: true, :result | 213 | when success: true, :result |
| 214 | print "success", result | 214 | print "Erfolg", result |
| 215 | when success: false | 215 | when success: false |
| 216 | print "failed", result | 216 | print "fehlgeschlagen", result |
| 217 | else | 217 | else |
| 218 | print "invalid" | 218 | print "ungültig" |
| 219 | ``` | 219 | ``` |
| 220 | 220 | ||
| 221 | </YueDisplay> | 221 | </YueDisplay> |
| 222 | 222 | ||
| 223 | Match against nested table structures. | 223 | Matchen gegen verschachtelte Tabellenstrukturen. |
| 224 | 224 | ||
| 225 | ```yuescript | 225 | ```yuescript |
| 226 | switch tb | 226 | switch tb |
| 227 | when data: {type: "success", :content} | 227 | when data: {type: "success", :content} |
| 228 | print "success", content | 228 | print "Erfolg", content |
| 229 | when data: {type: "error", :content} | 229 | when data: {type: "error", :content} |
| 230 | print "failed", content | 230 | print "fehlgeschlagen", content |
| 231 | else | 231 | else |
| 232 | print "invalid" | 232 | print "ungültig" |
| 233 | ``` | 233 | ``` |
| 234 | <YueDisplay> | 234 | <YueDisplay> |
| 235 | 235 | ||
| 236 | ```yue | 236 | ```yue |
| 237 | switch tb | 237 | switch tb |
| 238 | when data: {type: "success", :content} | 238 | when data: {type: "success", :content} |
| 239 | print "success", content | 239 | print "Erfolg", content |
| 240 | when data: {type: "error", :content} | 240 | when data: {type: "error", :content} |
| 241 | print "failed", content | 241 | print "fehlgeschlagen", content |
| 242 | else | 242 | else |
| 243 | print "invalid" | 243 | print "ungültig" |
| 244 | ``` | 244 | ``` |
| 245 | 245 | ||
| 246 | </YueDisplay> | 246 | </YueDisplay> |
| 247 | 247 | ||
| 248 | Match against array of tables. | 248 | Matchen gegen Array von Tabellen. |
| 249 | 249 | ||
| 250 | ```yuescript | 250 | ```yuescript |
| 251 | switch tb | 251 | switch tb |
| @@ -255,7 +255,7 @@ switch tb | |||
| 255 | {a: 5, b: 6} | 255 | {a: 5, b: 6} |
| 256 | fourth | 256 | fourth |
| 257 | ] | 257 | ] |
| 258 | print "matched", fourth | 258 | print "getroffen", fourth |
| 259 | ``` | 259 | ``` |
| 260 | <YueDisplay> | 260 | <YueDisplay> |
| 261 | 261 | ||
| @@ -267,20 +267,20 @@ switch tb | |||
| 267 | {a: 5, b: 6} | 267 | {a: 5, b: 6} |
| 268 | fourth | 268 | fourth |
| 269 | ] | 269 | ] |
| 270 | print "matched", fourth | 270 | print "getroffen", fourth |
| 271 | ``` | 271 | ``` |
| 272 | 272 | ||
| 273 | </YueDisplay> | 273 | </YueDisplay> |
| 274 | 274 | ||
| 275 | Match against a list and capture a range of elements. | 275 | Matchen gegen eine Liste und einen Bereich von Elementen erfassen. |
| 276 | 276 | ||
| 277 | ```yuescript | 277 | ```yuescript |
| 278 | segments = ["admin", "users", "logs", "view"] | 278 | segments = ["admin", "users", "logs", "view"] |
| 279 | switch segments | 279 | switch segments |
| 280 | when [...groups, resource, action] | 280 | when [...groups, resource, action] |
| 281 | print "Group:", groups -- prints: {"admin", "users"} | 281 | print "Gruppe:", groups -- gibt aus: {"admin", "users"} |
| 282 | print "Resource:", resource -- prints: "logs" | 282 | print "Ressource:", resource -- gibt aus: "logs" |
| 283 | print "Action:", action -- prints: "view" | 283 | print "Aktion:", action -- gibt aus: "view" |
| 284 | ``` | 284 | ``` |
| 285 | <YueDisplay> | 285 | <YueDisplay> |
| 286 | 286 | ||
| @@ -288,9 +288,9 @@ switch segments | |||
| 288 | segments = ["admin", "users", "logs", "view"] | 288 | segments = ["admin", "users", "logs", "view"] |
| 289 | switch segments | 289 | switch segments |
| 290 | when [...groups, resource, action] | 290 | when [...groups, resource, action] |
| 291 | print "Group:", groups -- prints: {"admin", "users"} | 291 | print "Gruppe:", groups -- gibt aus: {"admin", "users"} |
| 292 | print "Resource:", resource -- prints: "logs" | 292 | print "Ressource:", resource -- gibt aus: "logs" |
| 293 | print "Action:", action -- prints: "view" | 293 | print "Aktion:", action -- gibt aus: "view" |
| 294 | ``` | 294 | ``` |
| 295 | 295 | ||
| 296 | </YueDisplay> | 296 | </YueDisplay> |
diff --git a/doc/docs/de/doc/control-flow/while-loop.md b/doc/docs/de/doc/control-flow/while-loop.md index 502935e..a875bf9 100644 --- a/doc/docs/de/doc/control-flow/while-loop.md +++ b/doc/docs/de/doc/control-flow/while-loop.md | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | # While Loop | 1 | # While-Schleife |
| 2 | 2 | ||
| 3 | The while loop also comes in four variations: | 3 | Die `while`-Schleife gibt es ebenfalls in vier Variationen: |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | i = 10 | 6 | i = 10 |
| @@ -43,11 +43,11 @@ until running == false do my_function! | |||
| 43 | 43 | ||
| 44 | </YueDisplay> | 44 | </YueDisplay> |
| 45 | 45 | ||
| 46 | Like for loops, the while loop can also be used an expression. Additionally, for a function to return the accumulated value of a while loop, the statement must be explicitly returned. | 46 | Wie bei `for`-Schleifen kann die `while`-Schleife auch als Ausdruck verwendet werden. Damit eine Funktion den akkumulierten Wert einer `while`-Schleife zurückgibt, muss die Anweisung explizit mit `return` zurückgegeben werden. |
| 47 | 47 | ||
| 48 | ## Repeat Loop | 48 | ## Repeat-Schleife |
| 49 | 49 | ||
| 50 | The repeat loop comes from Lua: | 50 | Die `repeat`-Schleife stammt aus Lua: |
| 51 | 51 | ||
| 52 | ```yuescript | 52 | ```yuescript |
| 53 | i = 10 | 53 | i = 10 |
diff --git a/doc/docs/de/doc/data-structures/comprehensions.md b/doc/docs/de/doc/data-structures/comprehensions.md index 3a92167..7e00c57 100644 --- a/doc/docs/de/doc/data-structures/comprehensions.md +++ b/doc/docs/de/doc/data-structures/comprehensions.md | |||
| @@ -1,10 +1,10 @@ | |||
| 1 | # Comprehensions | 1 | # Comprehensions |
| 2 | 2 | ||
| 3 | Comprehensions provide a convenient syntax for constructing a new table by iterating over some existing object and applying an expression to its values. There are two kinds of comprehensions: list comprehensions and table comprehensions. They both produce Lua tables; list comprehensions accumulate values into an array-like table, and table comprehensions let you set both the key and the value on each iteration. | 3 | Comprehensions bieten eine bequeme Syntax, um eine neue Tabelle zu erzeugen, indem man über ein bestehendes Objekt iteriert und einen Ausdruck auf seine Werte anwendet. Es gibt zwei Arten: Listen-Comprehensions und Tabellen-Comprehensions. Beide erzeugen Lua-Tabellen; Listen-Comprehensions sammeln Werte in einer array-ähnlichen Tabelle, und Tabellen-Comprehensions erlauben es, Schlüssel und Wert pro Iteration zu setzen. |
| 4 | 4 | ||
| 5 | ## List Comprehensions | 5 | ## Listen-Comprehensions |
| 6 | 6 | ||
| 7 | The following creates a copy of the items table but with all the values doubled. | 7 | Das folgende Beispiel erstellt eine Kopie der `items`-Tabelle, aber mit verdoppelten Werten. |
| 8 | 8 | ||
| 9 | ```yuescript | 9 | ```yuescript |
| 10 | items = [ 1, 2, 3, 4 ] | 10 | items = [ 1, 2, 3, 4 ] |
| @@ -19,7 +19,7 @@ doubled = [item * 2 for i, item in ipairs items] | |||
| 19 | 19 | ||
| 20 | </YueDisplay> | 20 | </YueDisplay> |
| 21 | 21 | ||
| 22 | The items included in the new table can be restricted with a when clause: | 22 | Die Elemente in der neuen Tabelle können mit einer `when`-Klausel eingeschränkt werden: |
| 23 | 23 | ||
| 24 | ```yuescript | 24 | ```yuescript |
| 25 | slice = [item for i, item in ipairs items when i > 1 and i < 3] | 25 | slice = [item for i, item in ipairs items when i > 1 and i < 3] |
| @@ -32,7 +32,7 @@ slice = [item for i, item in ipairs items when i > 1 and i < 3] | |||
| 32 | 32 | ||
| 33 | </YueDisplay> | 33 | </YueDisplay> |
| 34 | 34 | ||
| 35 | Because it is common to iterate over the values of a numerically indexed table, an **\*** operator is introduced. The doubled example can be rewritten as: | 35 | Da es üblich ist, über die Werte einer numerisch indizierten Tabelle zu iterieren, gibt es den **\***-Operator. Das Verdopplungsbeispiel kann so umgeschrieben werden: |
| 36 | 36 | ||
| 37 | ```yuescript | 37 | ```yuescript |
| 38 | doubled = [item * 2 for item in *items] | 38 | doubled = [item * 2 for item in *items] |
| @@ -45,7 +45,7 @@ doubled = [item * 2 for item in *items] | |||
| 45 | 45 | ||
| 46 | </YueDisplay> | 46 | </YueDisplay> |
| 47 | 47 | ||
| 48 | In list comprehensions, you can also use the spread operator `...` to flatten nested lists, achieving a flat map effect: | 48 | In Listen-Comprehensions kannst du außerdem den Spread-Operator `...` verwenden, um verschachtelte Listen zu flatten und einen Flat-Map-Effekt zu erzielen: |
| 49 | 49 | ||
| 50 | ```yuescript | 50 | ```yuescript |
| 51 | data = | 51 | data = |
| @@ -53,7 +53,7 @@ data = | |||
| 53 | b: [4, 5, 6] | 53 | b: [4, 5, 6] |
| 54 | 54 | ||
| 55 | flat = [...v for k,v in pairs data] | 55 | flat = [...v for k,v in pairs data] |
| 56 | -- flat is now [1, 2, 3, 4, 5, 6] | 56 | -- flat ist jetzt [1, 2, 3, 4, 5, 6] |
| 57 | ``` | 57 | ``` |
| 58 | <YueDisplay> | 58 | <YueDisplay> |
| 59 | 59 | ||
| @@ -63,14 +63,14 @@ data = | |||
| 63 | b: [4, 5, 6] | 63 | b: [4, 5, 6] |
| 64 | 64 | ||
| 65 | flat = [...v for k,v in pairs data] | 65 | flat = [...v for k,v in pairs data] |
| 66 | -- flat is now [1, 2, 3, 4, 5, 6] | 66 | -- flat ist jetzt [1, 2, 3, 4, 5, 6] |
| 67 | ``` | 67 | ``` |
| 68 | 68 | ||
| 69 | </YueDisplay> | 69 | </YueDisplay> |
| 70 | 70 | ||
| 71 | The for and when clauses can be chained as much as desired. The only requirement is that a comprehension has at least one for clause. | 71 | Die `for`- und `when`-Klauseln können beliebig oft verkettet werden. Die einzige Anforderung ist, dass eine Comprehension mindestens eine `for`-Klausel enthält. |
| 72 | 72 | ||
| 73 | Using multiple for clauses is the same as using nested loops: | 73 | Mehrere `for`-Klauseln entsprechen verschachtelten Schleifen: |
| 74 | 74 | ||
| 75 | ```yuescript | 75 | ```yuescript |
| 76 | x_coords = [4, 5, 6, 7] | 76 | x_coords = [4, 5, 6, 7] |
| @@ -91,7 +91,7 @@ for y in *y_coords] | |||
| 91 | 91 | ||
| 92 | </YueDisplay> | 92 | </YueDisplay> |
| 93 | 93 | ||
| 94 | Numeric for loops can also be used in comprehensions: | 94 | Numerische `for`-Schleifen können ebenfalls in Comprehensions verwendet werden: |
| 95 | 95 | ||
| 96 | ```yuescript | 96 | ```yuescript |
| 97 | evens = [i for i = 1, 100 when i % 2 == 0] | 97 | evens = [i for i = 1, 100 when i % 2 == 0] |
| @@ -104,16 +104,16 @@ evens = [i for i = 1, 100 when i % 2 == 0] | |||
| 104 | 104 | ||
| 105 | </YueDisplay> | 105 | </YueDisplay> |
| 106 | 106 | ||
| 107 | ## Table Comprehensions | 107 | ## Tabellen-Comprehensions |
| 108 | 108 | ||
| 109 | The syntax for table comprehensions is very similar, only differing by using **{** and **}** and taking two values from each iteration. | 109 | Die Syntax für Tabellen-Comprehensions ist sehr ähnlich, unterscheidet sich jedoch dadurch, dass **{** und **}** verwendet werden und pro Iteration zwei Werte erzeugt werden. |
| 110 | 110 | ||
| 111 | This example makes a copy of the tablething: | 111 | Dieses Beispiel erstellt eine Kopie von `thing`: |
| 112 | 112 | ||
| 113 | ```yuescript | 113 | ```yuescript |
| 114 | thing = { | 114 | thing = { |
| 115 | color: "red" | 115 | color: "rot" |
| 116 | name: "fast" | 116 | name: "schnell" |
| 117 | width: 123 | 117 | width: 123 |
| 118 | } | 118 | } |
| 119 | 119 | ||
| @@ -123,8 +123,8 @@ thing_copy = {k, v for k, v in pairs thing} | |||
| 123 | 123 | ||
| 124 | ```yue | 124 | ```yue |
| 125 | thing = { | 125 | thing = { |
| 126 | color: "red" | 126 | color: "rot" |
| 127 | name: "fast" | 127 | name: "schnell" |
| 128 | width: 123 | 128 | width: 123 |
| 129 | } | 129 | } |
| 130 | 130 | ||
| @@ -144,7 +144,7 @@ no_color = {k, v for k, v in pairs thing when k != "color"} | |||
| 144 | 144 | ||
| 145 | </YueDisplay> | 145 | </YueDisplay> |
| 146 | 146 | ||
| 147 | The **\*** operator is also supported. Here we create a square root look up table for a few numbers. | 147 | Der **\***-Operator wird ebenfalls unterstützt. Hier erstellen wir eine Nachschlagetabelle für Quadratwurzeln einiger Zahlen. |
| 148 | 148 | ||
| 149 | ```yuescript | 149 | ```yuescript |
| 150 | numbers = [1, 2, 3, 4] | 150 | numbers = [1, 2, 3, 4] |
| @@ -159,18 +159,18 @@ sqrts = {i, math.sqrt i for i in *numbers} | |||
| 159 | 159 | ||
| 160 | </YueDisplay> | 160 | </YueDisplay> |
| 161 | 161 | ||
| 162 | The key-value tuple in a table comprehension can also come from a single expression, in which case the expression should return two values. The first is used as the key and the second is used as the value: | 162 | Das Schlüssel-Wert-Tupel in einer Tabellen-Comprehension kann auch aus einem einzelnen Ausdruck stammen; der Ausdruck muss dann zwei Werte zurückgeben. Der erste wird als Schlüssel und der zweite als Wert verwendet: |
| 163 | 163 | ||
| 164 | In this example we convert an array of pairs to a table where the first item in the pair is the key and the second is the value. | 164 | In diesem Beispiel konvertieren wir ein Array von Paaren in eine Tabelle, wobei das erste Element des Paars der Schlüssel und das zweite der Wert ist. |
| 165 | 165 | ||
| 166 | ```yuescript | 166 | ```yuescript |
| 167 | tuples = [ ["hello", "world"], ["foo", "bar"]] | 167 | tuples = [ ["hallo", "Welt"], ["foo", "bar"]] |
| 168 | tbl = {unpack tuple for tuple in *tuples} | 168 | tbl = {unpack tuple for tuple in *tuples} |
| 169 | ``` | 169 | ``` |
| 170 | <YueDisplay> | 170 | <YueDisplay> |
| 171 | 171 | ||
| 172 | ```yue | 172 | ```yue |
| 173 | tuples = [ ["hello", "world"], ["foo", "bar"]] | 173 | tuples = [ ["hallo", "Welt"], ["foo", "bar"]] |
| 174 | tbl = {unpack tuple for tuple in *tuples} | 174 | tbl = {unpack tuple for tuple in *tuples} |
| 175 | ``` | 175 | ``` |
| 176 | 176 | ||
| @@ -178,9 +178,9 @@ tbl = {unpack tuple for tuple in *tuples} | |||
| 178 | 178 | ||
| 179 | ## Slicing | 179 | ## Slicing |
| 180 | 180 | ||
| 181 | A special syntax is provided to restrict the items that are iterated over when using the **\*** operator. This is equivalent to setting the iteration bounds and a step size in a for loop. | 181 | Eine spezielle Syntax erlaubt es, die iterierten Elemente bei Verwendung des **\***-Operators einzuschränken. Das ist äquivalent zum Setzen von Iterationsgrenzen und Schrittweite in einer `for`-Schleife. |
| 182 | 182 | ||
| 183 | Here we can set the minimum and maximum bounds, taking all items with indexes between 1 and 5 inclusive: | 183 | Hier setzen wir die minimalen und maximalen Grenzen und nehmen alle Elemente mit Indizes zwischen 1 und 5 (inklusive): |
| 184 | 184 | ||
| 185 | ```yuescript | 185 | ```yuescript |
| 186 | slice = [item for item in *items[1, 5]] | 186 | slice = [item for item in *items[1, 5]] |
| @@ -193,7 +193,7 @@ slice = [item for item in *items[1, 5]] | |||
| 193 | 193 | ||
| 194 | </YueDisplay> | 194 | </YueDisplay> |
| 195 | 195 | ||
| 196 | Any of the slice arguments can be left off to use a sensible default. In this example, if the max index is left off it defaults to the length of the table. This will take everything but the first element: | 196 | Jedes der Slice-Argumente kann weggelassen werden, um einen sinnvollen Standard zu verwenden. Wenn der maximale Index weggelassen wird, entspricht er der Länge der Tabelle. Dieses Beispiel nimmt alles außer dem ersten Element: |
| 197 | 197 | ||
| 198 | ```yuescript | 198 | ```yuescript |
| 199 | slice = [item for item in *items[2,]] | 199 | slice = [item for item in *items[2,]] |
| @@ -206,7 +206,7 @@ slice = [item for item in *items[2,]] | |||
| 206 | 206 | ||
| 207 | </YueDisplay> | 207 | </YueDisplay> |
| 208 | 208 | ||
| 209 | If the minimum bound is left out, it defaults to 1. Here we only provide a step size and leave the other bounds blank. This takes all odd indexed items: (1, 3, 5, …) | 209 | Wenn die Mindestgrenze weggelassen wird, ist sie standardmäßig 1. Hier geben wir nur die Schrittweite an und lassen die anderen Grenzen leer. Das nimmt alle ungerad indizierten Elemente (1, 3, 5, …): |
| 210 | 210 | ||
| 211 | ```yuescript | 211 | ```yuescript |
| 212 | slice = [item for item in *items[,,2]] | 212 | slice = [item for item in *items[,,2]] |
| @@ -219,22 +219,22 @@ slice = [item for item in *items[,,2]] | |||
| 219 | 219 | ||
| 220 | </YueDisplay> | 220 | </YueDisplay> |
| 221 | 221 | ||
| 222 | Both the minimum and maximum bounds can be negative, which means that the bounds are counted from the end of the table. | 222 | Sowohl die Mindest- als auch die Maximalgrenze können negativ sein; dann werden die Grenzen vom Ende der Tabelle gezählt. |
| 223 | 223 | ||
| 224 | ```yuescript | 224 | ```yuescript |
| 225 | -- take the last 4 items | 225 | -- die letzten 4 Elemente nehmen |
| 226 | slice = [item for item in *items[-4,-1]] | 226 | slice = [item for item in *items[-4,-1]] |
| 227 | ``` | 227 | ``` |
| 228 | <YueDisplay> | 228 | <YueDisplay> |
| 229 | 229 | ||
| 230 | ```yue | 230 | ```yue |
| 231 | -- take the last 4 items | 231 | -- die letzten 4 Elemente nehmen |
| 232 | slice = [item for item in *items[-4,-1]] | 232 | slice = [item for item in *items[-4,-1]] |
| 233 | ``` | 233 | ``` |
| 234 | 234 | ||
| 235 | </YueDisplay> | 235 | </YueDisplay> |
| 236 | 236 | ||
| 237 | The step size can also be negative, which means that the items are taken in reverse order. | 237 | Die Schrittweite kann ebenfalls negativ sein, wodurch die Elemente in umgekehrter Reihenfolge genommen werden. |
| 238 | 238 | ||
| 239 | ```yuescript | 239 | ```yuescript |
| 240 | reverse_slice = [item for item in *items[-1,1,-1]] | 240 | reverse_slice = [item for item in *items[-1,1,-1]] |
| @@ -247,24 +247,24 @@ reverse_slice = [item for item in *items[-1,1,-1]] | |||
| 247 | 247 | ||
| 248 | </YueDisplay> | 248 | </YueDisplay> |
| 249 | 249 | ||
| 250 | ### Slicing Expression | 250 | ### Slicing-Ausdruck |
| 251 | 251 | ||
| 252 | Slicing can also be used as an expression. This is useful for getting a sub-list of a table. | 252 | Slicing kann auch als Ausdruck verwendet werden. Das ist nützlich, um eine Teilliste einer Tabelle zu erhalten. |
| 253 | 253 | ||
| 254 | ```yuescript | 254 | ```yuescript |
| 255 | -- take the 2nd and 4th items as a new list | 255 | -- das 2. und 4. Element als neue Liste nehmen |
| 256 | sub_list = items[2, 4] | 256 | sub_list = items[2, 4] |
| 257 | 257 | ||
| 258 | -- take the last 4 items | 258 | -- die letzten 4 Elemente nehmen |
| 259 | last_four_items = items[-4, -1] | 259 | last_four_items = items[-4, -1] |
| 260 | ``` | 260 | ``` |
| 261 | <YueDisplay> | 261 | <YueDisplay> |
| 262 | 262 | ||
| 263 | ```yue | 263 | ```yue |
| 264 | -- take the 2nd and 4th items as a new list | 264 | -- das 2. und 4. Element als neue Liste nehmen |
| 265 | sub_list = items[2, 4] | 265 | sub_list = items[2, 4] |
| 266 | 266 | ||
| 267 | -- take the last 4 items | 267 | -- die letzten 4 Elemente nehmen |
| 268 | last_four_items = items[-4, -1] | 268 | last_four_items = items[-4, -1] |
| 269 | ``` | 269 | ``` |
| 270 | 270 | ||
diff --git a/doc/docs/de/doc/data-structures/table-literals.md b/doc/docs/de/doc/data-structures/table-literals.md index c1adcab..46181d7 100644 --- a/doc/docs/de/doc/data-structures/table-literals.md +++ b/doc/docs/de/doc/data-structures/table-literals.md | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | # Table Literals | 1 | # Tabellenliterale |
| 2 | 2 | ||
| 3 | Like in Lua, tables are delimited in curly braces. | 3 | Wie in Lua werden Tabellen mit geschweiften Klammern definiert. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | some_values = [1, 2, 3, 4] | 6 | some_values = [1, 2, 3, 4] |
| @@ -13,13 +13,13 @@ some_values = [1, 2, 3, 4] | |||
| 13 | 13 | ||
| 14 | </YueDisplay> | 14 | </YueDisplay> |
| 15 | 15 | ||
| 16 | Unlike Lua, assigning a value to a key in a table is done with **:** (instead of **=**). | 16 | Anders als in Lua weist man einem Schlüssel in einer Tabelle mit **:** (statt **=**) einen Wert zu. |
| 17 | 17 | ||
| 18 | ```yuescript | 18 | ```yuescript |
| 19 | some_values = { | 19 | some_values = { |
| 20 | name: "Bill", | 20 | name: "Bill", |
| 21 | age: 200, | 21 | age: 200, |
| 22 | ["favorite food"]: "rice" | 22 | ["Lieblingsessen"]: "Reis" |
| 23 | } | 23 | } |
| 24 | ``` | 24 | ``` |
| 25 | <YueDisplay> | 25 | <YueDisplay> |
| @@ -28,39 +28,39 @@ some_values = { | |||
| 28 | some_values = { | 28 | some_values = { |
| 29 | name: "Bill", | 29 | name: "Bill", |
| 30 | age: 200, | 30 | age: 200, |
| 31 | ["favorite food"]: "rice" | 31 | ["Lieblingsessen"]: "Reis" |
| 32 | } | 32 | } |
| 33 | ``` | 33 | ``` |
| 34 | 34 | ||
| 35 | </YueDisplay> | 35 | </YueDisplay> |
| 36 | 36 | ||
| 37 | The curly braces can be left off if a single table of key value pairs is being assigned. | 37 | Die geschweiften Klammern können weggelassen werden, wenn eine einzelne Tabelle aus Schlüssel-Wert-Paaren zugewiesen wird. |
| 38 | 38 | ||
| 39 | ```yuescript | 39 | ```yuescript |
| 40 | profile = | 40 | profile = |
| 41 | height: "4 feet", | 41 | height: "4 Fuß", |
| 42 | shoe_size: 13, | 42 | shoe_size: 13, |
| 43 | favorite_foods: ["ice cream", "donuts"] | 43 | favorite_foods: ["Eis", "Donuts"] |
| 44 | ``` | 44 | ``` |
| 45 | <YueDisplay> | 45 | <YueDisplay> |
| 46 | 46 | ||
| 47 | ```yue | 47 | ```yue |
| 48 | profile = | 48 | profile = |
| 49 | height: "4 feet", | 49 | height: "4 Fuß", |
| 50 | shoe_size: 13, | 50 | shoe_size: 13, |
| 51 | favorite_foods: ["ice cream", "donuts"] | 51 | favorite_foods: ["Eis", "Donuts"] |
| 52 | ``` | 52 | ``` |
| 53 | 53 | ||
| 54 | </YueDisplay> | 54 | </YueDisplay> |
| 55 | 55 | ||
| 56 | Newlines can be used to delimit values instead of a comma (or both): | 56 | Zeilenumbrüche können Werte statt eines Kommas trennen (oder zusätzlich): |
| 57 | 57 | ||
| 58 | ```yuescript | 58 | ```yuescript |
| 59 | values = { | 59 | values = { |
| 60 | 1, 2, 3, 4 | 60 | 1, 2, 3, 4 |
| 61 | 5, 6, 7, 8 | 61 | 5, 6, 7, 8 |
| 62 | name: "superman" | 62 | name: "Superman" |
| 63 | occupation: "crime fighting" | 63 | occupation: "Verbrechensbekämpfung" |
| 64 | } | 64 | } |
| 65 | ``` | 65 | ``` |
| 66 | <YueDisplay> | 66 | <YueDisplay> |
| @@ -69,50 +69,50 @@ values = { | |||
| 69 | values = { | 69 | values = { |
| 70 | 1, 2, 3, 4 | 70 | 1, 2, 3, 4 |
| 71 | 5, 6, 7, 8 | 71 | 5, 6, 7, 8 |
| 72 | name: "superman" | 72 | name: "Superman" |
| 73 | occupation: "crime fighting" | 73 | occupation: "Verbrechensbekämpfung" |
| 74 | } | 74 | } |
| 75 | ``` | 75 | ``` |
| 76 | 76 | ||
| 77 | </YueDisplay> | 77 | </YueDisplay> |
| 78 | 78 | ||
| 79 | When creating a single line table literal, the curly braces can also be left off: | 79 | Beim Erstellen eines einzeiligen Tabellenliterals können die geschweiften Klammern ebenfalls weggelassen werden: |
| 80 | 80 | ||
| 81 | ```yuescript | 81 | ```yuescript |
| 82 | my_function dance: "Tango", partner: "none" | 82 | my_function dance: "Tango", partner: "keiner" |
| 83 | 83 | ||
| 84 | y = type: "dog", legs: 4, tails: 1 | 84 | y = type: "Hund", legs: 4, tails: 1 |
| 85 | ``` | 85 | ``` |
| 86 | <YueDisplay> | 86 | <YueDisplay> |
| 87 | 87 | ||
| 88 | ```yue | 88 | ```yue |
| 89 | my_function dance: "Tango", partner: "none" | 89 | my_function dance: "Tango", partner: "keiner" |
| 90 | 90 | ||
| 91 | y = type: "dog", legs: 4, tails: 1 | 91 | y = type: "Hund", legs: 4, tails: 1 |
| 92 | ``` | 92 | ``` |
| 93 | 93 | ||
| 94 | </YueDisplay> | 94 | </YueDisplay> |
| 95 | 95 | ||
| 96 | The keys of a table literal can be language keywords without being escaped: | 96 | Die Schlüssel eines Tabellenliterals können Sprach-Schlüsselwörter sein, ohne sie zu escapen: |
| 97 | 97 | ||
| 98 | ```yuescript | 98 | ```yuescript |
| 99 | tbl = { | 99 | tbl = { |
| 100 | do: "something" | 100 | do: "etwas" |
| 101 | end: "hunger" | 101 | end: "Hunger" |
| 102 | } | 102 | } |
| 103 | ``` | 103 | ``` |
| 104 | <YueDisplay> | 104 | <YueDisplay> |
| 105 | 105 | ||
| 106 | ```yue | 106 | ```yue |
| 107 | tbl = { | 107 | tbl = { |
| 108 | do: "something" | 108 | do: "etwas" |
| 109 | end: "hunger" | 109 | end: "Hunger" |
| 110 | } | 110 | } |
| 111 | ``` | 111 | ``` |
| 112 | 112 | ||
| 113 | </YueDisplay> | 113 | </YueDisplay> |
| 114 | 114 | ||
| 115 | If you are constructing a table out of variables and wish the keys to be the same as the variable names, then the **:** prefix operator can be used: | 115 | Wenn du eine Tabelle aus Variablen konstruierst und die Schlüssel den Variablennamen entsprechen sollen, kannst du den Präfix-Operator **:** verwenden: |
| 116 | 116 | ||
| 117 | ```yuescript | 117 | ```yuescript |
| 118 | hair = "golden" | 118 | hair = "golden" |
| @@ -133,26 +133,26 @@ print_table :hair, :height | |||
| 133 | 133 | ||
| 134 | </YueDisplay> | 134 | </YueDisplay> |
| 135 | 135 | ||
| 136 | If you want the key of a field in the table to to be result of an expression, then you can wrap it in **[ ]**, just like in Lua. You can also use a string literal directly as a key, leaving out the square brackets. This is useful if your key has any special characters. | 136 | Wenn der Schlüssel eines Feldes das Ergebnis eines Ausdrucks sein soll, kannst du ihn wie in Lua in **[ ]** setzen. Du kannst auch ein String-Literal direkt als Schlüssel verwenden und die eckigen Klammern weglassen. Das ist nützlich, wenn dein Schlüssel Sonderzeichen enthält. |
| 137 | 137 | ||
| 138 | ```yuescript | 138 | ```yuescript |
| 139 | t = { | 139 | t = { |
| 140 | [1 + 2]: "hello" | 140 | [1 + 2]: "hallo" |
| 141 | "hello world": true | 141 | "Hallo Welt": true |
| 142 | } | 142 | } |
| 143 | ``` | 143 | ``` |
| 144 | <YueDisplay> | 144 | <YueDisplay> |
| 145 | 145 | ||
| 146 | ```yue | 146 | ```yue |
| 147 | t = { | 147 | t = { |
| 148 | [1 + 2]: "hello" | 148 | [1 + 2]: "hallo" |
| 149 | "hello world": true | 149 | "Hallo Welt": true |
| 150 | } | 150 | } |
| 151 | ``` | 151 | ``` |
| 152 | 152 | ||
| 153 | </YueDisplay> | 153 | </YueDisplay> |
| 154 | 154 | ||
| 155 | Lua tables have both an array part and a hash part, but sometimes you want to make a semantic distinction between array and hash usage when writing Lua tables. Then you can write Lua table with **[ ]** instead of **{ }** to represent an array table and writing any key value pair in a list table won't be allowed. | 155 | Lua-Tabellen haben einen Array-Teil und einen Hash-Teil, aber manchmal möchte man beim Schreiben von Lua-Tabellen eine semantische Unterscheidung zwischen Array- und Hash-Nutzung machen. Dann kannst du eine Lua-Tabelle mit **[ ]** statt **{ }** schreiben, um eine Array-Tabelle darzustellen, und das Schreiben von Schlüssel-Wert-Paaren in einer Listentabelle ist nicht erlaubt. |
| 156 | 156 | ||
| 157 | ```yuescript | 157 | ```yuescript |
| 158 | some_values = [1, 2, 3, 4] | 158 | some_values = [1, 2, 3, 4] |
diff --git a/doc/docs/de/doc/functions/backcalls.md b/doc/docs/de/doc/functions/backcalls.md index e34331e..dbac86b 100644 --- a/doc/docs/de/doc/functions/backcalls.md +++ b/doc/docs/de/doc/functions/backcalls.md | |||
| @@ -1,21 +1,21 @@ | |||
| 1 | # Backcalls | 1 | # Backcalls |
| 2 | 2 | ||
| 3 | Backcalls are used for unnesting callbacks. They are defined using arrows pointed to the left as the last parameter by default filling in a function call. All the syntax is mostly the same as regular arrow functions except that it is just pointing the other way and the function body does not require indent. | 3 | Backcalls werden verwendet, um Callbacks zu entkoppeln (unnesting). Sie werden mit Pfeilen nach links definiert und füllen standardmäßig als letzter Parameter einen Funktionsaufruf. Die Syntax ist weitgehend wie bei normalen Pfeilfunktionen, nur dass der Pfeil in die andere Richtung zeigt und der Funktionskörper keine Einrückung benötigt. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | x <- f | 6 | x <- f |
| 7 | print "hello" .. x | 7 | print "hallo" .. x |
| 8 | ``` | 8 | ``` |
| 9 | <YueDisplay> | 9 | <YueDisplay> |
| 10 | 10 | ||
| 11 | ```yue | 11 | ```yue |
| 12 | x <- f | 12 | x <- f |
| 13 | print "hello" .. x | 13 | print "hallo" .. x |
| 14 | ``` | 14 | ``` |
| 15 | 15 | ||
| 16 | </YueDisplay> | 16 | </YueDisplay> |
| 17 | 17 | ||
| 18 | Fat arrow functions are also available. | 18 | Fat-Arrow-Funktionen sind ebenfalls verfügbar. |
| 19 | 19 | ||
| 20 | ```yuescript | 20 | ```yuescript |
| 21 | <= f | 21 | <= f |
| @@ -30,7 +30,7 @@ print @value | |||
| 30 | 30 | ||
| 31 | </YueDisplay> | 31 | </YueDisplay> |
| 32 | 32 | ||
| 33 | You can specify a placeholder for where you want the backcall function to go as a parameter. | 33 | Du kannst einen Platzhalter angeben, an welcher Stelle die Backcall-Funktion als Parameter eingesetzt werden soll. |
| 34 | 34 | ||
| 35 | ```yuescript | 35 | ```yuescript |
| 36 | (x) <- map _, [1, 2, 3] | 36 | (x) <- map _, [1, 2, 3] |
| @@ -45,11 +45,11 @@ x * 2 | |||
| 45 | 45 | ||
| 46 | </YueDisplay> | 46 | </YueDisplay> |
| 47 | 47 | ||
| 48 | If you wish to have further code after your backcalls, you can set them aside with a do statement. And the parentheses can be omitted with non-fat arrow functions. | 48 | Wenn du nach deinen Backcalls weiteren Code haben willst, kannst du sie mit einem `do`-Statement absetzen. Bei Nicht-Fat-Arrow-Funktionen können die Klammern weggelassen werden. |
| 49 | 49 | ||
| 50 | ```yuescript | 50 | ```yuescript |
| 51 | result, msg = do | 51 | result, msg = do |
| 52 | data <- readAsync "filename.txt" | 52 | data <- readAsync "dateiname.txt" |
| 53 | print data | 53 | print data |
| 54 | info <- processAsync data | 54 | info <- processAsync data |
| 55 | check info | 55 | check info |
| @@ -59,7 +59,7 @@ print result, msg | |||
| 59 | 59 | ||
| 60 | ```yue | 60 | ```yue |
| 61 | result, msg = do | 61 | result, msg = do |
| 62 | data <- readAsync "filename.txt" | 62 | data <- readAsync "dateiname.txt" |
| 63 | print data | 63 | print data |
| 64 | info <- processAsync data | 64 | info <- processAsync data |
| 65 | check info | 65 | check info |
diff --git a/doc/docs/de/doc/functions/function-literals.md b/doc/docs/de/doc/functions/function-literals.md index 316e07c..d3bfb11 100644 --- a/doc/docs/de/doc/functions/function-literals.md +++ b/doc/docs/de/doc/functions/function-literals.md | |||
| @@ -1,42 +1,42 @@ | |||
| 1 | # Function Literals | 1 | # Funktionsliterale |
| 2 | 2 | ||
| 3 | All functions are created using a function expression. A simple function is denoted using the arrow: **->**. | 3 | Alle Funktionen werden mit einem Funktionsausdruck erstellt. Eine einfache Funktion wird mit dem Pfeil **->** notiert. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | my_function = -> | 6 | my_function = -> |
| 7 | my_function() -- call the empty function | 7 | my_function() -- leere Funktion aufrufen |
| 8 | ``` | 8 | ``` |
| 9 | <YueDisplay> | 9 | <YueDisplay> |
| 10 | 10 | ||
| 11 | ```yue | 11 | ```yue |
| 12 | my_function = -> | 12 | my_function = -> |
| 13 | my_function() -- call the empty function | 13 | my_function() -- leere Funktion aufrufen |
| 14 | ``` | 14 | ``` |
| 15 | 15 | ||
| 16 | </YueDisplay> | 16 | </YueDisplay> |
| 17 | 17 | ||
| 18 | The body of the function can either be one statement placed directly after the arrow, or it can be a series of statements indented on the following lines: | 18 | Der Funktionskörper kann entweder eine einzelne Anweisung direkt nach dem Pfeil sein oder aus mehreren Anweisungen bestehen, die in den folgenden Zeilen eingerückt werden: |
| 19 | 19 | ||
| 20 | ```yuescript | 20 | ```yuescript |
| 21 | func_a = -> print "hello world" | 21 | func_a = -> print "Hallo Welt" |
| 22 | 22 | ||
| 23 | func_b = -> | 23 | func_b = -> |
| 24 | value = 100 | 24 | value = 100 |
| 25 | print "The value:", value | 25 | print "Der Wert:", value |
| 26 | ``` | 26 | ``` |
| 27 | <YueDisplay> | 27 | <YueDisplay> |
| 28 | 28 | ||
| 29 | ```yue | 29 | ```yue |
| 30 | func_a = -> print "hello world" | 30 | func_a = -> print "Hallo Welt" |
| 31 | 31 | ||
| 32 | func_b = -> | 32 | func_b = -> |
| 33 | value = 100 | 33 | value = 100 |
| 34 | print "The value:", value | 34 | print "Der Wert:", value |
| 35 | ``` | 35 | ``` |
| 36 | 36 | ||
| 37 | </YueDisplay> | 37 | </YueDisplay> |
| 38 | 38 | ||
| 39 | If a function has no arguments, it can be called using the ! operator, instead of empty parentheses. The ! invocation is the preferred way to call functions with no arguments. | 39 | Wenn eine Funktion keine Argumente hat, kann sie mit dem `!`-Operator statt leerer Klammern aufgerufen werden. Der `!`-Aufruf ist die bevorzugte Art, Funktionen ohne Argumente aufzurufen. |
| 40 | 40 | ||
| 41 | ```yuescript | 41 | ```yuescript |
| 42 | func_a! | 42 | func_a! |
| @@ -51,20 +51,20 @@ func_b() | |||
| 51 | 51 | ||
| 52 | </YueDisplay> | 52 | </YueDisplay> |
| 53 | 53 | ||
| 54 | Functions with arguments can be created by preceding the arrow with a list of argument names in parentheses: | 54 | Funktionen mit Argumenten werden erstellt, indem der Pfeil von einer Argumentliste in Klammern eingeleitet wird: |
| 55 | 55 | ||
| 56 | ```yuescript | 56 | ```yuescript |
| 57 | sum = (x, y) -> print "sum", x + y | 57 | sum = (x, y) -> print "Summe", x + y |
| 58 | ``` | 58 | ``` |
| 59 | <YueDisplay> | 59 | <YueDisplay> |
| 60 | 60 | ||
| 61 | ```yue | 61 | ```yue |
| 62 | sum = (x, y) -> print "sum", x + y | 62 | sum = (x, y) -> print "Summe", x + y |
| 63 | ``` | 63 | ``` |
| 64 | 64 | ||
| 65 | </YueDisplay> | 65 | </YueDisplay> |
| 66 | 66 | ||
| 67 | Functions can be called by listing the arguments after the name of an expression that evaluates to a function. When chaining together function calls, the arguments are applied to the closest function to the left. | 67 | Funktionen können aufgerufen werden, indem die Argumente hinter dem Namen eines Ausdrucks stehen, der zu einer Funktion evaluiert. Beim Verketten mehrerer Funktionsaufrufe werden die Argumente der nächstliegenden Funktion links zugeordnet. |
| 68 | 68 | ||
| 69 | ```yuescript | 69 | ```yuescript |
| 70 | sum 10, 20 | 70 | sum 10, 20 |
| @@ -83,7 +83,7 @@ a b c "a", "b", "c" | |||
| 83 | 83 | ||
| 84 | </YueDisplay> | 84 | </YueDisplay> |
| 85 | 85 | ||
| 86 | In order to avoid ambiguity in when calling functions, parentheses can also be used to surround the arguments. This is required here in order to make sure the right arguments get sent to the right functions. | 86 | Um Mehrdeutigkeiten beim Aufruf zu vermeiden, können die Argumente auch in Klammern gesetzt werden. Das ist hier nötig, damit die richtigen Argumente an die richtigen Funktionen gehen. |
| 87 | 87 | ||
| 88 | ```yuescript | 88 | ```yuescript |
| 89 | print "x:", sum(10, 20), "y:", sum(30, 40) | 89 | print "x:", sum(10, 20), "y:", sum(30, 40) |
| @@ -96,24 +96,24 @@ print "x:", sum(10, 20), "y:", sum(30, 40) | |||
| 96 | 96 | ||
| 97 | </YueDisplay> | 97 | </YueDisplay> |
| 98 | 98 | ||
| 99 | There must not be any space between the opening parenthesis and the function. | 99 | Zwischen öffnender Klammer und Funktionsname darf kein Leerzeichen stehen. |
| 100 | 100 | ||
| 101 | Functions will coerce the last statement in their body into a return statement, this is called implicit return: | 101 | Funktionen wandeln die letzte Anweisung im Funktionskörper in ein `return` um. Das nennt sich implizites Return: |
| 102 | 102 | ||
| 103 | ```yuescript | 103 | ```yuescript |
| 104 | sum = (x, y) -> x + y | 104 | sum = (x, y) -> x + y |
| 105 | print "The sum is ", sum 10, 20 | 105 | print "Die Summe ist ", sum 10, 20 |
| 106 | ``` | 106 | ``` |
| 107 | <YueDisplay> | 107 | <YueDisplay> |
| 108 | 108 | ||
| 109 | ```yue | 109 | ```yue |
| 110 | sum = (x, y) -> x + y | 110 | sum = (x, y) -> x + y |
| 111 | print "The sum is ", sum 10, 20 | 111 | print "Die Summe ist ", sum 10, 20 |
| 112 | ``` | 112 | ``` |
| 113 | 113 | ||
| 114 | </YueDisplay> | 114 | </YueDisplay> |
| 115 | 115 | ||
| 116 | And if you need to explicitly return, you can use the return keyword: | 116 | Wenn du explizit zurückgeben willst, verwende `return`: |
| 117 | 117 | ||
| 118 | ```yuescript | 118 | ```yuescript |
| 119 | sum = (x, y) -> return x + y | 119 | sum = (x, y) -> return x + y |
| @@ -126,7 +126,7 @@ sum = (x, y) -> return x + y | |||
| 126 | 126 | ||
| 127 | </YueDisplay> | 127 | </YueDisplay> |
| 128 | 128 | ||
| 129 | Just like in Lua, functions can return multiple values. The last statement must be a list of values separated by commas: | 129 | Wie in Lua können Funktionen mehrere Werte zurückgeben. Die letzte Anweisung muss eine Liste von Werten sein, getrennt durch Kommas: |
| 130 | 130 | ||
| 131 | ```yuescript | 131 | ```yuescript |
| 132 | mystery = (x, y) -> x + y, x - y | 132 | mystery = (x, y) -> x + y, x - y |
| @@ -143,7 +143,7 @@ a, b = mystery 10, 20 | |||
| 143 | 143 | ||
| 144 | ## Fat Arrows | 144 | ## Fat Arrows |
| 145 | 145 | ||
| 146 | Because it is an idiom in Lua to send an object as the first argument when calling a method, a special syntax is provided for creating functions which automatically includes a self argument. | 146 | Da es in Lua üblich ist, beim Methodenaufruf ein Objekt als erstes Argument zu übergeben, gibt es eine spezielle Syntax zum Erstellen von Funktionen, die automatisch ein `self`-Argument enthalten. |
| 147 | 147 | ||
| 148 | ```yuescript | 148 | ```yuescript |
| 149 | func = (num) => @value + num | 149 | func = (num) => @value + num |
| @@ -156,26 +156,26 @@ func = (num) => @value + num | |||
| 156 | 156 | ||
| 157 | </YueDisplay> | 157 | </YueDisplay> |
| 158 | 158 | ||
| 159 | ## Argument Defaults | 159 | ## Standardwerte für Argumente |
| 160 | 160 | ||
| 161 | It is possible to provide default values for the arguments of a function. An argument is determined to be empty if its value is nil. Any nil arguments that have a default value will be replace before the body of the function is run. | 161 | Es ist möglich, Standardwerte für Funktionsargumente anzugeben. Ein Argument gilt als leer, wenn sein Wert `nil` ist. Alle `nil`-Argumente mit Standardwert werden vor Ausführung des Funktionskörpers ersetzt. |
| 162 | 162 | ||
| 163 | ```yuescript | 163 | ```yuescript |
| 164 | my_function = (name = "something", height = 100) -> | 164 | my_function = (name = "etwas", height = 100) -> |
| 165 | print "Hello I am", name | 165 | print "Hallo, ich bin", name |
| 166 | print "My height is", height | 166 | print "Meine Größe ist", height |
| 167 | ``` | 167 | ``` |
| 168 | <YueDisplay> | 168 | <YueDisplay> |
| 169 | 169 | ||
| 170 | ```yue | 170 | ```yue |
| 171 | my_function = (name = "something", height = 100) -> | 171 | my_function = (name = "etwas", height = 100) -> |
| 172 | print "Hello I am", name | 172 | print "Hallo, ich bin", name |
| 173 | print "My height is", height | 173 | print "Meine Größe ist", height |
| 174 | ``` | 174 | ``` |
| 175 | 175 | ||
| 176 | </YueDisplay> | 176 | </YueDisplay> |
| 177 | 177 | ||
| 178 | An argument default value expression is evaluated in the body of the function in the order of the argument declarations. For this reason default values have access to previously declared arguments. | 178 | Der Ausdruck für den Standardwert wird im Funktionskörper in der Reihenfolge der Argumentdeklarationen ausgewertet. Daher können Standardwerte auf zuvor deklarierte Argumente zugreifen. |
| 179 | 179 | ||
| 180 | ```yuescript | 180 | ```yuescript |
| 181 | some_args = (x = 100, y = x + 1000) -> | 181 | some_args = (x = 100, y = x + 1000) -> |
| @@ -190,11 +190,11 @@ some_args = (x = 100, y = x + 1000) -> | |||
| 190 | 190 | ||
| 191 | </YueDisplay> | 191 | </YueDisplay> |
| 192 | 192 | ||
| 193 | ## Considerations | 193 | ## Hinweise |
| 194 | 194 | ||
| 195 | Because of the expressive parentheses-less way of calling functions, some restrictions must be put in place to avoid parsing ambiguity involving whitespace. | 195 | Aufgrund der ausdrucksstarken, klammerlosen Funktionsaufrufe müssen einige Einschränkungen gelten, um Parsing-Mehrdeutigkeiten mit Leerraum zu vermeiden. |
| 196 | 196 | ||
| 197 | The minus sign plays two roles, a unary negation operator and a binary subtraction operator. Consider how the following examples compile: | 197 | Das Minuszeichen hat zwei Rollen: unäre Negation und binäre Subtraktion. Sieh dir an, wie die folgenden Beispiele kompiliert werden: |
| 198 | 198 | ||
| 199 | ```yuescript | 199 | ```yuescript |
| 200 | a = x - 10 | 200 | a = x - 10 |
| @@ -213,30 +213,30 @@ d = x- z | |||
| 213 | 213 | ||
| 214 | </YueDisplay> | 214 | </YueDisplay> |
| 215 | 215 | ||
| 216 | The precedence of the first argument of a function call can be controlled using whitespace if the argument is a literal string. In Lua, it is common to leave off parentheses when calling a function with a single string or table literal. | 216 | Die Präzedenz des ersten Arguments eines Funktionsaufrufs kann mit Leerraum gesteuert werden, wenn das Argument ein String-Literal ist. In Lua lässt man bei Aufrufen mit einem einzelnen String- oder Tabellenliteral häufig die Klammern weg. |
| 217 | 217 | ||
| 218 | When there is no space between a variable and a string literal, the function call takes precedence over any following expressions. No other arguments can be passed to the function when it is called this way. | 218 | Wenn kein Leerzeichen zwischen Variable und String-Literal steht, hat der Funktionsaufruf Vorrang vor nachfolgenden Ausdrücken. In dieser Form können keine weiteren Argumente übergeben werden. |
| 219 | 219 | ||
| 220 | Where there is a space following a variable and a string literal, the function call acts as show above. The string literal belongs to any following expressions (if they exist), which serves as the argument list. | 220 | Steht ein Leerzeichen zwischen Variable und String-Literal, verhält sich der Aufruf wie oben gezeigt. Das String-Literal gehört dann zu nachfolgenden Ausdrücken (falls vorhanden) und dient als Argumentliste. |
| 221 | 221 | ||
| 222 | ```yuescript | 222 | ```yuescript |
| 223 | x = func"hello" + 100 | 223 | x = func"hallo" + 100 |
| 224 | y = func "hello" + 100 | 224 | y = func "hallo" + 100 |
| 225 | ``` | 225 | ``` |
| 226 | <YueDisplay> | 226 | <YueDisplay> |
| 227 | 227 | ||
| 228 | ```yue | 228 | ```yue |
| 229 | x = func"hello" + 100 | 229 | x = func"hallo" + 100 |
| 230 | y = func "hello" + 100 | 230 | y = func "hallo" + 100 |
| 231 | ``` | 231 | ``` |
| 232 | 232 | ||
| 233 | </YueDisplay> | 233 | </YueDisplay> |
| 234 | 234 | ||
| 235 | ## Multi-line arguments | 235 | ## Mehrzeilige Argumente |
| 236 | 236 | ||
| 237 | When calling functions that take a large number of arguments, it is convenient to split the argument list over multiple lines. Because of the white-space sensitive nature of the language, care must be taken when splitting up the argument list. | 237 | Wenn Funktionsaufrufe viele Argumente haben, ist es praktisch, die Argumentliste auf mehrere Zeilen zu verteilen. Wegen der whitespace-sensitiven Natur der Sprache muss man dabei sorgfältig sein. |
| 238 | 238 | ||
| 239 | If an argument list is to be continued onto the next line, the current line must end in a comma. And the following line must be indented more than the current indentation. Once indented, all other argument lines must be at the same level of indentation to be part of the argument list | 239 | Wenn eine Argumentliste in der nächsten Zeile fortgesetzt wird, muss die aktuelle Zeile mit einem Komma enden. Die folgende Zeile muss stärker eingerückt sein als die aktuelle. Sobald eingerückt, müssen alle weiteren Argumentzeilen auf derselben Einrückungsebene liegen, um Teil der Argumentliste zu sein. |
| 240 | 240 | ||
| 241 | ```yuescript | 241 | ```yuescript |
| 242 | my_func 5, 4, 3, | 242 | my_func 5, 4, 3, |
| @@ -261,7 +261,7 @@ cool_func 1, 2, | |||
| 261 | 261 | ||
| 262 | </YueDisplay> | 262 | </YueDisplay> |
| 263 | 263 | ||
| 264 | This type of invocation can be nested. The level of indentation is used to determine to which function the arguments belong to. | 264 | Diese Art des Aufrufs kann verschachtelt werden. Die Einrückungsebene bestimmt, zu welcher Funktion die Argumente gehören. |
| 265 | 265 | ||
| 266 | ```yuescript | 266 | ```yuescript |
| 267 | my_func 5, 6, 7, | 267 | my_func 5, 6, 7, |
| @@ -280,7 +280,7 @@ my_func 5, 6, 7, | |||
| 280 | 280 | ||
| 281 | </YueDisplay> | 281 | </YueDisplay> |
| 282 | 282 | ||
| 283 | Because tables also use the comma as a delimiter, this indentation syntax is helpful for letting values be part of the argument list instead of being part of the table. | 283 | Da Tabellen ebenfalls das Komma als Trennzeichen verwenden, hilft diese Einrückungssyntax dabei, Werte zur Argumentliste gehören zu lassen, statt zur Tabelle. |
| 284 | 284 | ||
| 285 | ```yuescript | 285 | ```yuescript |
| 286 | x = [ | 286 | x = [ |
| @@ -301,7 +301,7 @@ x = [ | |||
| 301 | 301 | ||
| 302 | </YueDisplay> | 302 | </YueDisplay> |
| 303 | 303 | ||
| 304 | Although uncommon, notice how we can give a deeper indentation for function arguments if we know we will be using a lower indentation further on. | 304 | Obwohl es selten ist: Du kannst Funktionsargumente tiefer einrücken, wenn du weißt, dass du später eine geringere Einrückungsebene verwenden wirst. |
| 305 | 305 | ||
| 306 | ```yuescript | 306 | ```yuescript |
| 307 | y = [ my_func 1, 2, 3, | 307 | y = [ my_func 1, 2, 3, |
| @@ -320,46 +320,45 @@ y = [ my_func 1, 2, 3, | |||
| 320 | 320 | ||
| 321 | </YueDisplay> | 321 | </YueDisplay> |
| 322 | 322 | ||
| 323 | The same thing can be done with other block level statements like conditionals. We can use indentation level to determine what statement a value belongs to: | 323 | Dasselbe lässt sich mit anderen Block-Statements wie Bedingungen machen. Wir können die Einrückungsebene verwenden, um zu bestimmen, zu welcher Anweisung ein Wert gehört: |
| 324 | 324 | ||
| 325 | ```yuescript | 325 | ```yuescript |
| 326 | if func 1, 2, 3, | 326 | if func 1, 2, 3, |
| 327 | "hello", | 327 | "hallo", |
| 328 | "world" | 328 | "Welt" |
| 329 | print "hello" | 329 | print "hallo" |
| 330 | print "I am inside if" | 330 | print "Ich bin innerhalb der if-Bedingung" |
| 331 | 331 | ||
| 332 | if func 1, 2, 3, | 332 | if func 1, 2, 3, |
| 333 | "hello", | 333 | "hallo", |
| 334 | "world" | 334 | "Welt" |
| 335 | print "hello" | 335 | print "hallo" |
| 336 | print "I am inside if" | 336 | print "Ich bin innerhalb der if-Bedingung" |
| 337 | ``` | 337 | ``` |
| 338 | <YueDisplay> | 338 | <YueDisplay> |
| 339 | 339 | ||
| 340 | ```yue | 340 | ```yue |
| 341 | if func 1, 2, 3, | 341 | if func 1, 2, 3, |
| 342 | "hello", | 342 | "hallo", |
| 343 | "world" | 343 | "Welt" |
| 344 | print "hello" | 344 | print "hallo" |
| 345 | print "I am inside if" | 345 | print "Ich bin innerhalb der if-Bedingung" |
| 346 | 346 | ||
| 347 | if func 1, 2, 3, | 347 | if func 1, 2, 3, |
| 348 | "hello", | 348 | "hallo", |
| 349 | "world" | 349 | "Welt" |
| 350 | print "hello" | 350 | print "hallo" |
| 351 | print "I am inside if" | 351 | print "Ich bin innerhalb der if-Bedingung" |
| 352 | ``` | 352 | ``` |
| 353 | 353 | ||
| 354 | </YueDisplay> | 354 | </YueDisplay> |
| 355 | 355 | ||
| 356 | ## Parameter Destructuring | 356 | ## Parameter-Destructuring |
| 357 | 357 | ||
| 358 | YueScript now supports destructuring function parameters when the argument is an object. Two forms of destructuring table literals are available: | 358 | YueScript unterstützt jetzt Destructuring von Funktionsparametern, wenn das Argument ein Objekt ist. Es gibt zwei Formen von Destructuring-Tabellenliteralen: |
| 359 | 359 | ||
| 360 | * **Curly-brace wrapped literals/object parameters**, allowing optional default values when fields are missing (e.g., `{:a, :b}`, `{a: a1 = 123}`). | 360 | * **Geschweifte Klammern/Objektparameter**, die optionale Standardwerte erlauben, wenn Felder fehlen (z. B. `{:a, :b}`, `{a: a1 = 123}`). |
| 361 | 361 | * **Unverpackte einfache Tabellensyntax**, die mit einer Sequenz aus Key-Value- oder Shorthand-Bindings beginnt und so lange läuft, bis ein anderer Ausdruck sie beendet (z. B. `:a, b: b1, :c`). Diese Form extrahiert mehrere Felder aus demselben Objekt. | |
| 362 | * **Unwrapped simple table syntax**, starting with a sequence of key-value or shorthand bindings and continuing until another expression terminates it (e.g., `:a, b: b1, :c`). This form extracts multiple fields from the same object. | ||
| 363 | 362 | ||
| 364 | ```yuescript | 363 | ```yuescript |
| 365 | f1 = (:a, :b, :c) -> | 364 | f1 = (:a, :b, :c) -> |
| @@ -390,9 +389,9 @@ f2 arg1, arg2 | |||
| 390 | 389 | ||
| 391 | </YueDisplay> | 390 | </YueDisplay> |
| 392 | 391 | ||
| 393 | ## Prefixed Return Expression | 392 | ## Präfixiertes Return-Expression |
| 394 | 393 | ||
| 395 | When working with deeply nested function bodies, it can be tedious to maintain readability and consistency of the return value. To address this, YueScript introduces the **Prefixed Return Expression** syntax. Its form is as follows: | 394 | Wenn du mit tief verschachtelten Funktionskörpern arbeitest, kann es mühsam sein, die Lesbarkeit und Konsistenz des Rückgabewerts zu erhalten. Dafür führt YueScript die Syntax der **präfixierten Return-Expression** ein. Sie hat folgende Form: |
| 396 | 395 | ||
| 397 | ```yuescript | 396 | ```yuescript |
| 398 | findFirstEven = (list): nil -> | 397 | findFirstEven = (list): nil -> |
| @@ -415,7 +414,7 @@ findFirstEven = (list): nil -> | |||
| 415 | 414 | ||
| 416 | </YueDisplay> | 415 | </YueDisplay> |
| 417 | 416 | ||
| 418 | This is equivalent to: | 417 | Das ist äquivalent zu: |
| 419 | 418 | ||
| 420 | ```yuescript | 419 | ```yuescript |
| 421 | findFirstEven = (list) -> | 420 | findFirstEven = (list) -> |
| @@ -440,16 +439,16 @@ findFirstEven = (list) -> | |||
| 440 | 439 | ||
| 441 | </YueDisplay> | 440 | </YueDisplay> |
| 442 | 441 | ||
| 443 | The only difference is that you can move the final return expression before the `->` or `=>` token to indicate the function’s implicit return value as the last statement. This way, even in functions with multiple nested loops or conditional branches, you no longer need to write a trailing return expression at the end of the function body, making the logic structure more straightforward and easier to follow. | 442 | Der einzige Unterschied ist, dass du den finalen Rückgabeausdruck vor das `->`- oder `=>`-Token ziehen kannst, um den impliziten Rückgabewert der Funktion als letzte Anweisung zu kennzeichnen. So musst du selbst bei Funktionen mit mehreren verschachtelten Schleifen oder bedingten Zweigen kein abschließendes `return` am Ende des Funktionskörpers mehr schreiben, was die Logikstruktur klarer und leichter nachvollziehbar macht. |
| 444 | 443 | ||
| 445 | ## Named Varargs | 444 | ## Benannte Varargs |
| 446 | 445 | ||
| 447 | You can use the `(...t) ->` syntax to automatically store varargs into a named table. This table will contain all passed arguments (including `nil` values), and the `n` field of the table will store the actual number of arguments passed (including `nil` values). | 446 | Mit der Syntax `(...t) ->` kannst du Varargs automatisch in einer benannten Tabelle speichern. Diese Tabelle enthält alle übergebenen Argumente (einschließlich `nil`-Werten), und das Feld `n` der Tabelle speichert die tatsächliche Anzahl übergebener Argumente (einschließlich `nil`-Werten). |
| 448 | 447 | ||
| 449 | ```yuescript | 448 | ```yuescript |
| 450 | f = (...t) -> | 449 | f = (...t) -> |
| 451 | print "argument count:", t.n | 450 | print "Anzahl der Argumente:", t.n |
| 452 | print "table length:", #t | 451 | print "Tabellenlänge:", #t |
| 453 | for i = 1, t.n | 452 | for i = 1, t.n |
| 454 | print t[i] | 453 | print t[i] |
| 455 | 454 | ||
| @@ -457,7 +456,7 @@ f 1, 2, 3 | |||
| 457 | f "a", "b", "c", "d" | 456 | f "a", "b", "c", "d" |
| 458 | f! | 457 | f! |
| 459 | 458 | ||
| 460 | -- Handling cases with nil values | 459 | -- Fälle mit nil-Werten behandeln |
| 461 | process = (...args) -> | 460 | process = (...args) -> |
| 462 | sum = 0 | 461 | sum = 0 |
| 463 | for i = 1, args.n | 462 | for i = 1, args.n |
| @@ -471,8 +470,8 @@ process 1, nil, 3, nil, 5 | |||
| 471 | 470 | ||
| 472 | ```yue | 471 | ```yue |
| 473 | f = (...t) -> | 472 | f = (...t) -> |
| 474 | print "argument count:", t.n | 473 | print "Anzahl der Argumente:", t.n |
| 475 | print "table length:", #t | 474 | print "Tabellenlänge:", #t |
| 476 | for i = 1, t.n | 475 | for i = 1, t.n |
| 477 | print t[i] | 476 | print t[i] |
| 478 | 477 | ||
| @@ -480,7 +479,7 @@ f 1, 2, 3 | |||
| 480 | f "a", "b", "c", "d" | 479 | f "a", "b", "c", "d" |
| 481 | f! | 480 | f! |
| 482 | 481 | ||
| 483 | -- Handling cases with nil values | 482 | -- Fälle mit nil-Werten behandeln |
| 484 | process = (...args) -> | 483 | process = (...args) -> |
| 485 | sum = 0 | 484 | sum = 0 |
| 486 | for i = 1, args.n | 485 | for i = 1, args.n |
diff --git a/doc/docs/de/doc/functions/function-stubs.md b/doc/docs/de/doc/functions/function-stubs.md index 57a8b0c..66b3ddb 100644 --- a/doc/docs/de/doc/functions/function-stubs.md +++ b/doc/docs/de/doc/functions/function-stubs.md | |||
| @@ -1,27 +1,27 @@ | |||
| 1 | # Function Stubs | 1 | # Funktions-Stubs |
| 2 | 2 | ||
| 3 | It is common to pass a function from an object around as a value, for example, passing an instance method into a function as a callback. If the function expects the object it is operating on as the first argument then you must somehow bundle that object with the function so it can be called properly. | 3 | Es ist üblich, eine Funktion eines Objekts als Wert weiterzureichen, z. B. eine Instanzmethode als Callback. Wenn die Funktion das Objekt, auf dem sie arbeitet, als erstes Argument erwartet, musst du dieses Objekt irgendwie mit der Funktion bündeln, damit sie korrekt aufgerufen werden kann. |
| 4 | 4 | ||
| 5 | The function stub syntax is a shorthand for creating a new closure function that bundles both the object and function. This new function calls the wrapped function in the correct context of the object. | 5 | Die Funktions-Stub-Syntax ist eine Kurzform, um eine neue Closure-Funktion zu erstellen, die sowohl Objekt als auch Funktion bündelt. Diese neue Funktion ruft die umschlossene Funktion im richtigen Kontext des Objekts auf. |
| 6 | 6 | ||
| 7 | Its syntax is the same as calling an instance method with the \ operator but with no argument list provided. | 7 | Die Syntax entspricht dem Aufruf einer Instanzmethode mit dem `\`-Operator, jedoch ohne Argumentliste. |
| 8 | 8 | ||
| 9 | ```yuescript | 9 | ```yuescript |
| 10 | my_object = { | 10 | my_object = { |
| 11 | value: 1000 | 11 | value: 1000 |
| 12 | write: => print "the value:", @value | 12 | write: => print "der Wert:", @value |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | run_callback = (func) -> | 15 | run_callback = (func) -> |
| 16 | print "running callback..." | 16 | print "Callback wird ausgeführt..." |
| 17 | func! | 17 | func! |
| 18 | 18 | ||
| 19 | -- this will not work: | 19 | -- das funktioniert nicht: |
| 20 | -- the function has to no reference to my_object | 20 | -- die Funktion darf keine Referenz auf my_object haben |
| 21 | run_callback my_object.write | 21 | run_callback my_object.write |
| 22 | 22 | ||
| 23 | -- function stub syntax | 23 | -- Funktions-Stub-Syntax |
| 24 | -- lets us bundle the object into a new function | 24 | -- bindet das Objekt in eine neue Funktion ein |
| 25 | run_callback my_object\write | 25 | run_callback my_object\write |
| 26 | ``` | 26 | ``` |
| 27 | <YueDisplay> | 27 | <YueDisplay> |
| @@ -29,19 +29,19 @@ run_callback my_object\write | |||
| 29 | ```yue | 29 | ```yue |
| 30 | my_object = { | 30 | my_object = { |
| 31 | value: 1000 | 31 | value: 1000 |
| 32 | write: => print "the value:", @value | 32 | write: => print "der Wert:", @value |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | run_callback = (func) -> | 35 | run_callback = (func) -> |
| 36 | print "running callback..." | 36 | print "Callback wird ausgeführt..." |
| 37 | func! | 37 | func! |
| 38 | 38 | ||
| 39 | -- this will not work: | 39 | -- das funktioniert nicht: |
| 40 | -- the function has to no reference to my_object | 40 | -- die Funktion darf keine Referenz auf my_object haben |
| 41 | run_callback my_object.write | 41 | run_callback my_object.write |
| 42 | 42 | ||
| 43 | -- function stub syntax | 43 | -- Funktions-Stub-Syntax |
| 44 | -- lets us bundle the object into a new function | 44 | -- bindet das Objekt in eine neue Funktion ein |
| 45 | run_callback my_object\write | 45 | run_callback my_object\write |
| 46 | ``` | 46 | ``` |
| 47 | 47 | ||
diff --git a/doc/docs/de/doc/getting-started/installation.md b/doc/docs/de/doc/getting-started/installation.md index a93ddfd..78187c7 100644 --- a/doc/docs/de/doc/getting-started/installation.md +++ b/doc/docs/de/doc/getting-started/installation.md | |||
| @@ -1,43 +1,43 @@ | |||
| 1 | # Installation | 1 | # Installation |
| 2 | 2 | ||
| 3 | ## Lua Module | 3 | ## Lua-Modul |
| 4 | 4 | ||
| 5 | Install [luarocks](https://luarocks.org), a package manager for Lua modules. Then install it as a Lua module and executable with: | 5 | Installiere [luarocks](https://luarocks.org), einen Paketmanager für Lua-Module. Installiere YueScript dann als Lua-Modul und ausführbare Datei mit: |
| 6 | 6 | ||
| 7 | ```shell | 7 | ```shell |
| 8 | luarocks install yuescript | 8 | luarocks install yuescript |
| 9 | ``` | 9 | ``` |
| 10 | 10 | ||
| 11 | Or you can build `yue.so` file with: | 11 | Oder du kannst die Datei `yue.so` bauen mit: |
| 12 | 12 | ||
| 13 | ```shell | 13 | ```shell |
| 14 | make shared LUAI=/usr/local/include/lua LUAL=/usr/local/lib/lua | 14 | make shared LUAI=/usr/local/include/lua LUAL=/usr/local/lib/lua |
| 15 | ``` | 15 | ``` |
| 16 | 16 | ||
| 17 | Then get the binary file from path **bin/shared/yue.so**. | 17 | Anschließend findest du die Binärdatei unter **bin/shared/yue.so**. |
| 18 | 18 | ||
| 19 | ## Build Binary Tool | 19 | ## Binär-Tool bauen |
| 20 | 20 | ||
| 21 | Clone this repo, then build and install executable with: | 21 | Klone dieses Repo und baue/installiere die ausführbare Datei mit: |
| 22 | 22 | ||
| 23 | ```shell | 23 | ```shell |
| 24 | make install | 24 | make install |
| 25 | ``` | 25 | ``` |
| 26 | 26 | ||
| 27 | Build YueScript tool without macro feature: | 27 | YueScript-Tool ohne Makro-Feature bauen: |
| 28 | 28 | ||
| 29 | ```shell | 29 | ```shell |
| 30 | make install NO_MACRO=true | 30 | make install NO_MACRO=true |
| 31 | ``` | 31 | ``` |
| 32 | 32 | ||
| 33 | Build YueScript tool without built-in Lua binary: | 33 | YueScript-Tool ohne eingebautes Lua-Binary bauen: |
| 34 | 34 | ||
| 35 | ```shell | 35 | ```shell |
| 36 | make install NO_LUA=true | 36 | make install NO_LUA=true |
| 37 | ``` | 37 | ``` |
| 38 | 38 | ||
| 39 | ## Download Precompiled Binary | 39 | ## Vorgefertigtes Binary herunterladen |
| 40 | 40 | ||
| 41 | You can download precompiled binary files, including binary executable files compatible with different Lua versions and library files. | 41 | Du kannst vorkompilierte Binärdateien herunterladen, inklusive ausführbarer Dateien für unterschiedliche Lua-Versionen und Bibliotheksdateien. |
| 42 | 42 | ||
| 43 | Download precompiled binary files from [here](https://github.com/IppClub/YueScript/releases). | 43 | Lade vorkompilierte Binärdateien von [hier](https://github.com/IppClub/YueScript/releases) herunter. |
diff --git a/doc/docs/de/doc/getting-started/introduction.md b/doc/docs/de/doc/getting-started/introduction.md index a9a9389..38354c1 100644 --- a/doc/docs/de/doc/getting-started/introduction.md +++ b/doc/docs/de/doc/getting-started/introduction.md | |||
| @@ -1,27 +1,27 @@ | |||
| 1 | # Introduction | 1 | # Einführung |
| 2 | 2 | ||
| 3 | YueScript is a dynamic language that compiles to Lua. And it's a [MoonScript](https://github.com/leafo/moonscript) dialect. The codes written in YueScript are expressive and extremely concise. And it is suitable for writing some changing application logic with more maintainable codes and runs in a Lua embeded environment such as games or website servers. | 3 | YueScript ist eine dynamische Sprache, die zu Lua kompiliert. Sie ist ein Dialekt von [MoonScript](https://github.com/leafo/moonscript). Code, der in YueScript geschrieben wird, ist ausdrucksstark und sehr kompakt. YueScript eignet sich zum Schreiben von veränderlicher Anwendungslogik mit besser wartbarem Code und läuft in eingebetteten Lua-Umgebungen wie Spielen oder Webservern. |
| 4 | 4 | ||
| 5 | Yue (月) is the name of moon in Chinese and it's pronounced as [jyɛ]. | 5 | Yue (月) ist das chinesische Wort für Mond und wird als [jyɛ] ausgesprochen. |
| 6 | 6 | ||
| 7 | ## An Overview of YueScript | 7 | ## Ein Überblick über YueScript |
| 8 | 8 | ||
| 9 | ```yuescript | 9 | ```yuescript |
| 10 | -- import syntax | 10 | -- Import-Syntax |
| 11 | import p, to_lua from "yue" | 11 | import p, to_lua from "yue" |
| 12 | 12 | ||
| 13 | -- object literals | 13 | -- Objekt-Literale |
| 14 | inventory = | 14 | inventory = |
| 15 | equipment: | 15 | equipment: |
| 16 | - "sword" | 16 | - "Schwert" |
| 17 | - "shield" | 17 | - "Schild" |
| 18 | items: | 18 | items: |
| 19 | - name: "potion" | 19 | - name: "Trank" |
| 20 | count: 10 | 20 | count: 10 |
| 21 | - name: "bread" | 21 | - name: "Brot" |
| 22 | count: 3 | 22 | count: 3 |
| 23 | 23 | ||
| 24 | -- list comprehension | 24 | -- Listen-Abstraktion |
| 25 | map = (arr, action) -> | 25 | map = (arr, action) -> |
| 26 | [action item for item in *arr] | 26 | [action item for item in *arr] |
| 27 | 27 | ||
| @@ -31,14 +31,14 @@ filter = (arr, cond) -> | |||
| 31 | reduce = (arr, init, action): init -> | 31 | reduce = (arr, init, action): init -> |
| 32 | init = action init, item for item in *arr | 32 | init = action init, item for item in *arr |
| 33 | 33 | ||
| 34 | -- pipe operator | 34 | -- Pipe-Operator |
| 35 | [1, 2, 3] | 35 | [1, 2, 3] |
| 36 | |> map (x) -> x * 2 | 36 | |> map (x) -> x * 2 |
| 37 | |> filter (x) -> x > 4 | 37 | |> filter (x) -> x > 4 |
| 38 | |> reduce 0, (a, b) -> a + b | 38 | |> reduce 0, (a, b) -> a + b |
| 39 | 39 | ||
| 40 | 40 | ||
| 41 | -- metatable manipulation | 41 | -- Metatable-Manipulation |
| 42 | apple = | 42 | apple = |
| 43 | size: 15 | 43 | size: 15 |
| 44 | <index>: | 44 | <index>: |
| @@ -47,28 +47,28 @@ apple = | |||
| 47 | with apple | 47 | with apple |
| 48 | p .size, .color, .<index> if .<>? | 48 | p .size, .color, .<index> if .<>? |
| 49 | 49 | ||
| 50 | -- js-like export syntax | 50 | -- export-Syntax (ähnlich wie in JavaScript) |
| 51 | export 🌛 = "月之脚本" | 51 | export 🌛 = "Skript des Mondes" |
| 52 | ``` | 52 | ``` |
| 53 | 53 | ||
| 54 | <YueDisplay> | 54 | <YueDisplay> |
| 55 | 55 | ||
| 56 | ```yue | 56 | ```yue |
| 57 | -- import syntax | 57 | -- Import-Syntax |
| 58 | import p, to_lua from "yue" | 58 | import p, to_lua from "yue" |
| 59 | 59 | ||
| 60 | -- object literals | 60 | -- Objekt-Literale |
| 61 | inventory = | 61 | inventory = |
| 62 | equipment: | 62 | equipment: |
| 63 | - "sword" | 63 | - "Schwert" |
| 64 | - "shield" | 64 | - "Schild" |
| 65 | items: | 65 | items: |
| 66 | - name: "potion" | 66 | - name: "Trank" |
| 67 | count: 10 | 67 | count: 10 |
| 68 | - name: "bread" | 68 | - name: "Brot" |
| 69 | count: 3 | 69 | count: 3 |
| 70 | 70 | ||
| 71 | -- list comprehension | 71 | -- Listen-Abstraktion |
| 72 | map = (arr, action) -> | 72 | map = (arr, action) -> |
| 73 | [action item for item in *arr] | 73 | [action item for item in *arr] |
| 74 | 74 | ||
| @@ -78,14 +78,14 @@ filter = (arr, cond) -> | |||
| 78 | reduce = (arr, init, action): init -> | 78 | reduce = (arr, init, action): init -> |
| 79 | init = action init, item for item in *arr | 79 | init = action init, item for item in *arr |
| 80 | 80 | ||
| 81 | -- pipe operator | 81 | -- Pipe-Operator |
| 82 | [1, 2, 3] | 82 | [1, 2, 3] |
| 83 | |> map (x) -> x * 2 | 83 | |> map (x) -> x * 2 |
| 84 | |> filter (x) -> x > 4 | 84 | |> filter (x) -> x > 4 |
| 85 | |> reduce 0, (a, b) -> a + b | 85 | |> reduce 0, (a, b) -> a + b |
| 86 | 86 | ||
| 87 | 87 | ||
| 88 | -- metatable manipulation | 88 | -- Metatable-Manipulation |
| 89 | apple = | 89 | apple = |
| 90 | size: 15 | 90 | size: 15 |
| 91 | <index>: | 91 | <index>: |
| @@ -94,12 +94,12 @@ apple = | |||
| 94 | with apple | 94 | with apple |
| 95 | p .size, .color, .<index> if .<>? | 95 | p .size, .color, .<index> if .<>? |
| 96 | 96 | ||
| 97 | -- js-like export syntax | 97 | -- export-Syntax (ähnlich wie in JavaScript) |
| 98 | export 🌛 = "月之脚本" | 98 | export 🌛 = "Skript des Mondes" |
| 99 | ``` | 99 | ``` |
| 100 | 100 | ||
| 101 | </YueDisplay> | 101 | </YueDisplay> |
| 102 | 102 | ||
| 103 | ## About Dora SSR | 103 | ## Über Dora SSR |
| 104 | 104 | ||
| 105 | YueScript is being developed and maintained alongside the open-source game engine [Dora SSR](https://github.com/Dora-SSR/Dora-SSR). It has been used to create engine tools, game demos and prototypes, validating its capabilities in real-world scenarios while enhancing the Dora SSR development experience. \ No newline at end of file | 105 | YueScript wird zusammen mit der Open-Source-Spiel-Engine [Dora SSR](https://github.com/Dora-SSR/Dora-SSR) entwickelt und gepflegt. Es wird zum Erstellen von Engine-Tools, Spiel-Demos und Prototypen eingesetzt und hat seine Leistungsfähigkeit in realen Szenarien unter Beweis gestellt, während es gleichzeitig die Dora-SSR-Entwicklungserfahrung verbessert. |
diff --git a/doc/docs/de/doc/getting-started/usage.md b/doc/docs/de/doc/getting-started/usage.md index 45161c6..f3c9333 100644 --- a/doc/docs/de/doc/getting-started/usage.md +++ b/doc/docs/de/doc/getting-started/usage.md | |||
| @@ -1,20 +1,20 @@ | |||
| 1 | # Usage | 1 | # Verwendung |
| 2 | 2 | ||
| 3 | ## Lua Module | 3 | ## Lua-Modul |
| 4 | 4 | ||
| 5 | Use YueScript module in Lua: | 5 | YueScript-Modul in Lua verwenden: |
| 6 | 6 | ||
| 7 | * **Case 1** | 7 | * **Fall 1** |
| 8 | 8 | ||
| 9 | Require "your_yuescript_entry.yue" in Lua. | 9 | "your_yuescript_entry.yue" in Lua require'n. |
| 10 | ```Lua | 10 | ```Lua |
| 11 | require("yue")("your_yuescript_entry") | 11 | require("yue")("your_yuescript_entry") |
| 12 | ``` | 12 | ``` |
| 13 | And this code still works when you compile "your_yuescript_entry.yue" to "your_yuescript_entry.lua" in the same path. In the rest YueScript files just use the normal **require** or **import**. The code line numbers in error messages will also be handled correctly. | 13 | Dieser Code funktioniert weiterhin, wenn du "your_yuescript_entry.yue" im gleichen Pfad zu "your_yuescript_entry.lua" kompilierst. In den restlichen YueScript-Dateien verwendest du einfach normales **require** oder **import**. Die Zeilennummern in Fehlermeldungen werden korrekt behandelt. |
| 14 | 14 | ||
| 15 | * **Case 2** | 15 | * **Fall 2** |
| 16 | 16 | ||
| 17 | Require YueScript module and rewite message by hand. | 17 | YueScript-Modul require'n und das Fehlermapping manuell umschreiben. |
| 18 | 18 | ||
| 19 | ```lua | 19 | ```lua |
| 20 | local yue = require("yue") | 20 | local yue = require("yue") |
| @@ -26,15 +26,15 @@ Use YueScript module in Lua: | |||
| 26 | end) | 26 | end) |
| 27 | ``` | 27 | ``` |
| 28 | 28 | ||
| 29 | * **Case 3** | 29 | * **Fall 3** |
| 30 | 30 | ||
| 31 | Use the YueScript compiler function in Lua. | 31 | Die YueScript-Compilerfunktion in Lua verwenden. |
| 32 | 32 | ||
| 33 | ```lua | 33 | ```lua |
| 34 | local yue = require("yue") | 34 | local yue = require("yue") |
| 35 | local codes, err, globals = yue.to_lua([[ | 35 | local codes, err, globals = yue.to_lua([[ |
| 36 | f = -> | 36 | f = -> |
| 37 | print "hello world" | 37 | print "Hallo Welt" |
| 38 | f! | 38 | f! |
| 39 | ]],{ | 39 | ]],{ |
| 40 | implicit_return_root = true, | 40 | implicit_return_root = true, |
| @@ -48,64 +48,66 @@ Use YueScript module in Lua: | |||
| 48 | }) | 48 | }) |
| 49 | ``` | 49 | ``` |
| 50 | 50 | ||
| 51 | ## YueScript Tool | 51 | ## YueScript-Tool |
| 52 | 52 | ||
| 53 | Use YueScript tool with: | 53 | YueScript-Tool verwenden mit: |
| 54 | 54 | ||
| 55 | ```shell | 55 | ```shell |
| 56 | > yue -h | 56 | > yue -h |
| 57 | Usage: yue | 57 | Verwendung: yue |
| 58 | [options] [<file/directory>] ... | 58 | [Optionen] [<Datei/Verzeichnis>] ... |
| 59 | yue -e <code_or_file> [args...] | 59 | yue -e <code_oder_datei> [argumente...] |
| 60 | yue -w [<directory>] [options] | 60 | yue -w [<verzeichnis>] [optionen] |
| 61 | yue - | 61 | yue - |
| 62 | 62 | ||
| 63 | Notes: | 63 | Hinweise: |
| 64 | - '-' / '--' must be the first and only argument. | 64 | - '-' / '--' muss das erste und einzige Argument sein. |
| 65 | - '-o/--output' can not be used with multiple input files. | 65 | - '-o/--output' kann nicht mit mehreren Eingabedateien verwendet werden. |
| 66 | - '-w/--watch' can not be used with file input (directory only). | 66 | - '-w/--watch' kann nicht mit Dateieingabe verwendet werden (nur Verzeichnisse). |
| 67 | - with '-e/--execute', remaining tokens are treated as script args. | 67 | - Mit '-e/--execute' werden verbleibende Tokens als Skriptargumente behandelt. |
| 68 | 68 | ||
| 69 | Options: | 69 | Optionen: |
| 70 | -h, --help Show this help message and exit. | 70 | -h, --help Zeigt diese Hilfemeldung an und beendet das Programm. |
| 71 | -e <str>, --execute <str> Execute a file or raw codes | 71 | -e <str>, --execute <str> Datei oder Quellcode ausführen |
| 72 | -m, --minify Generate minified codes | 72 | -m, --minify Minimierten Code erzeugen |
| 73 | -r, --rewrite Rewrite output to match original line numbers | 73 | -r, --rewrite Ausgabe so umschreiben, dass die Zeilennummern dem Original entsprechen |
| 74 | -t <output_to>, --output-to <output_to> | 74 | -t <ziel>, --output-to <ziel> |
| 75 | Specify where to place compiled files | 75 | Ziel für kompilierte Dateien angeben |
| 76 | -o <file>, --output <file> Write output to file | 76 | -o <datei>, --output <datei> |
| 77 | -p, --print Write output to standard out | 77 | Schreibe die Ausgabe in eine Datei |
| 78 | -b, --benchmark Dump compile time (doesn't write output) | 78 | -p, --print Schreibe die Ausgabe auf die Standardausgabe |
| 79 | -g, --globals Dump global variables used in NAME LINE COLUMN | 79 | -b, --benchmark Gibt die Kompilierungszeit aus (keine Ausgabe schreiben) |
| 80 | -s, --spaces Use spaces in generated codes instead of tabs | 80 | -g, --globals Gibt verwendete globale Variablen im Format NAME ZEILE SPALTE aus |
| 81 | -l, --line-numbers Write line numbers from source codes | 81 | -s, --spaces Verwende Leerzeichen anstelle von Tabs im generierten Code |
| 82 | -j, --no-implicit-return Disable implicit return at end of file | 82 | -l, --line-numbers Schreibe Zeilennummern aus dem Quellcode |
| 83 | -c, --reserve-comments Reserve comments before statement from source codes | 83 | -j, --no-implicit-return Deaktiviert implizites Rückgabe am Datei-Ende |
| 84 | -w [<dir>], --watch [<dir>] | 84 | -c, --reserve-comments Kommentare aus dem Quellcode vor Anweisungen beibehalten |
| 85 | Watch changes and compile every file under directory | 85 | -w [<verz>], --watch [<verz>] |
| 86 | -v, --version Print version | 86 | Änderungen beobachten und alle Dateien im Verzeichnis kompilieren |
| 87 | - Read from standard in, print to standard out | 87 | -v, --version Version ausgeben |
| 88 | (Must be first and only argument) | 88 | - Lese von Standardinput, schreibe auf Standardausgabe |
| 89 | -- Same as '-' (kept for backward compatibility) | 89 | (muss das erste und einzige Argument sein) |
| 90 | 90 | -- Wie '-', bleibt zur Abwärtskompatibilität bestehen | |
| 91 | --target <version> Specify the Lua version that codes will be generated to | 91 | |
| 92 | (version can only be 5.1 to 5.5) | 92 | --target <version> Gib an, welche Lua-Version erzeugt werden soll |
| 93 | --path <path_str> Append an extra Lua search path string to package.path | 93 | (Version nur von 5.1 bis 5.5 möglich) |
| 94 | --<key>=<value> Pass compiler option in key=value form (existing behavior) | 94 | --path <pfad_str> Füge einen zusätzlichen Lua-Suchpfad zu package.path hinzu |
| 95 | 95 | --<schlüssel>=<wert> Übertrage Compileroption im Schlüssel=Wert-Format (bestehendes Verhalten) | |
| 96 | Execute without options to enter REPL, type symbol '$' | 96 | |
| 97 | in a single line to start/stop multi-line mode | 97 | Ohne Optionen wird die REPL gestartet, gebe das Symbol '$' |
| 98 | in eine einzelne Zeile ein, um den Multi-Line-Modus zu starten/beenden | ||
| 98 | ``` | 99 | ``` |
| 99 | Use cases: | ||
| 100 | 100 | ||
| 101 | Recursively compile every YueScript file with extension **.yue** under current path: **yue .** | 101 | Anwendungsfälle: |
| 102 | 102 | ||
| 103 | Compile and save results to a target path: **yue -t /target/path/ .** | 103 | Rekursiv jede YueScript-Datei mit der Endung **.yue** unter dem aktuellen Pfad kompilieren: **yue .** |
| 104 | 104 | ||
| 105 | Compile and reserve debug info: **yue -l .** | 105 | Kompilieren und Ergebnisse in einen Zielpfad schreiben: **yue -t /target/path/ .** |
| 106 | 106 | ||
| 107 | Compile and generate minified codes: **yue -m .** | 107 | Kompilieren und Debug-Infos beibehalten: **yue -l .** |
| 108 | 108 | ||
| 109 | Execute raw codes: **yue -e 'print 123'** | 109 | Kompilieren und minifizierten Code erzeugen: **yue -m .** |
| 110 | 110 | ||
| 111 | Execute a YueScript file: **yue -e main.yue** | 111 | Rohcode ausführen: **yue -e 'print 123'** |
| 112 | |||
| 113 | Eine YueScript-Datei ausführen: **yue -e main.yue** | ||
diff --git a/doc/docs/de/doc/language-basics/attributes.md b/doc/docs/de/doc/language-basics/attributes.md index e6fd5a7..0fa3654 100644 --- a/doc/docs/de/doc/language-basics/attributes.md +++ b/doc/docs/de/doc/language-basics/attributes.md | |||
| @@ -1,21 +1,21 @@ | |||
| 1 | # Attributes | 1 | # Attribute |
| 2 | 2 | ||
| 3 | Syntax support for Lua 5.4 attributes. And you can still use both the `const` and `close` declaration and get constant check and scoped callback working when targeting Lua versions below 5.4. | 3 | Syntax-Unterstützung für Lua-5.4-Attribute. Du kannst weiterhin die Deklarationen `const` und `close` verwenden und erhältst Konstantenprüfung sowie Scoped-Callbacks, wenn du auf Lua-Versionen unter 5.4 zielst. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | const a = 123 | 6 | const a = 123 |
| 7 | close _ = <close>: -> print "Out of scope." | 7 | close _ = <close>: -> print "Außerhalb des Gültigkeitsbereichs." |
| 8 | ``` | 8 | ``` |
| 9 | <YueDisplay> | 9 | <YueDisplay> |
| 10 | 10 | ||
| 11 | ```yue | 11 | ```yue |
| 12 | const a = 123 | 12 | const a = 123 |
| 13 | close _ = <close>: -> print "Out of scope." | 13 | close _ = <close>: -> print "Außerhalb des Gültigkeitsbereichs." |
| 14 | ``` | 14 | ``` |
| 15 | 15 | ||
| 16 | </YueDisplay> | 16 | </YueDisplay> |
| 17 | 17 | ||
| 18 | You can do desctructuring with variables attributed as constant. | 18 | Du kannst Destructuring mit als konstant markierten Variablen verwenden. |
| 19 | 19 | ||
| 20 | ```yuescript | 20 | ```yuescript |
| 21 | const {:a, :b, c, d} = tb | 21 | const {:a, :b, c, d} = tb |
| @@ -30,7 +30,7 @@ const {:a, :b, c, d} = tb | |||
| 30 | 30 | ||
| 31 | </YueDisplay> | 31 | </YueDisplay> |
| 32 | 32 | ||
| 33 | You can also declare a global variable to be `const`. | 33 | Du kannst auch eine globale Variable als `const` deklarieren. |
| 34 | 34 | ||
| 35 | ```yuescript | 35 | ```yuescript |
| 36 | global const Constant = 123 | 36 | global const Constant = 123 |
diff --git a/doc/docs/de/doc/language-basics/comment.md b/doc/docs/de/doc/language-basics/comment.md index b67c97d..dec9bb0 100644 --- a/doc/docs/de/doc/language-basics/comment.md +++ b/doc/docs/de/doc/language-basics/comment.md | |||
| @@ -1,30 +1,30 @@ | |||
| 1 | # Comment | 1 | # Kommentare |
| 2 | 2 | ||
| 3 | ```yuescript | 3 | ```yuescript |
| 4 | -- I am a comment | 4 | -- Ich bin ein Kommentar |
| 5 | 5 | ||
| 6 | str = --[[ | 6 | str = --[[ |
| 7 | This is a multi-line comment. | 7 | Dies ist ein mehrzeiliger Kommentar. |
| 8 | It's OK. | 8 | Alles okay. |
| 9 | ]] strA \ -- comment 1 | 9 | ]] strA \ -- Kommentar 1 |
| 10 | .. strB \ -- comment 2 | 10 | .. strB \ -- Kommentar 2 |
| 11 | .. strC | 11 | .. strC |
| 12 | 12 | ||
| 13 | func --[[port]] 3000, --[[ip]] "192.168.1.1" | 13 | func --[[Port]] 3000, --[[IP]] "192.168.1.1" |
| 14 | ``` | 14 | ``` |
| 15 | <YueDisplay> | 15 | <YueDisplay> |
| 16 | 16 | ||
| 17 | ```yue | 17 | ```yue |
| 18 | -- I am a comment | 18 | -- Ich bin ein Kommentar |
| 19 | 19 | ||
| 20 | str = --[[ | 20 | str = --[[ |
| 21 | This is a multi-line comment. | 21 | Dies ist ein mehrzeiliger Kommentar. |
| 22 | It's OK. | 22 | Alles okay. |
| 23 | ]] strA \ -- comment 1 | 23 | ]] strA \ -- Kommentar 1 |
| 24 | .. strB \ -- comment 2 | 24 | .. strB \ -- Kommentar 2 |
| 25 | .. strC | 25 | .. strC |
| 26 | 26 | ||
| 27 | func --[[port]] 3000, --[[ip]] "192.168.1.1" | 27 | func --[[Port]] 3000, --[[IP]] "192.168.1.1" |
| 28 | ``` | 28 | ``` |
| 29 | 29 | ||
| 30 | </YueDisplay> | 30 | </YueDisplay> |
diff --git a/doc/docs/de/doc/language-basics/literals.md b/doc/docs/de/doc/language-basics/literals.md index e097c62..55a5aaa 100644 --- a/doc/docs/de/doc/language-basics/literals.md +++ b/doc/docs/de/doc/language-basics/literals.md | |||
| @@ -1,33 +1,33 @@ | |||
| 1 | # Literals | 1 | # Literale |
| 2 | 2 | ||
| 3 | All of the primitive literals in Lua can be used. This applies to numbers, strings, booleans, and **nil**. | 3 | Alle primitiven Literale in Lua können verwendet werden. Das gilt für Zahlen, Strings, Booleans und **nil**. |
| 4 | 4 | ||
| 5 | Unlike Lua, Line breaks are allowed inside of single and double quote strings without an escape sequence: | 5 | Anders als in Lua sind Zeilenumbrüche innerhalb einfacher und doppelter Anführungszeichen ohne Escape-Sequenz erlaubt: |
| 6 | 6 | ||
| 7 | ```yuescript | 7 | ```yuescript |
| 8 | some_string = "Here is a string | 8 | some_string = "Hier ist ein String |
| 9 | that has a line break in it." | 9 | mit einem Zeilenumbruch." |
| 10 | 10 | ||
| 11 | -- You can mix expressions into string literals using #{} syntax. | 11 | -- Mit der #{}-Syntax kannst du Ausdrücke in String-Literale einbinden. |
| 12 | -- String interpolation is only available in double quoted strings. | 12 | -- String-Interpolation gibt es nur in doppelt angeführten Strings. |
| 13 | print "I am #{math.random! * 100}% sure." | 13 | print "Ich bin mir zu #{math.random! * 100}% sicher." |
| 14 | ``` | 14 | ``` |
| 15 | <YueDisplay> | 15 | <YueDisplay> |
| 16 | 16 | ||
| 17 | ```yue | 17 | ```yue |
| 18 | some_string = "Here is a string | 18 | some_string = "Hier ist ein String |
| 19 | that has a line break in it." | 19 | mit einem Zeilenumbruch." |
| 20 | 20 | ||
| 21 | -- You can mix expressions into string literals using #{} syntax. | 21 | -- Mit der #{}-Syntax kannst du Ausdrücke in String-Literale einbinden. |
| 22 | -- String interpolation is only available in double quoted strings. | 22 | -- String-Interpolation gibt es nur in doppelt angeführten Strings. |
| 23 | print "I am #{math.random! * 100}% sure." | 23 | print "Ich bin mir zu #{math.random! * 100}% sicher." |
| 24 | ``` | 24 | ``` |
| 25 | 25 | ||
| 26 | </YueDisplay> | 26 | </YueDisplay> |
| 27 | 27 | ||
| 28 | ## Number Literals | 28 | ## Zahlenliterale |
| 29 | 29 | ||
| 30 | You can use underscores in a number literal to increase readability. | 30 | Du kannst Unterstriche in Zahlenliteralen verwenden, um die Lesbarkeit zu erhöhen. |
| 31 | 31 | ||
| 32 | ```yuescript | 32 | ```yuescript |
| 33 | integer = 1_000_000 | 33 | integer = 1_000_000 |
| @@ -44,9 +44,9 @@ binary = 0B10011 | |||
| 44 | 44 | ||
| 45 | </YueDisplay> | 45 | </YueDisplay> |
| 46 | 46 | ||
| 47 | ## YAML Multiline String | 47 | ## YAML-Mehrzeilen-String |
| 48 | 48 | ||
| 49 | The `|` prefix introduces a YAML-style multiline string literal: | 49 | Das Präfix `|` führt ein mehrzeiliges String-Literal im YAML-Stil ein: |
| 50 | 50 | ||
| 51 | ```yuescript | 51 | ```yuescript |
| 52 | str = | | 52 | str = | |
| @@ -67,9 +67,9 @@ str = | | |||
| 67 | 67 | ||
| 68 | </YueDisplay> | 68 | </YueDisplay> |
| 69 | 69 | ||
| 70 | This allows writing structured multiline text conveniently. All line breaks and indentation are preserved relative to the first non-empty line, and expressions inside `#{...}` are interpolated automatically as `tostring(expr)`. | 70 | Damit lässt sich strukturierter, mehrzeiliger Text bequem schreiben. Alle Zeilenumbrüche und Einrückungen bleiben relativ zur ersten nicht-leeren Zeile erhalten, und Ausdrücke innerhalb von `#{...}` werden automatisch als `tostring(expr)` interpoliert. |
| 71 | 71 | ||
| 72 | YAML Multiline String automatically detects the common leading whitespace prefix (minimum indentation across all non-empty lines) and removes it from all lines. This makes it easy to indent your code visually without affecting the resulting string content. | 72 | Der YAML-Mehrzeilen-String erkennt automatisch das gemeinsame führende Leerraumpräfix (minimale Einrückung über alle nicht-leeren Zeilen) und entfernt es aus allen Zeilen. So kannst du deinen Code optisch einrücken, ohne den resultierenden String zu verändern. |
| 73 | 73 | ||
| 74 | ```yuescript | 74 | ```yuescript |
| 75 | fn = -> | 75 | fn = -> |
| @@ -90,9 +90,9 @@ fn = -> | |||
| 90 | 90 | ||
| 91 | </YueDisplay> | 91 | </YueDisplay> |
| 92 | 92 | ||
| 93 | Internal indentation is preserved relative to the removed common prefix, allowing clean nested structures. | 93 | Die interne Einrückung bleibt relativ zum entfernten gemeinsamen Präfix erhalten, wodurch saubere, verschachtelte Strukturen möglich sind. |
| 94 | 94 | ||
| 95 | All special characters like quotes (`"`) and backslashes (`\`) in the YAMLMultiline block are automatically escaped so that the generated Lua string is syntactically valid and behaves as expected. | 95 | Alle Sonderzeichen wie Anführungszeichen (`"`) und Backslashes (`\`) im YAML-Mehrzeilen-Block werden automatisch escaped, sodass der erzeugte Lua-String syntaktisch korrekt ist und wie erwartet funktioniert. |
| 96 | 96 | ||
| 97 | ```yuescript | 97 | ```yuescript |
| 98 | str = | | 98 | str = | |
diff --git a/doc/docs/de/doc/language-basics/operator.md b/doc/docs/de/doc/language-basics/operator.md index 9a2e89b..a7b8c5c 100644 --- a/doc/docs/de/doc/language-basics/operator.md +++ b/doc/docs/de/doc/language-basics/operator.md | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | # Operator | 1 | # Operatoren |
| 2 | 2 | ||
| 3 | All of Lua's binary and unary operators are available. Additionally **!=** is as an alias for **~=**, and either **\\** or **::** can be used to write a chaining function call like `tb\func!` or `tb::func!`. And Yuescipt offers some other special operators to write more expressive codes. | 3 | Alle binären und unären Operatoren von Lua sind verfügbar. Zusätzlich ist **!=** ein Alias für **~=**, und entweder **\** oder **::** kann für verkettete Funktionsaufrufe wie `tb\func!` oder `tb::func!` verwendet werden. Außerdem bietet YueScript einige spezielle Operatoren für ausdrucksstärkeren Code. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | tb\func! if tb ~= nil | 6 | tb\func! if tb ~= nil |
| @@ -15,32 +15,32 @@ tb::func! if tb != nil | |||
| 15 | 15 | ||
| 16 | </YueDisplay> | 16 | </YueDisplay> |
| 17 | 17 | ||
| 18 | ## Chaining Comparisons | 18 | ## Verkettete Vergleiche |
| 19 | 19 | ||
| 20 | Comparisons can be arbitrarily chained: | 20 | Vergleiche können beliebig verkettet werden: |
| 21 | 21 | ||
| 22 | ```yuescript | 22 | ```yuescript |
| 23 | print 1 < 2 <= 2 < 3 == 3 > 2 >= 1 == 1 < 3 != 5 | 23 | print 1 < 2 <= 2 < 3 == 3 > 2 >= 1 == 1 < 3 != 5 |
| 24 | -- output: true | 24 | -- Ausgabe: true |
| 25 | 25 | ||
| 26 | a = 5 | 26 | a = 5 |
| 27 | print 1 <= a <= 10 | 27 | print 1 <= a <= 10 |
| 28 | -- output: true | 28 | -- Ausgabe: true |
| 29 | ``` | 29 | ``` |
| 30 | <YueDisplay> | 30 | <YueDisplay> |
| 31 | 31 | ||
| 32 | ```yue | 32 | ```yue |
| 33 | print 1 < 2 <= 2 < 3 == 3 > 2 >= 1 == 1 < 3 != 5 | 33 | print 1 < 2 <= 2 < 3 == 3 > 2 >= 1 == 1 < 3 != 5 |
| 34 | -- output: true | 34 | -- Ausgabe: true |
| 35 | 35 | ||
| 36 | a = 5 | 36 | a = 5 |
| 37 | print 1 <= a <= 10 | 37 | print 1 <= a <= 10 |
| 38 | -- output: true | 38 | -- Ausgabe: true |
| 39 | ``` | 39 | ``` |
| 40 | 40 | ||
| 41 | </YueDisplay> | 41 | </YueDisplay> |
| 42 | 42 | ||
| 43 | Note the evaluation behavior of chained comparisons: | 43 | Beachte das Auswertungsverhalten verketteter Vergleiche: |
| 44 | 44 | ||
| 45 | ```yuescript | 45 | ```yuescript |
| 46 | v = (x) -> | 46 | v = (x) -> |
| @@ -49,7 +49,7 @@ v = (x) -> | |||
| 49 | 49 | ||
| 50 | print v(1) < v(2) <= v(3) | 50 | print v(1) < v(2) <= v(3) |
| 51 | --[[ | 51 | --[[ |
| 52 | output: | 52 | Ausgabe: |
| 53 | 2 | 53 | 2 |
| 54 | 1 | 54 | 1 |
| 55 | 3 | 55 | 3 |
| @@ -58,7 +58,7 @@ print v(1) < v(2) <= v(3) | |||
| 58 | 58 | ||
| 59 | print v(1) > v(2) <= v(3) | 59 | print v(1) > v(2) <= v(3) |
| 60 | --[[ | 60 | --[[ |
| 61 | output: | 61 | Ausgabe: |
| 62 | 2 | 62 | 2 |
| 63 | 1 | 63 | 1 |
| 64 | false | 64 | false |
| @@ -73,7 +73,7 @@ v = (x) -> | |||
| 73 | 73 | ||
| 74 | print v(1) < v(2) <= v(3) | 74 | print v(1) < v(2) <= v(3) |
| 75 | --[[ | 75 | --[[ |
| 76 | output: | 76 | Ausgabe: |
| 77 | 2 | 77 | 2 |
| 78 | 1 | 78 | 1 |
| 79 | 3 | 79 | 3 |
| @@ -82,7 +82,7 @@ print v(1) < v(2) <= v(3) | |||
| 82 | 82 | ||
| 83 | print v(1) > v(2) <= v(3) | 83 | print v(1) > v(2) <= v(3) |
| 84 | --[[ | 84 | --[[ |
| 85 | output: | 85 | Ausgabe: |
| 86 | 2 | 86 | 2 |
| 87 | 1 | 87 | 1 |
| 88 | false | 88 | false |
| @@ -91,32 +91,32 @@ print v(1) > v(2) <= v(3) | |||
| 91 | 91 | ||
| 92 | </YueDisplay> | 92 | </YueDisplay> |
| 93 | 93 | ||
| 94 | The middle expression is only evaluated once, rather than twice as it would be if the expression were written as `v(1) < v(2) and v(2) <= v(3)`. However, the order of evaluations in a chained comparison is undefined. It is strongly recommended not to use expressions with side effects (such as printing) in chained comparisons. If side effects are required, the short-circuit `and` operator should be used explicitly. | 94 | Der mittlere Ausdruck wird nur einmal ausgewertet, nicht zweimal wie bei `v(1) < v(2) and v(2) <= v(3)`. Die Auswertungsreihenfolge in verketteten Vergleichen ist jedoch undefiniert. Es wird dringend empfohlen, in verketteten Vergleichen keine Ausdrücke mit Seiteneffekten (z. B. `print`) zu verwenden. Wenn Seiteneffekte nötig sind, sollte der Short-Circuit-Operator `and` explizit verwendet werden. |
| 95 | 95 | ||
| 96 | ## Table Appending | 96 | ## Tabellenerweiterung |
| 97 | 97 | ||
| 98 | The **[] =** operator is used to append values to tables. | 98 | Der Operator **[] =** wird verwendet, um Werte an Tabellen anzuhängen. |
| 99 | 99 | ||
| 100 | ```yuescript | 100 | ```yuescript |
| 101 | tab = [] | 101 | tab = [] |
| 102 | tab[] = "Value" | 102 | tab[] = "Wert" |
| 103 | ``` | 103 | ``` |
| 104 | <YueDisplay> | 104 | <YueDisplay> |
| 105 | 105 | ||
| 106 | ```yue | 106 | ```yue |
| 107 | tab = [] | 107 | tab = [] |
| 108 | tab[] = "Value" | 108 | tab[] = "Wert" |
| 109 | ``` | 109 | ``` |
| 110 | 110 | ||
| 111 | </YueDisplay> | 111 | </YueDisplay> |
| 112 | 112 | ||
| 113 | You can also use the spread operator `...` to append all elements from one list to another: | 113 | Du kannst auch den Spread-Operator `...` verwenden, um alle Elemente einer Liste an eine andere anzuhängen: |
| 114 | 114 | ||
| 115 | ```yuescript | 115 | ```yuescript |
| 116 | tbA = [1, 2, 3] | 116 | tbA = [1, 2, 3] |
| 117 | tbB = [4, 5, 6] | 117 | tbB = [4, 5, 6] |
| 118 | tbA[] = ...tbB | 118 | tbA[] = ...tbB |
| 119 | -- tbA is now [1, 2, 3, 4, 5, 6] | 119 | -- tbA ist jetzt [1, 2, 3, 4, 5, 6] |
| 120 | ``` | 120 | ``` |
| 121 | <YueDisplay> | 121 | <YueDisplay> |
| 122 | 122 | ||
| @@ -124,24 +124,24 @@ tbA[] = ...tbB | |||
| 124 | tbA = [1, 2, 3] | 124 | tbA = [1, 2, 3] |
| 125 | tbB = [4, 5, 6] | 125 | tbB = [4, 5, 6] |
| 126 | tbA[] = ...tbB | 126 | tbA[] = ...tbB |
| 127 | -- tbA is now [1, 2, 3, 4, 5, 6] | 127 | -- tbA ist jetzt [1, 2, 3, 4, 5, 6] |
| 128 | ``` | 128 | ``` |
| 129 | 129 | ||
| 130 | </YueDisplay> | 130 | </YueDisplay> |
| 131 | 131 | ||
| 132 | ## Table Spreading | 132 | ## Tabellen-Spread |
| 133 | 133 | ||
| 134 | You can concatenate array tables or hash tables using spread operator `...` before expressions in table literals. | 134 | Du kannst Array-Tabellen oder Hash-Tabellen mit dem Spread-Operator `...` vor Ausdrücken in Tabellenliteralen zusammenführen. |
| 135 | 135 | ||
| 136 | ```yuescript | 136 | ```yuescript |
| 137 | parts = | 137 | parts = |
| 138 | * "shoulders" | 138 | * "Schultern" |
| 139 | * "knees" | 139 | * "Knie" |
| 140 | lyrics = | 140 | lyrics = |
| 141 | * "head" | 141 | * "Kopf" |
| 142 | * ...parts | 142 | * ...parts |
| 143 | * "and" | 143 | * "und" |
| 144 | * "toes" | 144 | * "Zehen" |
| 145 | 145 | ||
| 146 | copy = {...other} | 146 | copy = {...other} |
| 147 | 147 | ||
| @@ -153,13 +153,13 @@ merge = {...a, ...b} | |||
| 153 | 153 | ||
| 154 | ```yue | 154 | ```yue |
| 155 | parts = | 155 | parts = |
| 156 | * "shoulders" | 156 | * "Schultern" |
| 157 | * "knees" | 157 | * "Knie" |
| 158 | lyrics = | 158 | lyrics = |
| 159 | * "head" | 159 | * "Kopf" |
| 160 | * ...parts | 160 | * ...parts |
| 161 | * "and" | 161 | * "und" |
| 162 | * "toes" | 162 | * "Zehen" |
| 163 | 163 | ||
| 164 | copy = {...other} | 164 | copy = {...other} |
| 165 | 165 | ||
| @@ -170,9 +170,9 @@ merge = {...a, ...b} | |||
| 170 | 170 | ||
| 171 | </YueDisplay> | 171 | </YueDisplay> |
| 172 | 172 | ||
| 173 | ## Table Reversed Indexing | 173 | ## Umgekehrter Tabellenindex |
| 174 | 174 | ||
| 175 | You can use the **#** operator to get the last elements of a table. | 175 | Mit dem Operator **#** kannst du auf die letzten Elemente einer Tabelle zugreifen. |
| 176 | 176 | ||
| 177 | ```yuescript | 177 | ```yuescript |
| 178 | last = data.items[#] | 178 | last = data.items[#] |
| @@ -191,11 +191,11 @@ data.items[#] = 1 | |||
| 191 | 191 | ||
| 192 | ## Metatable | 192 | ## Metatable |
| 193 | 193 | ||
| 194 | The **<>** operator can be used as a shortcut for metatable manipulation. | 194 | Der Operator **<>** kann als Abkürzung für Metatable-Manipulation verwendet werden. |
| 195 | 195 | ||
| 196 | ### Metatable Creation | 196 | ### Metatable erstellen |
| 197 | 197 | ||
| 198 | Create normal table with empty bracekets **<>** or metamethod key which is surrounded by **<>**. | 198 | Erzeuge eine normale Tabelle mit leeren Klammern **<>** oder einem Metamethod-Schlüssel, der von **<>** umschlossen ist. |
| 199 | 199 | ||
| 200 | ```yuescript | 200 | ```yuescript |
| 201 | mt = {} | 201 | mt = {} |
| @@ -203,14 +203,14 @@ add = (right) => <>: mt, value: @value + right.value | |||
| 203 | mt.__add = add | 203 | mt.__add = add |
| 204 | 204 | ||
| 205 | a = <>: mt, value: 1 | 205 | a = <>: mt, value: 1 |
| 206 | -- set field with variable of the same name | 206 | -- Feld mit gleichnamiger Variable setzen |
| 207 | b = :<add>, value: 2 | 207 | b = :<add>, value: 2 |
| 208 | c = <add>: mt.__add, value: 3 | 208 | c = <add>: mt.__add, value: 3 |
| 209 | 209 | ||
| 210 | d = a + b + c | 210 | d = a + b + c |
| 211 | print d.value | 211 | print d.value |
| 212 | 212 | ||
| 213 | close _ = <close>: -> print "out of scope" | 213 | close _ = <close>: -> print "Außerhalb des Gültigkeitsbereichs" |
| 214 | ``` | 214 | ``` |
| 215 | <YueDisplay> | 215 | <YueDisplay> |
| 216 | 216 | ||
| @@ -220,47 +220,47 @@ add = (right) => <>: mt, value: @value + right.value | |||
| 220 | mt.__add = add | 220 | mt.__add = add |
| 221 | 221 | ||
| 222 | a = <>: mt, value: 1 | 222 | a = <>: mt, value: 1 |
| 223 | -- set field with variable of the same name | 223 | -- Feld mit gleichnamiger Variable setzen |
| 224 | b = :<add>, value: 2 | 224 | b = :<add>, value: 2 |
| 225 | c = <add>: mt.__add, value: 3 | 225 | c = <add>: mt.__add, value: 3 |
| 226 | 226 | ||
| 227 | d = a + b + c | 227 | d = a + b + c |
| 228 | print d.value | 228 | print d.value |
| 229 | 229 | ||
| 230 | close _ = <close>: -> print "out of scope" | 230 | close _ = <close>: -> print "Außerhalb des Gültigkeitsbereichs" |
| 231 | ``` | 231 | ``` |
| 232 | 232 | ||
| 233 | </YueDisplay> | 233 | </YueDisplay> |
| 234 | 234 | ||
| 235 | ### Metatable Accessing | 235 | ### Metatable-Zugriff |
| 236 | 236 | ||
| 237 | Accessing metatable with **<>** or metamethod name surrounded by **<>** or writing some expression in **<>**. | 237 | Metatable mit **<>** oder einem von **<>** umschlossenen Metamethod-Namen aufrufen oder einen Ausdruck in **<>** schreiben. |
| 238 | 238 | ||
| 239 | ```yuescript | 239 | ```yuescript |
| 240 | -- create with metatable containing field "value" | 240 | -- erstellen mit Metatable, das das Feld "value" enthält |
| 241 | tb = <"value">: 123 | 241 | tb = <"value">: 123 |
| 242 | tb.<index> = tb.<> | 242 | tb.<index> = tb.<> |
| 243 | print tb.value | 243 | print tb.value |
| 244 | 244 | ||
| 245 | tb.<> = __index: {item: "hello"} | 245 | tb.<> = __index: {item: "hallo"} |
| 246 | print tb.item | 246 | print tb.item |
| 247 | ``` | 247 | ``` |
| 248 | <YueDisplay> | 248 | <YueDisplay> |
| 249 | 249 | ||
| 250 | ```yue | 250 | ```yue |
| 251 | -- create with metatable containing field "value" | 251 | -- erstellen mit Metatable, das das Feld "value" enthält |
| 252 | tb = <"value">: 123 | 252 | tb = <"value">: 123 |
| 253 | tb.<index> = tb.<> | 253 | tb.<index> = tb.<> |
| 254 | print tb.value | 254 | print tb.value |
| 255 | tb.<> = __index: {item: "hello"} | 255 | tb.<> = __index: {item: "hallo"} |
| 256 | print tb.item | 256 | print tb.item |
| 257 | ``` | 257 | ``` |
| 258 | 258 | ||
| 259 | </YueDisplay> | 259 | </YueDisplay> |
| 260 | 260 | ||
| 261 | ### Metatable Destructure | 261 | ### Metatable-Destrukturierung |
| 262 | 262 | ||
| 263 | Destruct metatable with metamethod key surrounded by **<>**. | 263 | Destrukturiere Metatable mit Metamethoden-Schlüssel, der von **<>** umschlossen ist. |
| 264 | 264 | ||
| 265 | ```yuescript | 265 | ```yuescript |
| 266 | {item, :new, :<close>, <index>: getter} = tb | 266 | {item, :new, :<close>, <index>: getter} = tb |
| @@ -275,9 +275,9 @@ print item, new, close, getter | |||
| 275 | 275 | ||
| 276 | </YueDisplay> | 276 | </YueDisplay> |
| 277 | 277 | ||
| 278 | ## Existence | 278 | ## Existenz |
| 279 | 279 | ||
| 280 | The **?** operator can be used in a variety of contexts to check for existence. | 280 | Der Operator **?** kann in verschiedenen Kontexten verwendet werden, um die Existenz zu prüfen. |
| 281 | 281 | ||
| 282 | ```yuescript | 282 | ```yuescript |
| 283 | func?! | 283 | func?! |
| @@ -314,14 +314,14 @@ with? io.open "test.txt", "w" | |||
| 314 | 314 | ||
| 315 | ## Piping | 315 | ## Piping |
| 316 | 316 | ||
| 317 | Instead of a series of nested function calls, you can pipe values with operator **|>**. | 317 | Anstelle einer Reihe verschachtelter Funktionsaufrufe kannst du Werte mit dem Operator **|>** weiterleiten. |
| 318 | 318 | ||
| 319 | ```yuescript | 319 | ```yuescript |
| 320 | "hello" |> print | 320 | "hello" |> print |
| 321 | 1 |> print 2 -- insert pipe item as the first argument | 321 | 1 |> print 2 -- Pipe-Element als erstes Argument einfügen |
| 322 | 2 |> print 1, _, 3 -- pipe with a placeholder | 322 | 2 |> print 1, _, 3 -- Pipe mit Platzhalter |
| 323 | 323 | ||
| 324 | -- pipe expression in multiline | 324 | -- Pipe-Ausdruck über mehrere Zeilen |
| 325 | readFile "example.txt" | 325 | readFile "example.txt" |
| 326 | |> extract language, {} | 326 | |> extract language, {} |
| 327 | |> parse language | 327 | |> parse language |
| @@ -333,9 +333,9 @@ readFile "example.txt" | |||
| 333 | 333 | ||
| 334 | ```yue | 334 | ```yue |
| 335 | "hello" |> print | 335 | "hello" |> print |
| 336 | 1 |> print 2 -- insert pipe item as the first argument | 336 | 1 |> print 2 -- Pipe-Element als erstes Argument einfügen |
| 337 | 2 |> print 1, _, 3 -- pipe with a placeholder | 337 | 2 |> print 1, _, 3 -- Pipe mit Platzhalter |
| 338 | -- pipe expression in multiline | 338 | -- Pipe-Ausdruck über mehrere Zeilen |
| 339 | readFile "example.txt" | 339 | readFile "example.txt" |
| 340 | |> extract language, {} | 340 | |> extract language, {} |
| 341 | |> parse language | 341 | |> parse language |
| @@ -346,9 +346,10 @@ readFile "example.txt" | |||
| 346 | 346 | ||
| 347 | </YueDisplay> | 347 | </YueDisplay> |
| 348 | 348 | ||
| 349 | ## Nil Coalescing | 349 | ## Nil-Coalescing |
| 350 | |||
| 351 | Der Nil-Coalescing-Operator **??** gibt den Wert des linken Operanden zurück, wenn er nicht **nil** ist; andernfalls wird der rechte Operand ausgewertet und sein Ergebnis zurückgegeben. Der **??**-Operator wertet seinen rechten Operanden nicht aus, wenn der linke Operand nicht nil ergibt. | ||
| 350 | 352 | ||
| 351 | The nil-coalescing operator **??** returns the value of its left-hand operand if it isn't **nil**; otherwise, it evaluates the right-hand operand and returns its result. The **??** operator doesn't evaluate its right-hand operand if the left-hand operand evaluates to non-nil. | ||
| 352 | ```yuescript | 353 | ```yuescript |
| 353 | local a, b, c, d | 354 | local a, b, c, d |
| 354 | a = b ?? c ?? d | 355 | a = b ?? c ?? d |
| @@ -367,31 +368,31 @@ a ??= false | |||
| 367 | 368 | ||
| 368 | </YueDisplay> | 369 | </YueDisplay> |
| 369 | 370 | ||
| 370 | ## Implicit Object | 371 | ## Implizites Objekt |
| 371 | 372 | ||
| 372 | You can write a list of implicit structures that starts with the symbol **\*** or **-** inside a table block. If you are creating implicit object, the fields of the object must be with the same indent. | 373 | Du kannst innerhalb eines Tabellenblocks eine Liste impliziter Strukturen schreiben, die mit dem Symbol **\*** oder **-** beginnt. Beim Erstellen eines impliziten Objekts müssen die Felder des Objekts dieselbe Einrückung haben. |
| 373 | 374 | ||
| 374 | ```yuescript | 375 | ```yuescript |
| 375 | -- assignment with implicit object | 376 | -- Zuweisung mit implizitem Objekt |
| 376 | list = | 377 | list = |
| 377 | * 1 | 378 | * 1 |
| 378 | * 2 | 379 | * 2 |
| 379 | * 3 | 380 | * 3 |
| 380 | 381 | ||
| 381 | -- function call with implicit object | 382 | -- Funktionsaufruf mit implizitem Objekt |
| 382 | func | 383 | func |
| 383 | * 1 | 384 | * 1 |
| 384 | * 2 | 385 | * 2 |
| 385 | * 3 | 386 | * 3 |
| 386 | 387 | ||
| 387 | -- return with implicit object | 388 | -- Rückgabe mit implizitem Objekt |
| 388 | f = -> | 389 | f = -> |
| 389 | return | 390 | return |
| 390 | * 1 | 391 | * 1 |
| 391 | * 2 | 392 | * 2 |
| 392 | * 3 | 393 | * 3 |
| 393 | 394 | ||
| 394 | -- table with implicit object | 395 | -- Tabelle mit implizitem Objekt |
| 395 | tb = | 396 | tb = |
| 396 | name: "abc" | 397 | name: "abc" |
| 397 | 398 | ||
| @@ -416,26 +417,26 @@ tb = | |||
| 416 | <YueDisplay> | 417 | <YueDisplay> |
| 417 | 418 | ||
| 418 | ```yue | 419 | ```yue |
| 419 | -- assignment with implicit object | 420 | -- Zuweisung mit implizitem Objekt |
| 420 | list = | 421 | list = |
| 421 | * 1 | 422 | * 1 |
| 422 | * 2 | 423 | * 2 |
| 423 | * 3 | 424 | * 3 |
| 424 | 425 | ||
| 425 | -- function call with implicit object | 426 | -- Funktionsaufruf mit implizitem Objekt |
| 426 | func | 427 | func |
| 427 | * 1 | 428 | * 1 |
| 428 | * 2 | 429 | * 2 |
| 429 | * 3 | 430 | * 3 |
| 430 | 431 | ||
| 431 | -- return with implicit object | 432 | -- Rückgabe mit implizitem Objekt |
| 432 | f = -> | 433 | f = -> |
| 433 | return | 434 | return |
| 434 | * 1 | 435 | * 1 |
| 435 | * 2 | 436 | * 2 |
| 436 | * 3 | 437 | * 3 |
| 437 | 438 | ||
| 438 | -- table with implicit object | 439 | -- Tabelle mit implizitem Objekt |
| 439 | tb = | 440 | tb = |
| 440 | name: "abc" | 441 | name: "abc" |
| 441 | 442 | ||
diff --git a/doc/docs/de/doc/language-basics/whitespace.md b/doc/docs/de/doc/language-basics/whitespace.md index d742a2b..9d5889d 100644 --- a/doc/docs/de/doc/language-basics/whitespace.md +++ b/doc/docs/de/doc/language-basics/whitespace.md | |||
| @@ -1,10 +1,10 @@ | |||
| 1 | # Whitespace | 1 | # Leerraum |
| 2 | 2 | ||
| 3 | YueScript is a whitespace significant language. You have to write some code block in the same indent with space **' '** or tab **'\t'** like function body, value list and some control blocks. And expressions containing different whitespaces might mean different things. Tab is treated like 4 space, but it's better not mix the use of spaces and tabs. | 3 | YueScript ist eine whitespace-sensible Sprache. Du musst bestimmte Code-Blöcke mit derselben Einrückung (Leerzeichen **' '** oder Tab **'\t'**) schreiben, z. B. Funktionskörper, Wertelisten und Kontrollblöcke. Ausdrücke mit unterschiedlichem Leerraum können unterschiedliche Bedeutungen haben. Ein Tab wird wie 4 Leerzeichen behandelt, aber es ist besser, Leerzeichen und Tabs nicht zu mischen. |
| 4 | 4 | ||
| 5 | ## Statement Separator | 5 | ## Anweisungs-Trenner |
| 6 | 6 | ||
| 7 | A statement normally ends at a line break. You can also use a semicolon `;` to explicitly terminate a statement, which allows writing multiple statements on the same line: | 7 | Eine Anweisung endet normalerweise an einem Zeilenumbruch. Du kannst auch ein Semikolon `;` verwenden, um eine Anweisung explizit zu beenden, wodurch mehrere Anweisungen in einer Zeile möglich sind: |
| 8 | 8 | ||
| 9 | ```yuescript | 9 | ```yuescript |
| 10 | a = 1; b = 2; print a + b | 10 | a = 1; b = 2; print a + b |
| @@ -17,9 +17,9 @@ a = 1; b = 2; print a + b | |||
| 17 | 17 | ||
| 18 | </YueDisplay> | 18 | </YueDisplay> |
| 19 | 19 | ||
| 20 | ## Multiline Chaining | 20 | ## Mehrzeiliges Chaining |
| 21 | 21 | ||
| 22 | You can write multi-line chaining function calls with a same indent. | 22 | Du kannst mehrzeilige, verkettete Funktionsaufrufe mit derselben Einrückung schreiben. |
| 23 | 23 | ||
| 24 | ```yuescript | 24 | ```yuescript |
| 25 | Rx.Observable | 25 | Rx.Observable |
diff --git a/doc/docs/de/doc/objects/object-oriented-programming.md b/doc/docs/de/doc/objects/object-oriented-programming.md index 6a8559e..1c116a3 100644 --- a/doc/docs/de/doc/objects/object-oriented-programming.md +++ b/doc/docs/de/doc/objects/object-oriented-programming.md | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | # Object Oriented Programming | 1 | # Objektorientierte Programmierung |
| 2 | 2 | ||
| 3 | In these examples, the generated Lua code may appear overwhelming. It is best to focus on the meaning of the YueScript code at first, then look into the Lua code if you wish to know the implementation details. | 3 | In diesen Beispielen kann der generierte Lua-Code überwältigend wirken. Am besten konzentrierst du dich zunächst auf die Bedeutung des YueScript-Codes und schaust dir den Lua-Code nur an, wenn du die Implementierungsdetails wissen möchtest. |
| 4 | 4 | ||
| 5 | A simple class: | 5 | Eine einfache Klasse: |
| 6 | 6 | ||
| 7 | ```yuescript | 7 | ```yuescript |
| 8 | class Inventory | 8 | class Inventory |
| @@ -31,36 +31,36 @@ class Inventory | |||
| 31 | 31 | ||
| 32 | </YueDisplay> | 32 | </YueDisplay> |
| 33 | 33 | ||
| 34 | A class is declared with a class statement followed by a table-like declaration where all of the methods and properties are listed. | 34 | Eine Klasse wird mit einem `class`-Statement deklariert, gefolgt von einer tabellenähnlichen Deklaration mit allen Methoden und Eigenschaften. |
| 35 | 35 | ||
| 36 | The new property is special in that it will become the constructor. | 36 | Die Eigenschaft `new` ist besonders, da sie zum Konstruktor wird. |
| 37 | 37 | ||
| 38 | Notice how all the methods in the class use the fat arrow function syntax. When calling methods on a instance, the instance itself is sent in as the first argument. The fat arrow handles the creation of a self argument. | 38 | Beachte, dass alle Methoden in der Klasse die Fat-Arrow-Syntax verwenden. Beim Aufruf von Methoden auf einer Instanz wird die Instanz selbst als erstes Argument übergeben. Der Fat-Arrow übernimmt die Erstellung des `self`-Arguments. |
| 39 | 39 | ||
| 40 | The @ prefix on a variable name is shorthand for self.. @items becomes self.items. | 40 | Das `@`-Präfix ist Kurzform für `self.`. `@items` wird zu `self.items`. |
| 41 | 41 | ||
| 42 | Creating an instance of the class is done by calling the name of the class as a function. | 42 | Eine Instanz der Klasse wird erstellt, indem man den Klassennamen wie eine Funktion aufruft. |
| 43 | 43 | ||
| 44 | ```yuescript | 44 | ```yuescript |
| 45 | inv = Inventory! | 45 | inv = Inventory! |
| 46 | inv\add_item "t-shirt" | 46 | inv\add_item "T-Shirt" |
| 47 | inv\add_item "pants" | 47 | inv\add_item "Hose" |
| 48 | ``` | 48 | ``` |
| 49 | <YueDisplay> | 49 | <YueDisplay> |
| 50 | 50 | ||
| 51 | ```yue | 51 | ```yue |
| 52 | inv = Inventory! | 52 | inv = Inventory! |
| 53 | inv\add_item "t-shirt" | 53 | inv\add_item "T-Shirt" |
| 54 | inv\add_item "pants" | 54 | inv\add_item "Hose" |
| 55 | ``` | 55 | ``` |
| 56 | 56 | ||
| 57 | </YueDisplay> | 57 | </YueDisplay> |
| 58 | 58 | ||
| 59 | Because the instance of the class needs to be sent to the methods when they are called, the \ operator is used. | 59 | Da die Instanz bei Methodenaufrufen an die Methoden übergeben werden muss, wird der `\`-Operator verwendet. |
| 60 | 60 | ||
| 61 | All properties of a class are shared among the instances. This is fine for functions, but for other types of objects, undesired results may occur. | 61 | Alle Eigenschaften einer Klasse werden von allen Instanzen gemeinsam genutzt. Für Funktionen ist das ok, aber bei anderen Objekten kann das zu unerwünschten Ergebnissen führen. |
| 62 | 62 | ||
| 63 | Consider the example below, the clothes property is shared amongst all instances, so modifications to it in one instance will show up in another: | 63 | Im folgenden Beispiel wird die Eigenschaft `clothes` von allen Instanzen geteilt, sodass Änderungen in einer Instanz in einer anderen sichtbar werden: |
| 64 | 64 | ||
| 65 | ```yuescript | 65 | ```yuescript |
| 66 | class Person | 66 | class Person |
| @@ -71,10 +71,10 @@ class Person | |||
| 71 | a = Person! | 71 | a = Person! |
| 72 | b = Person! | 72 | b = Person! |
| 73 | 73 | ||
| 74 | a\give_item "pants" | 74 | a\give_item "Hose" |
| 75 | b\give_item "shirt" | 75 | b\give_item "Hemd" |
| 76 | 76 | ||
| 77 | -- will print both pants and shirt | 77 | -- gibt sowohl Hose als auch Hemd aus |
| 78 | print item for item in *a.clothes | 78 | print item for item in *a.clothes |
| 79 | ``` | 79 | ``` |
| 80 | <YueDisplay> | 80 | <YueDisplay> |
| @@ -88,16 +88,16 @@ class Person | |||
| 88 | a = Person! | 88 | a = Person! |
| 89 | b = Person! | 89 | b = Person! |
| 90 | 90 | ||
| 91 | a\give_item "pants" | 91 | a\give_item "Hose" |
| 92 | b\give_item "shirt" | 92 | b\give_item "Hemd" |
| 93 | 93 | ||
| 94 | -- will print both pants and shirt | 94 | -- gibt sowohl Hose als auch Hemd aus |
| 95 | print item for item in *a.clothes | 95 | print item for item in *a.clothes |
| 96 | ``` | 96 | ``` |
| 97 | 97 | ||
| 98 | </YueDisplay> | 98 | </YueDisplay> |
| 99 | 99 | ||
| 100 | The proper way to avoid this problem is to create the mutable state of the object in the constructor: | 100 | Der richtige Weg, das zu vermeiden, ist, den veränderlichen Zustand im Konstruktor zu erstellen: |
| 101 | 101 | ||
| 102 | ```yuescript | 102 | ```yuescript |
| 103 | class Person | 103 | class Person |
| @@ -114,15 +114,15 @@ class Person | |||
| 114 | 114 | ||
| 115 | </YueDisplay> | 115 | </YueDisplay> |
| 116 | 116 | ||
| 117 | ## Inheritance | 117 | ## Vererbung |
| 118 | 118 | ||
| 119 | The extends keyword can be used in a class declaration to inherit the properties and methods from another class. | 119 | Das Schlüsselwort `extends` kann in einer Klassendeklaration verwendet werden, um Eigenschaften und Methoden von einer anderen Klasse zu erben. |
| 120 | 120 | ||
| 121 | ```yuescript | 121 | ```yuescript |
| 122 | class BackPack extends Inventory | 122 | class BackPack extends Inventory |
| 123 | size: 10 | 123 | size: 10 |
| 124 | add_item: (name) => | 124 | add_item: (name) => |
| 125 | if #@items > size then error "backpack is full" | 125 | if #@items > size then error "Rucksack ist voll" |
| 126 | super name | 126 | super name |
| 127 | ``` | 127 | ``` |
| 128 | <YueDisplay> | 128 | <YueDisplay> |
| @@ -131,24 +131,24 @@ class BackPack extends Inventory | |||
| 131 | class BackPack extends Inventory | 131 | class BackPack extends Inventory |
| 132 | size: 10 | 132 | size: 10 |
| 133 | add_item: (name) => | 133 | add_item: (name) => |
| 134 | if #@items > size then error "backpack is full" | 134 | if #@items > size then error "Rucksack ist voll" |
| 135 | super name | 135 | super name |
| 136 | ``` | 136 | ``` |
| 137 | 137 | ||
| 138 | </YueDisplay> | 138 | </YueDisplay> |
| 139 | 139 | ||
| 140 | Here we extend our Inventory class, and limit the amount of items it can carry. | 140 | Hier erweitern wir unsere `Inventory`-Klasse und begrenzen die Anzahl der Elemente. |
| 141 | 141 | ||
| 142 | In this example, we don't define a constructor on the subclass, so the parent class' constructor is called when we make a new instance. If we did define a constructor then we can use the super method to call the parent constructor. | 142 | In diesem Beispiel definieren wir keinen Konstruktor in der Subklasse, daher wird der Konstruktor der Elternklasse beim Erstellen einer neuen Instanz aufgerufen. Definieren wir einen Konstruktor, können wir mit `super` den Elternkonstruktor aufrufen. |
| 143 | 143 | ||
| 144 | Whenever a class inherits from another, it sends a message to the parent class by calling the method __inherited on the parent class if it exists. The function receives two arguments, the class that is being inherited and the child class. | 144 | Wenn eine Klasse von einer anderen erbt, sendet sie eine Nachricht an die Elternklasse, indem die Methode `__inherited` der Elternklasse aufgerufen wird, falls vorhanden. Die Funktion erhält zwei Argumente: die Klasse, die vererbt wird, und die Kindklasse. |
| 145 | 145 | ||
| 146 | ```yuescript | 146 | ```yuescript |
| 147 | class Shelf | 147 | class Shelf |
| 148 | @__inherited: (child) => | 148 | @__inherited: (child) => |
| 149 | print @__name, "was inherited by", child.__name | 149 | print @__name, "wurde vererbt von", child.__name |
| 150 | 150 | ||
| 151 | -- will print: Shelf was inherited by Cupboard | 151 | -- gibt aus: Shelf wurde von Cupboard geerbt |
| 152 | class Cupboard extends Shelf | 152 | class Cupboard extends Shelf |
| 153 | ``` | 153 | ``` |
| 154 | <YueDisplay> | 154 | <YueDisplay> |
| @@ -156,9 +156,9 @@ class Cupboard extends Shelf | |||
| 156 | ```yue | 156 | ```yue |
| 157 | class Shelf | 157 | class Shelf |
| 158 | @__inherited: (child) => | 158 | @__inherited: (child) => |
| 159 | print @__name, "was inherited by", child.__name | 159 | print @__name, "wurde vererbt von", child.__name |
| 160 | 160 | ||
| 161 | -- will print: Shelf was inherited by Cupboard | 161 | -- gibt aus: Shelf wurde von Cupboard geerbt |
| 162 | class Cupboard extends Shelf | 162 | class Cupboard extends Shelf |
| 163 | ``` | 163 | ``` |
| 164 | 164 | ||
| @@ -166,27 +166,27 @@ class Cupboard extends Shelf | |||
| 166 | 166 | ||
| 167 | ## Super | 167 | ## Super |
| 168 | 168 | ||
| 169 | **super** is a special keyword that can be used in two different ways: It can be treated as an object, or it can be called like a function. It only has special functionality when inside a class. | 169 | **super** ist ein spezielles Schlüsselwort, das auf zwei Arten verwendet werden kann: als Objekt oder als Funktionsaufruf. Es hat besondere Funktionalität nur innerhalb einer Klasse. |
| 170 | 170 | ||
| 171 | When called as a function, it will call the function of the same name in the parent class. The current self will automatically be passed as the first argument. (As seen in the inheritance example above) | 171 | Wenn es als Funktion aufgerufen wird, ruft es die gleichnamige Funktion in der Elternklasse auf. `self` wird automatisch als erstes Argument übergeben (wie im Vererbungsbeispiel oben). |
| 172 | 172 | ||
| 173 | When super is used as a normal value, it is a reference to the parent class object. | 173 | Wenn `super` als normaler Wert verwendet wird, ist es eine Referenz auf das Objekt der Elternklasse. |
| 174 | 174 | ||
| 175 | It can be accessed like any of object in order to retrieve values in the parent class that might have been shadowed by the child class. | 175 | Du kannst es wie jedes andere Objekt verwenden, um Werte der Elternklasse zu lesen, die von der Kindklasse überschattet wurden. |
| 176 | 176 | ||
| 177 | When the \ calling operator is used with super, self is inserted as the first argument instead of the value of super itself. When using . to retrieve a function, the raw function is returned. | 177 | Wenn der `\`-Aufrufoperator mit `super` verwendet wird, wird `self` als erstes Argument eingefügt statt des Wertes von `super`. Wenn man `.` zum Abrufen einer Funktion verwendet, wird die rohe Funktion zurückgegeben. |
| 178 | 178 | ||
| 179 | A few examples of using super in different ways: | 179 | Ein paar Beispiele für `super` in unterschiedlichen Formen: |
| 180 | 180 | ||
| 181 | ```yuescript | 181 | ```yuescript |
| 182 | class MyClass extends ParentClass | 182 | class MyClass extends ParentClass |
| 183 | a_method: => | 183 | a_method: => |
| 184 | -- the following have the same effect: | 184 | -- Folgendes hat dieselbe Wirkung: |
| 185 | super "hello", "world" | 185 | super "hallo", "Welt" |
| 186 | super\a_method "hello", "world" | 186 | super\a_method "hallo", "Welt" |
| 187 | super.a_method self, "hello", "world" | 187 | super.a_method self, "hallo", "Welt" |
| 188 | 188 | ||
| 189 | -- super as a value is equal to the parent class: | 189 | -- super als Wert entspricht der Elternklasse: |
| 190 | assert super == ParentClass | 190 | assert super == ParentClass |
| 191 | ``` | 191 | ``` |
| 192 | <YueDisplay> | 192 | <YueDisplay> |
| @@ -194,28 +194,28 @@ class MyClass extends ParentClass | |||
| 194 | ```yue | 194 | ```yue |
| 195 | class MyClass extends ParentClass | 195 | class MyClass extends ParentClass |
| 196 | a_method: => | 196 | a_method: => |
| 197 | -- the following have the same effect: | 197 | -- Folgendes hat dieselbe Wirkung: |
| 198 | super "hello", "world" | 198 | super "hallo", "Welt" |
| 199 | super\a_method "hello", "world" | 199 | super\a_method "hallo", "Welt" |
| 200 | super.a_method self, "hello", "world" | 200 | super.a_method self, "hallo", "Welt" |
| 201 | 201 | ||
| 202 | -- super as a value is equal to the parent class: | 202 | -- super als Wert entspricht der Elternklasse: |
| 203 | assert super == ParentClass | 203 | assert super == ParentClass |
| 204 | ``` | 204 | ``` |
| 205 | 205 | ||
| 206 | </YueDisplay> | 206 | </YueDisplay> |
| 207 | 207 | ||
| 208 | **super** can also be used on left side of a Function Stub. The only major difference is that instead of the resulting function being bound to the value of super, it is bound to self. | 208 | **super** kann auch links einer Funktions-Stub verwendet werden. Der einzige große Unterschied ist, dass die resultierende Funktion statt an `super` an `self` gebunden wird. |
| 209 | 209 | ||
| 210 | ## Types | 210 | ## Typen |
| 211 | 211 | ||
| 212 | Every instance of a class carries its type with it. This is stored in the special __class property. This property holds the class object. The class object is what we call to build a new instance. We can also index the class object to retrieve class methods and properties. | 212 | Jede Instanz einer Klasse trägt ihren Typ in sich. Dieser wird in der speziellen Eigenschaft `__class` gespeichert. Diese Eigenschaft enthält das Klassenobjekt. Das Klassenobjekt wird aufgerufen, um eine neue Instanz zu erstellen. Wir können das Klassenobjekt auch indizieren, um Klassenmethoden und Eigenschaften abzurufen. |
| 213 | 213 | ||
| 214 | ```yuescript | 214 | ```yuescript |
| 215 | b = BackPack! | 215 | b = BackPack! |
| 216 | assert b.__class == BackPack | 216 | assert b.__class == BackPack |
| 217 | 217 | ||
| 218 | print BackPack.size -- prints 10 | 218 | print BackPack.size -- gibt 10 aus |
| 219 | ``` | 219 | ``` |
| 220 | <YueDisplay> | 220 | <YueDisplay> |
| 221 | 221 | ||
| @@ -223,70 +223,70 @@ print BackPack.size -- prints 10 | |||
| 223 | b = BackPack! | 223 | b = BackPack! |
| 224 | assert b.__class == BackPack | 224 | assert b.__class == BackPack |
| 225 | 225 | ||
| 226 | print BackPack.size -- prints 10 | 226 | print BackPack.size -- gibt 10 aus |
| 227 | ``` | 227 | ``` |
| 228 | 228 | ||
| 229 | </YueDisplay> | 229 | </YueDisplay> |
| 230 | 230 | ||
| 231 | ## Class Objects | 231 | ## Klassenobjekte |
| 232 | 232 | ||
| 233 | The class object is what we create when we use a class statement. The class object is stored in a variable of the same name of the class. | 233 | Das Klassenobjekt entsteht, wenn wir ein `class`-Statement verwenden. Es wird in einer Variablen mit dem Klassennamen gespeichert. |
| 234 | 234 | ||
| 235 | The class object can be called like a function in order to create new instances. That's how we created instances of classes in the examples above. | 235 | Das Klassenobjekt kann wie eine Funktion aufgerufen werden, um neue Instanzen zu erstellen. So haben wir die Instanzen in den Beispielen oben erstellt. |
| 236 | 236 | ||
| 237 | A class is made up of two tables. The class table itself, and the base table. The base is used as the metatable for all the instances. All properties listed in the class declaration are placed in the base. | 237 | Eine Klasse besteht aus zwei Tabellen: der Klassentabelle selbst und der Basistabelle. Die Basis wird als Metatable für alle Instanzen verwendet. Alle in der Klassendeklaration aufgeführten Eigenschaften werden in der Basis platziert. |
| 238 | 238 | ||
| 239 | The class object's metatable reads properties from the base if they don't exist in the class object. This means we can access functions and properties directly from the class. | 239 | Das Metatable des Klassenobjekts liest Eigenschaften aus der Basis, wenn sie im Klassenobjekt nicht existieren. Das bedeutet, dass wir Funktionen und Eigenschaften direkt von der Klasse aus aufrufen können. |
| 240 | 240 | ||
| 241 | It is important to note that assigning to the class object does not assign into the base, so it's not a valid way to add new methods to instances. Instead the base must explicitly be changed. See the __base field below. | 241 | Wichtig: Zuweisungen an das Klassenobjekt schreiben nicht in die Basis. Das ist keine gültige Methode, um neue Methoden zu Instanzen hinzuzufügen. Stattdessen muss die Basis explizit geändert werden. Siehe das Feld `__base` unten. |
| 242 | 242 | ||
| 243 | The class object has a couple special properties: | 243 | Das Klassenobjekt hat einige spezielle Eigenschaften: |
| 244 | 244 | ||
| 245 | The name of the class as when it was declared is stored as a string in the __name field of the class object. | 245 | Der Name der Klasse, wie sie deklariert wurde, wird im Feld `__name` gespeichert. |
| 246 | 246 | ||
| 247 | ```yuescript | 247 | ```yuescript |
| 248 | print BackPack.__name -- prints Backpack | 248 | print BackPack.__name -- gibt Backpack aus |
| 249 | ``` | 249 | ``` |
| 250 | <YueDisplay> | 250 | <YueDisplay> |
| 251 | 251 | ||
| 252 | ```yue | 252 | ```yue |
| 253 | print BackPack.__name -- prints Backpack | 253 | print BackPack.__name -- gibt Backpack aus |
| 254 | ``` | 254 | ``` |
| 255 | 255 | ||
| 256 | </YueDisplay> | 256 | </YueDisplay> |
| 257 | 257 | ||
| 258 | The base object is stored in __base. We can modify this table to add functionality to instances that have already been created and ones that are yet to be created. | 258 | Die Basistabelle ist in `__base` gespeichert. Du kannst diese Tabelle ändern, um Instanzen Funktionalität hinzuzufügen, die bereits existieren oder noch erstellt werden. |
| 259 | 259 | ||
| 260 | If the class extends from anything, the parent class object is stored in __parent. | 260 | Wenn die Klasse von etwas erbt, ist das Elternklassenobjekt in `__parent` gespeichert. |
| 261 | 261 | ||
| 262 | ## Class Variables | 262 | ## Klassenvariablen |
| 263 | 263 | ||
| 264 | We can create variables directly in the class object instead of in the base by using @ in the front of the property name in a class declaration. | 264 | Du kannst Variablen direkt im Klassenobjekt statt in der Basis erstellen, indem du in der Klassendeklaration `@` vor den Eigenschaftsnamen setzt. |
| 265 | 265 | ||
| 266 | ```yuescript | 266 | ```yuescript |
| 267 | class Things | 267 | class Things |
| 268 | @some_func: => print "Hello from", @__name | 268 | @some_func: => print "Hallo von", @__name |
| 269 | 269 | ||
| 270 | Things\some_func! | 270 | Things\some_func! |
| 271 | 271 | ||
| 272 | -- class variables not visible in instances | 272 | -- Klassenvariablen in Instanzen nicht sichtbar |
| 273 | assert Things().some_func == nil | 273 | assert Things().some_func == nil |
| 274 | ``` | 274 | ``` |
| 275 | <YueDisplay> | 275 | <YueDisplay> |
| 276 | 276 | ||
| 277 | ```yue | 277 | ```yue |
| 278 | class Things | 278 | class Things |
| 279 | @some_func: => print "Hello from", @__name | 279 | @some_func: => print "Hallo von", @__name |
| 280 | 280 | ||
| 281 | Things\some_func! | 281 | Things\some_func! |
| 282 | 282 | ||
| 283 | -- class variables not visible in instances | 283 | -- Klassenvariablen in Instanzen nicht sichtbar |
| 284 | assert Things().some_func == nil | 284 | assert Things().some_func == nil |
| 285 | ``` | 285 | ``` |
| 286 | 286 | ||
| 287 | </YueDisplay> | 287 | </YueDisplay> |
| 288 | 288 | ||
| 289 | In expressions, we can use @@ to access a value that is stored in the __class of self. Thus, @@hello is shorthand for self.__class.hello. | 289 | In Ausdrücken können wir `@@` verwenden, um auf einen Wert zuzugreifen, der in `self.__class` gespeichert ist. `@@hello` ist also eine Kurzform für `self.__class.hello`. |
| 290 | 290 | ||
| 291 | ```yuescript | 291 | ```yuescript |
| 292 | class Counter | 292 | class Counter |
| @@ -298,7 +298,7 @@ class Counter | |||
| 298 | Counter! | 298 | Counter! |
| 299 | Counter! | 299 | Counter! |
| 300 | 300 | ||
| 301 | print Counter.count -- prints 2 | 301 | print Counter.count -- gibt 2 aus |
| 302 | ``` | 302 | ``` |
| 303 | <YueDisplay> | 303 | <YueDisplay> |
| 304 | 304 | ||
| @@ -312,12 +312,12 @@ class Counter | |||
| 312 | Counter! | 312 | Counter! |
| 313 | Counter! | 313 | Counter! |
| 314 | 314 | ||
| 315 | print Counter.count -- prints 2 | 315 | print Counter.count -- gibt 2 aus |
| 316 | ``` | 316 | ``` |
| 317 | 317 | ||
| 318 | </YueDisplay> | 318 | </YueDisplay> |
| 319 | 319 | ||
| 320 | The calling semantics of @@ are similar to @. Calling a @@ name will pass the class in as the first argument using Lua's colon syntax. | 320 | Die Aufrufsemantik von `@@` ist ähnlich wie bei `@`. Wenn du einen `@@`-Namen aufrufst, wird die Klasse als erstes Argument übergeben (Lua-`:`-Syntax). |
| 321 | 321 | ||
| 322 | ```yuescript | 322 | ```yuescript |
| 323 | @@hello 1,2,3,4 | 323 | @@hello 1,2,3,4 |
| @@ -330,28 +330,28 @@ The calling semantics of @@ are similar to @. Calling a @@ name will pass the cl | |||
| 330 | 330 | ||
| 331 | </YueDisplay> | 331 | </YueDisplay> |
| 332 | 332 | ||
| 333 | ## Class Declaration Statements | 333 | ## Klassendeklarations-Statements |
| 334 | 334 | ||
| 335 | In the body of a class declaration, we can have normal expressions in addition to key/value pairs. In this context, self is equal to the class object. | 335 | Im Rumpf einer Klassendeklaration können wir normale Ausdrücke zusätzlich zu Schlüssel/Wert-Paaren haben. In diesem Kontext ist `self` gleich dem Klassenobjekt. |
| 336 | 336 | ||
| 337 | Here is an alternative way to create a class variable compared to what's described above: | 337 | Hier ist eine alternative Möglichkeit, eine Klassenvariable zu erstellen: |
| 338 | 338 | ||
| 339 | ```yuescript | 339 | ```yuescript |
| 340 | class Things | 340 | class Things |
| 341 | @class_var = "hello world" | 341 | @class_var = "Hallo Welt" |
| 342 | ``` | 342 | ``` |
| 343 | <YueDisplay> | 343 | <YueDisplay> |
| 344 | 344 | ||
| 345 | ```yue | 345 | ```yue |
| 346 | class Things | 346 | class Things |
| 347 | @class_var = "hello world" | 347 | @class_var = "Hallo Welt" |
| 348 | ``` | 348 | ``` |
| 349 | 349 | ||
| 350 | </YueDisplay> | 350 | </YueDisplay> |
| 351 | 351 | ||
| 352 | These expressions are executed after all the properties have been added to the base. | 352 | Diese Ausdrücke werden ausgeführt, nachdem alle Eigenschaften zur Basis hinzugefügt wurden. |
| 353 | 353 | ||
| 354 | All variables declared in the body of the class are local to the classes properties. This is convenient for placing private values or helper functions that only the class methods can access: | 354 | Alle Variablen, die im Klassenkörper deklariert werden, sind lokal zu den Klasseneigenschaften. Das ist praktisch, um private Werte oder Hilfsfunktionen zu platzieren, auf die nur die Klassenmethoden zugreifen können: |
| 355 | 355 | ||
| 356 | ```yuescript | 356 | ```yuescript |
| 357 | class MoreThings | 357 | class MoreThings |
| @@ -359,7 +359,7 @@ class MoreThings | |||
| 359 | log = (msg) -> print "LOG:", msg | 359 | log = (msg) -> print "LOG:", msg |
| 360 | 360 | ||
| 361 | some_method: => | 361 | some_method: => |
| 362 | log "hello world: " .. secret | 362 | log "Hallo Welt: " .. secret |
| 363 | ``` | 363 | ``` |
| 364 | <YueDisplay> | 364 | <YueDisplay> |
| 365 | 365 | ||
| @@ -369,16 +369,16 @@ class MoreThings | |||
| 369 | log = (msg) -> print "LOG:", msg | 369 | log = (msg) -> print "LOG:", msg |
| 370 | 370 | ||
| 371 | some_method: => | 371 | some_method: => |
| 372 | log "hello world: " .. secret | 372 | log "Hallo Welt: " .. secret |
| 373 | ``` | 373 | ``` |
| 374 | 374 | ||
| 375 | </YueDisplay> | 375 | </YueDisplay> |
| 376 | 376 | ||
| 377 | ## @ and @@ Values | 377 | ## @- und @@-Werte |
| 378 | 378 | ||
| 379 | When @ and @@ are prefixed in front of a name they represent, respectively, that name accessed in self and self.__class. | 379 | Wenn `@` und `@@` vor einem Namen stehen, repräsentieren sie den Namen in `self` bzw. `self.__class`. |
| 380 | 380 | ||
| 381 | If they are used all by themselves, they are aliases for self and self.__class. | 381 | Wenn sie alleine verwendet werden, sind sie Aliase für `self` und `self.__class`. |
| 382 | 382 | ||
| 383 | ```yuescript | 383 | ```yuescript |
| 384 | assert @ == self | 384 | assert @ == self |
| @@ -393,7 +393,7 @@ assert @@ == self.__class | |||
| 393 | 393 | ||
| 394 | </YueDisplay> | 394 | </YueDisplay> |
| 395 | 395 | ||
| 396 | For example, a quick way to create a new instance of the same class from an instance method using @@: | 396 | Zum Beispiel kannst du mit `@@` in einer Instanzmethode schnell eine neue Instanz derselben Klasse erzeugen: |
| 397 | 397 | ||
| 398 | ```yuescript | 398 | ```yuescript |
| 399 | some_instance_method = (...) => @@ ... | 399 | some_instance_method = (...) => @@ ... |
| @@ -406,15 +406,15 @@ some_instance_method = (...) => @@ ... | |||
| 406 | 406 | ||
| 407 | </YueDisplay> | 407 | </YueDisplay> |
| 408 | 408 | ||
| 409 | ## Constructor Property Promotion | 409 | ## Konstruktor-Property-Promotion |
| 410 | 410 | ||
| 411 | To reduce the boilerplate code for definition of simple value objects. You can write a simple class like: | 411 | Um Boilerplate beim Definieren einfacher Value-Objekte zu reduzieren, kannst du eine Klasse so schreiben: |
| 412 | 412 | ||
| 413 | ```yuescript | 413 | ```yuescript |
| 414 | class Something | 414 | class Something |
| 415 | new: (@foo, @bar, @@biz, @@baz) => | 415 | new: (@foo, @bar, @@biz, @@baz) => |
| 416 | 416 | ||
| 417 | -- Which is short for | 417 | -- Kurzform für |
| 418 | 418 | ||
| 419 | class Something | 419 | class Something |
| 420 | new: (foo, bar, biz, baz) => | 420 | new: (foo, bar, biz, baz) => |
| @@ -429,7 +429,7 @@ class Something | |||
| 429 | class Something | 429 | class Something |
| 430 | new: (@foo, @bar, @@biz, @@baz) => | 430 | new: (@foo, @bar, @@biz, @@baz) => |
| 431 | 431 | ||
| 432 | -- Which is short for | 432 | -- Kurzform für |
| 433 | 433 | ||
| 434 | class Something | 434 | class Something |
| 435 | new: (foo, bar, biz, baz) => | 435 | new: (foo, bar, biz, baz) => |
| @@ -441,7 +441,7 @@ class Something | |||
| 441 | 441 | ||
| 442 | </YueDisplay> | 442 | </YueDisplay> |
| 443 | 443 | ||
| 444 | You can also use this syntax for a common function to initialize a object's fields. | 444 | Du kannst diese Syntax auch für eine gemeinsame Funktion verwenden, um Objektfelder zu initialisieren. |
| 445 | 445 | ||
| 446 | ```yuescript | 446 | ```yuescript |
| 447 | new = (@fieldA, @fieldB) => @ | 447 | new = (@fieldA, @fieldB) => @ |
| @@ -458,9 +458,9 @@ print obj | |||
| 458 | 458 | ||
| 459 | </YueDisplay> | 459 | </YueDisplay> |
| 460 | 460 | ||
| 461 | ## Class Expressions | 461 | ## Klassenausdrücke |
| 462 | 462 | ||
| 463 | The class syntax can also be used as an expression which can be assigned to a variable or explicitly returned. | 463 | Die `class`-Syntax kann auch als Ausdruck verwendet werden, der einer Variable zugewiesen oder explizit zurückgegeben wird. |
| 464 | 464 | ||
| 465 | ```yuescript | 465 | ```yuescript |
| 466 | x = class Bucket | 466 | x = class Bucket |
| @@ -477,9 +477,9 @@ x = class Bucket | |||
| 477 | 477 | ||
| 478 | </YueDisplay> | 478 | </YueDisplay> |
| 479 | 479 | ||
| 480 | ## Anonymous classes | 480 | ## Anonyme Klassen |
| 481 | 481 | ||
| 482 | The name can be left out when declaring a class. The __name attribute will be nil, unless the class expression is in an assignment. The name on the left hand side of the assignment is used instead of nil. | 482 | Der Name kann beim Deklarieren einer Klasse weggelassen werden. Das `__name`-Attribut ist dann `nil`, es sei denn, der Klassenausdruck steht in einer Zuweisung. In diesem Fall wird der Name auf der linken Seite statt `nil` verwendet. |
| 483 | 483 | ||
| 484 | ```yuescript | 484 | ```yuescript |
| 485 | BigBucket = class extends Bucket | 485 | BigBucket = class extends Bucket |
| @@ -498,7 +498,7 @@ assert Bucket.__name == "BigBucket" | |||
| 498 | 498 | ||
| 499 | </YueDisplay> | 499 | </YueDisplay> |
| 500 | 500 | ||
| 501 | You can even leave off the body, meaning you can write a blank anonymous class like this: | 501 | Du kannst sogar den Körper weglassen und eine leere anonyme Klasse schreiben: |
| 502 | 502 | ||
| 503 | ```yuescript | 503 | ```yuescript |
| 504 | x = class | 504 | x = class |
| @@ -513,7 +513,7 @@ x = class | |||
| 513 | 513 | ||
| 514 | ## Class Mixing | 514 | ## Class Mixing |
| 515 | 515 | ||
| 516 | You can do mixing with keyword `using` to copy functions from either a plain table or a predefined class object into your new class. When doing mixing with a plain table, you can override the class indexing function (metamethod `__index`) to your customized implementation. When doing mixing with an existing class object, the class object's metamethods won't be copied. | 516 | Du kannst mit dem Schlüsselwort `using` mischen, um Funktionen aus einer einfachen Tabelle oder einem vordefinierten Klassenobjekt in deine neue Klasse zu kopieren. Beim Mischen mit einer einfachen Tabelle kannst du die Klassen-Indexing-Funktion (Metamethod `__index`) überschreiben. Beim Mischen mit einem bestehenden Klassenobjekt werden dessen Metamethoden nicht kopiert. |
| 517 | 517 | ||
| 518 | ```yuescript | 518 | ```yuescript |
| 519 | MyIndex = __index: var: 1 | 519 | MyIndex = __index: var: 1 |
| @@ -530,7 +530,7 @@ class Y using X | |||
| 530 | y = Y! | 530 | y = Y! |
| 531 | y\func! | 531 | y\func! |
| 532 | 532 | ||
| 533 | assert y.__class.__parent ~= X -- X is not parent of Y | 533 | assert y.__class.__parent ~= X -- X ist nicht die Elternklasse von Y |
| 534 | ``` | 534 | ``` |
| 535 | <YueDisplay> | 535 | <YueDisplay> |
| 536 | 536 | ||
| @@ -549,7 +549,7 @@ class Y using X | |||
| 549 | y = Y! | 549 | y = Y! |
| 550 | y\func! | 550 | y\func! |
| 551 | 551 | ||
| 552 | assert y.__class.__parent ~= X -- X is not parent of Y | 552 | assert y.__class.__parent ~= X -- X ist nicht die Elternklasse von Y |
| 553 | ``` | 553 | ``` |
| 554 | 554 | ||
| 555 | </YueDisplay> | 555 | </YueDisplay> |
diff --git a/doc/docs/de/doc/objects/with-statement.md b/doc/docs/de/doc/objects/with-statement.md index 7786803..446f837 100644 --- a/doc/docs/de/doc/objects/with-statement.md +++ b/doc/docs/de/doc/objects/with-statement.md | |||
| @@ -1,13 +1,12 @@ | |||
| 1 | # With Statement | 1 | # With-Statement |
| 2 | 2 | ||
| 3 | Ein häufiges Muster bei der Erstellung eines Objekts ist, unmittelbar danach eine Reihe von Funktionen aufzurufen und Eigenschaften zu setzen. | ||
| 3 | 4 | ||
| 4 | A common pattern involving the creation of an object is calling a series of functions and setting a series of properties immediately after creating it. | 5 | Das führt dazu, dass der Objektname mehrfach wiederholt wird und unnötiges Rauschen entsteht. Eine gängige Lösung ist, eine Tabelle als Argument zu übergeben, die eine Sammlung von Schlüsseln und Werten enthält, die überschrieben werden sollen. Der Nachteil ist, dass der Konstruktor dieses Objekts diese Form unterstützen muss. |
| 5 | 6 | ||
| 6 | This results in repeating the name of the object multiple times in code, adding unnecessary noise. A common solution to this is to pass a table in as an argument which contains a collection of keys and values to overwrite. The downside to this is that the constructor of this object must support this form. | 7 | Der `with`-Block hilft, das zu vermeiden. Innerhalb eines `with`-Blocks können wir spezielle Anweisungen verwenden, die mit `.` oder `\` beginnen und die Operationen auf das Objekt anwenden, mit dem wir gerade arbeiten. |
| 7 | 8 | ||
| 8 | The with block helps to alleviate this. Within a with block we can use a special statements that begin with either . or \ which represent those operations applied to the object we are using with on. | 9 | Zum Beispiel arbeiten wir mit einem neu erstellten Objekt: |
| 9 | |||
| 10 | For example, we work with a newly created object: | ||
| 11 | 10 | ||
| 12 | ```yuescript | 11 | ```yuescript |
| 13 | with Person! | 12 | with Person! |
| @@ -28,22 +27,22 @@ with Person! | |||
| 28 | 27 | ||
| 29 | </YueDisplay> | 28 | </YueDisplay> |
| 30 | 29 | ||
| 31 | The with statement can also be used as an expression which returns the value it has been giving access to. | 30 | Das `with`-Statement kann auch als Ausdruck verwendet werden und gibt den Wert zurück, auf den es Zugriff gewährt. |
| 32 | 31 | ||
| 33 | ```yuescript | 32 | ```yuescript |
| 34 | file = with File "favorite_foods.txt" | 33 | file = with File "Lieblingsessen.txt" |
| 35 | \set_encoding "utf8" | 34 | \set_encoding "utf8" |
| 36 | ``` | 35 | ``` |
| 37 | <YueDisplay> | 36 | <YueDisplay> |
| 38 | 37 | ||
| 39 | ```yue | 38 | ```yue |
| 40 | file = with File "favorite_foods.txt" | 39 | file = with File "Lieblingsessen.txt" |
| 41 | \set_encoding "utf8" | 40 | \set_encoding "utf8" |
| 42 | ``` | 41 | ``` |
| 43 | 42 | ||
| 44 | </YueDisplay> | 43 | </YueDisplay> |
| 45 | 44 | ||
| 46 | Or… | 45 | Oder … |
| 47 | 46 | ||
| 48 | ```yuescript | 47 | ```yuescript |
| 49 | create_person = (name, relatives) -> | 48 | create_person = (name, relatives) -> |
| @@ -66,26 +65,26 @@ me = create_person "Leaf", [dad, mother, sister] | |||
| 66 | 65 | ||
| 67 | </YueDisplay> | 66 | </YueDisplay> |
| 68 | 67 | ||
| 69 | In this usage, with can be seen as a special form of the K combinator. | 68 | In dieser Verwendung kann `with` als spezielle Form des K-Kombinators gesehen werden. |
| 70 | 69 | ||
| 71 | The expression in the with statement can also be an assignment, if you want to give a name to the expression. | 70 | Der Ausdruck im `with`-Statement kann auch eine Zuweisung sein, wenn du dem Ausdruck einen Namen geben willst. |
| 72 | 71 | ||
| 73 | ```yuescript | 72 | ```yuescript |
| 74 | with str := "Hello" | 73 | with str := "Hallo" |
| 75 | print "original:", str | 74 | print "Original:", str |
| 76 | print "upper:", \upper! | 75 | print "Großbuchstaben:", \upper! |
| 77 | ``` | 76 | ``` |
| 78 | <YueDisplay> | 77 | <YueDisplay> |
| 79 | 78 | ||
| 80 | ```yue | 79 | ```yue |
| 81 | with str := "Hello" | 80 | with str := "Hallo" |
| 82 | print "original:", str | 81 | print "Original:", str |
| 83 | print "upper:", \upper! | 82 | print "Großbuchstaben:", \upper! |
| 84 | ``` | 83 | ``` |
| 85 | 84 | ||
| 86 | </YueDisplay> | 85 | </YueDisplay> |
| 87 | 86 | ||
| 88 | You can access special keys with `[]` in a `with` statement. | 87 | Du kannst in einem `with`-Statement über `[]` auf spezielle Schlüssel zugreifen. |
| 89 | 88 | ||
| 90 | ```yuescript | 89 | ```yuescript |
| 91 | with tb | 90 | with tb |
| @@ -94,7 +93,7 @@ with tb | |||
| 94 | with [abc] | 93 | with [abc] |
| 95 | [3] = [2]\func! | 94 | [3] = [2]\func! |
| 96 | ["key-name"] = value | 95 | ["key-name"] = value |
| 97 | [] = "abc" -- appending to "tb" | 96 | [] = "abc" -- an "tb" anhängen |
| 98 | ``` | 97 | ``` |
| 99 | <YueDisplay> | 98 | <YueDisplay> |
| 100 | 99 | ||
| @@ -105,12 +104,12 @@ with tb | |||
| 105 | with [abc] | 104 | with [abc] |
| 106 | [3] = [2]\func! | 105 | [3] = [2]\func! |
| 107 | ["key-name"] = value | 106 | ["key-name"] = value |
| 108 | [] = "abc" -- appending to "tb" | 107 | [] = "abc" -- an "tb" anhängen |
| 109 | ``` | 108 | ``` |
| 110 | 109 | ||
| 111 | </YueDisplay> | 110 | </YueDisplay> |
| 112 | 111 | ||
| 113 | `with?` is an enhanced version of `with` syntax, which introduces an existential check to safely access objects that may be nil without explicit null checks. | 112 | `with?` ist eine erweiterte Version der `with`-Syntax, die einen Existenz-Check einführt, um Objekte, die `nil` sein könnten, sicher zuzugreifen, ohne explizite Nullprüfungen. |
| 114 | 113 | ||
| 115 | ```yuescript | 114 | ```yuescript |
| 116 | with? obj | 115 | with? obj |
diff --git a/doc/docs/de/doc/reference/license-mit.md b/doc/docs/de/doc/reference/license-mit.md index f1d5d60..a5e9f70 100644 --- a/doc/docs/de/doc/reference/license-mit.md +++ b/doc/docs/de/doc/reference/license-mit.md | |||
| @@ -1,23 +1,11 @@ | |||
| 1 | # License: MIT | 1 | # Lizenz: MIT |
| 2 | 2 | ||
| 3 | Copyright (c) 2017-2026 Li Jin \<dragon-fly@qq.com\> | 3 | Hinweis: Die MIT-Lizenz ist unten im englischen Originaltext wiedergegeben. |
| 4 | 4 | ||
| 5 | Permission is hereby granted, free of charge, to any person obtaining a copy | 5 | Urheberrecht (c) 2017-2026 Li Jin <dragon-fly@qq.com> |
| 6 | of this software and associated documentation files (the "Software"), to deal | ||
| 7 | in the Software without restriction, including without limitation the rights | ||
| 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| 9 | copies of the Software, and to permit persons to whom the Software is | ||
| 10 | furnished to do so, subject to the following conditions: | ||
| 11 | 6 | ||
| 12 | The above copyright notice and this permission notice shall be included in all | 7 | Hiermit wird unentgeltlich jeder Person, die eine Kopie dieser Software und der zugehörigen Dokumentationsdateien (die "Software") erhält, die Erlaubnis erteilt, uneingeschränkt mit der Software zu verfahren, einschließlich und ohne Beschränkung der Rechte, die Software zu benutzen, zu kopieren, zu verändern, zusammenzuführen, zu veröffentlichen, zu verbreiten, zu unterlizenzieren und/oder zu verkaufen, sowie Personen, denen die Software zur Verfügung gestellt wird, dies ebenfalls zu gestatten, unter den folgenden Bedingungen: |
| 13 | copies or substantial portions of the Software. | ||
| 14 | 8 | ||
| 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 9 | Der obige Urheberrechtshinweis und dieser Genehmigungshinweis müssen in allen Kopien oder wesentlichen Teilen der Software enthalten sein. |
| 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| 21 | SOFTWARE. | ||
| 22 | 10 | ||
| 23 | <CompilerModal /> | 11 | DIE SOFTWARE WIRD OHNE JEGLICHE AUSDRÜCKLICHE ODER STILLSCHWEIGENDE GARANTIE ZUR VERFÜGUNG GESTELLT, EINSCHLIESSLICH DER GARANTIEN DER MARKTGÄNGIGKEIT, DER EIGNUNG FÜR EINEN BESTIMMTEN ZWECK UND DER NICHTVERLETZUNG. IN KEINEM FALL SIND DIE AUTOREN ODER URHEBERRECHTSINHABER FÜR ANSPRÜCHE, SCHÄDEN ODER SONSTIGE HAFTUNGEN VERANTWORTLICH, SEI ES AUS EINEM VERTRAG, EINER UNERLAUBTEN HANDLUNG ODER ANDERWEITIG, DIE SICH AUS DER SOFTWARE ODER DER BENUTZUNG DER SOFTWARE ODER ANDEREN GESCHÄFTEN MIT DER SOFTWARE ERGEBEN ODER DAMIT IN ZUSAMMENHANG STEHEN. |
diff --git a/doc/docs/de/doc/reference/the-yuescript-library.md b/doc/docs/de/doc/reference/the-yuescript-library.md index 3761755..1838ced 100644 --- a/doc/docs/de/doc/reference/the-yuescript-library.md +++ b/doc/docs/de/doc/reference/the-yuescript-library.md | |||
| @@ -1,61 +1,61 @@ | |||
| 1 | # The YueScript Library | 1 | # Die YueScript-Bibliothek |
| 2 | 2 | ||
| 3 | Access it by `local yue = require("yue")` in Lua. | 3 | Zugriff in Lua über `local yue = require("yue")`. |
| 4 | 4 | ||
| 5 | ## yue | 5 | ## yue |
| 6 | 6 | ||
| 7 | **Description:** | 7 | **Beschreibung:** |
| 8 | 8 | ||
| 9 | The YueScript language library. | 9 | Die YueScript-Sprachbibliothek. |
| 10 | 10 | ||
| 11 | ### version | 11 | ### version |
| 12 | 12 | ||
| 13 | **Type:** Field. | 13 | **Typ:** Feld. |
| 14 | 14 | ||
| 15 | **Description:** | 15 | **Beschreibung:** |
| 16 | 16 | ||
| 17 | The YueScript version. | 17 | Die YueScript-Version. |
| 18 | 18 | ||
| 19 | **Signature:** | 19 | **Signatur:** |
| 20 | ```lua | 20 | ```lua |
| 21 | version: string | 21 | version: string |
| 22 | ``` | 22 | ``` |
| 23 | 23 | ||
| 24 | ### dirsep | 24 | ### dirsep |
| 25 | 25 | ||
| 26 | **Type:** Field. | 26 | **Typ:** Feld. |
| 27 | 27 | ||
| 28 | **Description:** | 28 | **Beschreibung:** |
| 29 | 29 | ||
| 30 | The file separator for the current platform. | 30 | Der Dateitrennzeichen-String der aktuellen Plattform. |
| 31 | 31 | ||
| 32 | **Signature:** | 32 | **Signatur:** |
| 33 | ```lua | 33 | ```lua |
| 34 | dirsep: string | 34 | dirsep: string |
| 35 | ``` | 35 | ``` |
| 36 | 36 | ||
| 37 | ### yue_compiled | 37 | ### yue_compiled |
| 38 | 38 | ||
| 39 | **Type:** Field. | 39 | **Typ:** Feld. |
| 40 | 40 | ||
| 41 | **Description:** | 41 | **Beschreibung:** |
| 42 | 42 | ||
| 43 | The compiled module code cache. | 43 | Der Cache für kompilierten Modulcode. |
| 44 | 44 | ||
| 45 | **Signature:** | 45 | **Signatur:** |
| 46 | ```lua | 46 | ```lua |
| 47 | yue_compiled: {string: string} | 47 | yue_compiled: {string: string} |
| 48 | ``` | 48 | ``` |
| 49 | 49 | ||
| 50 | ### to_lua | 50 | ### to_lua |
| 51 | 51 | ||
| 52 | **Type:** Function. | 52 | **Typ:** Funktion. |
| 53 | 53 | ||
| 54 | **Description:** | 54 | **Beschreibung:** |
| 55 | 55 | ||
| 56 | The YueScript compiling function. It compiles the YueScript code to Lua code. | 56 | Die YueScript-Compilerfunktion. Sie kompiliert YueScript-Code zu Lua-Code. |
| 57 | 57 | ||
| 58 | **Signature:** | 58 | **Signatur:** |
| 59 | ```lua | 59 | ```lua |
| 60 | to_lua: function(code: string, config?: Config): | 60 | to_lua: function(code: string, config?: Config): |
| 61 | --[[codes]] string | nil, | 61 | --[[codes]] string | nil, |
| @@ -63,682 +63,682 @@ to_lua: function(code: string, config?: Config): | |||
| 63 | --[[globals]] {{string, integer, integer}} | nil | 63 | --[[globals]] {{string, integer, integer}} | nil |
| 64 | ``` | 64 | ``` |
| 65 | 65 | ||
| 66 | **Parameters:** | 66 | **Parameter:** |
| 67 | 67 | ||
| 68 | | Parameter | Type | Description | | 68 | | Parameter | Typ | Beschreibung | |
| 69 | | --- | --- | --- | | 69 | | --- | --- | --- | |
| 70 | | code | string | The YueScript code. | | 70 | | code | string | Der YueScript-Code. | |
| 71 | | config | Config | [Optional] The compiler options. | | 71 | | config | Config | [Optional] Die Compiler-Optionen. | |
| 72 | 72 | ||
| 73 | **Returns:** | 73 | **Rückgabe:** |
| 74 | 74 | ||
| 75 | | Return Type | Description | | 75 | | Rückgabetyp | Beschreibung | |
| 76 | | --- | --- | | 76 | | --- | --- | |
| 77 | | string \| nil | The compiled Lua code, or nil if the compilation failed. | | 77 | | string \| nil | Der kompilierte Lua-Code oder `nil`, falls die Kompilierung fehlgeschlagen ist. | |
| 78 | | string \| nil | The error message, or nil if the compilation succeeded. | | 78 | | string \| nil | Die Fehlermeldung oder `nil`, falls die Kompilierung erfolgreich war. | |
| 79 | | {{string, integer, integer}} \| nil | The global variables appearing in the code (with name, row and column), or nil if the compiler option `lint_global` is false. | | 79 | | {{string, integer, integer}} \| nil | Die globalen Variablen im Code (mit Name, Zeile und Spalte) oder `nil`, wenn die Compiler-Option `lint_global` false ist. | |
| 80 | 80 | ||
| 81 | ### file_exist | 81 | ### file_exist |
| 82 | 82 | ||
| 83 | **Type:** Function. | 83 | **Typ:** Funktion. |
| 84 | 84 | ||
| 85 | **Description:** | 85 | **Beschreibung:** |
| 86 | 86 | ||
| 87 | The source file existence checking function. Can be overridden to customize the behavior. | 87 | Prüft, ob eine Quelldatei existiert. Kann überschrieben werden, um das Verhalten anzupassen. |
| 88 | 88 | ||
| 89 | **Signature:** | 89 | **Signatur:** |
| 90 | ```lua | 90 | ```lua |
| 91 | file_exist: function(filename: string): boolean | 91 | file_exist: function(filename: string): boolean |
| 92 | ``` | 92 | ``` |
| 93 | 93 | ||
| 94 | **Parameters:** | 94 | **Parameter:** |
| 95 | 95 | ||
| 96 | | Parameter | Type | Description | | 96 | | Parameter | Typ | Beschreibung | |
| 97 | | --- | --- | --- | | 97 | | --- | --- | --- | |
| 98 | | filename | string | The file name. | | 98 | | filename | string | Der Dateiname. | |
| 99 | 99 | ||
| 100 | **Returns:** | 100 | **Rückgabe:** |
| 101 | 101 | ||
| 102 | | Return Type | Description | | 102 | | Rückgabetyp | Beschreibung | |
| 103 | | --- | --- | | 103 | | --- | --- | |
| 104 | | boolean | Whether the file exists. | | 104 | | boolean | Ob die Datei existiert. | |
| 105 | 105 | ||
| 106 | ### read_file | 106 | ### read_file |
| 107 | 107 | ||
| 108 | **Type:** Function. | 108 | **Typ:** Funktion. |
| 109 | 109 | ||
| 110 | **Description:** | 110 | **Beschreibung:** |
| 111 | 111 | ||
| 112 | The source file reading function. Can be overridden to customize the behavior. | 112 | Liest eine Quelldatei. Kann überschrieben werden, um das Verhalten anzupassen. |
| 113 | 113 | ||
| 114 | **Signature:** | 114 | **Signatur:** |
| 115 | ```lua | 115 | ```lua |
| 116 | read_file: function(filename: string): string | 116 | read_file: function(filename: string): string |
| 117 | ``` | 117 | ``` |
| 118 | 118 | ||
| 119 | **Parameters:** | 119 | **Parameter:** |
| 120 | 120 | ||
| 121 | | Parameter | Type | Description | | 121 | | Parameter | Typ | Beschreibung | |
| 122 | | --- | --- | --- | | 122 | | --- | --- | --- | |
| 123 | | filename | string | The file name. | | 123 | | filename | string | Der Dateiname. | |
| 124 | 124 | ||
| 125 | **Returns:** | 125 | **Rückgabe:** |
| 126 | 126 | ||
| 127 | | Return Type | Description | | 127 | | Rückgabetyp | Beschreibung | |
| 128 | | --- | --- | | 128 | | --- | --- | |
| 129 | | string | The file content. | | 129 | | string | Der Dateiinhalt. | |
| 130 | 130 | ||
| 131 | ### insert_loader | 131 | ### insert_loader |
| 132 | 132 | ||
| 133 | **Type:** Function. | 133 | **Typ:** Funktion. |
| 134 | 134 | ||
| 135 | **Description:** | 135 | **Beschreibung:** |
| 136 | 136 | ||
| 137 | Insert the YueScript loader to the package loaders (searchers). | 137 | Fügt den YueScript-Loader in die Package-Loader (Searcher) ein. |
| 138 | 138 | ||
| 139 | **Signature:** | 139 | **Signatur:** |
| 140 | ```lua | 140 | ```lua |
| 141 | insert_loader: function(pos?: integer): boolean | 141 | insert_loader: function(pos?: integer): boolean |
| 142 | ``` | 142 | ``` |
| 143 | 143 | ||
| 144 | **Parameters:** | 144 | **Parameter:** |
| 145 | 145 | ||
| 146 | | Parameter | Type | Description | | 146 | | Parameter | Typ | Beschreibung | |
| 147 | | --- | --- | --- | | 147 | | --- | --- | --- | |
| 148 | | pos | integer | [Optional] The position to insert the loader. Default is 3. | | 148 | | pos | integer | [Optional] Position, an der der Loader eingefügt wird. Standard ist 3. | |
| 149 | 149 | ||
| 150 | **Returns:** | 150 | **Rückgabe:** |
| 151 | 151 | ||
| 152 | | Return Type | Description | | 152 | | Rückgabetyp | Beschreibung | |
| 153 | | --- | --- | | 153 | | --- | --- | |
| 154 | | boolean | Whether the loader is inserted successfully. It will fail if the loader is already inserted. | | 154 | | boolean | Ob der Loader erfolgreich eingefügt wurde. Scheitert, wenn er bereits eingefügt ist. | |
| 155 | 155 | ||
| 156 | ### remove_loader | 156 | ### remove_loader |
| 157 | 157 | ||
| 158 | **Type:** Function. | 158 | **Typ:** Funktion. |
| 159 | 159 | ||
| 160 | **Description:** | 160 | **Beschreibung:** |
| 161 | 161 | ||
| 162 | Remove the YueScript loader from the package loaders (searchers). | 162 | Entfernt den YueScript-Loader aus den Package-Loadern (Searchern). |
| 163 | 163 | ||
| 164 | **Signature:** | 164 | **Signatur:** |
| 165 | ```lua | 165 | ```lua |
| 166 | remove_loader: function(): boolean | 166 | remove_loader: function(): boolean |
| 167 | ``` | 167 | ``` |
| 168 | 168 | ||
| 169 | **Returns:** | 169 | **Rückgabe:** |
| 170 | 170 | ||
| 171 | | Return Type | Description | | 171 | | Rückgabetyp | Beschreibung | |
| 172 | | --- | --- | | 172 | | --- | --- | |
| 173 | | boolean | Whether the loader is removed successfully. It will fail if the loader is not inserted. | | 173 | | boolean | Ob der Loader erfolgreich entfernt wurde. Scheitert, wenn er nicht eingefügt ist. | |
| 174 | 174 | ||
| 175 | ### loadstring | 175 | ### loadstring |
| 176 | 176 | ||
| 177 | **Type:** Function. | 177 | **Typ:** Funktion. |
| 178 | 178 | ||
| 179 | **Description:** | 179 | **Beschreibung:** |
| 180 | 180 | ||
| 181 | Loads YueScript code from a string into a function. | 181 | Lädt YueScript-Code aus einem String in eine Funktion. |
| 182 | 182 | ||
| 183 | **Signature:** | 183 | **Signatur:** |
| 184 | ```lua | 184 | ```lua |
| 185 | loadstring: function(input: string, chunkname: string, env: table, config?: Config): | 185 | loadstring: function(input: string, chunkname: string, env: table, config?: Config): |
| 186 | --[[loaded function]] nil | function(...: any): (any...), | 186 | --[[loaded function]] nil | function(...: any): (any...), |
| 187 | --[[error]] string | nil | 187 | --[[error]] string | nil |
| 188 | ``` | 188 | ``` |
| 189 | 189 | ||
| 190 | **Parameters:** | 190 | **Parameter:** |
| 191 | 191 | ||
| 192 | | Parameter | Type | Description | | 192 | | Parameter | Typ | Beschreibung | |
| 193 | | --- | --- | --- | | 193 | | --- | --- | --- | |
| 194 | | input | string | The YueScript code. | | 194 | | input | string | Der YueScript-Code. | |
| 195 | | chunkname | string | The name of the code chunk. | | 195 | | chunkname | string | Der Name des Code-Chunks. | |
| 196 | | env | table | The environment table. | | 196 | | env | table | Die Environment-Tabelle. | |
| 197 | | config | Config | [Optional] The compiler options. | | 197 | | config | Config | [Optional] Die Compiler-Optionen. | |
| 198 | 198 | ||
| 199 | **Returns:** | 199 | **Rückgabe:** |
| 200 | 200 | ||
| 201 | | Return Type | Description | | 201 | | Rückgabetyp | Beschreibung | |
| 202 | | --- | --- | | 202 | | --- | --- | |
| 203 | | function \| nil | The loaded function, or nil if the loading failed. | | 203 | | function \| nil | Die geladene Funktion oder `nil`, falls das Laden fehlgeschlagen ist. | |
| 204 | | string \| nil | The error message, or nil if the loading succeeded. | | 204 | | string \| nil | Die Fehlermeldung oder `nil`, falls das Laden erfolgreich war. | |
| 205 | 205 | ||
| 206 | ### loadstring | 206 | ### loadstring |
| 207 | 207 | ||
| 208 | **Type:** Function. | 208 | **Typ:** Funktion. |
| 209 | 209 | ||
| 210 | **Description:** | 210 | **Beschreibung:** |
| 211 | 211 | ||
| 212 | Loads YueScript code from a string into a function. | 212 | Lädt YueScript-Code aus einem String in eine Funktion. |
| 213 | 213 | ||
| 214 | **Signature:** | 214 | **Signatur:** |
| 215 | ```lua | 215 | ```lua |
| 216 | loadstring: function(input: string, chunkname: string, config?: Config): | 216 | loadstring: function(input: string, chunkname: string, config?: Config): |
| 217 | --[[loaded function]] nil | function(...: any): (any...), | 217 | --[[loaded function]] nil | function(...: any): (any...), |
| 218 | --[[error]] string | nil | 218 | --[[error]] string | nil |
| 219 | ``` | 219 | ``` |
| 220 | 220 | ||
| 221 | **Parameters:** | 221 | **Parameter:** |
| 222 | 222 | ||
| 223 | | Parameter | Type | Description | | 223 | | Parameter | Typ | Beschreibung | |
| 224 | | --- | --- | --- | | 224 | | --- | --- | --- | |
| 225 | | input | string | The YueScript code. | | 225 | | input | string | Der YueScript-Code. | |
| 226 | | chunkname | string | The name of the code chunk. | | 226 | | chunkname | string | Der Name des Code-Chunks. | |
| 227 | | config | Config | [Optional] The compiler options. | | 227 | | config | Config | [Optional] Die Compiler-Optionen. | |
| 228 | 228 | ||
| 229 | **Returns:** | 229 | **Rückgabe:** |
| 230 | 230 | ||
| 231 | | Return Type | Description | | 231 | | Rückgabetyp | Beschreibung | |
| 232 | | --- | --- | | 232 | | --- | --- | |
| 233 | | function \| nil | The loaded function, or nil if the loading failed. | | 233 | | function \| nil | Die geladene Funktion oder `nil`, falls das Laden fehlgeschlagen ist. | |
| 234 | | string \| nil | The error message, or nil if the loading succeeded. | | 234 | | string \| nil | Die Fehlermeldung oder `nil`, falls das Laden erfolgreich war. | |
| 235 | 235 | ||
| 236 | ### loadstring | 236 | ### loadstring |
| 237 | 237 | ||
| 238 | **Type:** Function. | 238 | **Typ:** Funktion. |
| 239 | 239 | ||
| 240 | **Description:** | 240 | **Beschreibung:** |
| 241 | 241 | ||
| 242 | Loads YueScript code from a string into a function. | 242 | Lädt YueScript-Code aus einem String in eine Funktion. |
| 243 | 243 | ||
| 244 | **Signature:** | 244 | **Signatur:** |
| 245 | ```lua | 245 | ```lua |
| 246 | loadstring: function(input: string, config?: Config): | 246 | loadstring: function(input: string, config?: Config): |
| 247 | --[[loaded function]] nil | function(...: any): (any...), | 247 | --[[loaded function]] nil | function(...: any): (any...), |
| 248 | --[[error]] string | nil | 248 | --[[error]] string | nil |
| 249 | ``` | 249 | ``` |
| 250 | 250 | ||
| 251 | **Parameters:** | 251 | **Parameter:** |
| 252 | 252 | ||
| 253 | | Parameter | Type | Description | | 253 | | Parameter | Typ | Beschreibung | |
| 254 | | --- | --- | --- | | 254 | | --- | --- | --- | |
| 255 | | input | string | The YueScript code. | | 255 | | input | string | Der YueScript-Code. | |
| 256 | | config | Config | [Optional] The compiler options. | | 256 | | config | Config | [Optional] Die Compiler-Optionen. | |
| 257 | 257 | ||
| 258 | **Returns:** | 258 | **Rückgabe:** |
| 259 | 259 | ||
| 260 | | Return Type | Description | | 260 | | Rückgabetyp | Beschreibung | |
| 261 | | --- | --- | | 261 | | --- | --- | |
| 262 | | function \| nil | The loaded function, or nil if the loading failed. | | 262 | | function \| nil | Die geladene Funktion oder `nil`, falls das Laden fehlgeschlagen ist. | |
| 263 | | string \| nil | The error message, or nil if the loading succeeded. | | 263 | | string \| nil | Die Fehlermeldung oder `nil`, falls das Laden erfolgreich war. | |
| 264 | 264 | ||
| 265 | ### loadfile | 265 | ### loadfile |
| 266 | 266 | ||
| 267 | **Type:** Function. | 267 | **Typ:** Funktion. |
| 268 | 268 | ||
| 269 | **Description:** | 269 | **Beschreibung:** |
| 270 | 270 | ||
| 271 | Loads YueScript code from a file into a function. | 271 | Lädt YueScript-Code aus einer Datei in eine Funktion. |
| 272 | 272 | ||
| 273 | **Signature:** | 273 | **Signatur:** |
| 274 | ```lua | 274 | ```lua |
| 275 | loadfile: function(filename: string, env: table, config?: Config): | 275 | loadfile: function(filename: string, env: table, config?: Config): |
| 276 | nil | function(...: any): (any...), | 276 | nil | function(...: any): (any...), |
| 277 | string | nil | 277 | string | nil |
| 278 | ``` | 278 | ``` |
| 279 | 279 | ||
| 280 | **Parameters:** | 280 | **Parameter:** |
| 281 | 281 | ||
| 282 | | Parameter | Type | Description | | 282 | | Parameter | Typ | Beschreibung | |
| 283 | | --- | --- | --- | | 283 | | --- | --- | --- | |
| 284 | | filename | string | The file name. | | 284 | | filename | string | Der Dateiname. | |
| 285 | | env | table | The environment table. | | 285 | | env | table | Die Environment-Tabelle. | |
| 286 | | config | Config | [Optional] The compiler options. | | 286 | | config | Config | [Optional] Die Compiler-Optionen. | |
| 287 | 287 | ||
| 288 | **Returns:** | 288 | **Rückgabe:** |
| 289 | 289 | ||
| 290 | | Return Type | Description | | 290 | | Rückgabetyp | Beschreibung | |
| 291 | | --- | --- | | 291 | | --- | --- | |
| 292 | | function \| nil | The loaded function, or nil if the loading failed. | | 292 | | function \| nil | Die geladene Funktion oder `nil`, falls das Laden fehlgeschlagen ist. | |
| 293 | | string \| nil | The error message, or nil if the loading succeeded. | | 293 | | string \| nil | Die Fehlermeldung oder `nil`, falls das Laden erfolgreich war. | |
| 294 | 294 | ||
| 295 | ### loadfile | 295 | ### loadfile |
| 296 | 296 | ||
| 297 | **Type:** Function. | 297 | **Typ:** Funktion. |
| 298 | 298 | ||
| 299 | **Description:** | 299 | **Beschreibung:** |
| 300 | 300 | ||
| 301 | Loads YueScript code from a file into a function. | 301 | Lädt YueScript-Code aus einer Datei in eine Funktion. |
| 302 | 302 | ||
| 303 | **Signature:** | 303 | **Signatur:** |
| 304 | ```lua | 304 | ```lua |
| 305 | loadfile: function(filename: string, config?: Config): | 305 | loadfile: function(filename: string, config?: Config): |
| 306 | nil | function(...: any): (any...), | 306 | nil | function(...: any): (any...), |
| 307 | string | nil | 307 | string | nil |
| 308 | ``` | 308 | ``` |
| 309 | 309 | ||
| 310 | **Parameters:** | 310 | **Parameter:** |
| 311 | 311 | ||
| 312 | | Parameter | Type | Description | | 312 | | Parameter | Typ | Beschreibung | |
| 313 | | --- | --- | --- | | 313 | | --- | --- | --- | |
| 314 | | filename | string | The file name. | | 314 | | filename | string | Der Dateiname. | |
| 315 | | config | Config | [Optional] The compiler options. | | 315 | | config | Config | [Optional] Die Compiler-Optionen. | |
| 316 | 316 | ||
| 317 | **Returns:** | 317 | **Rückgabe:** |
| 318 | 318 | ||
| 319 | | Return Type | Description | | 319 | | Rückgabetyp | Beschreibung | |
| 320 | | --- | --- | | 320 | | --- | --- | |
| 321 | | function \| nil | The loaded function, or nil if the loading failed. | | 321 | | function \| nil | Die geladene Funktion oder `nil`, falls das Laden fehlgeschlagen ist. | |
| 322 | | string \| nil | The error message, or nil if the loading succeeded. | | 322 | | string \| nil | Die Fehlermeldung oder `nil`, falls das Laden erfolgreich war. | |
| 323 | 323 | ||
| 324 | ### dofile | 324 | ### dofile |
| 325 | 325 | ||
| 326 | **Type:** Function. | 326 | **Typ:** Funktion. |
| 327 | 327 | ||
| 328 | **Description:** | 328 | **Beschreibung:** |
| 329 | 329 | ||
| 330 | Loads YueScript code from a file into a function and executes it. | 330 | Lädt YueScript-Code aus einer Datei in eine Funktion und führt sie aus. |
| 331 | 331 | ||
| 332 | **Signature:** | 332 | **Signatur:** |
| 333 | ```lua | 333 | ```lua |
| 334 | dofile: function(filename: string, env: table, config?: Config): any... | 334 | dofile: function(filename: string, env: table, config?: Config): any... |
| 335 | ``` | 335 | ``` |
| 336 | 336 | ||
| 337 | **Parameters:** | 337 | **Parameter:** |
| 338 | 338 | ||
| 339 | | Parameter | Type | Description | | 339 | | Parameter | Typ | Beschreibung | |
| 340 | | --- | --- | --- | | 340 | | --- | --- | --- | |
| 341 | | filename | string | The file name. | | 341 | | filename | string | Der Dateiname. | |
| 342 | | env | table | The environment table. | | 342 | | env | table | Die Environment-Tabelle. | |
| 343 | | config | Config | [Optional] The compiler options. | | 343 | | config | Config | [Optional] Die Compiler-Optionen. | |
| 344 | 344 | ||
| 345 | **Returns:** | 345 | **Rückgabe:** |
| 346 | 346 | ||
| 347 | | Return Type | Description | | 347 | | Rückgabetyp | Beschreibung | |
| 348 | | --- | --- | | 348 | | --- | --- | |
| 349 | | any... | The return values of the loaded function. | | 349 | | any... | Die Rückgabewerte der geladenen Funktion. | |
| 350 | 350 | ||
| 351 | ### dofile | 351 | ### dofile |
| 352 | 352 | ||
| 353 | **Type:** Function. | 353 | **Typ:** Funktion. |
| 354 | 354 | ||
| 355 | **Description:** | 355 | **Beschreibung:** |
| 356 | 356 | ||
| 357 | Loads YueScript code from a file into a function and executes it. | 357 | Lädt YueScript-Code aus einer Datei in eine Funktion und führt sie aus. |
| 358 | 358 | ||
| 359 | **Signature:** | 359 | **Signatur:** |
| 360 | ```lua | 360 | ```lua |
| 361 | dofile: function(filename: string, config?: Config): any... | 361 | dofile: function(filename: string, config?: Config): any... |
| 362 | ``` | 362 | ``` |
| 363 | 363 | ||
| 364 | **Parameters:** | 364 | **Parameter:** |
| 365 | 365 | ||
| 366 | | Parameter | Type | Description | | 366 | | Parameter | Typ | Beschreibung | |
| 367 | | --- | --- | --- | | 367 | | --- | --- | --- | |
| 368 | | filename | string | The file name. | | 368 | | filename | string | Der Dateiname. | |
| 369 | | config | Config | [Optional] The compiler options. | | 369 | | config | Config | [Optional] Die Compiler-Optionen. | |
| 370 | 370 | ||
| 371 | **Returns:** | 371 | **Rückgabe:** |
| 372 | 372 | ||
| 373 | | Return Type | Description | | 373 | | Rückgabetyp | Beschreibung | |
| 374 | | --- | --- | | 374 | | --- | --- | |
| 375 | | any... | The return values of the loaded function. | | 375 | | any... | Die Rückgabewerte der geladenen Funktion. | |
| 376 | 376 | ||
| 377 | ### find_modulepath | 377 | ### find_modulepath |
| 378 | 378 | ||
| 379 | **Type:** Function. | 379 | **Typ:** Funktion. |
| 380 | 380 | ||
| 381 | **Description:** | 381 | **Beschreibung:** |
| 382 | 382 | ||
| 383 | Resolves the YueScript module name to the file path. | 383 | Löst den YueScript-Modulnamen in einen Dateipfad auf. |
| 384 | 384 | ||
| 385 | **Signature:** | 385 | **Signatur:** |
| 386 | ```lua | 386 | ```lua |
| 387 | find_modulepath: function(name: string): string | 387 | find_modulepath: function(name: string): string |
| 388 | ``` | 388 | ``` |
| 389 | 389 | ||
| 390 | **Parameters:** | 390 | **Parameter:** |
| 391 | 391 | ||
| 392 | | Parameter | Type | Description | | 392 | | Parameter | Typ | Beschreibung | |
| 393 | | --- | --- | --- | | 393 | | --- | --- | --- | |
| 394 | | name | string | The module name. | | 394 | | name | string | Der Modulname. | |
| 395 | 395 | ||
| 396 | **Returns:** | 396 | **Rückgabe:** |
| 397 | 397 | ||
| 398 | | Return Type | Description | | 398 | | Rückgabetyp | Beschreibung | |
| 399 | | --- | --- | | 399 | | --- | --- | |
| 400 | | string | The file path. | | 400 | | string | Der Dateipfad. | |
| 401 | 401 | ||
| 402 | ### pcall | 402 | ### pcall |
| 403 | 403 | ||
| 404 | **Type:** Function. | 404 | **Typ:** Funktion. |
| 405 | 405 | ||
| 406 | **Description:** | 406 | **Beschreibung:** |
| 407 | 407 | ||
| 408 | Calls a function in protected mode. | 408 | Ruft eine Funktion im geschützten Modus auf. |
| 409 | Catches any errors and returns a status code and results or error object. | 409 | Fängt Fehler ab und gibt einen Statuscode sowie Ergebnisse oder ein Fehlerobjekt zurück. |
| 410 | Rewrites the error line number to the original line number in the YueScript code when errors occur. | 410 | Schreibt die Fehlerzeilennummer bei Fehlern auf die ursprüngliche Zeilennummer im YueScript-Code um. |
| 411 | 411 | ||
| 412 | **Signature:** | 412 | **Signatur:** |
| 413 | ```lua | 413 | ```lua |
| 414 | pcall: function(f: function, ...: any): boolean, any... | 414 | pcall: function(f: function, ...: any): boolean, any... |
| 415 | ``` | 415 | ``` |
| 416 | 416 | ||
| 417 | **Parameters:** | 417 | **Parameter:** |
| 418 | 418 | ||
| 419 | | Parameter | Type | Description | | 419 | | Parameter | Typ | Beschreibung | |
| 420 | | --- | --- | --- | | 420 | | --- | --- | --- | |
| 421 | | f | function | The function to call. | | 421 | | f | function | Die aufzurufende Funktion. | |
| 422 | | ... | any | Arguments to pass to the function. | | 422 | | ... | any | Argumente für die Funktion. | |
| 423 | 423 | ||
| 424 | **Returns:** | 424 | **Rückgabe:** |
| 425 | 425 | ||
| 426 | | Return Type | Description | | 426 | | Rückgabetyp | Beschreibung | |
| 427 | | --- | --- | | 427 | | --- | --- | |
| 428 | | boolean, ... | Status code and function results or error object. | | 428 | | boolean, ... | Statuscode und Funktionsresultate oder Fehlerobjekt. | |
| 429 | 429 | ||
| 430 | ### require | 430 | ### require |
| 431 | 431 | ||
| 432 | **Type:** Function. | 432 | **Typ:** Funktion. |
| 433 | 433 | ||
| 434 | **Description:** | 434 | **Beschreibung:** |
| 435 | 435 | ||
| 436 | Loads a given module. Can be either a Lua module or a YueScript module. | 436 | Lädt ein Modul (Lua oder YueScript). |
| 437 | Rewrites the error line number to the original line number in the YueScript code if the module is a YueScript module and loading fails. | 437 | Schreibt die Fehlerzeilennummer auf die ursprüngliche Zeilennummer im YueScript-Code um, wenn das Modul ein YueScript-Modul ist und das Laden fehlschlägt. |
| 438 | 438 | ||
| 439 | **Signature:** | 439 | **Signatur:** |
| 440 | ```lua | 440 | ```lua |
| 441 | require: function(name: string): any... | 441 | require: function(name: string): any... |
| 442 | ``` | 442 | ``` |
| 443 | 443 | ||
| 444 | **Parameters:** | 444 | **Parameter:** |
| 445 | 445 | ||
| 446 | | Parameter | Type | Description | | 446 | | Parameter | Typ | Beschreibung | |
| 447 | | --- | --- | --- | | 447 | | --- | --- | --- | |
| 448 | | modname | string | The name of the module to load. | | 448 | | modname | string | Der Name des zu ladenden Moduls. | |
| 449 | 449 | ||
| 450 | **Returns:** | 450 | **Rückgabe:** |
| 451 | 451 | ||
| 452 | | Return Type | Description | | 452 | | Rückgabetyp | Beschreibung | |
| 453 | | --- | --- | | 453 | | --- | --- | |
| 454 | | any | The value stored at package.loaded[modname] if the module is already loaded.Otherwise, tries to find a loader and returns the final value of package.loaded[modname] and a loader data as a second result. | | 454 | | any | Der Wert in `package.loaded[modname]`, falls das Modul bereits geladen ist. Andernfalls wird ein Loader gesucht und der finale Wert von `package.loaded[modname]` sowie Loader-Daten als zweites Ergebnis zurückgegeben. | |
| 455 | 455 | ||
| 456 | ### p | 456 | ### p |
| 457 | 457 | ||
| 458 | **Type:** Function. | 458 | **Typ:** Funktion. |
| 459 | 459 | ||
| 460 | **Description:** | 460 | **Beschreibung:** |
| 461 | 461 | ||
| 462 | Inspects the structures of the passed values and prints string representations. | 462 | Inspiziert die Struktur der übergebenen Werte und gibt String-Repräsentationen aus. |
| 463 | 463 | ||
| 464 | **Signature:** | 464 | **Signatur:** |
| 465 | ```lua | 465 | ```lua |
| 466 | p: function(...: any) | 466 | p: function(...: any) |
| 467 | ``` | 467 | ``` |
| 468 | 468 | ||
| 469 | **Parameters:** | 469 | **Parameter:** |
| 470 | 470 | ||
| 471 | | Parameter | Type | Description | | 471 | | Parameter | Typ | Beschreibung | |
| 472 | | --- | --- | --- | | 472 | | --- | --- | --- | |
| 473 | | ... | any | The values to inspect. | | 473 | | ... | any | Die zu inspizierenden Werte. | |
| 474 | 474 | ||
| 475 | ### options | 475 | ### options |
| 476 | 476 | ||
| 477 | **Type:** Field. | 477 | **Typ:** Feld. |
| 478 | 478 | ||
| 479 | **Description:** | 479 | **Beschreibung:** |
| 480 | 480 | ||
| 481 | The current compiler options. | 481 | Die aktuellen Compiler-Optionen. |
| 482 | 482 | ||
| 483 | **Signature:** | 483 | **Signatur:** |
| 484 | ```lua | 484 | ```lua |
| 485 | options: Config.Options | 485 | options: Config.Options |
| 486 | ``` | 486 | ``` |
| 487 | 487 | ||
| 488 | ### traceback | 488 | ### traceback |
| 489 | 489 | ||
| 490 | **Type:** Function. | 490 | **Typ:** Funktion. |
| 491 | 491 | ||
| 492 | **Description:** | 492 | **Beschreibung:** |
| 493 | 493 | ||
| 494 | The traceback function that rewrites the stack trace line numbers to the original line numbers in the YueScript code. | 494 | Die Traceback-Funktion, die Stacktrace-Zeilennummern auf die ursprünglichen Zeilennummern im YueScript-Code umschreibt. |
| 495 | 495 | ||
| 496 | **Signature:** | 496 | **Signatur:** |
| 497 | ```lua | 497 | ```lua |
| 498 | traceback: function(message: string): string | 498 | traceback: function(message: string): string |
| 499 | ``` | 499 | ``` |
| 500 | 500 | ||
| 501 | **Parameters:** | 501 | **Parameter:** |
| 502 | 502 | ||
| 503 | | Parameter | Type | Description | | 503 | | Parameter | Typ | Beschreibung | |
| 504 | | --- | --- | --- | | 504 | | --- | --- | --- | |
| 505 | | message | string | The traceback message. | | 505 | | message | string | Die Traceback-Nachricht. | |
| 506 | 506 | ||
| 507 | **Returns:** | 507 | **Rückgabe:** |
| 508 | 508 | ||
| 509 | | Return Type | Description | | 509 | | Rückgabetyp | Beschreibung | |
| 510 | | --- | --- | | 510 | | --- | --- | |
| 511 | | string | The rewritten traceback message. | | 511 | | string | Die umgeschriebene Traceback-Nachricht. | |
| 512 | 512 | ||
| 513 | ### is_ast | 513 | ### is_ast |
| 514 | 514 | ||
| 515 | **Type:** Function. | 515 | **Typ:** Funktion. |
| 516 | 516 | ||
| 517 | **Description:** | 517 | **Beschreibung:** |
| 518 | 518 | ||
| 519 | Checks whether the code matches the specified AST. | 519 | Prüft, ob der Code dem angegebenen AST entspricht. |
| 520 | 520 | ||
| 521 | **Signature:** | 521 | **Signatur:** |
| 522 | ```lua | 522 | ```lua |
| 523 | is_ast: function(astName: string, code: string): boolean | 523 | is_ast: function(astName: string, code: string): boolean |
| 524 | ``` | 524 | ``` |
| 525 | 525 | ||
| 526 | **Parameters:** | 526 | **Parameter:** |
| 527 | 527 | ||
| 528 | | Parameter | Type | Description | | 528 | | Parameter | Typ | Beschreibung | |
| 529 | | --- | --- | --- | | 529 | | --- | --- | --- | |
| 530 | | astName | string | The AST name. | | 530 | | astName | string | Der AST-Name. | |
| 531 | | code | string | The code. | | 531 | | code | string | Der Code. | |
| 532 | 532 | ||
| 533 | **Returns:** | 533 | **Rückgabe:** |
| 534 | 534 | ||
| 535 | | Return Type | Description | | 535 | | Rückgabetyp | Beschreibung | |
| 536 | | --- | --- | | 536 | | --- | --- | |
| 537 | | boolean | Whether the code matches the AST. | | 537 | | boolean | Ob der Code dem AST entspricht. | |
| 538 | 538 | ||
| 539 | ### AST | 539 | ### AST |
| 540 | 540 | ||
| 541 | **Type:** Field. | 541 | **Typ:** Feld. |
| 542 | 542 | ||
| 543 | **Description:** | 543 | **Beschreibung:** |
| 544 | 544 | ||
| 545 | The AST type definition with name, row, column and sub nodes. | 545 | Die AST-Typdefinition mit Name, Zeile, Spalte und Unterknoten. |
| 546 | 546 | ||
| 547 | **Signature:** | 547 | **Signatur:** |
| 548 | ```lua | 548 | ```lua |
| 549 | type AST = {string, integer, integer, any} | 549 | type AST = {string, integer, integer, any} |
| 550 | ``` | 550 | ``` |
| 551 | 551 | ||
| 552 | ### to_ast | 552 | ### to_ast |
| 553 | 553 | ||
| 554 | **Type:** Function. | 554 | **Typ:** Funktion. |
| 555 | 555 | ||
| 556 | **Description:** | 556 | **Beschreibung:** |
| 557 | 557 | ||
| 558 | Converts the code to the AST. | 558 | Konvertiert Code in AST. |
| 559 | 559 | ||
| 560 | **Signature:** | 560 | **Signatur:** |
| 561 | ```lua | 561 | ```lua |
| 562 | to_ast: function(code: string, flattenLevel?: number, astName?: string, reserveComment?: boolean): | 562 | to_ast: function(code: string, flattenLevel?: number, astName?: string, reserveComment?: boolean): |
| 563 | --[[AST]] AST | nil, | 563 | --[[AST]] AST | nil, |
| 564 | --[[error]] nil | string | 564 | --[[error]] nil | string |
| 565 | ``` | 565 | ``` |
| 566 | 566 | ||
| 567 | **Parameters:** | 567 | **Parameter:** |
| 568 | 568 | ||
| 569 | | Parameter | Type | Description | | 569 | | Parameter | Typ | Beschreibung | |
| 570 | | --- | --- | --- | | 570 | | --- | --- | --- | |
| 571 | | code | string | The code. | | 571 | | code | string | Der Code. | |
| 572 | | flattenLevel | integer | [Optional] The flatten level. Higher level means more flattening. Default is 0. Maximum is 2. | | 572 | | flattenLevel | integer | [Optional] Der Flatten-Level. Höher bedeutet mehr Flattening. Standard ist 0. Maximum ist 2. | |
| 573 | | astName | string | [Optional] The AST name. Default is "File". | | 573 | | astName | string | [Optional] Der AST-Name. Standard ist "File". | |
| 574 | | reserveComment | boolean | [Optional] Whether to reserve the original comments. Default is false. | | 574 | | reserveComment | boolean | [Optional] Ob die ursprünglichen Kommentare beibehalten werden. Standard ist false. | |
| 575 | 575 | ||
| 576 | **Returns:** | 576 | **Rückgabe:** |
| 577 | 577 | ||
| 578 | | Return Type | Description | | 578 | | Rückgabetyp | Beschreibung | |
| 579 | | --- | --- | | 579 | | --- | --- | |
| 580 | | AST \| nil | The AST, or nil if the conversion failed. | | 580 | | AST \| nil | Der AST oder `nil`, falls die Konvertierung fehlgeschlagen ist. | |
| 581 | | string \| nil | The error message, or nil if the conversion succeeded. | | 581 | | string \| nil | Die Fehlermeldung oder `nil`, falls die Konvertierung erfolgreich war. | |
| 582 | 582 | ||
| 583 | ### format | 583 | ### format |
| 584 | 584 | ||
| 585 | **Type:** Function. | 585 | **Typ:** Funktion. |
| 586 | 586 | ||
| 587 | **Description:** | 587 | **Beschreibung:** |
| 588 | 588 | ||
| 589 | Formats the YueScript code. | 589 | Formatiert den YueScript-Code. |
| 590 | 590 | ||
| 591 | **Signature:** | 591 | **Signatur:** |
| 592 | ```lua | 592 | ```lua |
| 593 | format: function(code: string, tabSize?: number, reserveComment?: boolean): string | 593 | format: function(code: string, tabSize?: number, reserveComment?: boolean): string |
| 594 | ``` | 594 | ``` |
| 595 | 595 | ||
| 596 | **Parameters:** | 596 | **Parameter:** |
| 597 | 597 | ||
| 598 | | Parameter | Type | Description | | 598 | | Parameter | Typ | Beschreibung | |
| 599 | | --- | --- | --- | | 599 | | --- | --- | --- | |
| 600 | | code | string | The code. | | 600 | | code | string | Der Code. | |
| 601 | | tabSize | integer | [Optional] The tab size. Default is 4. | | 601 | | tabSize | integer | [Optional] Die Tab-Größe. Standard ist 4. | |
| 602 | | reserveComment | boolean | [Optional] Whether to reserve the original comments. Default is true. | | 602 | | reserveComment | boolean | [Optional] Ob die ursprünglichen Kommentare beibehalten werden. Standard ist true. | |
| 603 | 603 | ||
| 604 | **Returns:** | 604 | **Rückgabe:** |
| 605 | 605 | ||
| 606 | | Return Type | Description | | 606 | | Rückgabetyp | Beschreibung | |
| 607 | | --- | --- | | 607 | | --- | --- | |
| 608 | | string | The formatted code. | | 608 | | string | Der formatierte Code. | |
| 609 | 609 | ||
| 610 | ### __call | 610 | ### __call |
| 611 | 611 | ||
| 612 | **Type:** Metamethod. | 612 | **Typ:** Metamethod. |
| 613 | 613 | ||
| 614 | **Description:** | 614 | **Beschreibung:** |
| 615 | 615 | ||
| 616 | Requires the YueScript module. | 616 | Required das YueScript-Modul. |
| 617 | Rewrites the error line number to the original line number in the YueScript code when loading fails. | 617 | Schreibt die Fehlerzeilennummer bei Ladefehlern auf die ursprüngliche Zeilennummer im YueScript-Code um. |
| 618 | 618 | ||
| 619 | **Signature:** | 619 | **Signatur:** |
| 620 | ```lua | 620 | ```lua |
| 621 | metamethod __call: function(self: yue, module: string): any... | 621 | metamethod __call: function(self: yue, module: string): any... |
| 622 | ``` | 622 | ``` |
| 623 | 623 | ||
| 624 | **Parameters:** | 624 | **Parameter:** |
| 625 | 625 | ||
| 626 | | Parameter | Type | Description | | 626 | | Parameter | Typ | Beschreibung | |
| 627 | | --- | --- | --- | | 627 | | --- | --- | --- | |
| 628 | | module | string | The module name. | | 628 | | module | string | Der Modulname. | |
| 629 | 629 | ||
| 630 | **Returns:** | 630 | **Rückgabe:** |
| 631 | 631 | ||
| 632 | | Return Type | Description | | 632 | | Rückgabetyp | Beschreibung | |
| 633 | | --- | --- | | 633 | | --- | --- | |
| 634 | | any | The module value. | | 634 | | any | Der Modulwert. | |
| 635 | 635 | ||
| 636 | ## Config | 636 | ## Config |
| 637 | 637 | ||
| 638 | **Description:** | 638 | **Beschreibung:** |
| 639 | 639 | ||
| 640 | The compiler compile options. | 640 | Die Compiler-Optionen. |
| 641 | 641 | ||
| 642 | ### lint_global | 642 | ### lint_global |
| 643 | 643 | ||
| 644 | **Type:** Field. | 644 | **Typ:** Feld. |
| 645 | 645 | ||
| 646 | **Description:** | 646 | **Beschreibung:** |
| 647 | 647 | ||
| 648 | Whether the compiler should collect the global variables appearing in the code. | 648 | Ob der Compiler die globalen Variablen im Code sammeln soll. |
| 649 | 649 | ||
| 650 | **Signature:** | 650 | **Signatur:** |
| 651 | ```lua | 651 | ```lua |
| 652 | lint_global: boolean | 652 | lint_global: boolean |
| 653 | ``` | 653 | ``` |
| 654 | 654 | ||
| 655 | ### implicit_return_root | 655 | ### implicit_return_root |
| 656 | 656 | ||
| 657 | **Type:** Field. | 657 | **Typ:** Feld. |
| 658 | 658 | ||
| 659 | **Description:** | 659 | **Beschreibung:** |
| 660 | 660 | ||
| 661 | Whether the compiler should do an implicit return for the root code block. | 661 | Ob der Compiler für den Root-Codeblock ein implizites Return verwenden soll. |
| 662 | 662 | ||
| 663 | **Signature:** | 663 | **Signatur:** |
| 664 | ```lua | 664 | ```lua |
| 665 | implicit_return_root: boolean | 665 | implicit_return_root: boolean |
| 666 | ``` | 666 | ``` |
| 667 | 667 | ||
| 668 | ### reserve_line_number | 668 | ### reserve_line_number |
| 669 | 669 | ||
| 670 | **Type:** Field. | 670 | **Typ:** Feld. |
| 671 | 671 | ||
| 672 | **Description:** | 672 | **Beschreibung:** |
| 673 | 673 | ||
| 674 | Whether the compiler should reserve the original line number in the compiled code. | 674 | Ob der Compiler die ursprüngliche Zeilennummer im kompilierten Code beibehalten soll. |
| 675 | 675 | ||
| 676 | **Signature:** | 676 | **Signatur:** |
| 677 | ```lua | 677 | ```lua |
| 678 | reserve_line_number: boolean | 678 | reserve_line_number: boolean |
| 679 | ``` | 679 | ``` |
| 680 | 680 | ||
| 681 | ### reserve_comment | 681 | ### reserve_comment |
| 682 | 682 | ||
| 683 | **Type:** Field. | 683 | **Typ:** Feld. |
| 684 | 684 | ||
| 685 | **Description:** | 685 | **Beschreibung:** |
| 686 | 686 | ||
| 687 | Whether the compiler should reserve the original comments in the compiled code. | 687 | Ob der Compiler die ursprünglichen Kommentare im kompilierten Code beibehalten soll. |
| 688 | 688 | ||
| 689 | **Signature:** | 689 | **Signatur:** |
| 690 | ```lua | 690 | ```lua |
| 691 | reserve_comment: boolean | 691 | reserve_comment: boolean |
| 692 | ``` | 692 | ``` |
| 693 | 693 | ||
| 694 | ### space_over_tab | 694 | ### space_over_tab |
| 695 | 695 | ||
| 696 | **Type:** Field. | 696 | **Typ:** Feld. |
| 697 | 697 | ||
| 698 | **Description:** | 698 | **Beschreibung:** |
| 699 | 699 | ||
| 700 | Whether the compiler should use the space character instead of the tab character in the compiled code. | 700 | Ob der Compiler statt Tabzeichen Leerzeichen verwenden soll. |
| 701 | 701 | ||
| 702 | **Signature:** | 702 | **Signatur:** |
| 703 | ```lua | 703 | ```lua |
| 704 | space_over_tab: boolean | 704 | space_over_tab: boolean |
| 705 | ``` | 705 | ``` |
| 706 | 706 | ||
| 707 | ### same_module | 707 | ### same_module |
| 708 | 708 | ||
| 709 | **Type:** Field. | 709 | **Typ:** Feld. |
| 710 | 710 | ||
| 711 | **Description:** | 711 | **Beschreibung:** |
| 712 | 712 | ||
| 713 | Whether the compiler should treat the code to be compiled as the same currently being compiled module. For internal use only. | 713 | Ob der Compiler den zu kompilierenden Code als dasselbe aktuell kompilierte Modul behandeln soll. Nur für internen Gebrauch. |
| 714 | 714 | ||
| 715 | **Signature:** | 715 | **Signatur:** |
| 716 | ```lua | 716 | ```lua |
| 717 | same_module: boolean | 717 | same_module: boolean |
| 718 | ``` | 718 | ``` |
| 719 | 719 | ||
| 720 | ### line_offset | 720 | ### line_offset |
| 721 | 721 | ||
| 722 | **Type:** Field. | 722 | **Typ:** Feld. |
| 723 | 723 | ||
| 724 | **Description:** | 724 | **Beschreibung:** |
| 725 | 725 | ||
| 726 | Whether the compiler error message should include the line number offset. For internal use only. | 726 | Ob die Compiler-Fehlermeldung einen Zeilennummern-Offset enthalten soll. Nur für internen Gebrauch. |
| 727 | 727 | ||
| 728 | **Signature:** | 728 | **Signatur:** |
| 729 | ```lua | 729 | ```lua |
| 730 | line_offset: integer | 730 | line_offset: integer |
| 731 | ``` | 731 | ``` |
| 732 | 732 | ||
| 733 | ### yue.Config.LuaTarget | 733 | ### yue.Config.LuaTarget |
| 734 | 734 | ||
| 735 | **Type:** Enumeration. | 735 | **Typ:** Enumeration. |
| 736 | 736 | ||
| 737 | **Description:** | 737 | **Beschreibung:** |
| 738 | 738 | ||
| 739 | The target Lua version enumeration. | 739 | Die Ziel-Lua-Version. |
| 740 | 740 | ||
| 741 | **Signature:** | 741 | **Signatur:** |
| 742 | ```lua | 742 | ```lua |
| 743 | enum LuaTarget | 743 | enum LuaTarget |
| 744 | "5.1" | 744 | "5.1" |
| @@ -751,71 +751,71 @@ end | |||
| 751 | 751 | ||
| 752 | ### options | 752 | ### options |
| 753 | 753 | ||
| 754 | **Type:** Field. | 754 | **Typ:** Feld. |
| 755 | 755 | ||
| 756 | **Description:** | 756 | **Beschreibung:** |
| 757 | 757 | ||
| 758 | The extra options to be passed to the compilation function. | 758 | Zusätzliche Optionen für die Kompilierung. |
| 759 | 759 | ||
| 760 | **Signature:** | 760 | **Signatur:** |
| 761 | ```lua | 761 | ```lua |
| 762 | options: Options | 762 | options: Options |
| 763 | ``` | 763 | ``` |
| 764 | 764 | ||
| 765 | ## Options | 765 | ## Options |
| 766 | 766 | ||
| 767 | **Description:** | 767 | **Beschreibung:** |
| 768 | 768 | ||
| 769 | The extra compiler options definition. | 769 | Zusätzliche Compiler-Optionen. |
| 770 | 770 | ||
| 771 | ### target | 771 | ### target |
| 772 | 772 | ||
| 773 | **Type:** Field. | 773 | **Typ:** Feld. |
| 774 | 774 | ||
| 775 | **Description:** | 775 | **Beschreibung:** |
| 776 | 776 | ||
| 777 | The target Lua version for the compilation. | 777 | Die Ziel-Lua-Version für die Kompilierung. |
| 778 | 778 | ||
| 779 | **Signature:** | 779 | **Signatur:** |
| 780 | ```lua | 780 | ```lua |
| 781 | target: LuaTarget | 781 | target: LuaTarget |
| 782 | ``` | 782 | ``` |
| 783 | 783 | ||
| 784 | ### path | 784 | ### path |
| 785 | 785 | ||
| 786 | **Type:** Field. | 786 | **Typ:** Feld. |
| 787 | 787 | ||
| 788 | **Description:** | 788 | **Beschreibung:** |
| 789 | 789 | ||
| 790 | The extra module search path. | 790 | Zusätzlicher Modul-Suchpfad. |
| 791 | 791 | ||
| 792 | **Signature:** | 792 | **Signatur:** |
| 793 | ```lua | 793 | ```lua |
| 794 | path: string | 794 | path: string |
| 795 | ``` | 795 | ``` |
| 796 | 796 | ||
| 797 | ### dump_locals | 797 | ### dump_locals |
| 798 | 798 | ||
| 799 | **Type:** Field. | 799 | **Typ:** Feld. |
| 800 | 800 | ||
| 801 | **Description:** | 801 | **Beschreibung:** |
| 802 | 802 | ||
| 803 | Whether to dump the local variables in the traceback error message. Default is false. | 803 | Ob lokale Variablen in Traceback-Fehlermeldungen ausgegeben werden sollen. Standard ist false. |
| 804 | 804 | ||
| 805 | **Signature:** | 805 | **Signatur:** |
| 806 | ```lua | 806 | ```lua |
| 807 | dump_locals: boolean | 807 | dump_locals: boolean |
| 808 | ``` | 808 | ``` |
| 809 | 809 | ||
| 810 | ### simplified | 810 | ### simplified |
| 811 | 811 | ||
| 812 | **Type:** Field. | 812 | **Typ:** Feld. |
| 813 | 813 | ||
| 814 | **Description:** | 814 | **Beschreibung:** |
| 815 | 815 | ||
| 816 | Whether to simplify the error message. Default is true. | 816 | Ob Fehlermeldungen vereinfacht werden sollen. Standard ist true. |
| 817 | 817 | ||
| 818 | **Signature:** | 818 | **Signatur:** |
| 819 | ```lua | 819 | ```lua |
| 820 | simplified: boolean | 820 | simplified: boolean |
| 821 | ``` | 821 | ``` |
diff --git a/doc/docs/doc/control-flow/conditionals.md b/doc/docs/doc/control-flow/conditionals.md index 5ba81cf..1bda514 100644 --- a/doc/docs/doc/control-flow/conditionals.md +++ b/doc/docs/doc/control-flow/conditionals.md | |||
| @@ -136,14 +136,3 @@ if a in list | |||
| 136 | ``` | 136 | ``` |
| 137 | 137 | ||
| 138 | </YueDisplay> | 138 | </YueDisplay> |
| 139 | |||
| 140 | ```yuescript | ||
| 141 | print "You're lucky!" unless math.random! > 0.1 | ||
| 142 | ``` | ||
| 143 | <YueDisplay> | ||
| 144 | |||
| 145 | ```yue | ||
| 146 | print "You're lucky!" unless math.random! > 0.1 | ||
| 147 | ``` | ||
| 148 | |||
| 149 | </YueDisplay> | ||
diff --git a/doc/docs/doc/getting-started/introduction.md b/doc/docs/doc/getting-started/introduction.md index a9a9389..9a76b23 100644 --- a/doc/docs/doc/getting-started/introduction.md +++ b/doc/docs/doc/getting-started/introduction.md | |||
| @@ -48,7 +48,7 @@ with apple | |||
| 48 | p .size, .color, .<index> if .<>? | 48 | p .size, .color, .<index> if .<>? |
| 49 | 49 | ||
| 50 | -- js-like export syntax | 50 | -- js-like export syntax |
| 51 | export 🌛 = "月之脚本" | 51 | export 🌛 = "Script of Moon" |
| 52 | ``` | 52 | ``` |
| 53 | 53 | ||
| 54 | <YueDisplay> | 54 | <YueDisplay> |
| @@ -95,7 +95,7 @@ with apple | |||
| 95 | p .size, .color, .<index> if .<>? | 95 | p .size, .color, .<index> if .<>? |
| 96 | 96 | ||
| 97 | -- js-like export syntax | 97 | -- js-like export syntax |
| 98 | export 🌛 = "月之脚本" | 98 | export 🌛 = "Script of Moon" |
| 99 | ``` | 99 | ``` |
| 100 | 100 | ||
| 101 | </YueDisplay> | 101 | </YueDisplay> |
diff --git a/doc/docs/doc/reference/license-mit.md b/doc/docs/doc/reference/license-mit.md index f1d5d60..49eae7e 100644 --- a/doc/docs/doc/reference/license-mit.md +++ b/doc/docs/doc/reference/license-mit.md | |||
| @@ -19,5 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | SOFTWARE. | 21 | SOFTWARE. |
| 22 | |||
| 23 | <CompilerModal /> | ||
diff --git a/doc/docs/id-id/doc/advanced/do.md b/doc/docs/id-id/doc/advanced/do.md index 4990d6f..ebbd2e2 100644 --- a/doc/docs/id-id/doc/advanced/do.md +++ b/doc/docs/id-id/doc/advanced/do.md | |||
| @@ -1,12 +1,12 @@ | |||
| 1 | # Do | 1 | # Do |
| 2 | 2 | ||
| 3 | When used as a statement, do works just like it does in Lua. | 3 | Saat digunakan sebagai pernyataan, `do` bekerja seperti di Lua. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | do | 6 | do |
| 7 | var = "hello" | 7 | var = "hello" |
| 8 | print var | 8 | print var |
| 9 | print var -- nil here | 9 | print var -- nil di sini |
| 10 | ``` | 10 | ``` |
| 11 | <YueDisplay> | 11 | <YueDisplay> |
| 12 | 12 | ||
| @@ -14,12 +14,12 @@ print var -- nil here | |||
| 14 | do | 14 | do |
| 15 | var = "hello" | 15 | var = "hello" |
| 16 | print var | 16 | print var |
| 17 | print var -- nil here | 17 | print var -- nil di sini |
| 18 | ``` | 18 | ``` |
| 19 | 19 | ||
| 20 | </YueDisplay> | 20 | </YueDisplay> |
| 21 | 21 | ||
| 22 | YueScript's **do** can also be used an expression . Allowing you to combine multiple lines into one. The result of the do expression is the last statement in its body. | 22 | `do` di YueScript juga bisa digunakan sebagai ekspresi, memungkinkan Anda menggabungkan beberapa baris menjadi satu. Hasil ekspresi `do` adalah pernyataan terakhir di badannya. |
| 23 | 23 | ||
| 24 | ```yuescript | 24 | ```yuescript |
| 25 | counter = do | 25 | counter = do |
diff --git a/doc/docs/id-id/doc/advanced/line-decorators.md b/doc/docs/id-id/doc/advanced/line-decorators.md index 292bc77..e90e205 100644 --- a/doc/docs/id-id/doc/advanced/line-decorators.md +++ b/doc/docs/id-id/doc/advanced/line-decorators.md | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | # Line Decorators | 1 | # Dekorator Baris |
| 2 | 2 | ||
| 3 | For convenience, the for loop and if statement can be applied to single statements at the end of the line: | 3 | Untuk kemudahan, loop for dan pernyataan if dapat diterapkan pada pernyataan tunggal di akhir baris: |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | print "hello world" if name == "Rob" | 6 | print "hello world" if name == "Rob" |
| @@ -13,7 +13,7 @@ print "hello world" if name == "Rob" | |||
| 13 | 13 | ||
| 14 | </YueDisplay> | 14 | </YueDisplay> |
| 15 | 15 | ||
| 16 | And with basic loops: | 16 | Dan dengan loop dasar: |
| 17 | 17 | ||
| 18 | ```yuescript | 18 | ```yuescript |
| 19 | print "item: ", item for item in *items | 19 | print "item: ", item for item in *items |
| @@ -26,7 +26,7 @@ print "item: ", item for item in *items | |||
| 26 | 26 | ||
| 27 | </YueDisplay> | 27 | </YueDisplay> |
| 28 | 28 | ||
| 29 | And with while loops: | 29 | Dan dengan loop while: |
| 30 | 30 | ||
| 31 | ```yuescript | 31 | ```yuescript |
| 32 | game\update! while game\isRunning! | 32 | game\update! while game\isRunning! |
diff --git a/doc/docs/id-id/doc/advanced/macro.md b/doc/docs/id-id/doc/advanced/macro.md index 6d194c3..ce0bafa 100644 --- a/doc/docs/id-id/doc/advanced/macro.md +++ b/doc/docs/id-id/doc/advanced/macro.md | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | # Macro | 1 | # Makro |
| 2 | 2 | ||
| 3 | ## Common Usage | 3 | ## Penggunaan Umum |
| 4 | 4 | ||
| 5 | Macro function is used for evaluating a string in the compile time and insert the generated codes into final compilation. | 5 | Fungsi macro digunakan untuk mengevaluasi string pada waktu kompilasi dan menyisipkan kode yang dihasilkan ke kompilasi akhir. |
| 6 | 6 | ||
| 7 | ```yuescript | 7 | ```yuescript |
| 8 | macro PI2 = -> math.pi * 2 | 8 | macro PI2 = -> math.pi * 2 |
| @@ -27,7 +27,7 @@ $asserts item ~= nil | |||
| 27 | $config false | 27 | $config false |
| 28 | value = $assert item | 28 | value = $assert item |
| 29 | 29 | ||
| 30 | -- the passed expressions are treated as strings | 30 | -- ekspresi yang dikirim diperlakukan sebagai string |
| 31 | macro and = (...) -> "#{ table.concat {...}, ' and ' }" | 31 | macro and = (...) -> "#{ table.concat {...}, ' and ' }" |
| 32 | if $and f1!, f2!, f3! | 32 | if $and f1!, f2!, f3! |
| 33 | print "OK" | 33 | print "OK" |
| @@ -57,7 +57,7 @@ $asserts item ~= nil | |||
| 57 | $config false | 57 | $config false |
| 58 | value = $assert item | 58 | value = $assert item |
| 59 | 59 | ||
| 60 | -- the passed expressions are treated as strings | 60 | -- ekspresi yang dikirim diperlakukan sebagai string |
| 61 | macro and = (...) -> "#{ table.concat {...}, ' and ' }" | 61 | macro and = (...) -> "#{ table.concat {...}, ' and ' }" |
| 62 | if $and f1!, f2!, f3! | 62 | if $and f1!, f2!, f3! |
| 63 | print "OK" | 63 | print "OK" |
| @@ -65,29 +65,29 @@ if $and f1!, f2!, f3! | |||
| 65 | 65 | ||
| 66 | </YueDisplay> | 66 | </YueDisplay> |
| 67 | 67 | ||
| 68 | ## Insert Raw Codes | 68 | ## Menyisipkan Kode Mentah |
| 69 | 69 | ||
| 70 | A macro function can either return a YueScript string or a config table containing Lua codes. | 70 | Fungsi macro bisa mengembalikan string YueScript atau tabel konfigurasi yang berisi kode Lua. |
| 71 | ```yuescript | 71 | ```yuescript |
| 72 | macro yueFunc = (var) -> "local #{var} = ->" | 72 | macro yueFunc = (var) -> "local #{var} = ->" |
| 73 | $yueFunc funcA | 73 | $yueFunc funcA |
| 74 | funcA = -> "fail to assign to the Yue macro defined variable" | 74 | funcA = -> "gagal meng-assign ke variabel yang didefinisikan oleh macro Yue" |
| 75 | 75 | ||
| 76 | macro luaFunc = (var) -> { | 76 | macro luaFunc = (var) -> { |
| 77 | code: "local function #{var}() end" | 77 | code: "local function #{var}() end" |
| 78 | type: "lua" | 78 | type: "lua" |
| 79 | } | 79 | } |
| 80 | $luaFunc funcB | 80 | $luaFunc funcB |
| 81 | funcB = -> "fail to assign to the Lua macro defined variable" | 81 | funcB = -> "gagal meng-assign ke variabel yang didefinisikan oleh macro Lua" |
| 82 | 82 | ||
| 83 | macro lua = (code) -> { | 83 | macro lua = (code) -> { |
| 84 | :code | 84 | :code |
| 85 | type: "lua" | 85 | type: "lua" |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | -- the raw string leading and ending symbols are auto trimed | 88 | -- simbol awal dan akhir string mentah otomatis di-trim |
| 89 | $lua[==[ | 89 | $lua[==[ |
| 90 | -- raw Lua codes insertion | 90 | -- penyisipan kode Lua mentah |
| 91 | if cond then | 91 | if cond then |
| 92 | print("output") | 92 | print("output") |
| 93 | end | 93 | end |
| @@ -98,23 +98,23 @@ end | |||
| 98 | ```yue | 98 | ```yue |
| 99 | macro yueFunc = (var) -> "local #{var} = ->" | 99 | macro yueFunc = (var) -> "local #{var} = ->" |
| 100 | $yueFunc funcA | 100 | $yueFunc funcA |
| 101 | funcA = -> "fail to assign to the Yue macro defined variable" | 101 | funcA = -> "gagal meng-assign ke variabel yang didefinisikan oleh macro Yue" |
| 102 | 102 | ||
| 103 | macro luaFunc = (var) -> { | 103 | macro luaFunc = (var) -> { |
| 104 | code: "local function #{var}() end" | 104 | code: "local function #{var}() end" |
| 105 | type: "lua" | 105 | type: "lua" |
| 106 | } | 106 | } |
| 107 | $luaFunc funcB | 107 | $luaFunc funcB |
| 108 | funcB = -> "fail to assign to the Lua macro defined variable" | 108 | funcB = -> "gagal meng-assign ke variabel yang didefinisikan oleh macro Lua" |
| 109 | 109 | ||
| 110 | macro lua = (code) -> { | 110 | macro lua = (code) -> { |
| 111 | :code | 111 | :code |
| 112 | type: "lua" | 112 | type: "lua" |
| 113 | } | 113 | } |
| 114 | 114 | ||
| 115 | -- the raw string leading and ending symbols are auto trimed | 115 | -- simbol awal dan akhir string mentah otomatis di-trim |
| 116 | $lua[==[ | 116 | $lua[==[ |
| 117 | -- raw Lua codes insertion | 117 | -- penyisipan kode Lua mentah |
| 118 | if cond then | 118 | if cond then |
| 119 | print("output") | 119 | print("output") |
| 120 | end | 120 | end |
| @@ -125,7 +125,7 @@ end | |||
| 125 | 125 | ||
| 126 | ## Export Macro | 126 | ## Export Macro |
| 127 | 127 | ||
| 128 | Macro functions can be exported from a module and get imported in another module. You have to put export macro functions in a single file to be used, and only macro definition, macro importing and macro expansion in place can be put into the macro exporting module. | 128 | 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. |
| 129 | ```yuescript | 129 | ```yuescript |
| 130 | -- file: utils.yue | 130 | -- file: utils.yue |
| 131 | export macro map = (items, action) -> "[#{action} for _ in *#{items}]" | 131 | export macro map = (items, action) -> "[#{action} for _ in *#{items}]" |
| @@ -135,8 +135,8 @@ export macro foreach = (items, action) -> "for _ in *#{items} | |||
| 135 | 135 | ||
| 136 | -- file main.yue | 136 | -- file main.yue |
| 137 | import "utils" as { | 137 | import "utils" as { |
| 138 | $, -- symbol to import all macros | 138 | $, -- simbol untuk mengimpor semua macro |
| 139 | $foreach: $each -- rename macro $foreach to $each | 139 | $foreach: $each -- ganti nama macro $foreach menjadi $each |
| 140 | } | 140 | } |
| 141 | [1, 2, 3] |> $map(_ * 2) |> $filter(_ > 4) |> $each print _ | 141 | [1, 2, 3] |> $map(_ * 2) |> $filter(_ > 4) |> $each print _ |
| 142 | ``` | 142 | ``` |
| @@ -150,11 +150,11 @@ export macro foreach = (items, action) -> "for _ in *#{items} | |||
| 150 | #{action}" | 150 | #{action}" |
| 151 | 151 | ||
| 152 | -- file main.yue | 152 | -- file main.yue |
| 153 | -- import function is not available in browser, try it in a real environment | 153 | -- fungsi import tidak tersedia di browser, coba di lingkungan nyata |
| 154 | --[[ | 154 | --[[ |
| 155 | import "utils" as { | 155 | import "utils" as { |
| 156 | $, -- symbol to import all macros | 156 | $, -- simbol untuk mengimpor semua macro |
| 157 | $foreach: $each -- rename macro $foreach to $each | 157 | $foreach: $each -- ganti nama macro $foreach menjadi $each |
| 158 | } | 158 | } |
| 159 | [1, 2, 3] |> $map(_ * 2) |> $filter(_ > 4) |> $each print _ | 159 | [1, 2, 3] |> $map(_ * 2) |> $filter(_ > 4) |> $each print _ |
| 160 | ]] | 160 | ]] |
| @@ -162,25 +162,25 @@ import "utils" as { | |||
| 162 | 162 | ||
| 163 | </YueDisplay> | 163 | </YueDisplay> |
| 164 | 164 | ||
| 165 | ## Builtin Macro | 165 | ## Macro Bawaan |
| 166 | 166 | ||
| 167 | There are some builtin macros but you can override them by declaring macros with the same names. | 167 | Ada beberapa macro bawaan tetapi Anda bisa menimpanya dengan mendeklarasikan macro dengan nama yang sama. |
| 168 | ```yuescript | 168 | ```yuescript |
| 169 | print $FILE -- get string of current module name | 169 | print $FILE -- mendapatkan string nama modul saat ini |
| 170 | print $LINE -- get number 2 | 170 | print $LINE -- mendapatkan angka 2 |
| 171 | ``` | 171 | ``` |
| 172 | <YueDisplay> | 172 | <YueDisplay> |
| 173 | 173 | ||
| 174 | ```yue | 174 | ```yue |
| 175 | print $FILE -- get string of current module name | 175 | print $FILE -- mendapatkan string nama modul saat ini |
| 176 | print $LINE -- get number 2 | 176 | print $LINE -- mendapatkan angka 2 |
| 177 | ``` | 177 | ``` |
| 178 | 178 | ||
| 179 | </YueDisplay> | 179 | </YueDisplay> |
| 180 | 180 | ||
| 181 | ## Generating Macros with Macros | 181 | ## Menghasilkan Macro dengan Macro |
| 182 | 182 | ||
| 183 | In YueScript, macro functions allow you to generate code at compile time. By nesting macro functions, you can create more complex generation patterns. This feature enables you to define a macro function that generates another macro function, allowing for more dynamic code generation. | 183 | Di YueScript, fungsi macro memungkinkan Anda menghasilkan kode pada waktu kompilasi. Dengan menumpuk fungsi macro, Anda dapat membuat pola generasi yang lebih kompleks. Fitur ini memungkinkan Anda mendefinisikan fungsi macro yang menghasilkan fungsi macro lain, sehingga menghasilkan kode yang lebih dinamis. |
| 184 | 184 | ||
| 185 | ```yuescript | 185 | ```yuescript |
| 186 | macro Enum = (...) -> | 186 | macro Enum = (...) -> |
| @@ -222,9 +222,9 @@ print "Valid enum type:", $BodyType Static | |||
| 222 | 222 | ||
| 223 | </YueDisplay> | 223 | </YueDisplay> |
| 224 | 224 | ||
| 225 | ## Argument Validation | 225 | ## Validasi Argumen |
| 226 | 226 | ||
| 227 | You can declare the expected AST node types in the argument list, and check whether the incoming macro arguments meet the expectations at compile time. | 227 | Anda dapat mendeklarasikan tipe node AST yang diharapkan dalam daftar argumen, dan memeriksa apakah argumen macro yang masuk memenuhi harapan pada waktu kompilasi. |
| 228 | 228 | ||
| 229 | ```yuescript | 229 | ```yuescript |
| 230 | macro printNumAndStr = (num `Num, str `String) -> | | 230 | macro printNumAndStr = (num `Num, str `String) -> | |
| @@ -249,7 +249,7 @@ $printNumAndStr 123, "hello" | |||
| 249 | 249 | ||
| 250 | </YueDisplay> | 250 | </YueDisplay> |
| 251 | 251 | ||
| 252 | If you need more flexible argument checking, you can use the built-in `$is_ast` macro function to manually check at the appropriate place. | 252 | Jika Anda membutuhkan pengecekan argumen yang lebih fleksibel, Anda dapat menggunakan fungsi macro bawaan `$is_ast` untuk memeriksa secara manual pada tempat yang tepat. |
| 253 | 253 | ||
| 254 | ```yuescript | 254 | ```yuescript |
| 255 | macro printNumAndStr = (num, str) -> | 255 | macro printNumAndStr = (num, str) -> |
| @@ -272,4 +272,4 @@ $printNumAndStr 123, "hello" | |||
| 272 | 272 | ||
| 273 | </YueDisplay> | 273 | </YueDisplay> |
| 274 | 274 | ||
| 275 | For more details about available AST nodes, please refer to the uppercased definitions in [yue_parser.cpp](https://github.com/IppClub/YueScript/blob/main/src/yuescript/yue_parser.cpp). | 275 | Untuk detail lebih lanjut tentang node AST yang tersedia, silakan lihat definisi huruf besar di [yue_parser.cpp](https://github.com/IppClub/YueScript/blob/main/src/yuescript/yue_parser.cpp). |
diff --git a/doc/docs/id-id/doc/advanced/module.md b/doc/docs/id-id/doc/advanced/module.md index c955092..dd97a32 100644 --- a/doc/docs/id-id/doc/advanced/module.md +++ b/doc/docs/id-id/doc/advanced/module.md | |||
| @@ -1,28 +1,28 @@ | |||
| 1 | # Module | 1 | # Modul |
| 2 | 2 | ||
| 3 | ## Import | 3 | ## Import |
| 4 | 4 | ||
| 5 | The import statement is a syntax sugar for requiring a module or help extracting items from an imported module. The imported items are const by default. | 5 | Pernyataan `import` adalah sintaks sugar untuk me-require modul atau membantu mengekstrak item dari modul yang diimpor. Item yang diimpor bersifat `const` secara default. |
| 6 | 6 | ||
| 7 | ```yuescript | 7 | ```yuescript |
| 8 | -- used as table destructuring | 8 | -- digunakan sebagai destrukturisasi tabel |
| 9 | do | 9 | do |
| 10 | import insert, concat from table | 10 | import insert, concat from table |
| 11 | -- report error when assigning to insert, concat | 11 | -- akan error saat meng-assign ke insert, concat |
| 12 | import C, Ct, Cmt from require "lpeg" | 12 | import C, Ct, Cmt from require "lpeg" |
| 13 | -- shortcut for implicit requiring | 13 | -- shortcut untuk require implisit |
| 14 | import x, y, z from 'mymodule' | 14 | import x, y, z from 'mymodule' |
| 15 | -- import with Python style | 15 | -- import gaya Python |
| 16 | from 'module' import a, b, c | 16 | from 'module' import a, b, c |
| 17 | 17 | ||
| 18 | -- shortcut for requring a module | 18 | -- shortcut untuk require modul |
| 19 | do | 19 | do |
| 20 | import 'module' | 20 | import 'module' |
| 21 | import 'module_x' | 21 | import 'module_x' |
| 22 | import "d-a-s-h-e-s" | 22 | import "d-a-s-h-e-s" |
| 23 | import "module.part" | 23 | import "module.part" |
| 24 | 24 | ||
| 25 | -- requring module with aliasing or table destructuring | 25 | -- require modul dengan aliasing atau destrukturisasi tabel |
| 26 | do | 26 | do |
| 27 | import "player" as PlayerModule | 27 | import "player" as PlayerModule |
| 28 | import "lpeg" as :C, :Ct, :Cmt | 28 | import "lpeg" as :C, :Ct, :Cmt |
| @@ -31,24 +31,24 @@ do | |||
| 31 | <YueDisplay> | 31 | <YueDisplay> |
| 32 | 32 | ||
| 33 | ```yue | 33 | ```yue |
| 34 | -- used as table destructuring | 34 | -- digunakan sebagai destrukturisasi tabel |
| 35 | do | 35 | do |
| 36 | import insert, concat from table | 36 | import insert, concat from table |
| 37 | -- report error when assigning to insert, concat | 37 | -- akan error saat meng-assign ke insert, concat |
| 38 | import C, Ct, Cmt from require "lpeg" | 38 | import C, Ct, Cmt from require "lpeg" |
| 39 | -- shortcut for implicit requiring | 39 | -- shortcut untuk require implisit |
| 40 | import x, y, z from 'mymodule' | 40 | import x, y, z from 'mymodule' |
| 41 | -- import with Python style | 41 | -- import gaya Python |
| 42 | from 'module' import a, b, c | 42 | from 'module' import a, b, c |
| 43 | 43 | ||
| 44 | -- shortcut for requring a module | 44 | -- shortcut untuk require modul |
| 45 | do | 45 | do |
| 46 | import 'module' | 46 | import 'module' |
| 47 | import 'module_x' | 47 | import 'module_x' |
| 48 | import "d-a-s-h-e-s" | 48 | import "d-a-s-h-e-s" |
| 49 | import "module.part" | 49 | import "module.part" |
| 50 | 50 | ||
| 51 | -- requring module with aliasing or table destructuring | 51 | -- require modul dengan aliasing atau destrukturisasi tabel |
| 52 | do | 52 | do |
| 53 | import "player" as PlayerModule | 53 | import "player" as PlayerModule |
| 54 | import "lpeg" as :C, :Ct, :Cmt | 54 | import "lpeg" as :C, :Ct, :Cmt |
| @@ -59,7 +59,7 @@ do | |||
| 59 | 59 | ||
| 60 | ## Import Global | 60 | ## Import Global |
| 61 | 61 | ||
| 62 | You can import specific globals into local variables with `import`. When importing a chain of global variable accessings, the last field will be assigned to the local variable. | 62 | Anda dapat mengimpor global tertentu ke variabel local dengan `import`. Saat mengimpor rangkaian akses variabel global, field terakhir akan di-assign ke variabel local. |
| 63 | 63 | ||
| 64 | ```yuescript | 64 | ```yuescript |
| 65 | do | 65 | do |
| @@ -78,11 +78,11 @@ do | |||
| 78 | 78 | ||
| 79 | </YueDisplay> | 79 | </YueDisplay> |
| 80 | 80 | ||
| 81 | ### Automatic Global Variable Import | 81 | ### Import Variabel Global Otomatis |
| 82 | 82 | ||
| 83 | You can place `import global` at the top of a block to automatically import all names that have not been explicitly declared or assigned in the current scope as globals. These implicit imports are treated as local consts that reference the corresponding globals at the position of the statement. | 83 | Anda dapat menempatkan `import global` di awal blok untuk mengimpor secara otomatis semua nama yang belum dideklarasikan atau di-assign secara eksplisit di scope saat ini sebagai global. Import implisit ini diperlakukan sebagai local const yang mereferensikan global terkait pada posisi pernyataan tersebut. |
| 84 | 84 | ||
| 85 | Names that are explicitly declared as globals in the same scope will not be imported, so you can still assign to them. | 85 | Nama yang secara eksplisit dideklarasikan sebagai global di scope yang sama tidak akan diimpor, sehingga Anda masih bisa meng-assign ke mereka. |
| 86 | 86 | ||
| 87 | ```yuescript | 87 | ```yuescript |
| 88 | do | 88 | do |
| @@ -92,7 +92,7 @@ do | |||
| 92 | -- print = nil -- error: imported globals are const | 92 | -- print = nil -- error: imported globals are const |
| 93 | 93 | ||
| 94 | do | 94 | do |
| 95 | -- explicit global variable will not be imported | 95 | -- variabel global eksplisit tidak akan diimpor |
| 96 | import global | 96 | import global |
| 97 | global FLAG | 97 | global FLAG |
| 98 | print FLAG | 98 | print FLAG |
| @@ -108,7 +108,7 @@ do | |||
| 108 | -- print = nil -- error: imported globals are const | 108 | -- print = nil -- error: imported globals are const |
| 109 | 109 | ||
| 110 | do | 110 | do |
| 111 | -- explicit global variable will not be imported | 111 | -- variabel global eksplisit tidak akan diimpor |
| 112 | import global | 112 | import global |
| 113 | global FLAG | 113 | global FLAG |
| 114 | print FLAG | 114 | print FLAG |
| @@ -119,11 +119,11 @@ do | |||
| 119 | 119 | ||
| 120 | ## Export | 120 | ## Export |
| 121 | 121 | ||
| 122 | The export statement offers a concise way to define modules. | 122 | Pernyataan `export` menawarkan cara ringkas untuk mendefinisikan modul. |
| 123 | 123 | ||
| 124 | ### Named Export | 124 | ### Export Bernama |
| 125 | 125 | ||
| 126 | Named export will define a local variable as well as adding a field in the exported table. | 126 | Export bernama akan mendefinisikan variabel local sekaligus menambahkan field di tabel export. |
| 127 | 127 | ||
| 128 | ```yuescript | 128 | ```yuescript |
| 129 | export a, b, c = 1, 2, 3 | 129 | export a, b, c = 1, 2, 3 |
| @@ -160,7 +160,7 @@ export class Something | |||
| 160 | 160 | ||
| 161 | </YueDisplay> | 161 | </YueDisplay> |
| 162 | 162 | ||
| 163 | Doing named export with destructuring. | 163 | Melakukan export bernama dengan destrukturisasi. |
| 164 | 164 | ||
| 165 | ```yuescript | 165 | ```yuescript |
| 166 | export :loadstring, to_lua: tolua = yue | 166 | export :loadstring, to_lua: tolua = yue |
| @@ -175,7 +175,7 @@ export {itemA: {:fieldA = 'default'}} = tb | |||
| 175 | 175 | ||
| 176 | </YueDisplay> | 176 | </YueDisplay> |
| 177 | 177 | ||
| 178 | Export named items from module without creating local variables. | 178 | Export item bernama dari modul tanpa membuat variabel local. |
| 179 | 179 | ||
| 180 | ```yuescript | 180 | ```yuescript |
| 181 | export.itemA = tb | 181 | export.itemA = tb |
| @@ -192,9 +192,9 @@ export["a-b-c"] = 123 | |||
| 192 | 192 | ||
| 193 | </YueDisplay> | 193 | </YueDisplay> |
| 194 | 194 | ||
| 195 | ### Unnamed Export | 195 | ### Export Tanpa Nama |
| 196 | 196 | ||
| 197 | Unnamed export will add the target item into the array part of the exported table. | 197 | Export tanpa nama akan menambahkan item target ke bagian array dari tabel export. |
| 198 | 198 | ||
| 199 | ```yuescript | 199 | ```yuescript |
| 200 | d, e, f = 3, 2, 1 | 200 | d, e, f = 3, 2, 1 |
| @@ -225,9 +225,9 @@ export with tmp | |||
| 225 | 225 | ||
| 226 | </YueDisplay> | 226 | </YueDisplay> |
| 227 | 227 | ||
| 228 | ### Default Export | 228 | ### Export Default |
| 229 | 229 | ||
| 230 | Using the **default** keyword in export statement to replace the exported table with any thing. | 230 | Gunakan kata kunci **default** dalam pernyataan export untuk mengganti tabel export dengan apa pun. |
| 231 | 231 | ||
| 232 | ```yuescript | 232 | ```yuescript |
| 233 | export default -> | 233 | export default -> |
diff --git a/doc/docs/id-id/doc/advanced/try.md b/doc/docs/id-id/doc/advanced/try.md index 23c7877..6607451 100644 --- a/doc/docs/id-id/doc/advanced/try.md +++ b/doc/docs/id-id/doc/advanced/try.md | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | # Try | 1 | # Try |
| 2 | 2 | ||
| 3 | The syntax for Lua error handling in a common form. | 3 | Sintaks untuk penanganan error Lua dalam bentuk umum. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | try | 6 | try |
| @@ -23,7 +23,7 @@ try | |||
| 23 | print "trying" | 23 | print "trying" |
| 24 | func 1, 2, 3 | 24 | func 1, 2, 3 |
| 25 | 25 | ||
| 26 | -- working with if assignment pattern | 26 | -- bekerja dengan pola if assignment |
| 27 | if success, result := try func 1, 2, 3 | 27 | if success, result := try func 1, 2, 3 |
| 28 | catch err | 28 | catch err |
| 29 | print yue.traceback err | 29 | print yue.traceback err |
| @@ -52,7 +52,7 @@ try | |||
| 52 | print "trying" | 52 | print "trying" |
| 53 | func 1, 2, 3 | 53 | func 1, 2, 3 |
| 54 | 54 | ||
| 55 | -- working with if assignment pattern | 55 | -- bekerja dengan pola if assignment |
| 56 | if success, result := try func 1, 2, 3 | 56 | if success, result := try func 1, 2, 3 |
| 57 | catch err | 57 | catch err |
| 58 | print yue.traceback err | 58 | print yue.traceback err |
| @@ -63,18 +63,18 @@ catch err | |||
| 63 | 63 | ||
| 64 | ## Try? | 64 | ## Try? |
| 65 | 65 | ||
| 66 | `try?` is a simplified use for error handling syntax that omit the boolean status from the `try` statement, and it will return the result from the try block when success, return nil instead of error object otherwise. | 66 | `try?` adalah bentuk sederhana untuk penanganan error yang menghilangkan status boolean dari pernyataan `try`, dan akan mengembalikan hasil dari blok try ketika berhasil, atau mengembalikan nil alih-alih objek error bila gagal. |
| 67 | 67 | ||
| 68 | ```yuescript | 68 | ```yuescript |
| 69 | a, b, c = try? func! | 69 | a, b, c = try? func! |
| 70 | 70 | ||
| 71 | -- with nil coalescing operator | 71 | -- dengan operator nil coalescing |
| 72 | a = (try? func!) ?? "default" | 72 | a = (try? func!) ?? "default" |
| 73 | 73 | ||
| 74 | -- as function argument | 74 | -- sebagai argumen fungsi |
| 75 | f try? func! | 75 | f try? func! |
| 76 | 76 | ||
| 77 | -- with catch block | 77 | -- dengan blok catch |
| 78 | f try? | 78 | f try? |
| 79 | print 123 | 79 | print 123 |
| 80 | func! | 80 | func! |
| @@ -87,13 +87,13 @@ catch e | |||
| 87 | ```yue | 87 | ```yue |
| 88 | a, b, c = try? func! | 88 | a, b, c = try? func! |
| 89 | 89 | ||
| 90 | -- with nil coalescing operator | 90 | -- dengan operator nil coalescing |
| 91 | a = (try? func!) ?? "default" | 91 | a = (try? func!) ?? "default" |
| 92 | 92 | ||
| 93 | -- as function argument | 93 | -- sebagai argumen fungsi |
| 94 | f try? func! | 94 | f try? func! |
| 95 | 95 | ||
| 96 | -- with catch block | 96 | -- dengan blok catch |
| 97 | f try? | 97 | f try? |
| 98 | print 123 | 98 | print 123 |
| 99 | func! | 99 | func! |
diff --git a/doc/docs/id-id/doc/assignment/assignment.md b/doc/docs/id-id/doc/assignment/assignment.md index 4dac6f4..d9fd45d 100644 --- a/doc/docs/id-id/doc/assignment/assignment.md +++ b/doc/docs/id-id/doc/assignment/assignment.md | |||
| @@ -1,25 +1,25 @@ | |||
| 1 | # Assignment | 1 | # Penugasan |
| 2 | 2 | ||
| 3 | The variable is dynamic typed and is defined as local by default. But you can change the scope of declaration by **local** and **global** statement. | 3 | Variabel bersifat bertipe dinamis dan secara default dideklarasikan sebagai local. Namun Anda dapat mengubah cakupan deklarasi dengan pernyataan **local** dan **global**. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | hello = "world" | 6 | hello = "world" |
| 7 | a, b, c = 1, 2, 3 | 7 | a, b, c = 1, 2, 3 |
| 8 | hello = 123 -- uses the existing variable | 8 | hello = 123 -- menggunakan variabel yang sudah ada |
| 9 | ``` | 9 | ``` |
| 10 | <YueDisplay> | 10 | <YueDisplay> |
| 11 | 11 | ||
| 12 | ```yue | 12 | ```yue |
| 13 | hello = "world" | 13 | hello = "world" |
| 14 | a, b, c = 1, 2, 3 | 14 | a, b, c = 1, 2, 3 |
| 15 | hello = 123 -- uses the existing variable | 15 | hello = 123 -- menggunakan variabel yang sudah ada |
| 16 | ``` | 16 | ``` |
| 17 | 17 | ||
| 18 | </YueDisplay> | 18 | </YueDisplay> |
| 19 | 19 | ||
| 20 | ## Perform Update | 20 | ## Pembaruan Nilai |
| 21 | 21 | ||
| 22 | You can perform update assignment with many binary operators. | 22 | Anda dapat melakukan assignment pembaruan dengan banyak operator biner. |
| 23 | ```yuescript | 23 | ```yuescript |
| 24 | x = 1 | 24 | x = 1 |
| 25 | x += 1 | 25 | x += 1 |
| @@ -27,7 +27,7 @@ x -= 1 | |||
| 27 | x *= 10 | 27 | x *= 10 |
| 28 | x /= 10 | 28 | x /= 10 |
| 29 | x %= 10 | 29 | x %= 10 |
| 30 | s ..= "world" -- will add a new local if local variable is not exist | 30 | s ..= "world" -- akan menambah local baru jika variabel local belum ada |
| 31 | arg or= "default value" | 31 | arg or= "default value" |
| 32 | ``` | 32 | ``` |
| 33 | <YueDisplay> | 33 | <YueDisplay> |
| @@ -39,15 +39,15 @@ x -= 1 | |||
| 39 | x *= 10 | 39 | x *= 10 |
| 40 | x /= 10 | 40 | x /= 10 |
| 41 | x %= 10 | 41 | x %= 10 |
| 42 | s ..= "world" -- will add a new local if local variable is not exist | 42 | s ..= "world" -- akan menambah local baru jika variabel local belum ada |
| 43 | arg or= "default value" | 43 | arg or= "default value" |
| 44 | ``` | 44 | ``` |
| 45 | 45 | ||
| 46 | </YueDisplay> | 46 | </YueDisplay> |
| 47 | 47 | ||
| 48 | ## Chaining Assignment | 48 | ## Assignment Berantai |
| 49 | 49 | ||
| 50 | You can do chaining assignment to assign multiple items to hold the same value. | 50 | Anda bisa melakukan assignment berantai untuk menetapkan beberapa item ke nilai yang sama. |
| 51 | ```yuescript | 51 | ```yuescript |
| 52 | a = b = c = d = e = 0 | 52 | a = b = c = d = e = 0 |
| 53 | x = y = z = f! | 53 | x = y = z = f! |
| @@ -61,12 +61,12 @@ x = y = z = f! | |||
| 61 | 61 | ||
| 62 | </YueDisplay> | 62 | </YueDisplay> |
| 63 | 63 | ||
| 64 | ## Explicit Locals | 64 | ## Local Eksplisit |
| 65 | ```yuescript | 65 | ```yuescript |
| 66 | do | 66 | do |
| 67 | local a = 1 | 67 | local a = 1 |
| 68 | local * | 68 | local * |
| 69 | print "forward declare all variables as locals" | 69 | print "deklarasikan semua variabel sebagai local di awal" |
| 70 | x = -> 1 + y + z | 70 | x = -> 1 + y + z |
| 71 | y, z = 2, 3 | 71 | y, z = 2, 3 |
| 72 | global instance = Item\new! | 72 | global instance = Item\new! |
| @@ -74,7 +74,7 @@ do | |||
| 74 | do | 74 | do |
| 75 | local X = 1 | 75 | local X = 1 |
| 76 | local ^ | 76 | local ^ |
| 77 | print "only forward declare upper case variables" | 77 | print "hanya deklarasikan variabel huruf besar sebagai local di awal" |
| 78 | a = 1 | 78 | a = 1 |
| 79 | B = 2 | 79 | B = 2 |
| 80 | ``` | 80 | ``` |
| @@ -84,7 +84,7 @@ do | |||
| 84 | do | 84 | do |
| 85 | local a = 1 | 85 | local a = 1 |
| 86 | local * | 86 | local * |
| 87 | print "forward declare all variables as locals" | 87 | print "deklarasikan semua variabel sebagai local di awal" |
| 88 | x = -> 1 + y + z | 88 | x = -> 1 + y + z |
| 89 | y, z = 2, 3 | 89 | y, z = 2, 3 |
| 90 | global instance = Item\new! | 90 | global instance = Item\new! |
| @@ -92,26 +92,26 @@ do | |||
| 92 | do | 92 | do |
| 93 | local X = 1 | 93 | local X = 1 |
| 94 | local ^ | 94 | local ^ |
| 95 | print "only forward declare upper case variables" | 95 | print "hanya deklarasikan variabel huruf besar sebagai local di awal" |
| 96 | a = 1 | 96 | a = 1 |
| 97 | B = 2 | 97 | B = 2 |
| 98 | ``` | 98 | ``` |
| 99 | 99 | ||
| 100 | </YueDisplay> | 100 | </YueDisplay> |
| 101 | 101 | ||
| 102 | ## Explicit Globals | 102 | ## Global Eksplisit |
| 103 | ```yuescript | 103 | ```yuescript |
| 104 | do | 104 | do |
| 105 | global a = 1 | 105 | global a = 1 |
| 106 | global * | 106 | global * |
| 107 | print "declare all variables as globals" | 107 | print "deklarasikan semua variabel sebagai global" |
| 108 | x = -> 1 + y + z | 108 | x = -> 1 + y + z |
| 109 | y, z = 2, 3 | 109 | y, z = 2, 3 |
| 110 | 110 | ||
| 111 | do | 111 | do |
| 112 | global X = 1 | 112 | global X = 1 |
| 113 | global ^ | 113 | global ^ |
| 114 | print "only declare upper case variables as globals" | 114 | print "hanya deklarasikan variabel huruf besar sebagai global" |
| 115 | a = 1 | 115 | a = 1 |
| 116 | B = 2 | 116 | B = 2 |
| 117 | local Temp = "a local value" | 117 | local Temp = "a local value" |
| @@ -122,14 +122,14 @@ do | |||
| 122 | do | 122 | do |
| 123 | global a = 1 | 123 | global a = 1 |
| 124 | global * | 124 | global * |
| 125 | print "declare all variables as globals" | 125 | print "deklarasikan semua variabel sebagai global" |
| 126 | x = -> 1 + y + z | 126 | x = -> 1 + y + z |
| 127 | y, z = 2, 3 | 127 | y, z = 2, 3 |
| 128 | 128 | ||
| 129 | do | 129 | do |
| 130 | global X = 1 | 130 | global X = 1 |
| 131 | global ^ | 131 | global ^ |
| 132 | print "only declare upper case variables as globals" | 132 | print "hanya deklarasikan variabel huruf besar sebagai global" |
| 133 | a = 1 | 133 | a = 1 |
| 134 | B = 2 | 134 | B = 2 |
| 135 | local Temp = "a local value" | 135 | local Temp = "a local value" |
diff --git a/doc/docs/id-id/doc/assignment/destructuring-assignment.md b/doc/docs/id-id/doc/assignment/destructuring-assignment.md index e7b8046..ba591fd 100644 --- a/doc/docs/id-id/doc/assignment/destructuring-assignment.md +++ b/doc/docs/id-id/doc/assignment/destructuring-assignment.md | |||
| @@ -1,10 +1,10 @@ | |||
| 1 | # Destructuring Assignment | 1 | # Penugasan Destrukturisasi |
| 2 | 2 | ||
| 3 | Destructuring assignment is a way to quickly extract values from a table by their name or position in array based tables. | 3 | Assignment destrukturisasi adalah cara cepat untuk mengekstrak nilai dari sebuah tabel berdasarkan nama kunci atau posisinya pada tabel berbasis array. |
| 4 | 4 | ||
| 5 | Typically when you see a table literal, {1,2,3}, it is on the right hand side of an assignment because it is a value. Destructuring assignment swaps the role of the table literal, and puts it on the left hand side of an assign statement. | 5 | Biasanya ketika Anda melihat literal tabel, `{1,2,3}`, ia berada di sisi kanan assignment karena merupakan nilai. Assignment destrukturisasi menukar peran literal tabel dan menaruhnya di sisi kiri pernyataan assignment. |
| 6 | 6 | ||
| 7 | This is best explained with examples. Here is how you would unpack the first two values from a table: | 7 | Ini paling mudah dijelaskan dengan contoh. Berikut cara membongkar dua nilai pertama dari sebuah tabel: |
| 8 | 8 | ||
| 9 | ```yuescript | 9 | ```yuescript |
| 10 | thing = [1, 2] | 10 | thing = [1, 2] |
| @@ -23,7 +23,7 @@ print a, b | |||
| 23 | 23 | ||
| 24 | </YueDisplay> | 24 | </YueDisplay> |
| 25 | 25 | ||
| 26 | In the destructuring table literal, the key represents the key to read from the right hand side, and the value represents the name the read value will be assigned to. | 26 | Di literal tabel destrukturisasi, kunci mewakili kunci yang dibaca dari sisi kanan, dan nilai mewakili nama yang akan menerima nilai tersebut. |
| 27 | 27 | ||
| 28 | ```yuescript | 28 | ```yuescript |
| 29 | obj = { | 29 | obj = { |
| @@ -35,7 +35,7 @@ obj = { | |||
| 35 | {hello: hello, day: the_day} = obj | 35 | {hello: hello, day: the_day} = obj |
| 36 | print hello, the_day | 36 | print hello, the_day |
| 37 | 37 | ||
| 38 | :day = obj -- OK to do simple destructuring without braces | 38 | :day = obj -- OK untuk destrukturisasi sederhana tanpa kurung |
| 39 | ``` | 39 | ``` |
| 40 | <YueDisplay> | 40 | <YueDisplay> |
| 41 | 41 | ||
| @@ -49,12 +49,12 @@ obj = { | |||
| 49 | {hello: hello, day: the_day} = obj | 49 | {hello: hello, day: the_day} = obj |
| 50 | print hello, the_day | 50 | print hello, the_day |
| 51 | 51 | ||
| 52 | :day = obj -- OK to do simple destructuring without braces | 52 | :day = obj -- OK untuk destrukturisasi sederhana tanpa kurung |
| 53 | ``` | 53 | ``` |
| 54 | 54 | ||
| 55 | </YueDisplay> | 55 | </YueDisplay> |
| 56 | 56 | ||
| 57 | This also works with nested data structures as well: | 57 | Ini juga bekerja pada struktur data bertingkat: |
| 58 | 58 | ||
| 59 | ```yuescript | 59 | ```yuescript |
| 60 | obj2 = { | 60 | obj2 = { |
| @@ -85,7 +85,7 @@ print first, second, color | |||
| 85 | 85 | ||
| 86 | </YueDisplay> | 86 | </YueDisplay> |
| 87 | 87 | ||
| 88 | If the destructuring statement is complicated, feel free to spread it out over a few lines. A slightly more complicated example: | 88 | Jika pernyataan destrukturisasi kompleks, Anda bisa memecahnya ke beberapa baris. Contoh yang sedikit lebih rumit: |
| 89 | 89 | ||
| 90 | ```yuescript | 90 | ```yuescript |
| 91 | { | 91 | { |
| @@ -108,7 +108,7 @@ If the destructuring statement is complicated, feel free to spread it out over a | |||
| 108 | 108 | ||
| 109 | </YueDisplay> | 109 | </YueDisplay> |
| 110 | 110 | ||
| 111 | It's common to extract values from at table and assign them the local variables that have the same name as the key. In order to avoid repetition we can use the **:** prefix operator: | 111 | Umumnya mengekstrak nilai dari tabel lalu menugaskannya ke variabel local dengan nama yang sama dengan kuncinya. Untuk menghindari pengulangan, kita bisa menggunakan operator prefiks **:**: |
| 112 | 112 | ||
| 113 | ```yuescript | 113 | ```yuescript |
| 114 | {:concat, :insert} = table | 114 | {:concat, :insert} = table |
| @@ -121,7 +121,7 @@ It's common to extract values from at table and assign them the local variables | |||
| 121 | 121 | ||
| 122 | </YueDisplay> | 122 | </YueDisplay> |
| 123 | 123 | ||
| 124 | This is effectively the same as import, but we can rename fields we want to extract by mixing the syntax: | 124 | Ini secara efektif sama seperti import, tetapi kita dapat mengganti nama field yang ingin diekstrak dengan menggabungkan sintaks: |
| 125 | 125 | ||
| 126 | ```yuescript | 126 | ```yuescript |
| 127 | {:mix, :max, random: rand} = math | 127 | {:mix, :max, random: rand} = math |
| @@ -134,7 +134,7 @@ This is effectively the same as import, but we can rename fields we want to extr | |||
| 134 | 134 | ||
| 135 | </YueDisplay> | 135 | </YueDisplay> |
| 136 | 136 | ||
| 137 | You can write default values while doing destructuring like: | 137 | Anda bisa menulis nilai default saat destrukturisasi seperti: |
| 138 | 138 | ||
| 139 | ```yuescript | 139 | ```yuescript |
| 140 | {:name = "nameless", :job = "jobless"} = person | 140 | {:name = "nameless", :job = "jobless"} = person |
| @@ -147,7 +147,7 @@ You can write default values while doing destructuring like: | |||
| 147 | 147 | ||
| 148 | </YueDisplay> | 148 | </YueDisplay> |
| 149 | 149 | ||
| 150 | You can use `_` as placeholder when doing a list destructuring: | 150 | Anda dapat menggunakan `_` sebagai placeholder saat destrukturisasi list: |
| 151 | 151 | ||
| 152 | ```yuescript | 152 | ```yuescript |
| 153 | [_, two, _, four] = items | 153 | [_, two, _, four] = items |
| @@ -160,9 +160,9 @@ You can use `_` as placeholder when doing a list destructuring: | |||
| 160 | 160 | ||
| 161 | </YueDisplay> | 161 | </YueDisplay> |
| 162 | 162 | ||
| 163 | ## Range Destructuring | 163 | ## Destrukturisasi Rentang |
| 164 | 164 | ||
| 165 | You can use the spread operator `...` in list destructuring to capture a range of values. This is useful when you want to extract specific elements from the beginning and end of a list while collecting the rest in between. | 165 | Anda dapat menggunakan operator spread `...` pada destrukturisasi list untuk menangkap rentang nilai. Ini berguna ketika Anda ingin mengekstrak elemen tertentu dari awal dan akhir list sambil mengumpulkan sisanya di tengah. |
| 166 | 166 | ||
| 167 | ```yuescript | 167 | ```yuescript |
| 168 | orders = ["first", "second", "third", "fourth", "last"] | 168 | orders = ["first", "second", "third", "fourth", "last"] |
| @@ -183,36 +183,36 @@ print last -- prints: last | |||
| 183 | 183 | ||
| 184 | </YueDisplay> | 184 | </YueDisplay> |
| 185 | 185 | ||
| 186 | The spread operator can be used in different positions to capture different ranges, and you can use `_` as a placeholder for the values you don't want to capture: | 186 | Operator spread dapat digunakan pada posisi berbeda untuk menangkap rentang yang berbeda, dan Anda bisa memakai `_` sebagai placeholder untuk nilai yang tidak ingin ditangkap: |
| 187 | 187 | ||
| 188 | ```yuescript | 188 | ```yuescript |
| 189 | -- Capture everything after first element | 189 | -- Tangkap semuanya setelah elemen pertama |
| 190 | [first, ...rest] = orders | 190 | [first, ...rest] = orders |
| 191 | 191 | ||
| 192 | -- Capture everything before last element | 192 | -- Tangkap semuanya sebelum elemen terakhir |
| 193 | [...start, last] = orders | 193 | [...start, last] = orders |
| 194 | 194 | ||
| 195 | -- Capture things except the middle elements | 195 | -- Tangkap semuanya kecuali elemen tengah |
| 196 | [first, ..._, last] = orders | 196 | [first, ..._, last] = orders |
| 197 | ``` | 197 | ``` |
| 198 | <YueDisplay> | 198 | <YueDisplay> |
| 199 | 199 | ||
| 200 | ```yue | 200 | ```yue |
| 201 | -- Capture everything after first element | 201 | -- Tangkap semuanya setelah elemen pertama |
| 202 | [first, ...rest] = orders | 202 | [first, ...rest] = orders |
| 203 | 203 | ||
| 204 | -- Capture everything before last element | 204 | -- Tangkap semuanya sebelum elemen terakhir |
| 205 | [...start, last] = orders | 205 | [...start, last] = orders |
| 206 | 206 | ||
| 207 | -- Capture things except the middle elements | 207 | -- Tangkap semuanya kecuali elemen tengah |
| 208 | [first, ..._, last] = orders | 208 | [first, ..._, last] = orders |
| 209 | ``` | 209 | ``` |
| 210 | 210 | ||
| 211 | </YueDisplay> | 211 | </YueDisplay> |
| 212 | 212 | ||
| 213 | ## Destructuring In Other Places | 213 | ## Destrukturisasi di Tempat Lain |
| 214 | 214 | ||
| 215 | Destructuring can also show up in places where an assignment implicitly takes place. An example of this is a for loop: | 215 | Destrukturisasi juga dapat muncul di tempat-tempat di mana assignment terjadi secara implisit. Contohnya adalah perulangan for: |
| 216 | 216 | ||
| 217 | ```yuescript | 217 | ```yuescript |
| 218 | tuples = [ | 218 | tuples = [ |
| @@ -237,4 +237,4 @@ for [left, right] in *tuples | |||
| 237 | 237 | ||
| 238 | </YueDisplay> | 238 | </YueDisplay> |
| 239 | 239 | ||
| 240 | We know each element in the array table is a two item tuple, so we can unpack it directly in the names clause of the for statement using a destructure. | 240 | Kita tahu setiap elemen pada tabel array adalah tuple dua item, sehingga kita dapat membongkarnya langsung di klausa nama pada pernyataan for menggunakan destrukturisasi. |
diff --git a/doc/docs/id-id/doc/assignment/if-assignment.md b/doc/docs/id-id/doc/assignment/if-assignment.md index 02984e8..b30d0d9 100644 --- a/doc/docs/id-id/doc/assignment/if-assignment.md +++ b/doc/docs/id-id/doc/assignment/if-assignment.md | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | # If Assignment | 1 | # Penugasan pada If |
| 2 | 2 | ||
| 3 | `if` and `elseif` blocks can take an assignment in place of a conditional expression. Upon evaluating the conditional, the assignment will take place and the value that was assigned to will be used as the conditional expression. The assigned variable is only in scope for the body of the conditional, meaning it is never available if the value is not truthy. And you have to use "the walrus operator" `:=` instead of `=` to do assignment. | 3 | Blok `if` dan `elseif` dapat menerima assignment sebagai ganti ekspresi kondisional. Saat kondisi dievaluasi, assignment akan dilakukan dan nilai yang di-assign akan digunakan sebagai ekspresi kondisional. Variabel yang di-assign hanya berada dalam scope badan kondisional, artinya tidak pernah tersedia jika nilai tidak truthy. Dan Anda harus menggunakan "walrus operator" `:=` sebagai ganti `=` untuk melakukan assignment. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | if user := database.find_user "moon" | 6 | if user := database.find_user "moon" |
| @@ -36,36 +36,36 @@ else | |||
| 36 | 36 | ||
| 37 | </YueDisplay> | 37 | </YueDisplay> |
| 38 | 38 | ||
| 39 | If assignment with multiple return values. Only the first value is getting checked, other values are scoped. | 39 | Assignment if dengan beberapa nilai return. Hanya nilai pertama yang dicek, nilai lainnya tetap berada dalam scope. |
| 40 | ```yuescript | 40 | ```yuescript |
| 41 | if success, result := pcall -> "get result without problems" | 41 | if success, result := pcall -> "get result without problems" |
| 42 | print result -- variable result is scoped | 42 | print result -- variabel result berada dalam scope |
| 43 | print "OK" | 43 | print "OK" |
| 44 | ``` | 44 | ``` |
| 45 | <YueDisplay> | 45 | <YueDisplay> |
| 46 | 46 | ||
| 47 | ```yue | 47 | ```yue |
| 48 | if success, result := pcall -> "get result without problems" | 48 | if success, result := pcall -> "get result without problems" |
| 49 | print result -- variable result is scoped | 49 | print result -- variabel result berada dalam scope |
| 50 | print "OK" | 50 | print "OK" |
| 51 | ``` | 51 | ``` |
| 52 | 52 | ||
| 53 | </YueDisplay> | 53 | </YueDisplay> |
| 54 | 54 | ||
| 55 | ## While Assignment | 55 | ## Assignment pada While |
| 56 | 56 | ||
| 57 | You can also use if assignment in a while loop to get the value as the loop condition. | 57 | Anda juga bisa menggunakan assignment if di loop while untuk mendapatkan nilai sebagai kondisi loop. |
| 58 | 58 | ||
| 59 | ```yuescript | 59 | ```yuescript |
| 60 | while byte := stream\read_one! | 60 | while byte := stream\read_one! |
| 61 | -- do something with the byte | 61 | -- lakukan sesuatu dengan byte |
| 62 | print byte | 62 | print byte |
| 63 | ``` | 63 | ``` |
| 64 | <YueDisplay> | 64 | <YueDisplay> |
| 65 | 65 | ||
| 66 | ```yue | 66 | ```yue |
| 67 | while byte := stream\read_one! | 67 | while byte := stream\read_one! |
| 68 | -- do something with the byte | 68 | -- lakukan sesuatu dengan byte |
| 69 | print byte | 69 | print byte |
| 70 | ``` | 70 | ``` |
| 71 | 71 | ||
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 fb9b740..6953138 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 | |||
| @@ -1,11 +1,11 @@ | |||
| 1 | # The Using Clause; Controlling Destructive Assignment | 1 | # Klausa Using; Mengendalikan Penugasan Destruktif |
| 2 | 2 | ||
| 3 | While lexical scoping can be a great help in reducing the complexity of the code we write, things can get unwieldy as the code size increases. Consider the following snippet: | 3 | Meskipun scope leksikal sangat membantu mengurangi kompleksitas kode yang kita tulis, hal ini bisa menjadi sulit ketika ukuran kode membesar. Pertimbangkan cuplikan berikut: |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | i = 100 | 6 | i = 100 |
| 7 | 7 | ||
| 8 | -- many lines of code... | 8 | -- banyak baris kode... |
| 9 | 9 | ||
| 10 | my_func = -> | 10 | my_func = -> |
| 11 | i = 10 | 11 | i = 10 |
| @@ -15,14 +15,14 @@ my_func = -> | |||
| 15 | 15 | ||
| 16 | my_func! | 16 | my_func! |
| 17 | 17 | ||
| 18 | print i -- will print 0 | 18 | print i -- akan mencetak 0 |
| 19 | ``` | 19 | ``` |
| 20 | <YueDisplay> | 20 | <YueDisplay> |
| 21 | 21 | ||
| 22 | ```yue | 22 | ```yue |
| 23 | i = 100 | 23 | i = 100 |
| 24 | 24 | ||
| 25 | -- many lines of code... | 25 | -- banyak baris kode... |
| 26 | 26 | ||
| 27 | my_func = -> | 27 | my_func = -> |
| 28 | i = 10 | 28 | i = 10 |
| @@ -32,25 +32,25 @@ my_func = -> | |||
| 32 | 32 | ||
| 33 | my_func! | 33 | my_func! |
| 34 | 34 | ||
| 35 | print i -- will print 0 | 35 | print i -- akan mencetak 0 |
| 36 | ``` | 36 | ``` |
| 37 | 37 | ||
| 38 | </YueDisplay> | 38 | </YueDisplay> |
| 39 | 39 | ||
| 40 | In my_func, we've overwritten the value of i mistakenly. In this example it is quite obvious, but consider a large, or foreign code base where it isn't clear what names have already been declared. | 40 | Di `my_func`, kita tanpa sengaja menimpa nilai `i`. Dalam contoh ini halnya cukup jelas, tetapi bayangkan kode besar atau basis kode asing di mana tidak jelas nama apa saja yang sudah dideklarasikan. |
| 41 | 41 | ||
| 42 | It would be helpful to say which variables from the enclosing scope we intend on change, in order to prevent us from changing others by accident. | 42 | Akan sangat membantu jika kita dapat menyatakan variabel mana dari scope luar yang memang ingin kita ubah, agar mencegah mengubah yang lain secara tidak sengaja. |
| 43 | 43 | ||
| 44 | The using keyword lets us do that. using nil makes sure that no closed variables are overwritten in assignment. The using clause is placed after the argument list in a function, or in place of it if there are no arguments. | 44 | Kata kunci `using` memungkinkan kita melakukan itu. `using nil` memastikan bahwa tidak ada variabel tertutup yang ditimpa dalam assignment. Klausa `using` ditempatkan setelah daftar argumen pada fungsi, atau menggantikannya jika tidak ada argumen. |
| 45 | 45 | ||
| 46 | ```yuescript | 46 | ```yuescript |
| 47 | i = 100 | 47 | i = 100 |
| 48 | 48 | ||
| 49 | my_func = (using nil) -> | 49 | my_func = (using nil) -> |
| 50 | i = "hello" -- a new local variable is created here | 50 | i = "hello" -- variabel local baru dibuat di sini |
| 51 | 51 | ||
| 52 | my_func! | 52 | my_func! |
| 53 | print i -- prints 100, i is unaffected | 53 | print i -- mencetak 100, i tidak terpengaruh |
| 54 | ``` | 54 | ``` |
| 55 | <YueDisplay> | 55 | <YueDisplay> |
| 56 | 56 | ||
| @@ -58,27 +58,27 @@ print i -- prints 100, i is unaffected | |||
| 58 | i = 100 | 58 | i = 100 |
| 59 | 59 | ||
| 60 | my_func = (using nil) -> | 60 | my_func = (using nil) -> |
| 61 | i = "hello" -- a new local variable is created here | 61 | i = "hello" -- variabel local baru dibuat di sini |
| 62 | 62 | ||
| 63 | my_func! | 63 | my_func! |
| 64 | print i -- prints 100, i is unaffected | 64 | print i -- mencetak 100, i tidak terpengaruh |
| 65 | ``` | 65 | ``` |
| 66 | 66 | ||
| 67 | </YueDisplay> | 67 | </YueDisplay> |
| 68 | 68 | ||
| 69 | Multiple names can be separated by commas. Closure values can still be accessed, they just cant be modified: | 69 | Beberapa nama dapat dipisahkan dengan koma. Nilai closure tetap bisa diakses, hanya saja tidak dapat dimodifikasi: |
| 70 | 70 | ||
| 71 | ```yuescript | 71 | ```yuescript |
| 72 | tmp = 1213 | 72 | tmp = 1213 |
| 73 | i, k = 100, 50 | 73 | i, k = 100, 50 |
| 74 | 74 | ||
| 75 | my_func = (add using k, i) -> | 75 | my_func = (add using k, i) -> |
| 76 | tmp = tmp + add -- a new local tmp is created | 76 | tmp = tmp + add -- tmp local baru dibuat |
| 77 | i += tmp | 77 | i += tmp |
| 78 | k += tmp | 78 | k += tmp |
| 79 | 79 | ||
| 80 | my_func(22) | 80 | my_func(22) |
| 81 | print i, k -- these have been updated | 81 | print i, k -- ini telah diperbarui |
| 82 | ``` | 82 | ``` |
| 83 | <YueDisplay> | 83 | <YueDisplay> |
| 84 | 84 | ||
| @@ -87,12 +87,12 @@ tmp = 1213 | |||
| 87 | i, k = 100, 50 | 87 | i, k = 100, 50 |
| 88 | 88 | ||
| 89 | my_func = (add using k, i) -> | 89 | my_func = (add using k, i) -> |
| 90 | tmp = tmp + add -- a new local tmp is created | 90 | tmp = tmp + add -- tmp local baru dibuat |
| 91 | i += tmp | 91 | i += tmp |
| 92 | k += tmp | 92 | k += tmp |
| 93 | 93 | ||
| 94 | my_func(22) | 94 | my_func(22) |
| 95 | print i, k -- these have been updated | 95 | print i, k -- ini telah diperbarui |
| 96 | ``` | 96 | ``` |
| 97 | 97 | ||
| 98 | </YueDisplay> | 98 | </YueDisplay> |
diff --git a/doc/docs/id-id/doc/assignment/varargs-assignment.md b/doc/docs/id-id/doc/assignment/varargs-assignment.md index 1d66680..f24652f 100644 --- a/doc/docs/id-id/doc/assignment/varargs-assignment.md +++ b/doc/docs/id-id/doc/assignment/varargs-assignment.md | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | # Varargs Assignment | 1 | # Penugasan Varargs |
| 2 | 2 | ||
| 3 | You can assign the results returned from a function to a varargs symbol `...`. And then access its content using the Lua way. | 3 | Anda dapat meng-assign hasil yang dikembalikan dari sebuah fungsi ke simbol varargs `...`. Lalu akses isinya menggunakan cara Lua. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | list = [1, 2, 3, 4, 5] | 6 | list = [1, 2, 3, 4, 5] |
diff --git a/doc/docs/id-id/doc/control-flow/conditionals.md b/doc/docs/id-id/doc/control-flow/conditionals.md index 5ba81cf..4f08b16 100644 --- a/doc/docs/id-id/doc/control-flow/conditionals.md +++ b/doc/docs/id-id/doc/control-flow/conditionals.md | |||
| @@ -1,55 +1,55 @@ | |||
| 1 | # Conditionals | 1 | # Kondisional |
| 2 | 2 | ||
| 3 | ```yuescript | 3 | ```yuescript |
| 4 | have_coins = false | 4 | have_coins = false |
| 5 | if have_coins | 5 | if have_coins |
| 6 | print "Got coins" | 6 | print "Dapat koin" |
| 7 | else | 7 | else |
| 8 | print "No coins" | 8 | print "Tidak ada koin" |
| 9 | ``` | 9 | ``` |
| 10 | <YueDisplay> | 10 | <YueDisplay> |
| 11 | 11 | ||
| 12 | ```yue | 12 | ```yue |
| 13 | have_coins = false | 13 | have_coins = false |
| 14 | if have_coins | 14 | if have_coins |
| 15 | print "Got coins" | 15 | print "Dapat koin" |
| 16 | else | 16 | else |
| 17 | print "No coins" | 17 | print "Tidak ada koin" |
| 18 | ``` | 18 | ``` |
| 19 | 19 | ||
| 20 | </YueDisplay> | 20 | </YueDisplay> |
| 21 | 21 | ||
| 22 | A short syntax for single statements can also be used: | 22 | Sintaks pendek untuk pernyataan tunggal juga bisa digunakan: |
| 23 | 23 | ||
| 24 | ```yuescript | 24 | ```yuescript |
| 25 | have_coins = false | 25 | have_coins = false |
| 26 | if have_coins then print "Got coins" else print "No coins" | 26 | if have_coins then print "Dapat koin" else print "Tidak ada koin" |
| 27 | ``` | 27 | ``` |
| 28 | <YueDisplay> | 28 | <YueDisplay> |
| 29 | 29 | ||
| 30 | ```yue | 30 | ```yue |
| 31 | have_coins = false | 31 | have_coins = false |
| 32 | if have_coins then print "Got coins" else print "No coins" | 32 | if have_coins then print "Dapat koin" else print "Tidak ada koin" |
| 33 | ``` | 33 | ``` |
| 34 | 34 | ||
| 35 | </YueDisplay> | 35 | </YueDisplay> |
| 36 | 36 | ||
| 37 | Because if statements can be used as expressions, this can also be written as: | 37 | Karena pernyataan if dapat digunakan sebagai ekspresi, ini juga bisa ditulis sebagai: |
| 38 | 38 | ||
| 39 | ```yuescript | 39 | ```yuescript |
| 40 | have_coins = false | 40 | have_coins = false |
| 41 | print if have_coins then "Got coins" else "No coins" | 41 | print if have_coins then "Dapat koin" else "Tidak ada koin" |
| 42 | ``` | 42 | ``` |
| 43 | <YueDisplay> | 43 | <YueDisplay> |
| 44 | 44 | ||
| 45 | ```yue | 45 | ```yue |
| 46 | have_coins = false | 46 | have_coins = false |
| 47 | print if have_coins then "Got coins" else "No coins" | 47 | print if have_coins then "Dapat koin" else "Tidak ada koin" |
| 48 | ``` | 48 | ``` |
| 49 | 49 | ||
| 50 | </YueDisplay> | 50 | </YueDisplay> |
| 51 | 51 | ||
| 52 | Conditionals can also be used in return statements and assignments: | 52 | Kondisional juga bisa digunakan di pernyataan return dan assignment: |
| 53 | 53 | ||
| 54 | ```yuescript | 54 | ```yuescript |
| 55 | is_tall = (name) -> | 55 | is_tall = (name) -> |
| @@ -59,11 +59,11 @@ is_tall = (name) -> | |||
| 59 | false | 59 | false |
| 60 | 60 | ||
| 61 | message = if is_tall "Rob" | 61 | message = if is_tall "Rob" |
| 62 | "I am very tall" | 62 | "Saya sangat tinggi" |
| 63 | else | 63 | else |
| 64 | "I am not so tall" | 64 | "Saya tidak terlalu tinggi" |
| 65 | 65 | ||
| 66 | print message -- prints: I am very tall | 66 | print message -- prints: Saya sangat tinggi |
| 67 | ``` | 67 | ``` |
| 68 | <YueDisplay> | 68 | <YueDisplay> |
| 69 | 69 | ||
| @@ -75,53 +75,53 @@ is_tall = (name) -> | |||
| 75 | false | 75 | false |
| 76 | 76 | ||
| 77 | message = if is_tall "Rob" | 77 | message = if is_tall "Rob" |
| 78 | "I am very tall" | 78 | "Saya sangat tinggi" |
| 79 | else | 79 | else |
| 80 | "I am not so tall" | 80 | "Saya tidak terlalu tinggi" |
| 81 | 81 | ||
| 82 | print message -- prints: I am very tall | 82 | print message -- prints: Saya sangat tinggi |
| 83 | ``` | 83 | ``` |
| 84 | 84 | ||
| 85 | </YueDisplay> | 85 | </YueDisplay> |
| 86 | 86 | ||
| 87 | The opposite of if is unless: | 87 | Kebalikan dari if adalah unless: |
| 88 | 88 | ||
| 89 | ```yuescript | 89 | ```yuescript |
| 90 | unless os.date("%A") == "Monday" | 90 | unless os.date("%A") == "Monday" |
| 91 | print "it is not Monday!" | 91 | print "hari ini bukan Senin!" |
| 92 | ``` | 92 | ``` |
| 93 | <YueDisplay> | 93 | <YueDisplay> |
| 94 | 94 | ||
| 95 | ```yue | 95 | ```yue |
| 96 | unless os.date("%A") == "Monday" | 96 | unless os.date("%A") == "Monday" |
| 97 | print "it is not Monday!" | 97 | print "hari ini bukan Senin!" |
| 98 | ``` | 98 | ``` |
| 99 | 99 | ||
| 100 | </YueDisplay> | 100 | </YueDisplay> |
| 101 | 101 | ||
| 102 | ```yuescript | 102 | ```yuescript |
| 103 | print "You're lucky!" unless math.random! > 0.1 | 103 | print "Kamu beruntung!" unless math.random! > 0.1 |
| 104 | ``` | 104 | ``` |
| 105 | <YueDisplay> | 105 | <YueDisplay> |
| 106 | 106 | ||
| 107 | ```yue | 107 | ```yue |
| 108 | print "You're lucky!" unless math.random! > 0.1 | 108 | print "Kamu beruntung!" unless math.random! > 0.1 |
| 109 | ``` | 109 | ``` |
| 110 | 110 | ||
| 111 | </YueDisplay> | 111 | </YueDisplay> |
| 112 | 112 | ||
| 113 | ## In Expression | 113 | ## Ekspresi In |
| 114 | 114 | ||
| 115 | You can write range checking code with an `in-expression`. | 115 | Anda dapat menulis kode pengecekan rentang dengan `ekspresi in`. |
| 116 | 116 | ||
| 117 | ```yuescript | 117 | ```yuescript |
| 118 | a = 5 | 118 | a = 5 |
| 119 | 119 | ||
| 120 | if a in [1, 3, 5, 7] | 120 | if a in [1, 3, 5, 7] |
| 121 | print "checking equality with discrete values" | 121 | print "memeriksa kesamaan dengan nilai-nilai diskrit" |
| 122 | 122 | ||
| 123 | if a in list | 123 | if a in list |
| 124 | print "checking if `a` is in a list" | 124 | print "memeriksa apakah `a` ada di dalam daftar" |
| 125 | ``` | 125 | ``` |
| 126 | <YueDisplay> | 126 | <YueDisplay> |
| 127 | 127 | ||
| @@ -129,21 +129,10 @@ if a in list | |||
| 129 | a = 5 | 129 | a = 5 |
| 130 | 130 | ||
| 131 | if a in [1, 3, 5, 7] | 131 | if a in [1, 3, 5, 7] |
| 132 | print "checking equality with discrete values" | 132 | print "memeriksa kesamaan dengan nilai-nilai diskrit" |
| 133 | 133 | ||
| 134 | if a in list | 134 | if a in list |
| 135 | print "checking if `a` is in a list" | 135 | print "memeriksa apakah `a` ada di dalam daftar" |
| 136 | ``` | ||
| 137 | |||
| 138 | </YueDisplay> | ||
| 139 | |||
| 140 | ```yuescript | ||
| 141 | print "You're lucky!" unless math.random! > 0.1 | ||
| 142 | ``` | ||
| 143 | <YueDisplay> | ||
| 144 | |||
| 145 | ```yue | ||
| 146 | print "You're lucky!" unless math.random! > 0.1 | ||
| 147 | ``` | 136 | ``` |
| 148 | 137 | ||
| 149 | </YueDisplay> | 138 | </YueDisplay> |
diff --git a/doc/docs/id-id/doc/control-flow/continue.md b/doc/docs/id-id/doc/control-flow/continue.md index b000765..3d7a68c 100644 --- a/doc/docs/id-id/doc/control-flow/continue.md +++ b/doc/docs/id-id/doc/control-flow/continue.md | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | # Continue | 1 | # Pernyataan Continue |
| 2 | 2 | ||
| 3 | A continue statement can be used to skip the current iteration in a loop. | 3 | Pernyataan continue dapat digunakan untuk melewati iterasi saat ini di dalam loop. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | i = 0 | 6 | i = 0 |
| @@ -21,7 +21,7 @@ while i < 10 | |||
| 21 | 21 | ||
| 22 | </YueDisplay> | 22 | </YueDisplay> |
| 23 | 23 | ||
| 24 | continue can also be used with loop expressions to prevent that iteration from accumulating into the result. This examples filters the array table into just even numbers: | 24 | continue juga bisa digunakan bersama ekspresi loop untuk mencegah iterasi tersebut diakumulasikan ke hasil. Contoh ini memfilter tabel array menjadi hanya angka genap: |
| 25 | 25 | ||
| 26 | ```yuescript | 26 | ```yuescript |
| 27 | my_numbers = [1, 2, 3, 4, 5, 6] | 27 | my_numbers = [1, 2, 3, 4, 5, 6] |
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 cabcde5..91ba22e 100644 --- a/doc/docs/id-id/doc/control-flow/for-loop.md +++ b/doc/docs/id-id/doc/control-flow/for-loop.md | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | # For Loop | 1 | # Perulangan For |
| 2 | 2 | ||
| 3 | There are two for loop forms, just like in Lua. A numeric one and a generic one: | 3 | Ada dua bentuk perulangan for, seperti di Lua. Satu numerik dan satu generik: |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | for i = 10, 20 | 6 | for i = 10, 20 |
| @@ -27,7 +27,7 @@ for key, value in pairs object | |||
| 27 | 27 | ||
| 28 | </YueDisplay> | 28 | </YueDisplay> |
| 29 | 29 | ||
| 30 | The slicing and **\*** operators can be used, just like with comprehensions: | 30 | Operator slicing dan **\*** dapat digunakan, seperti pada comprehension: |
| 31 | 31 | ||
| 32 | ```yuescript | 32 | ```yuescript |
| 33 | for item in *items[2, 4] | 33 | for item in *items[2, 4] |
| @@ -42,7 +42,7 @@ for item in *items[2, 4] | |||
| 42 | 42 | ||
| 43 | </YueDisplay> | 43 | </YueDisplay> |
| 44 | 44 | ||
| 45 | A shorter syntax is also available for all variations when the body is only a single line: | 45 | Sintaks yang lebih singkat juga tersedia untuk semua variasi ketika badan hanya satu baris: |
| 46 | 46 | ||
| 47 | ```yuescript | 47 | ```yuescript |
| 48 | for item in *items do print item | 48 | for item in *items do print item |
| @@ -59,9 +59,9 @@ for j = 1, 10, 3 do print j | |||
| 59 | 59 | ||
| 60 | </YueDisplay> | 60 | </YueDisplay> |
| 61 | 61 | ||
| 62 | A for loop can also be used as an expression. The last statement in the body of the for loop is coerced into an expression and appended to an accumulating array table. | 62 | Perulangan for juga bisa digunakan sebagai ekspresi. Pernyataan terakhir di badan for dipaksa menjadi ekspresi dan ditambahkan ke tabel array yang terakumulasi. |
| 63 | 63 | ||
| 64 | Doubling every even number: | 64 | Menggandakan setiap bilangan genap: |
| 65 | 65 | ||
| 66 | ```yuescript | 66 | ```yuescript |
| 67 | doubled_evens = for i = 1, 20 | 67 | doubled_evens = for i = 1, 20 |
| @@ -82,9 +82,9 @@ doubled_evens = for i = 1, 20 | |||
| 82 | 82 | ||
| 83 | </YueDisplay> | 83 | </YueDisplay> |
| 84 | 84 | ||
| 85 | In addition, for loops support break with a return value, allowing the loop itself to be used as an expression that exits early with a meaningful result. | 85 | Selain itu, loop for mendukung break dengan nilai kembalian, sehingga loop itu sendiri bisa dipakai sebagai ekspresi yang keluar lebih awal dengan hasil bermakna. |
| 86 | 86 | ||
| 87 | For example, to find the first number greater than 10: | 87 | Contohnya, untuk menemukan angka pertama yang lebih besar dari 10: |
| 88 | 88 | ||
| 89 | ```yuescript | 89 | ```yuescript |
| 90 | first_large = for n in *numbers | 90 | first_large = for n in *numbers |
| @@ -99,11 +99,11 @@ first_large = for n in *numbers | |||
| 99 | 99 | ||
| 100 | </YueDisplay> | 100 | </YueDisplay> |
| 101 | 101 | ||
| 102 | This break-with-value syntax enables concise and expressive search or early-exit patterns directly within loop expressions. | 102 | Sintaks break-dengan-nilai ini memungkinkan pola pencarian atau keluar-lebih-awal yang ringkas langsung di dalam ekspresi loop. |
| 103 | 103 | ||
| 104 | You can also filter values by combining the for loop expression with the continue statement. | 104 | Anda juga bisa memfilter nilai dengan menggabungkan ekspresi for dengan pernyataan continue. |
| 105 | 105 | ||
| 106 | For loops at the end of a function body are not accumulated into a table for a return value (Instead the function will return nil). Either an explicit return statement can be used, or the loop can be converted into a list comprehension. | 106 | Loop for di akhir badan fungsi tidak diakumulasikan menjadi tabel untuk nilai kembalian (sebaliknya fungsi akan mengembalikan nil). Gunakan pernyataan return eksplisit, atau ubah loop menjadi list comprehension. |
| 107 | 107 | ||
| 108 | ```yuescript | 108 | ```yuescript |
| 109 | func_a = -> for i = 1, 10 do print i | 109 | func_a = -> for i = 1, 10 do print i |
| @@ -123,5 +123,3 @@ print func_b! -- prints table object | |||
| 123 | ``` | 123 | ``` |
| 124 | 124 | ||
| 125 | </YueDisplay> | 125 | </YueDisplay> |
| 126 | |||
| 127 | This is done to avoid the needless creation of tables for functions that don't need to return the results of the loop. | ||
diff --git a/doc/docs/id-id/doc/control-flow/switch.md b/doc/docs/id-id/doc/control-flow/switch.md index f503a80..ced4748 100644 --- a/doc/docs/id-id/doc/control-flow/switch.md +++ b/doc/docs/id-id/doc/control-flow/switch.md | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | # Switch | 1 | # Pernyataan Switch |
| 2 | 2 | ||
| 3 | The switch statement is shorthand for writing a series of if statements that check against the same value. Note that the value is only evaluated once. Like if statements, switches can have an else block to handle no matches. Comparison is done with the == operator. In switch statement, you can also use assignment expression to store temporary variable value. | 3 | Pernyataan switch adalah bentuk singkat untuk menulis serangkaian if yang membandingkan nilai yang sama. Perhatikan bahwa nilainya hanya dievaluasi sekali. Seperti if, switch bisa memiliki blok else untuk menangani tidak ada yang cocok. Perbandingan dilakukan dengan operator `==`. Di dalam switch, Anda juga bisa memakai ekspresi assignment untuk menyimpan nilai variabel sementara. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | switch name := "Dan" | 6 | switch name := "Dan" |
| @@ -25,9 +25,9 @@ switch name := "Dan" | |||
| 25 | 25 | ||
| 26 | </YueDisplay> | 26 | </YueDisplay> |
| 27 | 27 | ||
| 28 | A switch when clause can match against multiple values by listing them out comma separated. | 28 | Klausa when pada switch bisa mencocokkan beberapa nilai dengan menuliskannya dipisah koma. |
| 29 | 29 | ||
| 30 | Switches can be used as expressions as well, here we can assign the result of the switch to a variable: | 30 | Switch juga bisa dipakai sebagai ekspresi; di sini kita dapat menetapkan hasil switch ke sebuah variabel: |
| 31 | 31 | ||
| 32 | ```yuescript | 32 | ```yuescript |
| 33 | b = 1 | 33 | b = 1 |
| @@ -54,7 +54,7 @@ next_number = switch b | |||
| 54 | 54 | ||
| 55 | </YueDisplay> | 55 | </YueDisplay> |
| 56 | 56 | ||
| 57 | We can use the then keyword to write a switch's when block on a single line. No extra keyword is needed to write the else block on a single line. | 57 | Kita bisa memakai kata kunci `then` untuk menulis blok when switch pada satu baris. Tidak ada kata kunci tambahan yang dibutuhkan untuk menulis blok else pada satu baris. |
| 58 | 58 | ||
| 59 | ```yuescript | 59 | ```yuescript |
| 60 | msg = switch math.random(1, 5) | 60 | msg = switch math.random(1, 5) |
| @@ -73,7 +73,7 @@ msg = switch math.random(1, 5) | |||
| 73 | 73 | ||
| 74 | </YueDisplay> | 74 | </YueDisplay> |
| 75 | 75 | ||
| 76 | If you want to write code with one less indent when writing a switch statement, you can put the first when clause on the statement start line, and then all other clauses can be written with one less indent. | 76 | Jika Anda ingin menulis kode dengan satu indentasi lebih sedikit saat menulis switch, Anda bisa menaruh klausa when pertama pada baris awal pernyataan, lalu semua klausa lain dapat ditulis dengan satu indentasi lebih sedikit. |
| 77 | 77 | ||
| 78 | ```yuescript | 78 | ```yuescript |
| 79 | switch math.random(1, 5) | 79 | switch math.random(1, 5) |
| @@ -104,11 +104,11 @@ else | |||
| 104 | 104 | ||
| 105 | </YueDisplay> | 105 | </YueDisplay> |
| 106 | 106 | ||
| 107 | It is worth noting the order of the case comparison expression. The case's expression is on the left hand side. This can be useful if the case's expression wants to overwrite how the comparison is done by defining an eq metamethod. | 107 | Perlu dicatat urutan ekspresi perbandingan kasus. Ekspresi kasus berada di sisi kiri. Ini bisa berguna jika ekspresi kasus ingin mengganti cara perbandingan dengan mendefinisikan metamethod `eq`. |
| 108 | 108 | ||
| 109 | ## Table Matching | 109 | ## Pencocokan Tabel |
| 110 | 110 | ||
| 111 | You can do table matching in a switch when clause, if the table can be destructured by a specific structure and get non-nil values. | 111 | Anda bisa melakukan pencocokan tabel dalam klausa when switch, jika tabel dapat didestrukturisasi oleh struktur tertentu dan mendapatkan nilai non-nil. |
| 112 | 112 | ||
| 113 | ```yuescript | 113 | ```yuescript |
| 114 | items = | 114 | items = |
| @@ -143,7 +143,7 @@ for item in *items | |||
| 143 | 143 | ||
| 144 | </YueDisplay> | 144 | </YueDisplay> |
| 145 | 145 | ||
| 146 | You can use default values to optionally destructure the table for some fields. | 146 | Anda dapat menggunakan nilai default untuk mendestrukturisasi tabel secara opsional pada beberapa field. |
| 147 | 147 | ||
| 148 | ```yuescript | 148 | ```yuescript |
| 149 | item = {} | 149 | item = {} |
| @@ -168,9 +168,9 @@ switch item | |||
| 168 | 168 | ||
| 169 | </YueDisplay> | 169 | </YueDisplay> |
| 170 | 170 | ||
| 171 | You can also match against array elements, table fields, and even nested structures with array or table literals. | 171 | Anda juga bisa mencocokkan elemen array, field tabel, dan bahkan struktur bertingkat dengan literal array atau tabel. |
| 172 | 172 | ||
| 173 | Match against array elements. | 173 | Cocokkan terhadap elemen array. |
| 174 | 174 | ||
| 175 | ```yuescript | 175 | ```yuescript |
| 176 | switch tb | 176 | switch tb |
| @@ -195,7 +195,7 @@ switch tb | |||
| 195 | 195 | ||
| 196 | </YueDisplay> | 196 | </YueDisplay> |
| 197 | 197 | ||
| 198 | Match against table fields with destructuring. | 198 | Cocokkan terhadap field tabel dengan destrukturisasi. |
| 199 | 199 | ||
| 200 | ```yuescript | 200 | ```yuescript |
| 201 | switch tb | 201 | switch tb |
| @@ -220,7 +220,7 @@ switch tb | |||
| 220 | 220 | ||
| 221 | </YueDisplay> | 221 | </YueDisplay> |
| 222 | 222 | ||
| 223 | Match against nested table structures. | 223 | Cocokkan terhadap struktur tabel bertingkat. |
| 224 | 224 | ||
| 225 | ```yuescript | 225 | ```yuescript |
| 226 | switch tb | 226 | switch tb |
| @@ -245,7 +245,7 @@ switch tb | |||
| 245 | 245 | ||
| 246 | </YueDisplay> | 246 | </YueDisplay> |
| 247 | 247 | ||
| 248 | Match against array of tables. | 248 | Cocokkan terhadap array dari tabel. |
| 249 | 249 | ||
| 250 | ```yuescript | 250 | ```yuescript |
| 251 | switch tb | 251 | switch tb |
| @@ -272,7 +272,7 @@ switch tb | |||
| 272 | 272 | ||
| 273 | </YueDisplay> | 273 | </YueDisplay> |
| 274 | 274 | ||
| 275 | Match against a list and capture a range of elements. | 275 | Cocokkan terhadap daftar dan tangkap rentang elemen. |
| 276 | 276 | ||
| 277 | ```yuescript | 277 | ```yuescript |
| 278 | segments = ["admin", "users", "logs", "view"] | 278 | segments = ["admin", "users", "logs", "view"] |
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 502935e..cd93c91 100644 --- a/doc/docs/id-id/doc/control-flow/while-loop.md +++ b/doc/docs/id-id/doc/control-flow/while-loop.md | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | # While Loop | 1 | # Perulangan While |
| 2 | 2 | ||
| 3 | The while loop also comes in four variations: | 3 | Perulangan while juga memiliki empat variasi: |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | i = 10 | 6 | i = 10 |
| @@ -43,11 +43,11 @@ until running == false do my_function! | |||
| 43 | 43 | ||
| 44 | </YueDisplay> | 44 | </YueDisplay> |
| 45 | 45 | ||
| 46 | Like for loops, the while loop can also be used an expression. Additionally, for a function to return the accumulated value of a while loop, the statement must be explicitly returned. | 46 | Seperti loop for, loop while juga bisa digunakan sebagai ekspresi. Selain itu, agar sebuah fungsi mengembalikan nilai akumulasi dari loop while, pernyataannya harus di-return secara eksplisit. |
| 47 | 47 | ||
| 48 | ## Repeat Loop | 48 | ## Repeat Loop |
| 49 | 49 | ||
| 50 | The repeat loop comes from Lua: | 50 | Loop repeat berasal dari Lua: |
| 51 | 51 | ||
| 52 | ```yuescript | 52 | ```yuescript |
| 53 | i = 10 | 53 | i = 10 |
diff --git a/doc/docs/id-id/doc/data-structures/comprehensions.md b/doc/docs/id-id/doc/data-structures/comprehensions.md index 3a92167..3a2a9ff 100644 --- a/doc/docs/id-id/doc/data-structures/comprehensions.md +++ b/doc/docs/id-id/doc/data-structures/comprehensions.md | |||
| @@ -1,10 +1,10 @@ | |||
| 1 | # Comprehensions | 1 | # Komprehensi |
| 2 | 2 | ||
| 3 | Comprehensions provide a convenient syntax for constructing a new table by iterating over some existing object and applying an expression to its values. There are two kinds of comprehensions: list comprehensions and table comprehensions. They both produce Lua tables; list comprehensions accumulate values into an array-like table, and table comprehensions let you set both the key and the value on each iteration. | 3 | Komprehensi menyediakan sintaks yang nyaman untuk membangun tabel baru dengan mengiterasi objek yang ada dan menerapkan ekspresi pada nilainya. Ada dua jenis komprehensi: komprehensi list dan komprehensi tabel. Keduanya menghasilkan tabel Lua; komprehensi list mengakumulasi nilai ke tabel mirip array, dan komprehensi tabel memungkinkan Anda menetapkan kunci dan nilai pada setiap iterasi. |
| 4 | 4 | ||
| 5 | ## List Comprehensions | 5 | ## Komprehensi List |
| 6 | 6 | ||
| 7 | The following creates a copy of the items table but with all the values doubled. | 7 | Berikut membuat salinan tabel `items` tetapi semua nilainya digandakan. |
| 8 | 8 | ||
| 9 | ```yuescript | 9 | ```yuescript |
| 10 | items = [ 1, 2, 3, 4 ] | 10 | items = [ 1, 2, 3, 4 ] |
| @@ -19,7 +19,7 @@ doubled = [item * 2 for i, item in ipairs items] | |||
| 19 | 19 | ||
| 20 | </YueDisplay> | 20 | </YueDisplay> |
| 21 | 21 | ||
| 22 | The items included in the new table can be restricted with a when clause: | 22 | Item yang disertakan dalam tabel baru bisa dibatasi dengan klausa `when`: |
| 23 | 23 | ||
| 24 | ```yuescript | 24 | ```yuescript |
| 25 | slice = [item for i, item in ipairs items when i > 1 and i < 3] | 25 | slice = [item for i, item in ipairs items when i > 1 and i < 3] |
| @@ -32,7 +32,7 @@ slice = [item for i, item in ipairs items when i > 1 and i < 3] | |||
| 32 | 32 | ||
| 33 | </YueDisplay> | 33 | </YueDisplay> |
| 34 | 34 | ||
| 35 | Because it is common to iterate over the values of a numerically indexed table, an **\*** operator is introduced. The doubled example can be rewritten as: | 35 | Karena umum untuk mengiterasi nilai dari tabel berindeks numerik, operator **\*** diperkenalkan. Contoh `doubled` bisa ditulis ulang sebagai: |
| 36 | 36 | ||
| 37 | ```yuescript | 37 | ```yuescript |
| 38 | doubled = [item * 2 for item in *items] | 38 | doubled = [item * 2 for item in *items] |
| @@ -45,7 +45,7 @@ doubled = [item * 2 for item in *items] | |||
| 45 | 45 | ||
| 46 | </YueDisplay> | 46 | </YueDisplay> |
| 47 | 47 | ||
| 48 | In list comprehensions, you can also use the spread operator `...` to flatten nested lists, achieving a flat map effect: | 48 | Dalam komprehensi list, Anda juga bisa menggunakan operator spread `...` untuk meratakan list bertingkat, menghasilkan efek flat map: |
| 49 | 49 | ||
| 50 | ```yuescript | 50 | ```yuescript |
| 51 | data = | 51 | data = |
| @@ -53,7 +53,7 @@ data = | |||
| 53 | b: [4, 5, 6] | 53 | b: [4, 5, 6] |
| 54 | 54 | ||
| 55 | flat = [...v for k,v in pairs data] | 55 | flat = [...v for k,v in pairs data] |
| 56 | -- flat is now [1, 2, 3, 4, 5, 6] | 56 | -- flat sekarang [1, 2, 3, 4, 5, 6] |
| 57 | ``` | 57 | ``` |
| 58 | <YueDisplay> | 58 | <YueDisplay> |
| 59 | 59 | ||
| @@ -63,14 +63,14 @@ data = | |||
| 63 | b: [4, 5, 6] | 63 | b: [4, 5, 6] |
| 64 | 64 | ||
| 65 | flat = [...v for k,v in pairs data] | 65 | flat = [...v for k,v in pairs data] |
| 66 | -- flat is now [1, 2, 3, 4, 5, 6] | 66 | -- flat sekarang [1, 2, 3, 4, 5, 6] |
| 67 | ``` | 67 | ``` |
| 68 | 68 | ||
| 69 | </YueDisplay> | 69 | </YueDisplay> |
| 70 | 70 | ||
| 71 | The for and when clauses can be chained as much as desired. The only requirement is that a comprehension has at least one for clause. | 71 | Klausa `for` dan `when` dapat dirantai sebanyak yang diinginkan. Satu-satunya syarat adalah komprehensi memiliki setidaknya satu klausa `for`. |
| 72 | 72 | ||
| 73 | Using multiple for clauses is the same as using nested loops: | 73 | Menggunakan beberapa klausa `for` sama seperti menggunakan loop bertingkat: |
| 74 | 74 | ||
| 75 | ```yuescript | 75 | ```yuescript |
| 76 | x_coords = [4, 5, 6, 7] | 76 | x_coords = [4, 5, 6, 7] |
| @@ -91,7 +91,7 @@ for y in *y_coords] | |||
| 91 | 91 | ||
| 92 | </YueDisplay> | 92 | </YueDisplay> |
| 93 | 93 | ||
| 94 | Numeric for loops can also be used in comprehensions: | 94 | Perulangan for numerik juga bisa digunakan dalam komprehensi: |
| 95 | 95 | ||
| 96 | ```yuescript | 96 | ```yuescript |
| 97 | evens = [i for i = 1, 100 when i % 2 == 0] | 97 | evens = [i for i = 1, 100 when i % 2 == 0] |
| @@ -104,11 +104,11 @@ evens = [i for i = 1, 100 when i % 2 == 0] | |||
| 104 | 104 | ||
| 105 | </YueDisplay> | 105 | </YueDisplay> |
| 106 | 106 | ||
| 107 | ## Table Comprehensions | 107 | ## Komprehensi Tabel |
| 108 | 108 | ||
| 109 | The syntax for table comprehensions is very similar, only differing by using **{** and **}** and taking two values from each iteration. | 109 | Sintaks untuk komprehensi tabel sangat mirip, hanya berbeda dengan penggunaan **{** dan **}** serta mengambil dua nilai dari setiap iterasi. |
| 110 | 110 | ||
| 111 | This example makes a copy of the tablething: | 111 | Contoh ini membuat salinan tabel `thing`: |
| 112 | 112 | ||
| 113 | ```yuescript | 113 | ```yuescript |
| 114 | thing = { | 114 | thing = { |
| @@ -144,7 +144,7 @@ no_color = {k, v for k, v in pairs thing when k != "color"} | |||
| 144 | 144 | ||
| 145 | </YueDisplay> | 145 | </YueDisplay> |
| 146 | 146 | ||
| 147 | The **\*** operator is also supported. Here we create a square root look up table for a few numbers. | 147 | Operator **\*** juga didukung. Di sini kita membuat tabel lookup akar kuadrat untuk beberapa angka. |
| 148 | 148 | ||
| 149 | ```yuescript | 149 | ```yuescript |
| 150 | numbers = [1, 2, 3, 4] | 150 | numbers = [1, 2, 3, 4] |
| @@ -159,9 +159,9 @@ sqrts = {i, math.sqrt i for i in *numbers} | |||
| 159 | 159 | ||
| 160 | </YueDisplay> | 160 | </YueDisplay> |
| 161 | 161 | ||
| 162 | The key-value tuple in a table comprehension can also come from a single expression, in which case the expression should return two values. The first is used as the key and the second is used as the value: | 162 | Tuple key-value dalam komprehensi tabel juga bisa berasal dari satu ekspresi, yang berarti ekspresi tersebut harus mengembalikan dua nilai. Nilai pertama digunakan sebagai kunci dan nilai kedua digunakan sebagai nilai: |
| 163 | 163 | ||
| 164 | In this example we convert an array of pairs to a table where the first item in the pair is the key and the second is the value. | 164 | Dalam contoh ini kita mengonversi array pasangan menjadi tabel di mana item pertama dalam pasangan menjadi kunci dan item kedua menjadi nilai. |
| 165 | 165 | ||
| 166 | ```yuescript | 166 | ```yuescript |
| 167 | tuples = [ ["hello", "world"], ["foo", "bar"]] | 167 | tuples = [ ["hello", "world"], ["foo", "bar"]] |
| @@ -178,9 +178,9 @@ tbl = {unpack tuple for tuple in *tuples} | |||
| 178 | 178 | ||
| 179 | ## Slicing | 179 | ## Slicing |
| 180 | 180 | ||
| 181 | A special syntax is provided to restrict the items that are iterated over when using the **\*** operator. This is equivalent to setting the iteration bounds and a step size in a for loop. | 181 | Sintaks khusus disediakan untuk membatasi item yang diiterasi saat menggunakan operator **\***. Ini setara dengan mengatur batas iterasi dan ukuran langkah pada loop for. |
| 182 | 182 | ||
| 183 | Here we can set the minimum and maximum bounds, taking all items with indexes between 1 and 5 inclusive: | 183 | Di sini kita bisa menetapkan batas minimum dan maksimum, mengambil semua item dengan indeks antara 1 dan 5 (inklusif): |
| 184 | 184 | ||
| 185 | ```yuescript | 185 | ```yuescript |
| 186 | slice = [item for item in *items[1, 5]] | 186 | slice = [item for item in *items[1, 5]] |
| @@ -193,7 +193,7 @@ slice = [item for item in *items[1, 5]] | |||
| 193 | 193 | ||
| 194 | </YueDisplay> | 194 | </YueDisplay> |
| 195 | 195 | ||
| 196 | Any of the slice arguments can be left off to use a sensible default. In this example, if the max index is left off it defaults to the length of the table. This will take everything but the first element: | 196 | Salah satu argumen slice boleh dikosongkan untuk menggunakan default yang masuk akal. Pada contoh ini, jika indeks maksimum dikosongkan, defaultnya adalah panjang tabel. Ini akan mengambil semua item kecuali elemen pertama: |
| 197 | 197 | ||
| 198 | ```yuescript | 198 | ```yuescript |
| 199 | slice = [item for item in *items[2,]] | 199 | slice = [item for item in *items[2,]] |
| @@ -206,7 +206,7 @@ slice = [item for item in *items[2,]] | |||
| 206 | 206 | ||
| 207 | </YueDisplay> | 207 | </YueDisplay> |
| 208 | 208 | ||
| 209 | If the minimum bound is left out, it defaults to 1. Here we only provide a step size and leave the other bounds blank. This takes all odd indexed items: (1, 3, 5, …) | 209 | Jika batas minimum dikosongkan, defaultnya adalah 1. Di sini kita hanya memberikan ukuran langkah dan membiarkan batas lainnya kosong. Ini akan mengambil semua item berindeks ganjil: (1, 3, 5, …) |
| 210 | 210 | ||
| 211 | ```yuescript | 211 | ```yuescript |
| 212 | slice = [item for item in *items[,,2]] | 212 | slice = [item for item in *items[,,2]] |
| @@ -219,22 +219,22 @@ slice = [item for item in *items[,,2]] | |||
| 219 | 219 | ||
| 220 | </YueDisplay> | 220 | </YueDisplay> |
| 221 | 221 | ||
| 222 | Both the minimum and maximum bounds can be negative, which means that the bounds are counted from the end of the table. | 222 | Batas minimum dan maksimum bisa bernilai negatif, yang berarti batas dihitung dari akhir tabel. |
| 223 | 223 | ||
| 224 | ```yuescript | 224 | ```yuescript |
| 225 | -- take the last 4 items | 225 | -- ambil 4 item terakhir |
| 226 | slice = [item for item in *items[-4,-1]] | 226 | slice = [item for item in *items[-4,-1]] |
| 227 | ``` | 227 | ``` |
| 228 | <YueDisplay> | 228 | <YueDisplay> |
| 229 | 229 | ||
| 230 | ```yue | 230 | ```yue |
| 231 | -- take the last 4 items | 231 | -- ambil 4 item terakhir |
| 232 | slice = [item for item in *items[-4,-1]] | 232 | slice = [item for item in *items[-4,-1]] |
| 233 | ``` | 233 | ``` |
| 234 | 234 | ||
| 235 | </YueDisplay> | 235 | </YueDisplay> |
| 236 | 236 | ||
| 237 | The step size can also be negative, which means that the items are taken in reverse order. | 237 | Ukuran langkah juga bisa negatif, yang berarti item diambil dalam urutan terbalik. |
| 238 | 238 | ||
| 239 | ```yuescript | 239 | ```yuescript |
| 240 | reverse_slice = [item for item in *items[-1,1,-1]] | 240 | reverse_slice = [item for item in *items[-1,1,-1]] |
| @@ -247,24 +247,24 @@ reverse_slice = [item for item in *items[-1,1,-1]] | |||
| 247 | 247 | ||
| 248 | </YueDisplay> | 248 | </YueDisplay> |
| 249 | 249 | ||
| 250 | ### Slicing Expression | 250 | ### Ekspresi Slicing |
| 251 | 251 | ||
| 252 | Slicing can also be used as an expression. This is useful for getting a sub-list of a table. | 252 | Slicing juga bisa digunakan sebagai ekspresi. Ini berguna untuk mendapatkan sub-list dari sebuah tabel. |
| 253 | 253 | ||
| 254 | ```yuescript | 254 | ```yuescript |
| 255 | -- take the 2nd and 4th items as a new list | 255 | -- ambil item ke-2 dan ke-4 sebagai list baru |
| 256 | sub_list = items[2, 4] | 256 | sub_list = items[2, 4] |
| 257 | 257 | ||
| 258 | -- take the last 4 items | 258 | -- ambil 4 item terakhir |
| 259 | last_four_items = items[-4, -1] | 259 | last_four_items = items[-4, -1] |
| 260 | ``` | 260 | ``` |
| 261 | <YueDisplay> | 261 | <YueDisplay> |
| 262 | 262 | ||
| 263 | ```yue | 263 | ```yue |
| 264 | -- take the 2nd and 4th items as a new list | 264 | -- ambil item ke-2 dan ke-4 sebagai list baru |
| 265 | sub_list = items[2, 4] | 265 | sub_list = items[2, 4] |
| 266 | 266 | ||
| 267 | -- take the last 4 items | 267 | -- ambil 4 item terakhir |
| 268 | last_four_items = items[-4, -1] | 268 | last_four_items = items[-4, -1] |
| 269 | ``` | 269 | ``` |
| 270 | 270 | ||
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 c1adcab..df32f1c 100644 --- a/doc/docs/id-id/doc/data-structures/table-literals.md +++ b/doc/docs/id-id/doc/data-structures/table-literals.md | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | # Table Literals | 1 | # Literal Tabel |
| 2 | 2 | ||
| 3 | Like in Lua, tables are delimited in curly braces. | 3 | Seperti di Lua, tabel dibatasi dengan kurung kurawal. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | some_values = [1, 2, 3, 4] | 6 | some_values = [1, 2, 3, 4] |
| @@ -13,7 +13,7 @@ some_values = [1, 2, 3, 4] | |||
| 13 | 13 | ||
| 14 | </YueDisplay> | 14 | </YueDisplay> |
| 15 | 15 | ||
| 16 | Unlike Lua, assigning a value to a key in a table is done with **:** (instead of **=**). | 16 | Berbeda dengan Lua, assignment nilai ke sebuah kunci di tabel dilakukan dengan **:** (bukan **=**). |
| 17 | 17 | ||
| 18 | ```yuescript | 18 | ```yuescript |
| 19 | some_values = { | 19 | some_values = { |
| @@ -34,7 +34,7 @@ some_values = { | |||
| 34 | 34 | ||
| 35 | </YueDisplay> | 35 | </YueDisplay> |
| 36 | 36 | ||
| 37 | The curly braces can be left off if a single table of key value pairs is being assigned. | 37 | Kurung kurawal dapat dihilangkan jika hanya satu tabel pasangan key-value yang di-assign. |
| 38 | 38 | ||
| 39 | ```yuescript | 39 | ```yuescript |
| 40 | profile = | 40 | profile = |
| @@ -53,7 +53,7 @@ profile = | |||
| 53 | 53 | ||
| 54 | </YueDisplay> | 54 | </YueDisplay> |
| 55 | 55 | ||
| 56 | Newlines can be used to delimit values instead of a comma (or both): | 56 | Baris baru dapat digunakan untuk memisahkan nilai sebagai ganti koma (atau keduanya): |
| 57 | 57 | ||
| 58 | ```yuescript | 58 | ```yuescript |
| 59 | values = { | 59 | values = { |
| @@ -76,7 +76,7 @@ values = { | |||
| 76 | 76 | ||
| 77 | </YueDisplay> | 77 | </YueDisplay> |
| 78 | 78 | ||
| 79 | When creating a single line table literal, the curly braces can also be left off: | 79 | Saat membuat literal tabel satu baris, kurung kurawal juga bisa dihilangkan: |
| 80 | 80 | ||
| 81 | ```yuescript | 81 | ```yuescript |
| 82 | my_function dance: "Tango", partner: "none" | 82 | my_function dance: "Tango", partner: "none" |
| @@ -93,7 +93,7 @@ y = type: "dog", legs: 4, tails: 1 | |||
| 93 | 93 | ||
| 94 | </YueDisplay> | 94 | </YueDisplay> |
| 95 | 95 | ||
| 96 | The keys of a table literal can be language keywords without being escaped: | 96 | Kunci literal tabel dapat berupa kata kunci bahasa tanpa perlu di-escape: |
| 97 | 97 | ||
| 98 | ```yuescript | 98 | ```yuescript |
| 99 | tbl = { | 99 | tbl = { |
| @@ -112,7 +112,7 @@ tbl = { | |||
| 112 | 112 | ||
| 113 | </YueDisplay> | 113 | </YueDisplay> |
| 114 | 114 | ||
| 115 | If you are constructing a table out of variables and wish the keys to be the same as the variable names, then the **:** prefix operator can be used: | 115 | Jika Anda membangun tabel dari variabel dan ingin kunci sama dengan nama variabel, maka operator prefiks **:** dapat digunakan: |
| 116 | 116 | ||
| 117 | ```yuescript | 117 | ```yuescript |
| 118 | hair = "golden" | 118 | hair = "golden" |
| @@ -133,7 +133,7 @@ print_table :hair, :height | |||
| 133 | 133 | ||
| 134 | </YueDisplay> | 134 | </YueDisplay> |
| 135 | 135 | ||
| 136 | If you want the key of a field in the table to to be result of an expression, then you can wrap it in **[ ]**, just like in Lua. You can also use a string literal directly as a key, leaving out the square brackets. This is useful if your key has any special characters. | 136 | Jika Anda ingin kunci field dalam tabel menjadi hasil suatu ekspresi, Anda dapat membungkusnya dengan **[ ]**, seperti di Lua. Anda juga bisa menggunakan literal string langsung sebagai kunci tanpa tanda kurung siku. Ini berguna jika kunci memiliki karakter khusus. |
| 137 | 137 | ||
| 138 | ```yuescript | 138 | ```yuescript |
| 139 | t = { | 139 | t = { |
| @@ -152,7 +152,7 @@ t = { | |||
| 152 | 152 | ||
| 153 | </YueDisplay> | 153 | </YueDisplay> |
| 154 | 154 | ||
| 155 | Lua tables have both an array part and a hash part, but sometimes you want to make a semantic distinction between array and hash usage when writing Lua tables. Then you can write Lua table with **[ ]** instead of **{ }** to represent an array table and writing any key value pair in a list table won't be allowed. | 155 | Tabel Lua memiliki bagian array dan bagian hash, tetapi terkadang Anda ingin membedakan penggunaan array dan hash secara semantik saat menulis tabel Lua. Maka Anda bisa menulis tabel Lua dengan **[ ]** alih-alih **{ }** untuk merepresentasikan tabel array, dan menuliskan pasangan key-value di tabel list tidak akan diizinkan. |
| 156 | 156 | ||
| 157 | ```yuescript | 157 | ```yuescript |
| 158 | some_values = [1, 2, 3, 4] | 158 | some_values = [1, 2, 3, 4] |
diff --git a/doc/docs/id-id/doc/functions/backcalls.md b/doc/docs/id-id/doc/functions/backcalls.md index e34331e..8d542ee 100644 --- a/doc/docs/id-id/doc/functions/backcalls.md +++ b/doc/docs/id-id/doc/functions/backcalls.md | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | # Backcalls | 1 | # Backcall |
| 2 | 2 | ||
| 3 | Backcalls are used for unnesting callbacks. They are defined using arrows pointed to the left as the last parameter by default filling in a function call. All the syntax is mostly the same as regular arrow functions except that it is just pointing the other way and the function body does not require indent. | 3 | Backcall digunakan untuk meratakan callback yang bersarang. Backcall didefinisikan menggunakan panah yang mengarah ke kiri sebagai parameter terakhir secara default yang akan mengisi pemanggilan fungsi. Semua sintaks pada dasarnya sama seperti fungsi panah biasa, kecuali arahnya berlawanan dan badan fungsi tidak memerlukan indentasi. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | x <- f | 6 | x <- f |
| @@ -15,7 +15,7 @@ print "hello" .. x | |||
| 15 | 15 | ||
| 16 | </YueDisplay> | 16 | </YueDisplay> |
| 17 | 17 | ||
| 18 | Fat arrow functions are also available. | 18 | Fungsi panah tebal juga tersedia. |
| 19 | 19 | ||
| 20 | ```yuescript | 20 | ```yuescript |
| 21 | <= f | 21 | <= f |
| @@ -30,7 +30,7 @@ print @value | |||
| 30 | 30 | ||
| 31 | </YueDisplay> | 31 | </YueDisplay> |
| 32 | 32 | ||
| 33 | You can specify a placeholder for where you want the backcall function to go as a parameter. | 33 | Anda dapat menentukan placeholder untuk posisi fungsi backcall sebagai parameter. |
| 34 | 34 | ||
| 35 | ```yuescript | 35 | ```yuescript |
| 36 | (x) <- map _, [1, 2, 3] | 36 | (x) <- map _, [1, 2, 3] |
| @@ -45,7 +45,7 @@ x * 2 | |||
| 45 | 45 | ||
| 46 | </YueDisplay> | 46 | </YueDisplay> |
| 47 | 47 | ||
| 48 | If you wish to have further code after your backcalls, you can set them aside with a do statement. And the parentheses can be omitted with non-fat arrow functions. | 48 | Jika Anda ingin menulis kode lanjutan setelah backcall, Anda dapat memisahkannya dengan pernyataan `do`. Tanda kurung dapat dihilangkan untuk fungsi panah non-tebal. |
| 49 | 49 | ||
| 50 | ```yuescript | 50 | ```yuescript |
| 51 | result, msg = do | 51 | result, msg = do |
diff --git a/doc/docs/id-id/doc/functions/function-literals.md b/doc/docs/id-id/doc/functions/function-literals.md index 316e07c..589a26d 100644 --- a/doc/docs/id-id/doc/functions/function-literals.md +++ b/doc/docs/id-id/doc/functions/function-literals.md | |||
| @@ -1,21 +1,21 @@ | |||
| 1 | # Function Literals | 1 | # Literal Fungsi |
| 2 | 2 | ||
| 3 | All functions are created using a function expression. A simple function is denoted using the arrow: **->**. | 3 | Semua fungsi dibuat menggunakan ekspresi fungsi. Fungsi sederhana ditandai dengan panah: **->**. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | my_function = -> | 6 | my_function = -> |
| 7 | my_function() -- call the empty function | 7 | my_function() -- memanggil fungsi kosong |
| 8 | ``` | 8 | ``` |
| 9 | <YueDisplay> | 9 | <YueDisplay> |
| 10 | 10 | ||
| 11 | ```yue | 11 | ```yue |
| 12 | my_function = -> | 12 | my_function = -> |
| 13 | my_function() -- call the empty function | 13 | my_function() -- memanggil fungsi kosong |
| 14 | ``` | 14 | ``` |
| 15 | 15 | ||
| 16 | </YueDisplay> | 16 | </YueDisplay> |
| 17 | 17 | ||
| 18 | The body of the function can either be one statement placed directly after the arrow, or it can be a series of statements indented on the following lines: | 18 | Badan fungsi bisa berupa satu pernyataan yang ditulis langsung setelah panah, atau berupa serangkaian pernyataan yang diindentasi di baris berikutnya: |
| 19 | 19 | ||
| 20 | ```yuescript | 20 | ```yuescript |
| 21 | func_a = -> print "hello world" | 21 | func_a = -> print "hello world" |
| @@ -36,7 +36,7 @@ func_b = -> | |||
| 36 | 36 | ||
| 37 | </YueDisplay> | 37 | </YueDisplay> |
| 38 | 38 | ||
| 39 | If a function has no arguments, it can be called using the ! operator, instead of empty parentheses. The ! invocation is the preferred way to call functions with no arguments. | 39 | Jika fungsi tidak memiliki argumen, ia dapat dipanggil menggunakan operator `!`, sebagai ganti tanda kurung kosong. Pemanggilan `!` adalah cara yang disarankan untuk memanggil fungsi tanpa argumen. |
| 40 | 40 | ||
| 41 | ```yuescript | 41 | ```yuescript |
| 42 | func_a! | 42 | func_a! |
| @@ -51,7 +51,7 @@ func_b() | |||
| 51 | 51 | ||
| 52 | </YueDisplay> | 52 | </YueDisplay> |
| 53 | 53 | ||
| 54 | Functions with arguments can be created by preceding the arrow with a list of argument names in parentheses: | 54 | Fungsi dengan argumen dapat dibuat dengan menaruh daftar nama argumen dalam tanda kurung sebelum panah: |
| 55 | 55 | ||
| 56 | ```yuescript | 56 | ```yuescript |
| 57 | sum = (x, y) -> print "sum", x + y | 57 | sum = (x, y) -> print "sum", x + y |
| @@ -64,7 +64,7 @@ sum = (x, y) -> print "sum", x + y | |||
| 64 | 64 | ||
| 65 | </YueDisplay> | 65 | </YueDisplay> |
| 66 | 66 | ||
| 67 | Functions can be called by listing the arguments after the name of an expression that evaluates to a function. When chaining together function calls, the arguments are applied to the closest function to the left. | 67 | Fungsi dapat dipanggil dengan menuliskan argumen setelah nama ekspresi yang mengevaluasi ke fungsi. Saat merangkai pemanggilan fungsi, argumen diterapkan ke fungsi terdekat di sebelah kiri. |
| 68 | 68 | ||
| 69 | ```yuescript | 69 | ```yuescript |
| 70 | sum 10, 20 | 70 | sum 10, 20 |
| @@ -83,7 +83,7 @@ a b c "a", "b", "c" | |||
| 83 | 83 | ||
| 84 | </YueDisplay> | 84 | </YueDisplay> |
| 85 | 85 | ||
| 86 | In order to avoid ambiguity in when calling functions, parentheses can also be used to surround the arguments. This is required here in order to make sure the right arguments get sent to the right functions. | 86 | Untuk menghindari ambiguitas saat memanggil fungsi, tanda kurung juga bisa digunakan untuk mengelilingi argumen. Ini diperlukan di sini agar argumen yang tepat dikirim ke fungsi yang tepat. |
| 87 | 87 | ||
| 88 | ```yuescript | 88 | ```yuescript |
| 89 | print "x:", sum(10, 20), "y:", sum(30, 40) | 89 | print "x:", sum(10, 20), "y:", sum(30, 40) |
| @@ -96,9 +96,9 @@ print "x:", sum(10, 20), "y:", sum(30, 40) | |||
| 96 | 96 | ||
| 97 | </YueDisplay> | 97 | </YueDisplay> |
| 98 | 98 | ||
| 99 | There must not be any space between the opening parenthesis and the function. | 99 | Tidak boleh ada spasi antara tanda kurung buka dan nama fungsi. |
| 100 | 100 | ||
| 101 | Functions will coerce the last statement in their body into a return statement, this is called implicit return: | 101 | Fungsi akan memaksa pernyataan terakhir di badannya menjadi pernyataan return, ini disebut return implisit: |
| 102 | 102 | ||
| 103 | ```yuescript | 103 | ```yuescript |
| 104 | sum = (x, y) -> x + y | 104 | sum = (x, y) -> x + y |
| @@ -113,7 +113,7 @@ print "The sum is ", sum 10, 20 | |||
| 113 | 113 | ||
| 114 | </YueDisplay> | 114 | </YueDisplay> |
| 115 | 115 | ||
| 116 | And if you need to explicitly return, you can use the return keyword: | 116 | Dan jika Anda perlu return secara eksplisit, Anda bisa menggunakan kata kunci `return`: |
| 117 | 117 | ||
| 118 | ```yuescript | 118 | ```yuescript |
| 119 | sum = (x, y) -> return x + y | 119 | sum = (x, y) -> return x + y |
| @@ -126,7 +126,7 @@ sum = (x, y) -> return x + y | |||
| 126 | 126 | ||
| 127 | </YueDisplay> | 127 | </YueDisplay> |
| 128 | 128 | ||
| 129 | Just like in Lua, functions can return multiple values. The last statement must be a list of values separated by commas: | 129 | Seperti di Lua, fungsi dapat mengembalikan beberapa nilai. Pernyataan terakhir harus berupa daftar nilai yang dipisahkan koma: |
| 130 | 130 | ||
| 131 | ```yuescript | 131 | ```yuescript |
| 132 | mystery = (x, y) -> x + y, x - y | 132 | mystery = (x, y) -> x + y, x - y |
| @@ -141,9 +141,9 @@ a, b = mystery 10, 20 | |||
| 141 | 141 | ||
| 142 | </YueDisplay> | 142 | </YueDisplay> |
| 143 | 143 | ||
| 144 | ## Fat Arrows | 144 | ## Panah Tebal |
| 145 | 145 | ||
| 146 | Because it is an idiom in Lua to send an object as the first argument when calling a method, a special syntax is provided for creating functions which automatically includes a self argument. | 146 | Karena sudah menjadi idiom di Lua untuk mengirim objek sebagai argumen pertama saat memanggil method, disediakan sintaks khusus untuk membuat fungsi yang otomatis menyertakan argumen `self`. |
| 147 | 147 | ||
| 148 | ```yuescript | 148 | ```yuescript |
| 149 | func = (num) => @value + num | 149 | func = (num) => @value + num |
| @@ -156,9 +156,9 @@ func = (num) => @value + num | |||
| 156 | 156 | ||
| 157 | </YueDisplay> | 157 | </YueDisplay> |
| 158 | 158 | ||
| 159 | ## Argument Defaults | 159 | ## Nilai Default Argumen |
| 160 | 160 | ||
| 161 | It is possible to provide default values for the arguments of a function. An argument is determined to be empty if its value is nil. Any nil arguments that have a default value will be replace before the body of the function is run. | 161 | Dimungkinkan untuk menyediakan nilai default bagi argumen fungsi. Argumen dianggap kosong jika nilainya nil. Argumen nil yang memiliki nilai default akan diganti sebelum badan fungsi dijalankan. |
| 162 | 162 | ||
| 163 | ```yuescript | 163 | ```yuescript |
| 164 | my_function = (name = "something", height = 100) -> | 164 | my_function = (name = "something", height = 100) -> |
| @@ -175,7 +175,7 @@ my_function = (name = "something", height = 100) -> | |||
| 175 | 175 | ||
| 176 | </YueDisplay> | 176 | </YueDisplay> |
| 177 | 177 | ||
| 178 | An argument default value expression is evaluated in the body of the function in the order of the argument declarations. For this reason default values have access to previously declared arguments. | 178 | Ekspresi nilai default argumen dievaluasi di dalam badan fungsi sesuai urutan deklarasi argumen. Karena itu, nilai default dapat mengakses argumen yang dideklarasikan sebelumnya. |
| 179 | 179 | ||
| 180 | ```yuescript | 180 | ```yuescript |
| 181 | some_args = (x = 100, y = x + 1000) -> | 181 | some_args = (x = 100, y = x + 1000) -> |
| @@ -190,11 +190,11 @@ some_args = (x = 100, y = x + 1000) -> | |||
| 190 | 190 | ||
| 191 | </YueDisplay> | 191 | </YueDisplay> |
| 192 | 192 | ||
| 193 | ## Considerations | 193 | ## Pertimbangan |
| 194 | 194 | ||
| 195 | Because of the expressive parentheses-less way of calling functions, some restrictions must be put in place to avoid parsing ambiguity involving whitespace. | 195 | Karena cara pemanggilan fungsi tanpa tanda kurung yang ekspresif, beberapa pembatasan harus diterapkan untuk menghindari ambiguitas parsing yang melibatkan spasi. |
| 196 | 196 | ||
| 197 | The minus sign plays two roles, a unary negation operator and a binary subtraction operator. Consider how the following examples compile: | 197 | Tanda minus memiliki dua peran, operator negasi unari dan operator pengurangan biner. Perhatikan bagaimana contoh berikut dikompilasi: |
| 198 | 198 | ||
| 199 | ```yuescript | 199 | ```yuescript |
| 200 | a = x - 10 | 200 | a = x - 10 |
| @@ -213,11 +213,11 @@ d = x- z | |||
| 213 | 213 | ||
| 214 | </YueDisplay> | 214 | </YueDisplay> |
| 215 | 215 | ||
| 216 | The precedence of the first argument of a function call can be controlled using whitespace if the argument is a literal string. In Lua, it is common to leave off parentheses when calling a function with a single string or table literal. | 216 | Prioritas argumen pertama pada pemanggilan fungsi dapat dikendalikan menggunakan spasi jika argumennya adalah literal string. Di Lua, sudah umum untuk menghilangkan tanda kurung saat memanggil fungsi dengan satu literal string atau tabel. |
| 217 | 217 | ||
| 218 | When there is no space between a variable and a string literal, the function call takes precedence over any following expressions. No other arguments can be passed to the function when it is called this way. | 218 | Ketika tidak ada spasi antara variabel dan literal string, pemanggilan fungsi akan memiliki prioritas atas ekspresi yang mengikuti. Tidak ada argumen lain yang dapat diberikan pada fungsi ketika dipanggil dengan cara ini. |
| 219 | 219 | ||
| 220 | Where there is a space following a variable and a string literal, the function call acts as show above. The string literal belongs to any following expressions (if they exist), which serves as the argument list. | 220 | Ketika ada spasi setelah variabel dan literal string, pemanggilan fungsi bertindak seperti yang dijelaskan di atas. Literal string menjadi milik ekspresi berikutnya (jika ada), yang berfungsi sebagai daftar argumen. |
| 221 | 221 | ||
| 222 | ```yuescript | 222 | ```yuescript |
| 223 | x = func"hello" + 100 | 223 | x = func"hello" + 100 |
| @@ -232,11 +232,11 @@ y = func "hello" + 100 | |||
| 232 | 232 | ||
| 233 | </YueDisplay> | 233 | </YueDisplay> |
| 234 | 234 | ||
| 235 | ## Multi-line arguments | 235 | ## Argumen Multi-baris |
| 236 | 236 | ||
| 237 | When calling functions that take a large number of arguments, it is convenient to split the argument list over multiple lines. Because of the white-space sensitive nature of the language, care must be taken when splitting up the argument list. | 237 | Saat memanggil fungsi yang menerima banyak argumen, akan lebih nyaman untuk memecah daftar argumen menjadi beberapa baris. Karena sifat bahasa yang peka terhadap spasi, perlu hati-hati saat memecah daftar argumen. |
| 238 | 238 | ||
| 239 | If an argument list is to be continued onto the next line, the current line must end in a comma. And the following line must be indented more than the current indentation. Once indented, all other argument lines must be at the same level of indentation to be part of the argument list | 239 | Jika daftar argumen akan dilanjutkan ke baris berikutnya, baris saat ini harus diakhiri dengan koma. Dan baris berikutnya harus lebih terindentasi daripada indentasi saat ini. Setelah diindentasi, semua baris argumen lainnya harus berada pada tingkat indentasi yang sama agar menjadi bagian dari daftar argumen. |
| 240 | 240 | ||
| 241 | ```yuescript | 241 | ```yuescript |
| 242 | my_func 5, 4, 3, | 242 | my_func 5, 4, 3, |
| @@ -261,7 +261,7 @@ cool_func 1, 2, | |||
| 261 | 261 | ||
| 262 | </YueDisplay> | 262 | </YueDisplay> |
| 263 | 263 | ||
| 264 | This type of invocation can be nested. The level of indentation is used to determine to which function the arguments belong to. | 264 | Jenis pemanggilan ini dapat dinest. Tingkat indentasi digunakan untuk menentukan argumen milik fungsi yang mana. |
| 265 | 265 | ||
| 266 | ```yuescript | 266 | ```yuescript |
| 267 | my_func 5, 6, 7, | 267 | my_func 5, 6, 7, |
| @@ -280,7 +280,7 @@ my_func 5, 6, 7, | |||
| 280 | 280 | ||
| 281 | </YueDisplay> | 281 | </YueDisplay> |
| 282 | 282 | ||
| 283 | Because tables also use the comma as a delimiter, this indentation syntax is helpful for letting values be part of the argument list instead of being part of the table. | 283 | Karena tabel juga menggunakan koma sebagai pemisah, sintaks indentasi ini membantu agar nilai menjadi bagian dari daftar argumen, bukan bagian dari tabel. |
| 284 | 284 | ||
| 285 | ```yuescript | 285 | ```yuescript |
| 286 | x = [ | 286 | x = [ |
| @@ -301,7 +301,7 @@ x = [ | |||
| 301 | 301 | ||
| 302 | </YueDisplay> | 302 | </YueDisplay> |
| 303 | 303 | ||
| 304 | Although uncommon, notice how we can give a deeper indentation for function arguments if we know we will be using a lower indentation further on. | 304 | Meskipun jarang, perhatikan bahwa kita bisa memberikan indentasi yang lebih dalam untuk argumen fungsi jika kita tahu akan menggunakan indentasi yang lebih dangkal di bagian selanjutnya. |
| 305 | 305 | ||
| 306 | ```yuescript | 306 | ```yuescript |
| 307 | y = [ my_func 1, 2, 3, | 307 | y = [ my_func 1, 2, 3, |
| @@ -320,7 +320,7 @@ y = [ my_func 1, 2, 3, | |||
| 320 | 320 | ||
| 321 | </YueDisplay> | 321 | </YueDisplay> |
| 322 | 322 | ||
| 323 | The same thing can be done with other block level statements like conditionals. We can use indentation level to determine what statement a value belongs to: | 323 | Hal yang sama juga dapat dilakukan pada pernyataan tingkat blok lainnya seperti kondisional. Kita bisa menggunakan tingkat indentasi untuk menentukan nilai milik pernyataan apa: |
| 324 | 324 | ||
| 325 | ```yuescript | 325 | ```yuescript |
| 326 | if func 1, 2, 3, | 326 | if func 1, 2, 3, |
| @@ -353,13 +353,13 @@ if func 1, 2, 3, | |||
| 353 | 353 | ||
| 354 | </YueDisplay> | 354 | </YueDisplay> |
| 355 | 355 | ||
| 356 | ## Parameter Destructuring | 356 | ## Destrukturisasi Parameter |
| 357 | 357 | ||
| 358 | YueScript now supports destructuring function parameters when the argument is an object. Two forms of destructuring table literals are available: | 358 | YueScript kini mendukung destrukturisasi parameter fungsi ketika argumen berupa objek. Dua bentuk destrukturisasi literal tabel tersedia: |
| 359 | 359 | ||
| 360 | * **Curly-brace wrapped literals/object parameters**, allowing optional default values when fields are missing (e.g., `{:a, :b}`, `{a: a1 = 123}`). | 360 | * **Literal berkurung kurawal/parameter objek**, memungkinkan nilai default opsional ketika field hilang (misalnya, `{:a, :b}`, `{a: a1 = 123}`). |
| 361 | 361 | ||
| 362 | * **Unwrapped simple table syntax**, starting with a sequence of key-value or shorthand bindings and continuing until another expression terminates it (e.g., `:a, b: b1, :c`). This form extracts multiple fields from the same object. | 362 | * **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. |
| 363 | 363 | ||
| 364 | ```yuescript | 364 | ```yuescript |
| 365 | f1 = (:a, :b, :c) -> | 365 | f1 = (:a, :b, :c) -> |
| @@ -390,9 +390,9 @@ f2 arg1, arg2 | |||
| 390 | 390 | ||
| 391 | </YueDisplay> | 391 | </YueDisplay> |
| 392 | 392 | ||
| 393 | ## Prefixed Return Expression | 393 | ## Ekspresi Return Berawalan |
| 394 | 394 | ||
| 395 | When working with deeply nested function bodies, it can be tedious to maintain readability and consistency of the return value. To address this, YueScript introduces the **Prefixed Return Expression** syntax. Its form is as follows: | 395 | Saat bekerja dengan badan fungsi yang sangat bertingkat, menjaga keterbacaan dan konsistensi nilai return bisa terasa melelahkan. Untuk mengatasinya, YueScript memperkenalkan sintaks **Ekspresi Return Berawalan**. Bentuknya sebagai berikut: |
| 396 | 396 | ||
| 397 | ```yuescript | 397 | ```yuescript |
| 398 | findFirstEven = (list): nil -> | 398 | findFirstEven = (list): nil -> |
| @@ -415,7 +415,7 @@ findFirstEven = (list): nil -> | |||
| 415 | 415 | ||
| 416 | </YueDisplay> | 416 | </YueDisplay> |
| 417 | 417 | ||
| 418 | This is equivalent to: | 418 | Ini setara dengan: |
| 419 | 419 | ||
| 420 | ```yuescript | 420 | ```yuescript |
| 421 | findFirstEven = (list) -> | 421 | findFirstEven = (list) -> |
| @@ -440,11 +440,11 @@ findFirstEven = (list) -> | |||
| 440 | 440 | ||
| 441 | </YueDisplay> | 441 | </YueDisplay> |
| 442 | 442 | ||
| 443 | The only difference is that you can move the final return expression before the `->` or `=>` token to indicate the function’s implicit return value as the last statement. This way, even in functions with multiple nested loops or conditional branches, you no longer need to write a trailing return expression at the end of the function body, making the logic structure more straightforward and easier to follow. | 443 | Satu-satunya perbedaan adalah Anda dapat memindahkan ekspresi return terakhir sebelum token `->` atau `=>` untuk menunjukkan nilai return implisit fungsi sebagai pernyataan terakhir. Dengan cara ini, bahkan pada fungsi dengan banyak loop bertingkat atau cabang kondisional, Anda tidak lagi perlu menulis ekspresi return di akhir badan fungsi, sehingga struktur logika menjadi lebih lurus dan mudah diikuti. |
| 444 | 444 | ||
| 445 | ## Named Varargs | 445 | ## Varargs Bernama |
| 446 | 446 | ||
| 447 | You can use the `(...t) ->` syntax to automatically store varargs into a named table. This table will contain all passed arguments (including `nil` values), and the `n` field of the table will store the actual number of arguments passed (including `nil` values). | 447 | Anda dapat menggunakan sintaks `(...t) ->` untuk otomatis menyimpan varargs ke tabel bernama. Tabel ini berisi semua argumen yang diteruskan (termasuk nilai `nil`), dan field `n` pada tabel menyimpan jumlah argumen yang benar-benar diteruskan (termasuk nilai `nil`). |
| 448 | 448 | ||
| 449 | ```yuescript | 449 | ```yuescript |
| 450 | f = (...t) -> | 450 | f = (...t) -> |
| @@ -457,7 +457,7 @@ f 1, 2, 3 | |||
| 457 | f "a", "b", "c", "d" | 457 | f "a", "b", "c", "d" |
| 458 | f! | 458 | f! |
| 459 | 459 | ||
| 460 | -- Handling cases with nil values | 460 | -- Menangani kasus dengan nilai nil |
| 461 | process = (...args) -> | 461 | process = (...args) -> |
| 462 | sum = 0 | 462 | sum = 0 |
| 463 | for i = 1, args.n | 463 | for i = 1, args.n |
| @@ -480,7 +480,7 @@ f 1, 2, 3 | |||
| 480 | f "a", "b", "c", "d" | 480 | f "a", "b", "c", "d" |
| 481 | f! | 481 | f! |
| 482 | 482 | ||
| 483 | -- Handling cases with nil values | 483 | -- Menangani kasus dengan nilai nil |
| 484 | process = (...args) -> | 484 | process = (...args) -> |
| 485 | sum = 0 | 485 | sum = 0 |
| 486 | for i = 1, args.n | 486 | for i = 1, args.n |
diff --git a/doc/docs/id-id/doc/functions/function-stubs.md b/doc/docs/id-id/doc/functions/function-stubs.md index 57a8b0c..57ed5c1 100644 --- a/doc/docs/id-id/doc/functions/function-stubs.md +++ b/doc/docs/id-id/doc/functions/function-stubs.md | |||
| @@ -1,10 +1,10 @@ | |||
| 1 | # Function Stubs | 1 | # Stub Fungsi |
| 2 | 2 | ||
| 3 | It is common to pass a function from an object around as a value, for example, passing an instance method into a function as a callback. If the function expects the object it is operating on as the first argument then you must somehow bundle that object with the function so it can be called properly. | 3 | Sering kali fungsi dari sebuah objek diteruskan sebagai nilai, misalnya meneruskan method instance ke fungsi lain sebagai callback. Jika fungsi mengharapkan objek yang dioperasikan sebagai argumen pertama, maka Anda harus menggabungkan objek tersebut dengan fungsi agar dapat dipanggil dengan benar. |
| 4 | 4 | ||
| 5 | The function stub syntax is a shorthand for creating a new closure function that bundles both the object and function. This new function calls the wrapped function in the correct context of the object. | 5 | Sintaks stub fungsi adalah singkatan untuk membuat fungsi closure baru yang menggabungkan objek dan fungsi. Fungsi baru ini memanggil fungsi yang dibungkus dalam konteks objek yang benar. |
| 6 | 6 | ||
| 7 | Its syntax is the same as calling an instance method with the \ operator but with no argument list provided. | 7 | Sintaksnya sama seperti memanggil method instance dengan operator `\`, tetapi tanpa menyediakan daftar argumen. |
| 8 | 8 | ||
| 9 | ```yuescript | 9 | ```yuescript |
| 10 | my_object = { | 10 | my_object = { |
| @@ -16,12 +16,12 @@ run_callback = (func) -> | |||
| 16 | print "running callback..." | 16 | print "running callback..." |
| 17 | func! | 17 | func! |
| 18 | 18 | ||
| 19 | -- this will not work: | 19 | -- ini tidak akan berfungsi: |
| 20 | -- the function has to no reference to my_object | 20 | -- fungsi tidak memiliki referensi ke my_object |
| 21 | run_callback my_object.write | 21 | run_callback my_object.write |
| 22 | 22 | ||
| 23 | -- function stub syntax | 23 | -- sintaks stub fungsi |
| 24 | -- lets us bundle the object into a new function | 24 | -- memungkinkan kita membundel objek ke fungsi baru |
| 25 | run_callback my_object\write | 25 | run_callback my_object\write |
| 26 | ``` | 26 | ``` |
| 27 | <YueDisplay> | 27 | <YueDisplay> |
| @@ -36,12 +36,12 @@ run_callback = (func) -> | |||
| 36 | print "running callback..." | 36 | print "running callback..." |
| 37 | func! | 37 | func! |
| 38 | 38 | ||
| 39 | -- this will not work: | 39 | -- ini tidak akan berfungsi: |
| 40 | -- the function has to no reference to my_object | 40 | -- fungsi tidak memiliki referensi ke my_object |
| 41 | run_callback my_object.write | 41 | run_callback my_object.write |
| 42 | 42 | ||
| 43 | -- function stub syntax | 43 | -- sintaks stub fungsi |
| 44 | -- lets us bundle the object into a new function | 44 | -- memungkinkan kita membundel objek ke fungsi baru |
| 45 | run_callback my_object\write | 45 | run_callback my_object\write |
| 46 | ``` | 46 | ``` |
| 47 | 47 | ||
diff --git a/doc/docs/id-id/doc/getting-started/installation.md b/doc/docs/id-id/doc/getting-started/installation.md index a93ddfd..2809cca 100644 --- a/doc/docs/id-id/doc/getting-started/installation.md +++ b/doc/docs/id-id/doc/getting-started/installation.md | |||
| @@ -1,43 +1,43 @@ | |||
| 1 | # Installation | 1 | # Instalasi |
| 2 | 2 | ||
| 3 | ## Lua Module | 3 | ## Modul Lua |
| 4 | 4 | ||
| 5 | Install [luarocks](https://luarocks.org), a package manager for Lua modules. Then install it as a Lua module and executable with: | 5 | Instal [luarocks](https://luarocks.org), manajer paket untuk modul Lua. Lalu instal sebagai modul Lua dan executable dengan: |
| 6 | 6 | ||
| 7 | ```shell | 7 | ```shell |
| 8 | luarocks install yuescript | 8 | luarocks install yuescript |
| 9 | ``` | 9 | ``` |
| 10 | 10 | ||
| 11 | Or you can build `yue.so` file with: | 11 | Atau Anda dapat membangun file `yue.so` dengan: |
| 12 | 12 | ||
| 13 | ```shell | 13 | ```shell |
| 14 | make shared LUAI=/usr/local/include/lua LUAL=/usr/local/lib/lua | 14 | make shared LUAI=/usr/local/include/lua LUAL=/usr/local/lib/lua |
| 15 | ``` | 15 | ``` |
| 16 | 16 | ||
| 17 | Then get the binary file from path **bin/shared/yue.so**. | 17 | Lalu ambil file biner dari path **bin/shared/yue.so**. |
| 18 | 18 | ||
| 19 | ## Build Binary Tool | 19 | ## Membangun Tool Biner |
| 20 | 20 | ||
| 21 | Clone this repo, then build and install executable with: | 21 | Klon repo ini, lalu bangun dan instal executable dengan: |
| 22 | 22 | ||
| 23 | ```shell | 23 | ```shell |
| 24 | make install | 24 | make install |
| 25 | ``` | 25 | ``` |
| 26 | 26 | ||
| 27 | Build YueScript tool without macro feature: | 27 | Bangun tool YueScript tanpa fitur macro: |
| 28 | 28 | ||
| 29 | ```shell | 29 | ```shell |
| 30 | make install NO_MACRO=true | 30 | make install NO_MACRO=true |
| 31 | ``` | 31 | ``` |
| 32 | 32 | ||
| 33 | Build YueScript tool without built-in Lua binary: | 33 | Bangun tool YueScript tanpa biner Lua bawaan: |
| 34 | 34 | ||
| 35 | ```shell | 35 | ```shell |
| 36 | make install NO_LUA=true | 36 | make install NO_LUA=true |
| 37 | ``` | 37 | ``` |
| 38 | 38 | ||
| 39 | ## Download Precompiled Binary | 39 | ## Unduh Biner Pra-kompilasi |
| 40 | 40 | ||
| 41 | You can download precompiled binary files, including binary executable files compatible with different Lua versions and library files. | 41 | Anda dapat mengunduh file biner pra-kompilasi, termasuk file executable biner yang kompatibel dengan berbagai versi Lua dan file library. |
| 42 | 42 | ||
| 43 | Download precompiled binary files from [here](https://github.com/IppClub/YueScript/releases). | 43 | Unduh file biner pra-kompilasi dari [sini](https://github.com/IppClub/YueScript/releases). |
diff --git a/doc/docs/id-id/doc/getting-started/introduction.md b/doc/docs/id-id/doc/getting-started/introduction.md index a9a9389..c2fc236 100644 --- a/doc/docs/id-id/doc/getting-started/introduction.md +++ b/doc/docs/id-id/doc/getting-started/introduction.md | |||
| @@ -1,10 +1,10 @@ | |||
| 1 | # Introduction | 1 | # Pendahuluan |
| 2 | 2 | ||
| 3 | YueScript is a dynamic language that compiles to Lua. And it's a [MoonScript](https://github.com/leafo/moonscript) dialect. The codes written in YueScript are expressive and extremely concise. And it is suitable for writing some changing application logic with more maintainable codes and runs in a Lua embeded environment such as games or website servers. | 3 | YueScript adalah bahasa dinamis yang dikompilasi ke Lua, dan merupakan dialek [MoonScript](https://github.com/leafo/moonscript). Kode yang ditulis dengan YueScript ekspresif dan sangat ringkas. YueScript cocok untuk menulis logika aplikasi yang sering berubah dengan kode yang lebih mudah dipelihara, serta berjalan di lingkungan embed Lua seperti game atau server situs web. |
| 4 | 4 | ||
| 5 | Yue (月) is the name of moon in Chinese and it's pronounced as [jyɛ]. | 5 | Yue (月) adalah kata untuk bulan dalam bahasa Tionghoa dan diucapkan sebagai [jyɛ]. |
| 6 | 6 | ||
| 7 | ## An Overview of YueScript | 7 | ## Ikhtisar YueScript |
| 8 | 8 | ||
| 9 | ```yuescript | 9 | ```yuescript |
| 10 | -- import syntax | 10 | -- import syntax |
| @@ -48,7 +48,7 @@ with apple | |||
| 48 | p .size, .color, .<index> if .<>? | 48 | p .size, .color, .<index> if .<>? |
| 49 | 49 | ||
| 50 | -- js-like export syntax | 50 | -- js-like export syntax |
| 51 | export 🌛 = "月之脚本" | 51 | export 🌛 = "Skrip Bulan" |
| 52 | ``` | 52 | ``` |
| 53 | 53 | ||
| 54 | <YueDisplay> | 54 | <YueDisplay> |
| @@ -95,11 +95,11 @@ with apple | |||
| 95 | p .size, .color, .<index> if .<>? | 95 | p .size, .color, .<index> if .<>? |
| 96 | 96 | ||
| 97 | -- js-like export syntax | 97 | -- js-like export syntax |
| 98 | export 🌛 = "月之脚本" | 98 | export 🌛 = "Skrip Bulan" |
| 99 | ``` | 99 | ``` |
| 100 | 100 | ||
| 101 | </YueDisplay> | 101 | </YueDisplay> |
| 102 | 102 | ||
| 103 | ## About Dora SSR | 103 | ## Tentang Dora SSR |
| 104 | 104 | ||
| 105 | YueScript is being developed and maintained alongside the open-source game engine [Dora SSR](https://github.com/Dora-SSR/Dora-SSR). It has been used to create engine tools, game demos and prototypes, validating its capabilities in real-world scenarios while enhancing the Dora SSR development experience. \ No newline at end of file | 105 | YueScript dikembangkan dan dipelihara bersama mesin game open-source [Dora SSR](https://github.com/Dora-SSR/Dora-SSR). YueScript telah digunakan untuk membuat alat mesin, demo game, dan prototipe, membuktikan kemampuannya dalam skenario dunia nyata sekaligus meningkatkan pengalaman pengembangan Dora SSR. |
diff --git a/doc/docs/id-id/doc/getting-started/usage.md b/doc/docs/id-id/doc/getting-started/usage.md index 45161c6..85cad07 100644 --- a/doc/docs/id-id/doc/getting-started/usage.md +++ b/doc/docs/id-id/doc/getting-started/usage.md | |||
| @@ -1,20 +1,20 @@ | |||
| 1 | # Usage | 1 | # Penggunaan |
| 2 | 2 | ||
| 3 | ## Lua Module | 3 | ## Modul Lua |
| 4 | 4 | ||
| 5 | Use YueScript module in Lua: | 5 | Gunakan modul YueScript di Lua: |
| 6 | 6 | ||
| 7 | * **Case 1** | 7 | * **Kasus 1** |
| 8 | 8 | ||
| 9 | Require "your_yuescript_entry.yue" in Lua. | 9 | Require "your_yuescript_entry.yue" di Lua. |
| 10 | ```Lua | 10 | ```Lua |
| 11 | require("yue")("your_yuescript_entry") | 11 | require("yue")("your_yuescript_entry") |
| 12 | ``` | 12 | ``` |
| 13 | And this code still works when you compile "your_yuescript_entry.yue" to "your_yuescript_entry.lua" in the same path. In the rest YueScript files just use the normal **require** or **import**. The code line numbers in error messages will also be handled correctly. | 13 | 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. |
| 14 | 14 | ||
| 15 | * **Case 2** | 15 | * **Kasus 2** |
| 16 | 16 | ||
| 17 | Require YueScript module and rewite message by hand. | 17 | Require modul YueScript dan tulis ulang pesan secara manual. |
| 18 | 18 | ||
| 19 | ```lua | 19 | ```lua |
| 20 | local yue = require("yue") | 20 | local yue = require("yue") |
| @@ -26,9 +26,9 @@ Use YueScript module in Lua: | |||
| 26 | end) | 26 | end) |
| 27 | ``` | 27 | ``` |
| 28 | 28 | ||
| 29 | * **Case 3** | 29 | * **Kasus 3** |
| 30 | 30 | ||
| 31 | Use the YueScript compiler function in Lua. | 31 | Gunakan fungsi kompiler YueScript di Lua. |
| 32 | 32 | ||
| 33 | ```lua | 33 | ```lua |
| 34 | local yue = require("yue") | 34 | local yue = require("yue") |
| @@ -48,64 +48,65 @@ Use YueScript module in Lua: | |||
| 48 | }) | 48 | }) |
| 49 | ``` | 49 | ``` |
| 50 | 50 | ||
| 51 | ## YueScript Tool | 51 | ## Tool YueScript |
| 52 | 52 | ||
| 53 | Use YueScript tool with: | 53 | Gunakan tool YueScript dengan: |
| 54 | 54 | ||
| 55 | ```shell | 55 | ```shell |
| 56 | > yue -h | 56 | > yue -h |
| 57 | Usage: yue | 57 | Penggunaan: yue |
| 58 | [options] [<file/directory>] ... | 58 | [opsi] [<file/direktori>] ... |
| 59 | yue -e <code_or_file> [args...] | 59 | yue -e <kode_atau_file> [argumen...] |
| 60 | yue -w [<directory>] [options] | 60 | yue -w [<direktori>] [opsi] |
| 61 | yue - | 61 | yue - |
| 62 | 62 | ||
| 63 | Notes: | 63 | Catatan: |
| 64 | - '-' / '--' must be the first and only argument. | 64 | - '-' / '--' harus menjadi argumen pertama dan satu-satunya. |
| 65 | - '-o/--output' can not be used with multiple input files. | 65 | - '-o/--output' tidak dapat digunakan dengan beberapa file input. |
| 66 | - '-w/--watch' can not be used with file input (directory only). | 66 | - '-w/--watch' tidak dapat digunakan dengan file input (khusus direktori). |
| 67 | - with '-e/--execute', remaining tokens are treated as script args. | 67 | - dengan '-e/--execute', token sisanya dianggap sebagai argumen skrip. |
| 68 | 68 | ||
| 69 | Options: | 69 | Opsi: |
| 70 | -h, --help Show this help message and exit. | 70 | -h, --help Tampilkan pesan bantuan ini dan keluar. |
| 71 | -e <str>, --execute <str> Execute a file or raw codes | 71 | -e <str>, --execute <str> Eksekusi file atau kode mentah |
| 72 | -m, --minify Generate minified codes | 72 | -m, --minify Menghasilkan kode yang sudah diminimasi |
| 73 | -r, --rewrite Rewrite output to match original line numbers | 73 | -r, --rewrite Tulis ulang output agar sesuai dengan nomor baris asal |
| 74 | -t <output_to>, --output-to <output_to> | 74 | -t <output_to>, --output-to <output_to> |
| 75 | Specify where to place compiled files | 75 | Tentukan lokasi untuk menaruh file hasil kompilasi |
| 76 | -o <file>, --output <file> Write output to file | 76 | -o <file>, --output <file> Tulis output ke file |
| 77 | -p, --print Write output to standard out | 77 | -p, --print Tulis output ke standar output |
| 78 | -b, --benchmark Dump compile time (doesn't write output) | 78 | -b, --benchmark Tampilkan waktu kompilasi (tanpa menulis output) |
| 79 | -g, --globals Dump global variables used in NAME LINE COLUMN | 79 | -g, --globals Tampilkan variabel global yang digunakan dalam FORMAT NAMA BARIS KOLOM |
| 80 | -s, --spaces Use spaces in generated codes instead of tabs | 80 | -s, --spaces Pakai spasi di kode hasil kompilasi (bukan tab) |
| 81 | -l, --line-numbers Write line numbers from source codes | 81 | -l, --line-numbers Tulis nomor baris dari kode sumber |
| 82 | -j, --no-implicit-return Disable implicit return at end of file | 82 | -j, --no-implicit-return Nonaktifkan return implisit di akhir file |
| 83 | -c, --reserve-comments Reserve comments before statement from source codes | 83 | -c, --reserve-comments Pertahankan komentar sebelum pernyataan dari kode sumber |
| 84 | -w [<dir>], --watch [<dir>] | 84 | -w [<dir>], --watch [<dir>] |
| 85 | Watch changes and compile every file under directory | 85 | Pantau perubahan dan kompilasi setiap file di bawah direktori |
| 86 | -v, --version Print version | 86 | -v, --version Tampilkan versi |
| 87 | - Read from standard in, print to standard out | 87 | - Baca dari standar input, tulis ke standar output |
| 88 | (Must be first and only argument) | 88 | (harus menjadi argumen pertama dan satu-satunya) |
| 89 | -- Same as '-' (kept for backward compatibility) | 89 | -- Sama dengan '-', dipertahankan untuk kompatibilitas lama |
| 90 | 90 | ||
| 91 | --target <version> Specify the Lua version that codes will be generated to | 91 | --target <versi> Tentukan versi Lua yang akan dihasilkan kodenya |
| 92 | (version can only be 5.1 to 5.5) | 92 | (versi hanya bisa dari 5.1 sampai 5.5) |
| 93 | --path <path_str> Append an extra Lua search path string to package.path | 93 | --path <path_str> Tambahkan path pencarian Lua tambahan ke package.path |
| 94 | --<key>=<value> Pass compiler option in key=value form (existing behavior) | 94 | --<key>=<value> Kirim opsi kompilasi dalam bentuk key=value (perilaku standar) |
| 95 | 95 | ||
| 96 | Execute without options to enter REPL, type symbol '$' | 96 | Jalankan tanpa opsi untuk masuk ke REPL, ketik simbol '$' |
| 97 | in a single line to start/stop multi-line mode | 97 | dalam satu baris untuk memulai/mengakhiri mode multi-baris |
| 98 | ``` | 98 | ``` |
| 99 | Use cases: | ||
| 100 | 99 | ||
| 101 | Recursively compile every YueScript file with extension **.yue** under current path: **yue .** | 100 | Gunakan kasus: |
| 102 | 101 | ||
| 103 | Compile and save results to a target path: **yue -t /target/path/ .** | 102 | Kompilasi semua file YueScript dengan ekstensi **.yue** secara rekursif di bawah path saat ini: **yue .** |
| 104 | 103 | ||
| 105 | Compile and reserve debug info: **yue -l .** | 104 | Kompilasi dan simpan hasil ke path target: **yue -t /target/path/ .** |
| 106 | 105 | ||
| 107 | Compile and generate minified codes: **yue -m .** | 106 | Kompilasi dan pertahankan info debug: **yue -l .** |
| 108 | 107 | ||
| 109 | Execute raw codes: **yue -e 'print 123'** | 108 | Kompilasi dan hasilkan kode yang diminisasi: **yue -m .** |
| 110 | 109 | ||
| 111 | Execute a YueScript file: **yue -e main.yue** | 110 | Eksekusi kode mentah: **yue -e 'print 123'** |
| 111 | |||
| 112 | Eksekusi file YueScript: **yue -e main.yue** | ||
diff --git a/doc/docs/id-id/doc/index.md b/doc/docs/id-id/doc/index.md index b7f609b..5df2cc3 100755 --- a/doc/docs/id-id/doc/index.md +++ b/doc/docs/id-id/doc/index.md | |||
| @@ -1,11 +1,11 @@ | |||
| 1 | --- | 1 | --- |
| 2 | title: Reference | 2 | title: Referensi |
| 3 | --- | 3 | --- |
| 4 | 4 | ||
| 5 | # YueScript Documentation | 5 | # Dokumentasi YueScript |
| 6 | 6 | ||
| 7 | <img src="/image/yuescript.svg" width="250px" height="250px" alt="logo" style="padding-top: 3em; padding-bottom: 2em;"/> | 7 | <img src="/image/yuescript.svg" width="250px" height="250px" alt="logo" style="padding-top: 3em; padding-bottom: 2em;"/> |
| 8 | 8 | ||
| 9 | Welcome to the <b>YueScript</b> official documentation!<br/> | 9 | Selamat datang di dokumentasi resmi <b>YueScript</b>!<br/> |
| 10 | Here you can find the language features, usage, reference examples and resources.<br/> | 10 | Di sini Anda dapat menemukan fitur bahasa, penggunaan, contoh referensi, dan sumber daya.<br/> |
| 11 | Please select a chapter from the sidebar to start learning about YueScript. | 11 | Silakan pilih bab dari sidebar untuk mulai mempelajari YueScript. |
diff --git a/doc/docs/id-id/doc/language-basics/attributes.md b/doc/docs/id-id/doc/language-basics/attributes.md index e6fd5a7..5b92947 100644 --- a/doc/docs/id-id/doc/language-basics/attributes.md +++ b/doc/docs/id-id/doc/language-basics/attributes.md | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | # Attributes | 1 | # Atribut |
| 2 | 2 | ||
| 3 | Syntax support for Lua 5.4 attributes. And you can still use both the `const` and `close` declaration and get constant check and scoped callback working when targeting Lua versions below 5.4. | 3 | Dukungan sintaks untuk atribut Lua 5.4. Anda juga masih bisa menggunakan deklarasi `const` dan `close` dan mendapatkan pemeriksaan konstanta serta callback berbatas-scope ketika menargetkan versi Lua di bawah 5.4. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | const a = 123 | 6 | const a = 123 |
| @@ -15,7 +15,7 @@ close _ = <close>: -> print "Out of scope." | |||
| 15 | 15 | ||
| 16 | </YueDisplay> | 16 | </YueDisplay> |
| 17 | 17 | ||
| 18 | You can do desctructuring with variables attributed as constant. | 18 | Anda dapat melakukan destrukturisasi dengan variabel yang diberi atribut sebagai konstanta. |
| 19 | 19 | ||
| 20 | ```yuescript | 20 | ```yuescript |
| 21 | const {:a, :b, c, d} = tb | 21 | const {:a, :b, c, d} = tb |
| @@ -30,7 +30,7 @@ const {:a, :b, c, d} = tb | |||
| 30 | 30 | ||
| 31 | </YueDisplay> | 31 | </YueDisplay> |
| 32 | 32 | ||
| 33 | You can also declare a global variable to be `const`. | 33 | Anda juga bisa mendeklarasikan variabel global sebagai `const`. |
| 34 | 34 | ||
| 35 | ```yuescript | 35 | ```yuescript |
| 36 | global const Constant = 123 | 36 | global const Constant = 123 |
diff --git a/doc/docs/id-id/doc/language-basics/comment.md b/doc/docs/id-id/doc/language-basics/comment.md index b67c97d..99f7b51 100644 --- a/doc/docs/id-id/doc/language-basics/comment.md +++ b/doc/docs/id-id/doc/language-basics/comment.md | |||
| @@ -1,13 +1,13 @@ | |||
| 1 | # Comment | 1 | # Komentar |
| 2 | 2 | ||
| 3 | ```yuescript | 3 | ```yuescript |
| 4 | -- I am a comment | 4 | -- Saya adalah komentar |
| 5 | 5 | ||
| 6 | str = --[[ | 6 | str = --[[ |
| 7 | This is a multi-line comment. | 7 | Ini komentar multi-baris. |
| 8 | It's OK. | 8 | Tidak masalah. |
| 9 | ]] strA \ -- comment 1 | 9 | ]] strA \ -- komentar 1 |
| 10 | .. strB \ -- comment 2 | 10 | .. strB \ -- komentar 2 |
| 11 | .. strC | 11 | .. strC |
| 12 | 12 | ||
| 13 | func --[[port]] 3000, --[[ip]] "192.168.1.1" | 13 | func --[[port]] 3000, --[[ip]] "192.168.1.1" |
| @@ -15,13 +15,13 @@ func --[[port]] 3000, --[[ip]] "192.168.1.1" | |||
| 15 | <YueDisplay> | 15 | <YueDisplay> |
| 16 | 16 | ||
| 17 | ```yue | 17 | ```yue |
| 18 | -- I am a comment | 18 | -- Saya adalah komentar |
| 19 | 19 | ||
| 20 | str = --[[ | 20 | str = --[[ |
| 21 | This is a multi-line comment. | 21 | Ini komentar multi-baris. |
| 22 | It's OK. | 22 | Tidak masalah. |
| 23 | ]] strA \ -- comment 1 | 23 | ]] strA \ -- komentar 1 |
| 24 | .. strB \ -- comment 2 | 24 | .. strB \ -- komentar 2 |
| 25 | .. strC | 25 | .. strC |
| 26 | 26 | ||
| 27 | func --[[port]] 3000, --[[ip]] "192.168.1.1" | 27 | func --[[port]] 3000, --[[ip]] "192.168.1.1" |
diff --git a/doc/docs/id-id/doc/language-basics/literals.md b/doc/docs/id-id/doc/language-basics/literals.md index e097c62..c17c310 100644 --- a/doc/docs/id-id/doc/language-basics/literals.md +++ b/doc/docs/id-id/doc/language-basics/literals.md | |||
| @@ -1,15 +1,15 @@ | |||
| 1 | # Literals | 1 | # Literal |
| 2 | 2 | ||
| 3 | All of the primitive literals in Lua can be used. This applies to numbers, strings, booleans, and **nil**. | 3 | Semua literal primitif di Lua dapat digunakan. Ini berlaku untuk angka, string, boolean, dan **nil**. |
| 4 | 4 | ||
| 5 | Unlike Lua, Line breaks are allowed inside of single and double quote strings without an escape sequence: | 5 | Berbeda dengan Lua, pemisah baris diizinkan di dalam string bertanda kutip tunggal maupun ganda tanpa urutan escape: |
| 6 | 6 | ||
| 7 | ```yuescript | 7 | ```yuescript |
| 8 | some_string = "Here is a string | 8 | some_string = "Here is a string |
| 9 | that has a line break in it." | 9 | that has a line break in it." |
| 10 | 10 | ||
| 11 | -- You can mix expressions into string literals using #{} syntax. | 11 | -- Anda dapat mencampur ekspresi ke dalam literal string dengan sintaks #{}. |
| 12 | -- String interpolation is only available in double quoted strings. | 12 | -- Interpolasi string hanya tersedia pada string dengan tanda kutip ganda. |
| 13 | print "I am #{math.random! * 100}% sure." | 13 | print "I am #{math.random! * 100}% sure." |
| 14 | ``` | 14 | ``` |
| 15 | <YueDisplay> | 15 | <YueDisplay> |
| @@ -18,16 +18,16 @@ print "I am #{math.random! * 100}% sure." | |||
| 18 | some_string = "Here is a string | 18 | some_string = "Here is a string |
| 19 | that has a line break in it." | 19 | that has a line break in it." |
| 20 | 20 | ||
| 21 | -- You can mix expressions into string literals using #{} syntax. | 21 | -- Anda dapat mencampur ekspresi ke dalam literal string dengan sintaks #{}. |
| 22 | -- String interpolation is only available in double quoted strings. | 22 | -- Interpolasi string hanya tersedia pada string dengan tanda kutip ganda. |
| 23 | print "I am #{math.random! * 100}% sure." | 23 | print "I am #{math.random! * 100}% sure." |
| 24 | ``` | 24 | ``` |
| 25 | 25 | ||
| 26 | </YueDisplay> | 26 | </YueDisplay> |
| 27 | 27 | ||
| 28 | ## Number Literals | 28 | ## Literal Angka |
| 29 | 29 | ||
| 30 | You can use underscores in a number literal to increase readability. | 30 | Anda bisa menggunakan garis bawah pada literal angka untuk meningkatkan keterbacaan. |
| 31 | 31 | ||
| 32 | ```yuescript | 32 | ```yuescript |
| 33 | integer = 1_000_000 | 33 | integer = 1_000_000 |
| @@ -44,9 +44,9 @@ binary = 0B10011 | |||
| 44 | 44 | ||
| 45 | </YueDisplay> | 45 | </YueDisplay> |
| 46 | 46 | ||
| 47 | ## YAML Multiline String | 47 | ## String Multibaris YAML |
| 48 | 48 | ||
| 49 | The `|` prefix introduces a YAML-style multiline string literal: | 49 | Prefiks `|` memperkenalkan literal string multibaris bergaya YAML: |
| 50 | 50 | ||
| 51 | ```yuescript | 51 | ```yuescript |
| 52 | str = | | 52 | str = | |
| @@ -67,9 +67,9 @@ str = | | |||
| 67 | 67 | ||
| 68 | </YueDisplay> | 68 | </YueDisplay> |
| 69 | 69 | ||
| 70 | This allows writing structured multiline text conveniently. All line breaks and indentation are preserved relative to the first non-empty line, and expressions inside `#{...}` are interpolated automatically as `tostring(expr)`. | 70 | Ini memungkinkan penulisan teks multibaris terstruktur dengan mudah. Semua pemisah baris dan indentasi dipertahankan relatif terhadap baris non-kosong pertama, dan ekspresi di dalam `#{...}` diinterpolasi otomatis sebagai `tostring(expr)`. |
| 71 | 71 | ||
| 72 | YAML Multiline String automatically detects the common leading whitespace prefix (minimum indentation across all non-empty lines) and removes it from all lines. This makes it easy to indent your code visually without affecting the resulting string content. | 72 | String Multibaris YAML secara otomatis mendeteksi prefiks spasi awal yang sama (indentasi minimum di seluruh baris non-kosong) dan menghapusnya dari semua baris. Ini memudahkan untuk mengindentasi kode secara visual tanpa memengaruhi isi string yang dihasilkan. |
| 73 | 73 | ||
| 74 | ```yuescript | 74 | ```yuescript |
| 75 | fn = -> | 75 | fn = -> |
| @@ -90,9 +90,9 @@ fn = -> | |||
| 90 | 90 | ||
| 91 | </YueDisplay> | 91 | </YueDisplay> |
| 92 | 92 | ||
| 93 | Internal indentation is preserved relative to the removed common prefix, allowing clean nested structures. | 93 | Indentasi internal dipertahankan relatif terhadap prefiks umum yang dihapus, sehingga struktur bertingkat tetap rapi. |
| 94 | 94 | ||
| 95 | All special characters like quotes (`"`) and backslashes (`\`) in the YAMLMultiline block are automatically escaped so that the generated Lua string is syntactically valid and behaves as expected. | 95 | Semua karakter khusus seperti tanda kutip (`"`) dan backslash (`\`) di dalam blok YAMLMultiline di-escape secara otomatis agar string Lua yang dihasilkan valid secara sintaks dan berperilaku sebagaimana mestinya. |
| 96 | 96 | ||
| 97 | ```yuescript | 97 | ```yuescript |
| 98 | str = | | 98 | str = | |
diff --git a/doc/docs/id-id/doc/language-basics/operator.md b/doc/docs/id-id/doc/language-basics/operator.md index 9a2e89b..f3fe092 100644 --- a/doc/docs/id-id/doc/language-basics/operator.md +++ b/doc/docs/id-id/doc/language-basics/operator.md | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | # Operator | 1 | # Operator |
| 2 | 2 | ||
| 3 | All of Lua's binary and unary operators are available. Additionally **!=** is as an alias for **~=**, and either **\\** or **::** can be used to write a chaining function call like `tb\func!` or `tb::func!`. And Yuescipt offers some other special operators to write more expressive codes. | 3 | Semua operator biner dan unari Lua tersedia. Selain itu **!=** adalah alias untuk **~=**, dan **\\** atau **::** bisa digunakan untuk menulis pemanggilan fungsi berantai seperti `tb\func!` atau `tb::func!`. YueScript juga menawarkan beberapa operator khusus lain untuk menulis kode yang lebih ekspresif. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | tb\func! if tb ~= nil | 6 | tb\func! if tb ~= nil |
| @@ -15,9 +15,9 @@ tb::func! if tb != nil | |||
| 15 | 15 | ||
| 16 | </YueDisplay> | 16 | </YueDisplay> |
| 17 | 17 | ||
| 18 | ## Chaining Comparisons | 18 | ## Perbandingan Berantai |
| 19 | 19 | ||
| 20 | Comparisons can be arbitrarily chained: | 20 | Perbandingan bisa dirantai secara bebas: |
| 21 | 21 | ||
| 22 | ```yuescript | 22 | ```yuescript |
| 23 | print 1 < 2 <= 2 < 3 == 3 > 2 >= 1 == 1 < 3 != 5 | 23 | print 1 < 2 <= 2 < 3 == 3 > 2 >= 1 == 1 < 3 != 5 |
| @@ -40,7 +40,7 @@ print 1 <= a <= 10 | |||
| 40 | 40 | ||
| 41 | </YueDisplay> | 41 | </YueDisplay> |
| 42 | 42 | ||
| 43 | Note the evaluation behavior of chained comparisons: | 43 | Perhatikan perilaku evaluasi perbandingan berantai: |
| 44 | 44 | ||
| 45 | ```yuescript | 45 | ```yuescript |
| 46 | v = (x) -> | 46 | v = (x) -> |
| @@ -91,11 +91,11 @@ print v(1) > v(2) <= v(3) | |||
| 91 | 91 | ||
| 92 | </YueDisplay> | 92 | </YueDisplay> |
| 93 | 93 | ||
| 94 | The middle expression is only evaluated once, rather than twice as it would be if the expression were written as `v(1) < v(2) and v(2) <= v(3)`. However, the order of evaluations in a chained comparison is undefined. It is strongly recommended not to use expressions with side effects (such as printing) in chained comparisons. If side effects are required, the short-circuit `and` operator should be used explicitly. | 94 | Ekspresi tengah hanya dievaluasi sekali, bukan dua kali seperti jika ekspresi ditulis sebagai `v(1) < v(2) and v(2) <= v(3)`. Namun, urutan evaluasi pada perbandingan berantai tidak didefinisikan. Sangat disarankan untuk tidak menggunakan ekspresi dengan efek samping (seperti `print`) di perbandingan berantai. Jika efek samping diperlukan, operator short-circuit `and` sebaiknya digunakan secara eksplisit. |
| 95 | 95 | ||
| 96 | ## Table Appending | 96 | ## Menambahkan ke Tabel |
| 97 | 97 | ||
| 98 | The **[] =** operator is used to append values to tables. | 98 | Operator **[] =** digunakan untuk menambahkan nilai ke tabel. |
| 99 | 99 | ||
| 100 | ```yuescript | 100 | ```yuescript |
| 101 | tab = [] | 101 | tab = [] |
| @@ -110,13 +110,13 @@ tab[] = "Value" | |||
| 110 | 110 | ||
| 111 | </YueDisplay> | 111 | </YueDisplay> |
| 112 | 112 | ||
| 113 | You can also use the spread operator `...` to append all elements from one list to another: | 113 | Anda juga bisa memakai operator spread `...` untuk menambahkan semua elemen dari satu list ke list lain: |
| 114 | 114 | ||
| 115 | ```yuescript | 115 | ```yuescript |
| 116 | tbA = [1, 2, 3] | 116 | tbA = [1, 2, 3] |
| 117 | tbB = [4, 5, 6] | 117 | tbB = [4, 5, 6] |
| 118 | tbA[] = ...tbB | 118 | tbA[] = ...tbB |
| 119 | -- tbA is now [1, 2, 3, 4, 5, 6] | 119 | -- tbA sekarang [1, 2, 3, 4, 5, 6] |
| 120 | ``` | 120 | ``` |
| 121 | <YueDisplay> | 121 | <YueDisplay> |
| 122 | 122 | ||
| @@ -124,14 +124,14 @@ tbA[] = ...tbB | |||
| 124 | tbA = [1, 2, 3] | 124 | tbA = [1, 2, 3] |
| 125 | tbB = [4, 5, 6] | 125 | tbB = [4, 5, 6] |
| 126 | tbA[] = ...tbB | 126 | tbA[] = ...tbB |
| 127 | -- tbA is now [1, 2, 3, 4, 5, 6] | 127 | -- tbA sekarang [1, 2, 3, 4, 5, 6] |
| 128 | ``` | 128 | ``` |
| 129 | 129 | ||
| 130 | </YueDisplay> | 130 | </YueDisplay> |
| 131 | 131 | ||
| 132 | ## Table Spreading | 132 | ## Penyebaran Tabel |
| 133 | 133 | ||
| 134 | You can concatenate array tables or hash tables using spread operator `...` before expressions in table literals. | 134 | Anda bisa menggabungkan tabel array atau tabel hash menggunakan operator spread `...` sebelum ekspresi di literal tabel. |
| 135 | 135 | ||
| 136 | ```yuescript | 136 | ```yuescript |
| 137 | parts = | 137 | parts = |
| @@ -170,9 +170,9 @@ merge = {...a, ...b} | |||
| 170 | 170 | ||
| 171 | </YueDisplay> | 171 | </YueDisplay> |
| 172 | 172 | ||
| 173 | ## Table Reversed Indexing | 173 | ## Indeks Balik Tabel |
| 174 | 174 | ||
| 175 | You can use the **#** operator to get the last elements of a table. | 175 | Anda dapat menggunakan operator **#** untuk mendapatkan elemen terakhir dari tabel. |
| 176 | 176 | ||
| 177 | ```yuescript | 177 | ```yuescript |
| 178 | last = data.items[#] | 178 | last = data.items[#] |
| @@ -191,11 +191,11 @@ data.items[#] = 1 | |||
| 191 | 191 | ||
| 192 | ## Metatable | 192 | ## Metatable |
| 193 | 193 | ||
| 194 | The **<>** operator can be used as a shortcut for metatable manipulation. | 194 | Operator **<>** dapat digunakan sebagai pintasan untuk manipulasi metatable. |
| 195 | 195 | ||
| 196 | ### Metatable Creation | 196 | ### Pembuatan Metatable |
| 197 | 197 | ||
| 198 | Create normal table with empty bracekets **<>** or metamethod key which is surrounded by **<>**. | 198 | Buat tabel normal dengan tanda kurung siku kosong **<>** atau kunci metamethod yang dikelilingi oleh **<>**. |
| 199 | 199 | ||
| 200 | ```yuescript | 200 | ```yuescript |
| 201 | mt = {} | 201 | mt = {} |
| @@ -203,7 +203,7 @@ add = (right) => <>: mt, value: @value + right.value | |||
| 203 | mt.__add = add | 203 | mt.__add = add |
| 204 | 204 | ||
| 205 | a = <>: mt, value: 1 | 205 | a = <>: mt, value: 1 |
| 206 | -- set field with variable of the same name | 206 | -- set field dengan variabel bernama sama |
| 207 | b = :<add>, value: 2 | 207 | b = :<add>, value: 2 |
| 208 | c = <add>: mt.__add, value: 3 | 208 | c = <add>: mt.__add, value: 3 |
| 209 | 209 | ||
| @@ -220,7 +220,7 @@ add = (right) => <>: mt, value: @value + right.value | |||
| 220 | mt.__add = add | 220 | mt.__add = add |
| 221 | 221 | ||
| 222 | a = <>: mt, value: 1 | 222 | a = <>: mt, value: 1 |
| 223 | -- set field with variable of the same name | 223 | -- set field dengan variabel bernama sama |
| 224 | b = :<add>, value: 2 | 224 | b = :<add>, value: 2 |
| 225 | c = <add>: mt.__add, value: 3 | 225 | c = <add>: mt.__add, value: 3 |
| 226 | 226 | ||
| @@ -232,12 +232,12 @@ close _ = <close>: -> print "out of scope" | |||
| 232 | 232 | ||
| 233 | </YueDisplay> | 233 | </YueDisplay> |
| 234 | 234 | ||
| 235 | ### Metatable Accessing | 235 | ### Mengakses Metatable |
| 236 | 236 | ||
| 237 | Accessing metatable with **<>** or metamethod name surrounded by **<>** or writing some expression in **<>**. | 237 | Akses metatable dengan **<>**, nama metamethod yang dikelilingi **<>**, atau menulis ekspresi di dalam **<>**. |
| 238 | 238 | ||
| 239 | ```yuescript | 239 | ```yuescript |
| 240 | -- create with metatable containing field "value" | 240 | -- dibuat dengan metatable yang berisi field "value" |
| 241 | tb = <"value">: 123 | 241 | tb = <"value">: 123 |
| 242 | tb.<index> = tb.<> | 242 | tb.<index> = tb.<> |
| 243 | print tb.value | 243 | print tb.value |
| @@ -248,7 +248,7 @@ print tb.item | |||
| 248 | <YueDisplay> | 248 | <YueDisplay> |
| 249 | 249 | ||
| 250 | ```yue | 250 | ```yue |
| 251 | -- create with metatable containing field "value" | 251 | -- dibuat dengan metatable yang berisi field "value" |
| 252 | tb = <"value">: 123 | 252 | tb = <"value">: 123 |
| 253 | tb.<index> = tb.<> | 253 | tb.<index> = tb.<> |
| 254 | print tb.value | 254 | print tb.value |
| @@ -258,9 +258,9 @@ print tb.item | |||
| 258 | 258 | ||
| 259 | </YueDisplay> | 259 | </YueDisplay> |
| 260 | 260 | ||
| 261 | ### Metatable Destructure | 261 | ### Destrukturisasi Metatable |
| 262 | 262 | ||
| 263 | Destruct metatable with metamethod key surrounded by **<>**. | 263 | Destrukturisasi metatable dengan kunci metamethod yang dikelilingi **<>**. |
| 264 | 264 | ||
| 265 | ```yuescript | 265 | ```yuescript |
| 266 | {item, :new, :<close>, <index>: getter} = tb | 266 | {item, :new, :<close>, <index>: getter} = tb |
| @@ -275,9 +275,9 @@ print item, new, close, getter | |||
| 275 | 275 | ||
| 276 | </YueDisplay> | 276 | </YueDisplay> |
| 277 | 277 | ||
| 278 | ## Existence | 278 | ## Keberadaan |
| 279 | 279 | ||
| 280 | The **?** operator can be used in a variety of contexts to check for existence. | 280 | Operator **?** dapat digunakan dalam berbagai konteks untuk memeriksa keberadaan. |
| 281 | 281 | ||
| 282 | ```yuescript | 282 | ```yuescript |
| 283 | func?! | 283 | func?! |
| @@ -314,14 +314,14 @@ with? io.open "test.txt", "w" | |||
| 314 | 314 | ||
| 315 | ## Piping | 315 | ## Piping |
| 316 | 316 | ||
| 317 | Instead of a series of nested function calls, you can pipe values with operator **|>**. | 317 | Sebagai ganti serangkaian pemanggilan fungsi bersarang, Anda bisa mengalirkan nilai dengan operator **|>**. |
| 318 | 318 | ||
| 319 | ```yuescript | 319 | ```yuescript |
| 320 | "hello" |> print | 320 | "hello" |> print |
| 321 | 1 |> print 2 -- insert pipe item as the first argument | 321 | 1 |> print 2 -- sisipkan nilai pipe sebagai argumen pertama |
| 322 | 2 |> print 1, _, 3 -- pipe with a placeholder | 322 | 2 |> print 1, _, 3 -- pipe dengan placeholder |
| 323 | 323 | ||
| 324 | -- pipe expression in multiline | 324 | -- ekspresi pipe multi-baris |
| 325 | readFile "example.txt" | 325 | readFile "example.txt" |
| 326 | |> extract language, {} | 326 | |> extract language, {} |
| 327 | |> parse language | 327 | |> parse language |
| @@ -333,9 +333,9 @@ readFile "example.txt" | |||
| 333 | 333 | ||
| 334 | ```yue | 334 | ```yue |
| 335 | "hello" |> print | 335 | "hello" |> print |
| 336 | 1 |> print 2 -- insert pipe item as the first argument | 336 | 1 |> print 2 -- sisipkan nilai pipe sebagai argumen pertama |
| 337 | 2 |> print 1, _, 3 -- pipe with a placeholder | 337 | 2 |> print 1, _, 3 -- pipe dengan placeholder |
| 338 | -- pipe expression in multiline | 338 | -- ekspresi pipe multi-baris |
| 339 | readFile "example.txt" | 339 | readFile "example.txt" |
| 340 | |> extract language, {} | 340 | |> extract language, {} |
| 341 | |> parse language | 341 | |> parse language |
| @@ -348,7 +348,7 @@ readFile "example.txt" | |||
| 348 | 348 | ||
| 349 | ## Nil Coalescing | 349 | ## Nil Coalescing |
| 350 | 350 | ||
| 351 | The nil-coalescing operator **??** returns the value of its left-hand operand if it isn't **nil**; otherwise, it evaluates the right-hand operand and returns its result. The **??** operator doesn't evaluate its right-hand operand if the left-hand operand evaluates to non-nil. | 351 | 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. |
| 352 | ```yuescript | 352 | ```yuescript |
| 353 | local a, b, c, d | 353 | local a, b, c, d |
| 354 | a = b ?? c ?? d | 354 | a = b ?? c ?? d |
| @@ -367,31 +367,31 @@ a ??= false | |||
| 367 | 367 | ||
| 368 | </YueDisplay> | 368 | </YueDisplay> |
| 369 | 369 | ||
| 370 | ## Implicit Object | 370 | ## Objek Implisit |
| 371 | 371 | ||
| 372 | You can write a list of implicit structures that starts with the symbol **\*** or **-** inside a table block. If you are creating implicit object, the fields of the object must be with the same indent. | 372 | Anda dapat menulis daftar struktur implisit yang diawali simbol **\*** atau **-** di dalam blok tabel. Jika Anda membuat objek implisit, field objek harus berada pada indentasi yang sama. |
| 373 | 373 | ||
| 374 | ```yuescript | 374 | ```yuescript |
| 375 | -- assignment with implicit object | 375 | -- assignment dengan objek implisit |
| 376 | list = | 376 | list = |
| 377 | * 1 | 377 | * 1 |
| 378 | * 2 | 378 | * 2 |
| 379 | * 3 | 379 | * 3 |
| 380 | 380 | ||
| 381 | -- function call with implicit object | 381 | -- pemanggilan fungsi dengan objek implisit |
| 382 | func | 382 | func |
| 383 | * 1 | 383 | * 1 |
| 384 | * 2 | 384 | * 2 |
| 385 | * 3 | 385 | * 3 |
| 386 | 386 | ||
| 387 | -- return with implicit object | 387 | -- return dengan objek implisit |
| 388 | f = -> | 388 | f = -> |
| 389 | return | 389 | return |
| 390 | * 1 | 390 | * 1 |
| 391 | * 2 | 391 | * 2 |
| 392 | * 3 | 392 | * 3 |
| 393 | 393 | ||
| 394 | -- table with implicit object | 394 | -- tabel dengan objek implisit |
| 395 | tb = | 395 | tb = |
| 396 | name: "abc" | 396 | name: "abc" |
| 397 | 397 | ||
| @@ -416,26 +416,26 @@ tb = | |||
| 416 | <YueDisplay> | 416 | <YueDisplay> |
| 417 | 417 | ||
| 418 | ```yue | 418 | ```yue |
| 419 | -- assignment with implicit object | 419 | -- assignment dengan objek implisit |
| 420 | list = | 420 | list = |
| 421 | * 1 | 421 | * 1 |
| 422 | * 2 | 422 | * 2 |
| 423 | * 3 | 423 | * 3 |
| 424 | 424 | ||
| 425 | -- function call with implicit object | 425 | -- pemanggilan fungsi dengan objek implisit |
| 426 | func | 426 | func |
| 427 | * 1 | 427 | * 1 |
| 428 | * 2 | 428 | * 2 |
| 429 | * 3 | 429 | * 3 |
| 430 | 430 | ||
| 431 | -- return with implicit object | 431 | -- return dengan objek implisit |
| 432 | f = -> | 432 | f = -> |
| 433 | return | 433 | return |
| 434 | * 1 | 434 | * 1 |
| 435 | * 2 | 435 | * 2 |
| 436 | * 3 | 436 | * 3 |
| 437 | 437 | ||
| 438 | -- table with implicit object | 438 | -- tabel dengan objek implisit |
| 439 | tb = | 439 | tb = |
| 440 | name: "abc" | 440 | name: "abc" |
| 441 | 441 | ||
diff --git a/doc/docs/id-id/doc/language-basics/whitespace.md b/doc/docs/id-id/doc/language-basics/whitespace.md index d742a2b..bdc124e 100644 --- a/doc/docs/id-id/doc/language-basics/whitespace.md +++ b/doc/docs/id-id/doc/language-basics/whitespace.md | |||
| @@ -1,10 +1,10 @@ | |||
| 1 | # Whitespace | 1 | # Spasi Kosong |
| 2 | 2 | ||
| 3 | YueScript is a whitespace significant language. You have to write some code block in the same indent with space **' '** or tab **'\t'** like function body, value list and some control blocks. And expressions containing different whitespaces might mean different things. Tab is treated like 4 space, but it's better not mix the use of spaces and tabs. | 3 | YueScript adalah bahasa yang peka terhadap spasi. Anda harus menulis beberapa blok kode dengan indentasi yang sama menggunakan spasi **' '** atau tab **'\t'** seperti badan fungsi, daftar nilai, dan beberapa blok kontrol. Ekspresi yang mengandung spasi berbeda dapat bermakna berbeda. Tab diperlakukan seperti 4 spasi, tetapi sebaiknya jangan mencampur penggunaan spasi dan tab. |
| 4 | 4 | ||
| 5 | ## Statement Separator | 5 | ## Pemisah Pernyataan |
| 6 | 6 | ||
| 7 | A statement normally ends at a line break. You can also use a semicolon `;` to explicitly terminate a statement, which allows writing multiple statements on the same line: | 7 | Sebuah pernyataan biasanya berakhir pada pergantian baris. Anda juga bisa memakai titik koma `;` untuk mengakhiri pernyataan secara eksplisit, yang memungkinkan menulis beberapa pernyataan pada satu baris: |
| 8 | 8 | ||
| 9 | ```yuescript | 9 | ```yuescript |
| 10 | a = 1; b = 2; print a + b | 10 | a = 1; b = 2; print a + b |
| @@ -17,9 +17,9 @@ a = 1; b = 2; print a + b | |||
| 17 | 17 | ||
| 18 | </YueDisplay> | 18 | </YueDisplay> |
| 19 | 19 | ||
| 20 | ## Multiline Chaining | 20 | ## Rantai Multibaris |
| 21 | 21 | ||
| 22 | You can write multi-line chaining function calls with a same indent. | 22 | Anda bisa menulis pemanggilan fungsi berantai multi-baris dengan indentasi yang sama. |
| 23 | 23 | ||
| 24 | ```yuescript | 24 | ```yuescript |
| 25 | Rx.Observable | 25 | Rx.Observable |
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 6a8559e..96c19d7 100644 --- a/doc/docs/id-id/doc/objects/object-oriented-programming.md +++ b/doc/docs/id-id/doc/objects/object-oriented-programming.md | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | # Object Oriented Programming | 1 | # Pemrograman Berorientasi Objek |
| 2 | 2 | ||
| 3 | In these examples, the generated Lua code may appear overwhelming. It is best to focus on the meaning of the YueScript code at first, then look into the Lua code if you wish to know the implementation details. | 3 | Dalam contoh-contoh ini, kode Lua yang dihasilkan mungkin tampak berat. Sebaiknya fokus dulu pada makna kode YueScript, lalu lihat kode Lua jika Anda ingin mengetahui detail implementasinya. |
| 4 | 4 | ||
| 5 | A simple class: | 5 | Kelas sederhana: |
| 6 | 6 | ||
| 7 | ```yuescript | 7 | ```yuescript |
| 8 | class Inventory | 8 | class Inventory |
| @@ -31,15 +31,15 @@ class Inventory | |||
| 31 | 31 | ||
| 32 | </YueDisplay> | 32 | </YueDisplay> |
| 33 | 33 | ||
| 34 | A class is declared with a class statement followed by a table-like declaration where all of the methods and properties are listed. | 34 | Kelas dideklarasikan dengan pernyataan `class` diikuti deklarasi mirip tabel di mana semua method dan properti dicantumkan. |
| 35 | 35 | ||
| 36 | The new property is special in that it will become the constructor. | 36 | Properti `new` bersifat khusus karena akan menjadi konstruktor. |
| 37 | 37 | ||
| 38 | Notice how all the methods in the class use the fat arrow function syntax. When calling methods on a instance, the instance itself is sent in as the first argument. The fat arrow handles the creation of a self argument. | 38 | Perhatikan bahwa semua method di kelas menggunakan sintaks fungsi panah tebal. Saat memanggil method pada instance, instance itu sendiri dikirim sebagai argumen pertama. Panah tebal menangani pembuatan argumen `self`. |
| 39 | 39 | ||
| 40 | The @ prefix on a variable name is shorthand for self.. @items becomes self.items. | 40 | Prefiks `@` pada nama variabel adalah singkatan untuk `self.`. `@items` menjadi `self.items`. |
| 41 | 41 | ||
| 42 | Creating an instance of the class is done by calling the name of the class as a function. | 42 | Membuat instance kelas dilakukan dengan memanggil nama kelas sebagai fungsi. |
| 43 | 43 | ||
| 44 | ```yuescript | 44 | ```yuescript |
| 45 | inv = Inventory! | 45 | inv = Inventory! |
| @@ -56,11 +56,11 @@ inv\add_item "pants" | |||
| 56 | 56 | ||
| 57 | </YueDisplay> | 57 | </YueDisplay> |
| 58 | 58 | ||
| 59 | Because the instance of the class needs to be sent to the methods when they are called, the \ operator is used. | 59 | Karena instance kelas perlu dikirim ke method saat dipanggil, operator `\` digunakan. |
| 60 | 60 | ||
| 61 | All properties of a class are shared among the instances. This is fine for functions, but for other types of objects, undesired results may occur. | 61 | Semua properti kelas dibagikan di antara instance. Ini baik untuk fungsi, tetapi untuk jenis objek lain dapat menimbulkan hasil yang tidak diinginkan. |
| 62 | 62 | ||
| 63 | Consider the example below, the clothes property is shared amongst all instances, so modifications to it in one instance will show up in another: | 63 | Pertimbangkan contoh di bawah ini, properti `clothes` dibagikan di antara semua instance, sehingga perubahan di satu instance akan terlihat di instance lainnya: |
| 64 | 64 | ||
| 65 | ```yuescript | 65 | ```yuescript |
| 66 | class Person | 66 | class Person |
| @@ -74,7 +74,7 @@ b = Person! | |||
| 74 | a\give_item "pants" | 74 | a\give_item "pants" |
| 75 | b\give_item "shirt" | 75 | b\give_item "shirt" |
| 76 | 76 | ||
| 77 | -- will print both pants and shirt | 77 | -- akan mencetak pants dan shirt |
| 78 | print item for item in *a.clothes | 78 | print item for item in *a.clothes |
| 79 | ``` | 79 | ``` |
| 80 | <YueDisplay> | 80 | <YueDisplay> |
| @@ -91,13 +91,13 @@ b = Person! | |||
| 91 | a\give_item "pants" | 91 | a\give_item "pants" |
| 92 | b\give_item "shirt" | 92 | b\give_item "shirt" |
| 93 | 93 | ||
| 94 | -- will print both pants and shirt | 94 | -- akan mencetak pants dan shirt |
| 95 | print item for item in *a.clothes | 95 | print item for item in *a.clothes |
| 96 | ``` | 96 | ``` |
| 97 | 97 | ||
| 98 | </YueDisplay> | 98 | </YueDisplay> |
| 99 | 99 | ||
| 100 | The proper way to avoid this problem is to create the mutable state of the object in the constructor: | 100 | Cara yang benar untuk menghindari masalah ini adalah membuat state yang dapat berubah di konstruktor: |
| 101 | 101 | ||
| 102 | ```yuescript | 102 | ```yuescript |
| 103 | class Person | 103 | class Person |
| @@ -114,9 +114,9 @@ class Person | |||
| 114 | 114 | ||
| 115 | </YueDisplay> | 115 | </YueDisplay> |
| 116 | 116 | ||
| 117 | ## Inheritance | 117 | ## Pewarisan |
| 118 | 118 | ||
| 119 | The extends keyword can be used in a class declaration to inherit the properties and methods from another class. | 119 | Kata kunci `extends` dapat digunakan dalam deklarasi kelas untuk mewarisi properti dan method dari kelas lain. |
| 120 | 120 | ||
| 121 | ```yuescript | 121 | ```yuescript |
| 122 | class BackPack extends Inventory | 122 | class BackPack extends Inventory |
| @@ -137,18 +137,18 @@ class BackPack extends Inventory | |||
| 137 | 137 | ||
| 138 | </YueDisplay> | 138 | </YueDisplay> |
| 139 | 139 | ||
| 140 | Here we extend our Inventory class, and limit the amount of items it can carry. | 140 | Di sini kita memperluas kelas Inventory, dan membatasi jumlah item yang bisa dibawa. |
| 141 | 141 | ||
| 142 | In this example, we don't define a constructor on the subclass, so the parent class' constructor is called when we make a new instance. If we did define a constructor then we can use the super method to call the parent constructor. | 142 | Dalam contoh ini, kita tidak mendefinisikan konstruktor pada subclass, sehingga konstruktor kelas induk dipanggil ketika membuat instance baru. Jika kita mendefinisikan konstruktor, kita bisa menggunakan method `super` untuk memanggil konstruktor induk. |
| 143 | 143 | ||
| 144 | Whenever a class inherits from another, it sends a message to the parent class by calling the method __inherited on the parent class if it exists. The function receives two arguments, the class that is being inherited and the child class. | 144 | Setiap kali sebuah kelas mewarisi dari kelas lain, ia mengirim pesan ke kelas induk dengan memanggil method `__inherited` pada kelas induk jika ada. Fungsi menerima dua argumen, kelas yang diwarisi dan kelas anak. |
| 145 | 145 | ||
| 146 | ```yuescript | 146 | ```yuescript |
| 147 | class Shelf | 147 | class Shelf |
| 148 | @__inherited: (child) => | 148 | @__inherited: (child) => |
| 149 | print @__name, "was inherited by", child.__name | 149 | print @__name, "was inherited by", child.__name |
| 150 | 150 | ||
| 151 | -- will print: Shelf was inherited by Cupboard | 151 | -- akan mencetak: Shelf was inherited by Cupboard |
| 152 | class Cupboard extends Shelf | 152 | class Cupboard extends Shelf |
| 153 | ``` | 153 | ``` |
| 154 | <YueDisplay> | 154 | <YueDisplay> |
| @@ -158,7 +158,7 @@ class Shelf | |||
| 158 | @__inherited: (child) => | 158 | @__inherited: (child) => |
| 159 | print @__name, "was inherited by", child.__name | 159 | print @__name, "was inherited by", child.__name |
| 160 | 160 | ||
| 161 | -- will print: Shelf was inherited by Cupboard | 161 | -- akan mencetak: Shelf was inherited by Cupboard |
| 162 | class Cupboard extends Shelf | 162 | class Cupboard extends Shelf |
| 163 | ``` | 163 | ``` |
| 164 | 164 | ||
| @@ -166,27 +166,27 @@ class Cupboard extends Shelf | |||
| 166 | 166 | ||
| 167 | ## Super | 167 | ## Super |
| 168 | 168 | ||
| 169 | **super** is a special keyword that can be used in two different ways: It can be treated as an object, or it can be called like a function. It only has special functionality when inside a class. | 169 | **super** adalah kata kunci khusus yang dapat digunakan dengan dua cara: sebagai objek, atau dipanggil seperti fungsi. Ia hanya memiliki fungsi khusus ketika berada di dalam kelas. |
| 170 | 170 | ||
| 171 | When called as a function, it will call the function of the same name in the parent class. The current self will automatically be passed as the first argument. (As seen in the inheritance example above) | 171 | Ketika dipanggil sebagai fungsi, ia akan memanggil fungsi dengan nama yang sama di kelas induk. `self` saat ini akan otomatis dikirim sebagai argumen pertama. (Seperti pada contoh pewarisan di atas) |
| 172 | 172 | ||
| 173 | When super is used as a normal value, it is a reference to the parent class object. | 173 | Ketika `super` digunakan sebagai nilai normal, ia merupakan referensi ke objek kelas induk. |
| 174 | 174 | ||
| 175 | It can be accessed like any of object in order to retrieve values in the parent class that might have been shadowed by the child class. | 175 | Ia dapat diakses seperti objek biasa untuk mengambil nilai di kelas induk yang mungkin tertutup oleh kelas anak. |
| 176 | 176 | ||
| 177 | When the \ calling operator is used with super, self is inserted as the first argument instead of the value of super itself. When using . to retrieve a function, the raw function is returned. | 177 | Ketika operator pemanggilan `\` digunakan dengan `super`, `self` disisipkan sebagai argumen pertama alih-alih nilai `super` itu sendiri. Saat menggunakan `.` untuk mengambil fungsi, fungsi mentah dikembalikan. |
| 178 | 178 | ||
| 179 | A few examples of using super in different ways: | 179 | Beberapa contoh penggunaan `super` dengan cara berbeda: |
| 180 | 180 | ||
| 181 | ```yuescript | 181 | ```yuescript |
| 182 | class MyClass extends ParentClass | 182 | class MyClass extends ParentClass |
| 183 | a_method: => | 183 | a_method: => |
| 184 | -- the following have the same effect: | 184 | -- berikut memiliki efek yang sama: |
| 185 | super "hello", "world" | 185 | super "hello", "world" |
| 186 | super\a_method "hello", "world" | 186 | super\a_method "hello", "world" |
| 187 | super.a_method self, "hello", "world" | 187 | super.a_method self, "hello", "world" |
| 188 | 188 | ||
| 189 | -- super as a value is equal to the parent class: | 189 | -- super sebagai nilai sama dengan kelas induk: |
| 190 | assert super == ParentClass | 190 | assert super == ParentClass |
| 191 | ``` | 191 | ``` |
| 192 | <YueDisplay> | 192 | <YueDisplay> |
| @@ -194,28 +194,28 @@ class MyClass extends ParentClass | |||
| 194 | ```yue | 194 | ```yue |
| 195 | class MyClass extends ParentClass | 195 | class MyClass extends ParentClass |
| 196 | a_method: => | 196 | a_method: => |
| 197 | -- the following have the same effect: | 197 | -- berikut memiliki efek yang sama: |
| 198 | super "hello", "world" | 198 | super "hello", "world" |
| 199 | super\a_method "hello", "world" | 199 | super\a_method "hello", "world" |
| 200 | super.a_method self, "hello", "world" | 200 | super.a_method self, "hello", "world" |
| 201 | 201 | ||
| 202 | -- super as a value is equal to the parent class: | 202 | -- super sebagai nilai sama dengan kelas induk: |
| 203 | assert super == ParentClass | 203 | assert super == ParentClass |
| 204 | ``` | 204 | ``` |
| 205 | 205 | ||
| 206 | </YueDisplay> | 206 | </YueDisplay> |
| 207 | 207 | ||
| 208 | **super** can also be used on left side of a Function Stub. The only major difference is that instead of the resulting function being bound to the value of super, it is bound to self. | 208 | **super** juga dapat digunakan di sisi kiri Function Stub. Perbedaan utamanya adalah, alih-alih fungsi hasil terikat pada nilai `super`, fungsi terikat pada `self`. |
| 209 | 209 | ||
| 210 | ## Types | 210 | ## Tipe |
| 211 | 211 | ||
| 212 | Every instance of a class carries its type with it. This is stored in the special __class property. This property holds the class object. The class object is what we call to build a new instance. We can also index the class object to retrieve class methods and properties. | 212 | Setiap instance kelas membawa tipenya sendiri. Ini disimpan di properti khusus `__class`. Properti ini memuat objek kelas. Objek kelas adalah yang kita panggil untuk membuat instance baru. Kita juga dapat mengindeks objek kelas untuk mengambil method dan properti kelas. |
| 213 | 213 | ||
| 214 | ```yuescript | 214 | ```yuescript |
| 215 | b = BackPack! | 215 | b = BackPack! |
| 216 | assert b.__class == BackPack | 216 | assert b.__class == BackPack |
| 217 | 217 | ||
| 218 | print BackPack.size -- prints 10 | 218 | print BackPack.size -- mencetak 10 |
| 219 | ``` | 219 | ``` |
| 220 | <YueDisplay> | 220 | <YueDisplay> |
| 221 | 221 | ||
| @@ -223,45 +223,45 @@ print BackPack.size -- prints 10 | |||
| 223 | b = BackPack! | 223 | b = BackPack! |
| 224 | assert b.__class == BackPack | 224 | assert b.__class == BackPack |
| 225 | 225 | ||
| 226 | print BackPack.size -- prints 10 | 226 | print BackPack.size -- mencetak 10 |
| 227 | ``` | 227 | ``` |
| 228 | 228 | ||
| 229 | </YueDisplay> | 229 | </YueDisplay> |
| 230 | 230 | ||
| 231 | ## Class Objects | 231 | ## Objek Kelas |
| 232 | 232 | ||
| 233 | The class object is what we create when we use a class statement. The class object is stored in a variable of the same name of the class. | 233 | Objek kelas adalah yang kita buat saat menggunakan pernyataan `class`. Objek kelas disimpan dalam variabel dengan nama yang sama dengan kelas. |
| 234 | 234 | ||
| 235 | The class object can be called like a function in order to create new instances. That's how we created instances of classes in the examples above. | 235 | Objek kelas dapat dipanggil seperti fungsi untuk membuat instance baru. Begitulah cara kita membuat instance kelas pada contoh di atas. |
| 236 | 236 | ||
| 237 | A class is made up of two tables. The class table itself, and the base table. The base is used as the metatable for all the instances. All properties listed in the class declaration are placed in the base. | 237 | Sebuah kelas terdiri dari dua tabel: tabel kelas itu sendiri dan tabel base. Base digunakan sebagai metatable untuk semua instance. Semua properti yang dicantumkan dalam deklarasi kelas ditempatkan di base. |
| 238 | 238 | ||
| 239 | The class object's metatable reads properties from the base if they don't exist in the class object. This means we can access functions and properties directly from the class. | 239 | Metatable objek kelas membaca properti dari base jika tidak ada di objek kelas. Ini berarti kita dapat mengakses fungsi dan properti langsung dari kelas. |
| 240 | 240 | ||
| 241 | It is important to note that assigning to the class object does not assign into the base, so it's not a valid way to add new methods to instances. Instead the base must explicitly be changed. See the __base field below. | 241 | Penting untuk dicatat bahwa assignment ke objek kelas tidak meng-assign ke base, sehingga itu bukan cara yang valid untuk menambahkan method baru ke instance. Sebagai gantinya, base harus diubah secara eksplisit. Lihat field `__base` di bawah. |
| 242 | 242 | ||
| 243 | The class object has a couple special properties: | 243 | Objek kelas memiliki beberapa properti khusus: |
| 244 | 244 | ||
| 245 | The name of the class as when it was declared is stored as a string in the __name field of the class object. | 245 | Nama kelas saat dideklarasikan disimpan sebagai string di field `__name` pada objek kelas. |
| 246 | 246 | ||
| 247 | ```yuescript | 247 | ```yuescript |
| 248 | print BackPack.__name -- prints Backpack | 248 | print BackPack.__name -- mencetak Backpack |
| 249 | ``` | 249 | ``` |
| 250 | <YueDisplay> | 250 | <YueDisplay> |
| 251 | 251 | ||
| 252 | ```yue | 252 | ```yue |
| 253 | print BackPack.__name -- prints Backpack | 253 | print BackPack.__name -- mencetak Backpack |
| 254 | ``` | 254 | ``` |
| 255 | 255 | ||
| 256 | </YueDisplay> | 256 | </YueDisplay> |
| 257 | 257 | ||
| 258 | The base object is stored in __base. We can modify this table to add functionality to instances that have already been created and ones that are yet to be created. | 258 | Objek base disimpan di `__base`. Kita dapat memodifikasi tabel ini untuk menambahkan fungsionalitas ke instance yang sudah dibuat maupun yang akan dibuat. |
| 259 | 259 | ||
| 260 | If the class extends from anything, the parent class object is stored in __parent. | 260 | Jika kelas memperluas kelas lain, objek kelas induk disimpan di `__parent`. |
| 261 | 261 | ||
| 262 | ## Class Variables | 262 | ## Variabel Kelas |
| 263 | 263 | ||
| 264 | We can create variables directly in the class object instead of in the base by using @ in the front of the property name in a class declaration. | 264 | Kita dapat membuat variabel langsung di objek kelas alih-alih di base dengan menggunakan `@` di depan nama properti pada deklarasi kelas. |
| 265 | 265 | ||
| 266 | ```yuescript | 266 | ```yuescript |
| 267 | class Things | 267 | class Things |
| @@ -269,7 +269,7 @@ class Things | |||
| 269 | 269 | ||
| 270 | Things\some_func! | 270 | Things\some_func! |
| 271 | 271 | ||
| 272 | -- class variables not visible in instances | 272 | -- variabel kelas tidak terlihat pada instance |
| 273 | assert Things().some_func == nil | 273 | assert Things().some_func == nil |
| 274 | ``` | 274 | ``` |
| 275 | <YueDisplay> | 275 | <YueDisplay> |
| @@ -280,13 +280,13 @@ class Things | |||
| 280 | 280 | ||
| 281 | Things\some_func! | 281 | Things\some_func! |
| 282 | 282 | ||
| 283 | -- class variables not visible in instances | 283 | -- variabel kelas tidak terlihat pada instance |
| 284 | assert Things().some_func == nil | 284 | assert Things().some_func == nil |
| 285 | ``` | 285 | ``` |
| 286 | 286 | ||
| 287 | </YueDisplay> | 287 | </YueDisplay> |
| 288 | 288 | ||
| 289 | In expressions, we can use @@ to access a value that is stored in the __class of self. Thus, @@hello is shorthand for self.__class.hello. | 289 | Dalam ekspresi, kita dapat menggunakan `@@` untuk mengakses nilai yang disimpan di `__class` milik `self`. Jadi, `@@hello` adalah singkatan dari `self.__class.hello`. |
| 290 | 290 | ||
| 291 | ```yuescript | 291 | ```yuescript |
| 292 | class Counter | 292 | class Counter |
| @@ -298,7 +298,7 @@ class Counter | |||
| 298 | Counter! | 298 | Counter! |
| 299 | Counter! | 299 | Counter! |
| 300 | 300 | ||
| 301 | print Counter.count -- prints 2 | 301 | print Counter.count -- mencetak 2 |
| 302 | ``` | 302 | ``` |
| 303 | <YueDisplay> | 303 | <YueDisplay> |
| 304 | 304 | ||
| @@ -312,12 +312,12 @@ class Counter | |||
| 312 | Counter! | 312 | Counter! |
| 313 | Counter! | 313 | Counter! |
| 314 | 314 | ||
| 315 | print Counter.count -- prints 2 | 315 | print Counter.count -- mencetak 2 |
| 316 | ``` | 316 | ``` |
| 317 | 317 | ||
| 318 | </YueDisplay> | 318 | </YueDisplay> |
| 319 | 319 | ||
| 320 | The calling semantics of @@ are similar to @. Calling a @@ name will pass the class in as the first argument using Lua's colon syntax. | 320 | Semantik pemanggilan `@@` mirip dengan `@`. Memanggil nama `@@` akan meneruskan kelas sebagai argumen pertama menggunakan sintaks kolon Lua. |
| 321 | 321 | ||
| 322 | ```yuescript | 322 | ```yuescript |
| 323 | @@hello 1,2,3,4 | 323 | @@hello 1,2,3,4 |
| @@ -330,11 +330,11 @@ The calling semantics of @@ are similar to @. Calling a @@ name will pass the cl | |||
| 330 | 330 | ||
| 331 | </YueDisplay> | 331 | </YueDisplay> |
| 332 | 332 | ||
| 333 | ## Class Declaration Statements | 333 | ## Pernyataan Deklarasi Kelas |
| 334 | 334 | ||
| 335 | In the body of a class declaration, we can have normal expressions in addition to key/value pairs. In this context, self is equal to the class object. | 335 | Di dalam badan deklarasi kelas, kita bisa memiliki ekspresi normal selain pasangan key/value. Dalam konteks ini, `self` sama dengan objek kelas. |
| 336 | 336 | ||
| 337 | Here is an alternative way to create a class variable compared to what's described above: | 337 | Berikut cara alternatif untuk membuat variabel kelas dibandingkan yang dijelaskan di atas: |
| 338 | 338 | ||
| 339 | ```yuescript | 339 | ```yuescript |
| 340 | class Things | 340 | class Things |
| @@ -349,9 +349,9 @@ class Things | |||
| 349 | 349 | ||
| 350 | </YueDisplay> | 350 | </YueDisplay> |
| 351 | 351 | ||
| 352 | These expressions are executed after all the properties have been added to the base. | 352 | Ekspresi ini dieksekusi setelah semua properti ditambahkan ke base. |
| 353 | 353 | ||
| 354 | All variables declared in the body of the class are local to the classes properties. This is convenient for placing private values or helper functions that only the class methods can access: | 354 | Semua variabel yang dideklarasikan di badan kelas bersifat lokal terhadap properti kelas. Ini berguna untuk menempatkan nilai privat atau fungsi pembantu yang hanya dapat diakses oleh method kelas: |
| 355 | 355 | ||
| 356 | ```yuescript | 356 | ```yuescript |
| 357 | class MoreThings | 357 | class MoreThings |
| @@ -374,11 +374,11 @@ class MoreThings | |||
| 374 | 374 | ||
| 375 | </YueDisplay> | 375 | </YueDisplay> |
| 376 | 376 | ||
| 377 | ## @ and @@ Values | 377 | ## Nilai @ dan @@ |
| 378 | 378 | ||
| 379 | When @ and @@ are prefixed in front of a name they represent, respectively, that name accessed in self and self.__class. | 379 | Ketika `@` dan `@@` diprefiks di depan sebuah nama, masing-masing merepresentasikan nama tersebut yang diakses di `self` dan `self.__class`. |
| 380 | 380 | ||
| 381 | If they are used all by themselves, they are aliases for self and self.__class. | 381 | Jika digunakan sendirian, keduanya adalah alias untuk `self` dan `self.__class`. |
| 382 | 382 | ||
| 383 | ```yuescript | 383 | ```yuescript |
| 384 | assert @ == self | 384 | assert @ == self |
| @@ -393,7 +393,7 @@ assert @@ == self.__class | |||
| 393 | 393 | ||
| 394 | </YueDisplay> | 394 | </YueDisplay> |
| 395 | 395 | ||
| 396 | For example, a quick way to create a new instance of the same class from an instance method using @@: | 396 | Contohnya, cara cepat untuk membuat instance baru dari kelas yang sama dari method instance menggunakan `@@`: |
| 397 | 397 | ||
| 398 | ```yuescript | 398 | ```yuescript |
| 399 | some_instance_method = (...) => @@ ... | 399 | some_instance_method = (...) => @@ ... |
| @@ -406,15 +406,15 @@ some_instance_method = (...) => @@ ... | |||
| 406 | 406 | ||
| 407 | </YueDisplay> | 407 | </YueDisplay> |
| 408 | 408 | ||
| 409 | ## Constructor Property Promotion | 409 | ## Promosi Properti Konstruktor |
| 410 | 410 | ||
| 411 | To reduce the boilerplate code for definition of simple value objects. You can write a simple class like: | 411 | Untuk mengurangi boilerplate saat mendefinisikan objek nilai sederhana, Anda dapat menulis kelas sederhana seperti: |
| 412 | 412 | ||
| 413 | ```yuescript | 413 | ```yuescript |
| 414 | class Something | 414 | class Something |
| 415 | new: (@foo, @bar, @@biz, @@baz) => | 415 | new: (@foo, @bar, @@biz, @@baz) => |
| 416 | 416 | ||
| 417 | -- Which is short for | 417 | -- Yang merupakan singkatan dari |
| 418 | 418 | ||
| 419 | class Something | 419 | class Something |
| 420 | new: (foo, bar, biz, baz) => | 420 | new: (foo, bar, biz, baz) => |
| @@ -429,7 +429,7 @@ class Something | |||
| 429 | class Something | 429 | class Something |
| 430 | new: (@foo, @bar, @@biz, @@baz) => | 430 | new: (@foo, @bar, @@biz, @@baz) => |
| 431 | 431 | ||
| 432 | -- Which is short for | 432 | -- Yang merupakan singkatan dari |
| 433 | 433 | ||
| 434 | class Something | 434 | class Something |
| 435 | new: (foo, bar, biz, baz) => | 435 | new: (foo, bar, biz, baz) => |
| @@ -441,7 +441,7 @@ class Something | |||
| 441 | 441 | ||
| 442 | </YueDisplay> | 442 | </YueDisplay> |
| 443 | 443 | ||
| 444 | You can also use this syntax for a common function to initialize a object's fields. | 444 | Anda juga bisa menggunakan sintaks ini untuk fungsi umum guna menginisialisasi field objek. |
| 445 | 445 | ||
| 446 | ```yuescript | 446 | ```yuescript |
| 447 | new = (@fieldA, @fieldB) => @ | 447 | new = (@fieldA, @fieldB) => @ |
| @@ -458,9 +458,9 @@ print obj | |||
| 458 | 458 | ||
| 459 | </YueDisplay> | 459 | </YueDisplay> |
| 460 | 460 | ||
| 461 | ## Class Expressions | 461 | ## Ekspresi Kelas |
| 462 | 462 | ||
| 463 | The class syntax can also be used as an expression which can be assigned to a variable or explicitly returned. | 463 | Sintaks kelas juga bisa digunakan sebagai ekspresi yang dapat di-assign ke variabel atau di-return secara eksplisit. |
| 464 | 464 | ||
| 465 | ```yuescript | 465 | ```yuescript |
| 466 | x = class Bucket | 466 | x = class Bucket |
| @@ -477,9 +477,9 @@ x = class Bucket | |||
| 477 | 477 | ||
| 478 | </YueDisplay> | 478 | </YueDisplay> |
| 479 | 479 | ||
| 480 | ## Anonymous classes | 480 | ## Kelas Anonim |
| 481 | 481 | ||
| 482 | The name can be left out when declaring a class. The __name attribute will be nil, unless the class expression is in an assignment. The name on the left hand side of the assignment is used instead of nil. | 482 | Nama bisa dihilangkan saat mendeklarasikan kelas. Atribut `__name` akan bernilai nil, kecuali ekspresi kelas berada dalam assignment. Nama di sisi kiri assignment digunakan sebagai ganti nil. |
| 483 | 483 | ||
| 484 | ```yuescript | 484 | ```yuescript |
| 485 | BigBucket = class extends Bucket | 485 | BigBucket = class extends Bucket |
| @@ -498,7 +498,7 @@ assert Bucket.__name == "BigBucket" | |||
| 498 | 498 | ||
| 499 | </YueDisplay> | 499 | </YueDisplay> |
| 500 | 500 | ||
| 501 | You can even leave off the body, meaning you can write a blank anonymous class like this: | 501 | Anda bahkan bisa menghilangkan badan kelas, artinya Anda bisa menulis kelas anonim kosong seperti ini: |
| 502 | 502 | ||
| 503 | ```yuescript | 503 | ```yuescript |
| 504 | x = class | 504 | x = class |
| @@ -511,9 +511,9 @@ x = class | |||
| 511 | 511 | ||
| 512 | </YueDisplay> | 512 | </YueDisplay> |
| 513 | 513 | ||
| 514 | ## Class Mixing | 514 | ## Pencampuran Kelas |
| 515 | 515 | ||
| 516 | You can do mixing with keyword `using` to copy functions from either a plain table or a predefined class object into your new class. When doing mixing with a plain table, you can override the class indexing function (metamethod `__index`) to your customized implementation. When doing mixing with an existing class object, the class object's metamethods won't be copied. | 516 | Anda bisa melakukan mixing dengan kata kunci `using` untuk menyalin fungsi dari tabel biasa atau objek kelas yang sudah didefinisikan ke kelas baru Anda. Saat mixing dengan tabel biasa, Anda dapat mengganti fungsi pengindeksan kelas (metamethod `__index`) dengan implementasi kustom. Saat mixing dengan objek kelas yang sudah ada, metamethod objek kelas tidak akan disalin. |
| 517 | 517 | ||
| 518 | ```yuescript | 518 | ```yuescript |
| 519 | MyIndex = __index: var: 1 | 519 | MyIndex = __index: var: 1 |
| @@ -530,7 +530,7 @@ class Y using X | |||
| 530 | y = Y! | 530 | y = Y! |
| 531 | y\func! | 531 | y\func! |
| 532 | 532 | ||
| 533 | assert y.__class.__parent ~= X -- X is not parent of Y | 533 | assert y.__class.__parent ~= X -- X bukan parent dari Y |
| 534 | ``` | 534 | ``` |
| 535 | <YueDisplay> | 535 | <YueDisplay> |
| 536 | 536 | ||
| @@ -549,7 +549,7 @@ class Y using X | |||
| 549 | y = Y! | 549 | y = Y! |
| 550 | y\func! | 550 | y\func! |
| 551 | 551 | ||
| 552 | assert y.__class.__parent ~= X -- X is not parent of Y | 552 | assert y.__class.__parent ~= X -- X bukan parent dari Y |
| 553 | ``` | 553 | ``` |
| 554 | 554 | ||
| 555 | </YueDisplay> | 555 | </YueDisplay> |
diff --git a/doc/docs/id-id/doc/objects/with-statement.md b/doc/docs/id-id/doc/objects/with-statement.md index 7786803..3c0a8a5 100644 --- a/doc/docs/id-id/doc/objects/with-statement.md +++ b/doc/docs/id-id/doc/objects/with-statement.md | |||
| @@ -1,13 +1,12 @@ | |||
| 1 | # With Statement | 1 | # Pernyataan With |
| 2 | 2 | ||
| 3 | Pola umum saat membuat objek adalah memanggil serangkaian fungsi dan mengatur serangkaian properti segera setelah objek dibuat. | ||
| 3 | 4 | ||
| 4 | A common pattern involving the creation of an object is calling a series of functions and setting a series of properties immediately after creating it. | 5 | Hal ini menyebabkan nama objek diulang berkali-kali di kode, menambah noise yang tidak perlu. Solusi umum untuk ini adalah meneruskan tabel sebagai argumen yang berisi kumpulan kunci dan nilai untuk ditimpa. Kekurangannya adalah konstruktor objek harus mendukung bentuk ini. |
| 5 | 6 | ||
| 6 | This results in repeating the name of the object multiple times in code, adding unnecessary noise. A common solution to this is to pass a table in as an argument which contains a collection of keys and values to overwrite. The downside to this is that the constructor of this object must support this form. | 7 | Blok `with` membantu mengatasi hal ini. Di dalam blok `with`, kita bisa menggunakan pernyataan khusus yang diawali dengan `.` atau `\` yang merepresentasikan operasi tersebut diterapkan pada objek yang sedang dipakai. |
| 7 | 8 | ||
| 8 | The with block helps to alleviate this. Within a with block we can use a special statements that begin with either . or \ which represent those operations applied to the object we are using with on. | 9 | Sebagai contoh, kita bekerja dengan objek yang baru dibuat: |
| 9 | |||
| 10 | For example, we work with a newly created object: | ||
| 11 | 10 | ||
| 12 | ```yuescript | 11 | ```yuescript |
| 13 | with Person! | 12 | with Person! |
| @@ -28,7 +27,7 @@ with Person! | |||
| 28 | 27 | ||
| 29 | </YueDisplay> | 28 | </YueDisplay> |
| 30 | 29 | ||
| 31 | The with statement can also be used as an expression which returns the value it has been giving access to. | 30 | Pernyataan `with` juga bisa digunakan sebagai ekspresi yang mengembalikan nilai yang diberi akses. |
| 32 | 31 | ||
| 33 | ```yuescript | 32 | ```yuescript |
| 34 | file = with File "favorite_foods.txt" | 33 | file = with File "favorite_foods.txt" |
| @@ -43,7 +42,7 @@ file = with File "favorite_foods.txt" | |||
| 43 | 42 | ||
| 44 | </YueDisplay> | 43 | </YueDisplay> |
| 45 | 44 | ||
| 46 | Or… | 45 | Atau… |
| 47 | 46 | ||
| 48 | ```yuescript | 47 | ```yuescript |
| 49 | create_person = (name, relatives) -> | 48 | create_person = (name, relatives) -> |
| @@ -66,9 +65,9 @@ me = create_person "Leaf", [dad, mother, sister] | |||
| 66 | 65 | ||
| 67 | </YueDisplay> | 66 | </YueDisplay> |
| 68 | 67 | ||
| 69 | In this usage, with can be seen as a special form of the K combinator. | 68 | Dalam penggunaan ini, `with` dapat dilihat sebagai bentuk khusus dari kombinator K. |
| 70 | 69 | ||
| 71 | The expression in the with statement can also be an assignment, if you want to give a name to the expression. | 70 | Ekspresi pada pernyataan `with` juga bisa berupa assignment jika Anda ingin memberi nama pada ekspresi tersebut. |
| 72 | 71 | ||
| 73 | ```yuescript | 72 | ```yuescript |
| 74 | with str := "Hello" | 73 | with str := "Hello" |
| @@ -85,7 +84,7 @@ with str := "Hello" | |||
| 85 | 84 | ||
| 86 | </YueDisplay> | 85 | </YueDisplay> |
| 87 | 86 | ||
| 88 | You can access special keys with `[]` in a `with` statement. | 87 | Anda bisa mengakses kunci khusus dengan `[]` di dalam pernyataan `with`. |
| 89 | 88 | ||
| 90 | ```yuescript | 89 | ```yuescript |
| 91 | with tb | 90 | with tb |
| @@ -94,7 +93,7 @@ with tb | |||
| 94 | with [abc] | 93 | with [abc] |
| 95 | [3] = [2]\func! | 94 | [3] = [2]\func! |
| 96 | ["key-name"] = value | 95 | ["key-name"] = value |
| 97 | [] = "abc" -- appending to "tb" | 96 | [] = "abc" -- menambahkan ke "tb" |
| 98 | ``` | 97 | ``` |
| 99 | <YueDisplay> | 98 | <YueDisplay> |
| 100 | 99 | ||
| @@ -105,12 +104,12 @@ with tb | |||
| 105 | with [abc] | 104 | with [abc] |
| 106 | [3] = [2]\func! | 105 | [3] = [2]\func! |
| 107 | ["key-name"] = value | 106 | ["key-name"] = value |
| 108 | [] = "abc" -- appending to "tb" | 107 | [] = "abc" -- menambahkan ke "tb" |
| 109 | ``` | 108 | ``` |
| 110 | 109 | ||
| 111 | </YueDisplay> | 110 | </YueDisplay> |
| 112 | 111 | ||
| 113 | `with?` is an enhanced version of `with` syntax, which introduces an existential check to safely access objects that may be nil without explicit null checks. | 112 | `with?` adalah versi yang ditingkatkan dari sintaks `with`, yang memperkenalkan pengecekan keberadaan untuk mengakses objek yang mungkin nil secara aman tanpa pemeriksaan null eksplisit. |
| 114 | 113 | ||
| 115 | ```yuescript | 114 | ```yuescript |
| 116 | with? obj | 115 | with? obj |
diff --git a/doc/docs/id-id/doc/reference/license-mit.md b/doc/docs/id-id/doc/reference/license-mit.md index f1d5d60..5289f50 100644 --- a/doc/docs/id-id/doc/reference/license-mit.md +++ b/doc/docs/id-id/doc/reference/license-mit.md | |||
| @@ -1,23 +1,22 @@ | |||
| 1 | # License: MIT | 1 | # Lisensi: MIT |
| 2 | 2 | ||
| 3 | Copyright (c) 2017-2026 Li Jin \<dragon-fly@qq.com\> | 3 | Copyright (c) 2017-2026 Li Jin <dragon-fly@qq.com> |
| 4 | 4 | ||
| 5 | Permission is hereby granted, free of charge, to any person obtaining a copy | 5 | Izin dengan ini diberikan, tanpa biaya, kepada siapa pun yang memperoleh salinan |
| 6 | of this software and associated documentation files (the "Software"), to deal | 6 | perangkat lunak ini beserta file dokumentasi terkait ("Perangkat Lunak"), untuk |
| 7 | in the Software without restriction, including without limitation the rights | 7 | berurusan dengan Perangkat Lunak tanpa pembatasan, termasuk tanpa batasan hak |
| 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 8 | untuk menggunakan, menyalin, memodifikasi, menggabungkan, menerbitkan, |
| 9 | copies of the Software, and to permit persons to whom the Software is | 9 | mendistribusikan, mensublisensikan, dan/atau menjual salinan Perangkat Lunak, |
| 10 | furnished to do so, subject to the following conditions: | 10 | dan untuk mengizinkan orang yang menerima Perangkat Lunak untuk melakukannya, |
| 11 | dengan syarat-syarat berikut: | ||
| 11 | 12 | ||
| 12 | The above copyright notice and this permission notice shall be included in all | 13 | Pemberitahuan hak cipta di atas dan pemberitahuan izin ini harus disertakan dalam |
| 13 | copies or substantial portions of the Software. | 14 | semua salinan atau bagian substansial dari Perangkat Lunak. |
| 14 | 15 | ||
| 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 16 | PERANGKAT LUNAK DISEDIAKAN "APA ADANYA", TANPA JAMINAN APA PUN, BAIK TERSURAT |
| 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 17 | MAUPUN TERSIRAT, TERMASUK NAMUN TIDAK TERBATAS PADA JAMINAN KELAYAKAN |
| 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 18 | DIPERDAGANGKAN, KESESUAIAN UNTUK TUJUAN TERTENTU, DAN TIDAK MELANGGAR HAK. |
| 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 19 | DALAM KEADAAN APA PUN, PENULIS ATAU PEMEGANG HAK CIPTA TIDAK BERTANGGUNG JAWAB |
| 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 20 | ATAS KLAIM, KERUSAKAN, ATAU KEWAJIBAN LAINNYA, BAIK DALAM TINDAKAN KONTRAK, |
| 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | 21 | PERBUATAN MELAWAN HUKUM, ATAU LAINNYA, YANG TIMBUL DARI, DI LUAR, ATAU TERKAIT |
| 21 | SOFTWARE. | 22 | DENGAN PERANGKAT LUNAK ATAU PENGGUNAAN ATAU URUSAN LAIN DALAM PERANGKAT LUNAK. |
| 22 | |||
| 23 | <CompilerModal /> | ||
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 3761755..0a398a5 100644 --- a/doc/docs/id-id/doc/reference/the-yuescript-library.md +++ b/doc/docs/id-id/doc/reference/the-yuescript-library.md | |||
| @@ -1,20 +1,20 @@ | |||
| 1 | # The YueScript Library | 1 | # Pustaka YueScript |
| 2 | 2 | ||
| 3 | Access it by `local yue = require("yue")` in Lua. | 3 | Akses dengan `local yue = require("yue")` di Lua. |
| 4 | 4 | ||
| 5 | ## yue | 5 | ## yue |
| 6 | 6 | ||
| 7 | **Description:** | 7 | **Deskripsi:** |
| 8 | 8 | ||
| 9 | The YueScript language library. | 9 | Pustaka bahasa YueScript. |
| 10 | 10 | ||
| 11 | ### version | 11 | ### version |
| 12 | 12 | ||
| 13 | **Type:** Field. | 13 | **Tipe:** Field. |
| 14 | 14 | ||
| 15 | **Description:** | 15 | **Deskripsi:** |
| 16 | 16 | ||
| 17 | The YueScript version. | 17 | Versi YueScript. |
| 18 | 18 | ||
| 19 | **Signature:** | 19 | **Signature:** |
| 20 | ```lua | 20 | ```lua |
| @@ -23,11 +23,11 @@ version: string | |||
| 23 | 23 | ||
| 24 | ### dirsep | 24 | ### dirsep |
| 25 | 25 | ||
| 26 | **Type:** Field. | 26 | **Tipe:** Field. |
| 27 | 27 | ||
| 28 | **Description:** | 28 | **Deskripsi:** |
| 29 | 29 | ||
| 30 | The file separator for the current platform. | 30 | Pemisah file untuk platform saat ini. |
| 31 | 31 | ||
| 32 | **Signature:** | 32 | **Signature:** |
| 33 | ```lua | 33 | ```lua |
| @@ -36,11 +36,11 @@ dirsep: string | |||
| 36 | 36 | ||
| 37 | ### yue_compiled | 37 | ### yue_compiled |
| 38 | 38 | ||
| 39 | **Type:** Field. | 39 | **Tipe:** Field. |
| 40 | 40 | ||
| 41 | **Description:** | 41 | **Deskripsi:** |
| 42 | 42 | ||
| 43 | The compiled module code cache. | 43 | Cache kode modul yang telah dikompilasi. |
| 44 | 44 | ||
| 45 | **Signature:** | 45 | **Signature:** |
| 46 | ```lua | 46 | ```lua |
| @@ -49,11 +49,11 @@ yue_compiled: {string: string} | |||
| 49 | 49 | ||
| 50 | ### to_lua | 50 | ### to_lua |
| 51 | 51 | ||
| 52 | **Type:** Function. | 52 | **Tipe:** Function. |
| 53 | 53 | ||
| 54 | **Description:** | 54 | **Deskripsi:** |
| 55 | 55 | ||
| 56 | The YueScript compiling function. It compiles the YueScript code to Lua code. | 56 | Fungsi kompilasi YueScript. Mengompilasi kode YueScript menjadi kode Lua. |
| 57 | 57 | ||
| 58 | **Signature:** | 58 | **Signature:** |
| 59 | ```lua | 59 | ```lua |
| @@ -63,122 +63,122 @@ to_lua: function(code: string, config?: Config): | |||
| 63 | --[[globals]] {{string, integer, integer}} | nil | 63 | --[[globals]] {{string, integer, integer}} | nil |
| 64 | ``` | 64 | ``` |
| 65 | 65 | ||
| 66 | **Parameters:** | 66 | **Parameter:** |
| 67 | 67 | ||
| 68 | | Parameter | Type | Description | | 68 | | Parameter | Tipe | Deskripsi | |
| 69 | | --- | --- | --- | | 69 | | --- | --- | --- | |
| 70 | | code | string | The YueScript code. | | 70 | | code | string | Kode YueScript. | |
| 71 | | config | Config | [Optional] The compiler options. | | 71 | | config | Config | [Opsional] Opsi kompiler. | |
| 72 | 72 | ||
| 73 | **Returns:** | 73 | **Return:** |
| 74 | 74 | ||
| 75 | | Return Type | Description | | 75 | | Tipe Return | Deskripsi | |
| 76 | | --- | --- | | 76 | | --- | --- | |
| 77 | | string \| nil | The compiled Lua code, or nil if the compilation failed. | | 77 | | string \| nil | Kode Lua hasil kompilasi, atau nil jika kompilasi gagal. | |
| 78 | | string \| nil | The error message, or nil if the compilation succeeded. | | 78 | | string \| nil | Pesan error, atau nil jika kompilasi berhasil. | |
| 79 | | {{string, integer, integer}} \| nil | The global variables appearing in the code (with name, row and column), or nil if the compiler option `lint_global` is false. | | 79 | | {{string, integer, integer}} \| nil | Variabel global yang muncul dalam kode (dengan nama, baris, dan kolom), atau nil jika opsi kompiler `lint_global` bernilai false. | |
| 80 | 80 | ||
| 81 | ### file_exist | 81 | ### file_exist |
| 82 | 82 | ||
| 83 | **Type:** Function. | 83 | **Tipe:** Function. |
| 84 | 84 | ||
| 85 | **Description:** | 85 | **Deskripsi:** |
| 86 | 86 | ||
| 87 | The source file existence checking function. Can be overridden to customize the behavior. | 87 | Fungsi untuk memeriksa keberadaan file sumber. Dapat ditimpa untuk menyesuaikan perilaku. |
| 88 | 88 | ||
| 89 | **Signature:** | 89 | **Signature:** |
| 90 | ```lua | 90 | ```lua |
| 91 | file_exist: function(filename: string): boolean | 91 | file_exist: function(filename: string): boolean |
| 92 | ``` | 92 | ``` |
| 93 | 93 | ||
| 94 | **Parameters:** | 94 | **Parameter:** |
| 95 | 95 | ||
| 96 | | Parameter | Type | Description | | 96 | | Parameter | Tipe | Deskripsi | |
| 97 | | --- | --- | --- | | 97 | | --- | --- | --- | |
| 98 | | filename | string | The file name. | | 98 | | filename | string | Nama file. | |
| 99 | 99 | ||
| 100 | **Returns:** | 100 | **Return:** |
| 101 | 101 | ||
| 102 | | Return Type | Description | | 102 | | Tipe Return | Deskripsi | |
| 103 | | --- | --- | | 103 | | --- | --- | |
| 104 | | boolean | Whether the file exists. | | 104 | | boolean | Apakah file ada. | |
| 105 | 105 | ||
| 106 | ### read_file | 106 | ### read_file |
| 107 | 107 | ||
| 108 | **Type:** Function. | 108 | **Tipe:** Function. |
| 109 | 109 | ||
| 110 | **Description:** | 110 | **Deskripsi:** |
| 111 | 111 | ||
| 112 | The source file reading function. Can be overridden to customize the behavior. | 112 | Fungsi untuk membaca file sumber. Dapat ditimpa untuk menyesuaikan perilaku. |
| 113 | 113 | ||
| 114 | **Signature:** | 114 | **Signature:** |
| 115 | ```lua | 115 | ```lua |
| 116 | read_file: function(filename: string): string | 116 | read_file: function(filename: string): string |
| 117 | ``` | 117 | ``` |
| 118 | 118 | ||
| 119 | **Parameters:** | 119 | **Parameter:** |
| 120 | 120 | ||
| 121 | | Parameter | Type | Description | | 121 | | Parameter | Tipe | Deskripsi | |
| 122 | | --- | --- | --- | | 122 | | --- | --- | --- | |
| 123 | | filename | string | The file name. | | 123 | | filename | string | Nama file. | |
| 124 | 124 | ||
| 125 | **Returns:** | 125 | **Return:** |
| 126 | 126 | ||
| 127 | | Return Type | Description | | 127 | | Tipe Return | Deskripsi | |
| 128 | | --- | --- | | 128 | | --- | --- | |
| 129 | | string | The file content. | | 129 | | string | Isi file. | |
| 130 | 130 | ||
| 131 | ### insert_loader | 131 | ### insert_loader |
| 132 | 132 | ||
| 133 | **Type:** Function. | 133 | **Tipe:** Function. |
| 134 | 134 | ||
| 135 | **Description:** | 135 | **Deskripsi:** |
| 136 | 136 | ||
| 137 | Insert the YueScript loader to the package loaders (searchers). | 137 | Menyisipkan loader YueScript ke package loaders (searchers). |
| 138 | 138 | ||
| 139 | **Signature:** | 139 | **Signature:** |
| 140 | ```lua | 140 | ```lua |
| 141 | insert_loader: function(pos?: integer): boolean | 141 | insert_loader: function(pos?: integer): boolean |
| 142 | ``` | 142 | ``` |
| 143 | 143 | ||
| 144 | **Parameters:** | 144 | **Parameter:** |
| 145 | 145 | ||
| 146 | | Parameter | Type | Description | | 146 | | Parameter | Tipe | Deskripsi | |
| 147 | | --- | --- | --- | | 147 | | --- | --- | --- | |
| 148 | | pos | integer | [Optional] The position to insert the loader. Default is 3. | | 148 | | pos | integer | [Opsional] Posisi untuk menyisipkan loader. Default adalah 3. | |
| 149 | 149 | ||
| 150 | **Returns:** | 150 | **Return:** |
| 151 | 151 | ||
| 152 | | Return Type | Description | | 152 | | Tipe Return | Deskripsi | |
| 153 | | --- | --- | | 153 | | --- | --- | |
| 154 | | boolean | Whether the loader is inserted successfully. It will fail if the loader is already inserted. | | 154 | | boolean | Apakah loader berhasil disisipkan. Akan gagal jika loader sudah disisipkan. | |
| 155 | 155 | ||
| 156 | ### remove_loader | 156 | ### remove_loader |
| 157 | 157 | ||
| 158 | **Type:** Function. | 158 | **Tipe:** Function. |
| 159 | 159 | ||
| 160 | **Description:** | 160 | **Deskripsi:** |
| 161 | 161 | ||
| 162 | Remove the YueScript loader from the package loaders (searchers). | 162 | Menghapus loader YueScript dari package loaders (searchers). |
| 163 | 163 | ||
| 164 | **Signature:** | 164 | **Signature:** |
| 165 | ```lua | 165 | ```lua |
| 166 | remove_loader: function(): boolean | 166 | remove_loader: function(): boolean |
| 167 | ``` | 167 | ``` |
| 168 | 168 | ||
| 169 | **Returns:** | 169 | **Return:** |
| 170 | 170 | ||
| 171 | | Return Type | Description | | 171 | | Tipe Return | Deskripsi | |
| 172 | | --- | --- | | 172 | | --- | --- | |
| 173 | | boolean | Whether the loader is removed successfully. It will fail if the loader is not inserted. | | 173 | | boolean | Apakah loader berhasil dihapus. Akan gagal jika loader belum disisipkan. | |
| 174 | 174 | ||
| 175 | ### loadstring | 175 | ### loadstring |
| 176 | 176 | ||
| 177 | **Type:** Function. | 177 | **Tipe:** Function. |
| 178 | 178 | ||
| 179 | **Description:** | 179 | **Deskripsi:** |
| 180 | 180 | ||
| 181 | Loads YueScript code from a string into a function. | 181 | Memuat kode YueScript dari string menjadi fungsi. |
| 182 | 182 | ||
| 183 | **Signature:** | 183 | **Signature:** |
| 184 | ```lua | 184 | ```lua |
| @@ -187,29 +187,29 @@ loadstring: function(input: string, chunkname: string, env: table, config?: Conf | |||
| 187 | --[[error]] string | nil | 187 | --[[error]] string | nil |
| 188 | ``` | 188 | ``` |
| 189 | 189 | ||
| 190 | **Parameters:** | 190 | **Parameter:** |
| 191 | 191 | ||
| 192 | | Parameter | Type | Description | | 192 | | Parameter | Tipe | Deskripsi | |
| 193 | | --- | --- | --- | | 193 | | --- | --- | --- | |
| 194 | | input | string | The YueScript code. | | 194 | | input | string | Kode YueScript. | |
| 195 | | chunkname | string | The name of the code chunk. | | 195 | | chunkname | string | Nama chunk kode. | |
| 196 | | env | table | The environment table. | | 196 | | env | table | Tabel environment. | |
| 197 | | config | Config | [Optional] The compiler options. | | 197 | | config | Config | [Opsional] Opsi kompiler. | |
| 198 | 198 | ||
| 199 | **Returns:** | 199 | **Return:** |
| 200 | 200 | ||
| 201 | | Return Type | Description | | 201 | | Tipe Return | Deskripsi | |
| 202 | | --- | --- | | 202 | | --- | --- | |
| 203 | | function \| nil | The loaded function, or nil if the loading failed. | | 203 | | function \| nil | Fungsi yang dimuat, atau nil jika pemuatan gagal. | |
| 204 | | string \| nil | The error message, or nil if the loading succeeded. | | 204 | | string \| nil | Pesan error, atau nil jika pemuatan berhasil. | |
| 205 | 205 | ||
| 206 | ### loadstring | 206 | ### loadstring |
| 207 | 207 | ||
| 208 | **Type:** Function. | 208 | **Tipe:** Function. |
| 209 | 209 | ||
| 210 | **Description:** | 210 | **Deskripsi:** |
| 211 | 211 | ||
| 212 | Loads YueScript code from a string into a function. | 212 | Memuat kode YueScript dari string menjadi fungsi. |
| 213 | 213 | ||
| 214 | **Signature:** | 214 | **Signature:** |
| 215 | ```lua | 215 | ```lua |
| @@ -218,28 +218,28 @@ loadstring: function(input: string, chunkname: string, config?: Config): | |||
| 218 | --[[error]] string | nil | 218 | --[[error]] string | nil |
| 219 | ``` | 219 | ``` |
| 220 | 220 | ||
| 221 | **Parameters:** | 221 | **Parameter:** |
| 222 | 222 | ||
| 223 | | Parameter | Type | Description | | 223 | | Parameter | Tipe | Deskripsi | |
| 224 | | --- | --- | --- | | 224 | | --- | --- | --- | |
| 225 | | input | string | The YueScript code. | | 225 | | input | string | Kode YueScript. | |
| 226 | | chunkname | string | The name of the code chunk. | | 226 | | chunkname | string | Nama chunk kode. | |
| 227 | | config | Config | [Optional] The compiler options. | | 227 | | config | Config | [Opsional] Opsi kompiler. | |
| 228 | 228 | ||
| 229 | **Returns:** | 229 | **Return:** |
| 230 | 230 | ||
| 231 | | Return Type | Description | | 231 | | Tipe Return | Deskripsi | |
| 232 | | --- | --- | | 232 | | --- | --- | |
| 233 | | function \| nil | The loaded function, or nil if the loading failed. | | 233 | | function \| nil | Fungsi yang dimuat, atau nil jika pemuatan gagal. | |
| 234 | | string \| nil | The error message, or nil if the loading succeeded. | | 234 | | string \| nil | Pesan error, atau nil jika pemuatan berhasil. | |
| 235 | 235 | ||
| 236 | ### loadstring | 236 | ### loadstring |
| 237 | 237 | ||
| 238 | **Type:** Function. | 238 | **Tipe:** Function. |
| 239 | 239 | ||
| 240 | **Description:** | 240 | **Deskripsi:** |
| 241 | 241 | ||
| 242 | Loads YueScript code from a string into a function. | 242 | Memuat kode YueScript dari string menjadi fungsi. |
| 243 | 243 | ||
| 244 | **Signature:** | 244 | **Signature:** |
| 245 | ```lua | 245 | ```lua |
| @@ -248,27 +248,27 @@ loadstring: function(input: string, config?: Config): | |||
| 248 | --[[error]] string | nil | 248 | --[[error]] string | nil |
| 249 | ``` | 249 | ``` |
| 250 | 250 | ||
| 251 | **Parameters:** | 251 | **Parameter:** |
| 252 | 252 | ||
| 253 | | Parameter | Type | Description | | 253 | | Parameter | Tipe | Deskripsi | |
| 254 | | --- | --- | --- | | 254 | | --- | --- | --- | |
| 255 | | input | string | The YueScript code. | | 255 | | input | string | Kode YueScript. | |
| 256 | | config | Config | [Optional] The compiler options. | | 256 | | config | Config | [Opsional] Opsi kompiler. | |
| 257 | 257 | ||
| 258 | **Returns:** | 258 | **Return:** |
| 259 | 259 | ||
| 260 | | Return Type | Description | | 260 | | Tipe Return | Deskripsi | |
| 261 | | --- | --- | | 261 | | --- | --- | |
| 262 | | function \| nil | The loaded function, or nil if the loading failed. | | 262 | | function \| nil | Fungsi yang dimuat, atau nil jika pemuatan gagal. | |
| 263 | | string \| nil | The error message, or nil if the loading succeeded. | | 263 | | string \| nil | Pesan error, atau nil jika pemuatan berhasil. | |
| 264 | 264 | ||
| 265 | ### loadfile | 265 | ### loadfile |
| 266 | 266 | ||
| 267 | **Type:** Function. | 267 | **Tipe:** Function. |
| 268 | 268 | ||
| 269 | **Description:** | 269 | **Deskripsi:** |
| 270 | 270 | ||
| 271 | Loads YueScript code from a file into a function. | 271 | Memuat kode YueScript dari file menjadi fungsi. |
| 272 | 272 | ||
| 273 | **Signature:** | 273 | **Signature:** |
| 274 | ```lua | 274 | ```lua |
| @@ -277,28 +277,28 @@ loadfile: function(filename: string, env: table, config?: Config): | |||
| 277 | string | nil | 277 | string | nil |
| 278 | ``` | 278 | ``` |
| 279 | 279 | ||
| 280 | **Parameters:** | 280 | **Parameter:** |
| 281 | 281 | ||
| 282 | | Parameter | Type | Description | | 282 | | Parameter | Tipe | Deskripsi | |
| 283 | | --- | --- | --- | | 283 | | --- | --- | --- | |
| 284 | | filename | string | The file name. | | 284 | | filename | string | Nama file. | |
| 285 | | env | table | The environment table. | | 285 | | env | table | Tabel environment. | |
| 286 | | config | Config | [Optional] The compiler options. | | 286 | | config | Config | [Opsional] Opsi kompiler. | |
| 287 | 287 | ||
| 288 | **Returns:** | 288 | **Return:** |
| 289 | 289 | ||
| 290 | | Return Type | Description | | 290 | | Tipe Return | Deskripsi | |
| 291 | | --- | --- | | 291 | | --- | --- | |
| 292 | | function \| nil | The loaded function, or nil if the loading failed. | | 292 | | function \| nil | Fungsi yang dimuat, atau nil jika pemuatan gagal. | |
| 293 | | string \| nil | The error message, or nil if the loading succeeded. | | 293 | | string \| nil | Pesan error, atau nil jika pemuatan berhasil. | |
| 294 | 294 | ||
| 295 | ### loadfile | 295 | ### loadfile |
| 296 | 296 | ||
| 297 | **Type:** Function. | 297 | **Tipe:** Function. |
| 298 | 298 | ||
| 299 | **Description:** | 299 | **Deskripsi:** |
| 300 | 300 | ||
| 301 | Loads YueScript code from a file into a function. | 301 | Memuat kode YueScript dari file menjadi fungsi. |
| 302 | 302 | ||
| 303 | **Signature:** | 303 | **Signature:** |
| 304 | ```lua | 304 | ```lua |
| @@ -307,178 +307,178 @@ loadfile: function(filename: string, config?: Config): | |||
| 307 | string | nil | 307 | string | nil |
| 308 | ``` | 308 | ``` |
| 309 | 309 | ||
| 310 | **Parameters:** | 310 | **Parameter:** |
| 311 | 311 | ||
| 312 | | Parameter | Type | Description | | 312 | | Parameter | Tipe | Deskripsi | |
| 313 | | --- | --- | --- | | 313 | | --- | --- | --- | |
| 314 | | filename | string | The file name. | | 314 | | filename | string | Nama file. | |
| 315 | | config | Config | [Optional] The compiler options. | | 315 | | config | Config | [Opsional] Opsi kompiler. | |
| 316 | 316 | ||
| 317 | **Returns:** | 317 | **Return:** |
| 318 | 318 | ||
| 319 | | Return Type | Description | | 319 | | Tipe Return | Deskripsi | |
| 320 | | --- | --- | | 320 | | --- | --- | |
| 321 | | function \| nil | The loaded function, or nil if the loading failed. | | 321 | | function \| nil | Fungsi yang dimuat, atau nil jika pemuatan gagal. | |
| 322 | | string \| nil | The error message, or nil if the loading succeeded. | | 322 | | string \| nil | Pesan error, atau nil jika pemuatan berhasil. | |
| 323 | 323 | ||
| 324 | ### dofile | 324 | ### dofile |
| 325 | 325 | ||
| 326 | **Type:** Function. | 326 | **Tipe:** Function. |
| 327 | 327 | ||
| 328 | **Description:** | 328 | **Deskripsi:** |
| 329 | 329 | ||
| 330 | Loads YueScript code from a file into a function and executes it. | 330 | Memuat kode YueScript dari file menjadi fungsi dan mengeksekusinya. |
| 331 | 331 | ||
| 332 | **Signature:** | 332 | **Signature:** |
| 333 | ```lua | 333 | ```lua |
| 334 | dofile: function(filename: string, env: table, config?: Config): any... | 334 | dofile: function(filename: string, env: table, config?: Config): any... |
| 335 | ``` | 335 | ``` |
| 336 | 336 | ||
| 337 | **Parameters:** | 337 | **Parameter:** |
| 338 | 338 | ||
| 339 | | Parameter | Type | Description | | 339 | | Parameter | Tipe | Deskripsi | |
| 340 | | --- | --- | --- | | 340 | | --- | --- | --- | |
| 341 | | filename | string | The file name. | | 341 | | filename | string | Nama file. | |
| 342 | | env | table | The environment table. | | 342 | | env | table | Tabel environment. | |
| 343 | | config | Config | [Optional] The compiler options. | | 343 | | config | Config | [Opsional] Opsi kompiler. | |
| 344 | 344 | ||
| 345 | **Returns:** | 345 | **Return:** |
| 346 | 346 | ||
| 347 | | Return Type | Description | | 347 | | Tipe Return | Deskripsi | |
| 348 | | --- | --- | | 348 | | --- | --- | |
| 349 | | any... | The return values of the loaded function. | | 349 | | any... | Nilai return dari fungsi yang dimuat. | |
| 350 | 350 | ||
| 351 | ### dofile | 351 | ### dofile |
| 352 | 352 | ||
| 353 | **Type:** Function. | 353 | **Tipe:** Function. |
| 354 | 354 | ||
| 355 | **Description:** | 355 | **Deskripsi:** |
| 356 | 356 | ||
| 357 | Loads YueScript code from a file into a function and executes it. | 357 | Memuat kode YueScript dari file menjadi fungsi dan mengeksekusinya. |
| 358 | 358 | ||
| 359 | **Signature:** | 359 | **Signature:** |
| 360 | ```lua | 360 | ```lua |
| 361 | dofile: function(filename: string, config?: Config): any... | 361 | dofile: function(filename: string, config?: Config): any... |
| 362 | ``` | 362 | ``` |
| 363 | 363 | ||
| 364 | **Parameters:** | 364 | **Parameter:** |
| 365 | 365 | ||
| 366 | | Parameter | Type | Description | | 366 | | Parameter | Tipe | Deskripsi | |
| 367 | | --- | --- | --- | | 367 | | --- | --- | --- | |
| 368 | | filename | string | The file name. | | 368 | | filename | string | Nama file. | |
| 369 | | config | Config | [Optional] The compiler options. | | 369 | | config | Config | [Opsional] Opsi kompiler. | |
| 370 | 370 | ||
| 371 | **Returns:** | 371 | **Return:** |
| 372 | 372 | ||
| 373 | | Return Type | Description | | 373 | | Tipe Return | Deskripsi | |
| 374 | | --- | --- | | 374 | | --- | --- | |
| 375 | | any... | The return values of the loaded function. | | 375 | | any... | Nilai return dari fungsi yang dimuat. | |
| 376 | 376 | ||
| 377 | ### find_modulepath | 377 | ### find_modulepath |
| 378 | 378 | ||
| 379 | **Type:** Function. | 379 | **Tipe:** Function. |
| 380 | 380 | ||
| 381 | **Description:** | 381 | **Deskripsi:** |
| 382 | 382 | ||
| 383 | Resolves the YueScript module name to the file path. | 383 | Menguraikan nama modul YueScript menjadi path file. |
| 384 | 384 | ||
| 385 | **Signature:** | 385 | **Signature:** |
| 386 | ```lua | 386 | ```lua |
| 387 | find_modulepath: function(name: string): string | 387 | find_modulepath: function(name: string): string |
| 388 | ``` | 388 | ``` |
| 389 | 389 | ||
| 390 | **Parameters:** | 390 | **Parameter:** |
| 391 | 391 | ||
| 392 | | Parameter | Type | Description | | 392 | | Parameter | Tipe | Deskripsi | |
| 393 | | --- | --- | --- | | 393 | | --- | --- | --- | |
| 394 | | name | string | The module name. | | 394 | | name | string | Nama modul. | |
| 395 | 395 | ||
| 396 | **Returns:** | 396 | **Return:** |
| 397 | 397 | ||
| 398 | | Return Type | Description | | 398 | | Tipe Return | Deskripsi | |
| 399 | | --- | --- | | 399 | | --- | --- | |
| 400 | | string | The file path. | | 400 | | string | Path file. | |
| 401 | 401 | ||
| 402 | ### pcall | 402 | ### pcall |
| 403 | 403 | ||
| 404 | **Type:** Function. | 404 | **Tipe:** Function. |
| 405 | 405 | ||
| 406 | **Description:** | 406 | **Deskripsi:** |
| 407 | 407 | ||
| 408 | Calls a function in protected mode. | 408 | Memanggil fungsi dalam mode terlindungi. |
| 409 | Catches any errors and returns a status code and results or error object. | 409 | Menangkap error apa pun dan mengembalikan kode status beserta hasil atau objek error. |
| 410 | Rewrites the error line number to the original line number in the YueScript code when errors occur. | 410 | Menulis ulang nomor baris error ke nomor baris asli di kode YueScript saat error terjadi. |
| 411 | 411 | ||
| 412 | **Signature:** | 412 | **Signature:** |
| 413 | ```lua | 413 | ```lua |
| 414 | pcall: function(f: function, ...: any): boolean, any... | 414 | pcall: function(f: function, ...: any): boolean, any... |
| 415 | ``` | 415 | ``` |
| 416 | 416 | ||
| 417 | **Parameters:** | 417 | **Parameter:** |
| 418 | 418 | ||
| 419 | | Parameter | Type | Description | | 419 | | Parameter | Tipe | Deskripsi | |
| 420 | | --- | --- | --- | | 420 | | --- | --- | --- | |
| 421 | | f | function | The function to call. | | 421 | | f | function | Fungsi yang akan dipanggil. | |
| 422 | | ... | any | Arguments to pass to the function. | | 422 | | ... | any | Argumen yang diteruskan ke fungsi. | |
| 423 | 423 | ||
| 424 | **Returns:** | 424 | **Return:** |
| 425 | 425 | ||
| 426 | | Return Type | Description | | 426 | | Tipe Return | Deskripsi | |
| 427 | | --- | --- | | 427 | | --- | --- | |
| 428 | | boolean, ... | Status code and function results or error object. | | 428 | | boolean, ... | Kode status dan hasil fungsi atau objek error. | |
| 429 | 429 | ||
| 430 | ### require | 430 | ### require |
| 431 | 431 | ||
| 432 | **Type:** Function. | 432 | **Tipe:** Function. |
| 433 | 433 | ||
| 434 | **Description:** | 434 | **Deskripsi:** |
| 435 | 435 | ||
| 436 | Loads a given module. Can be either a Lua module or a YueScript module. | 436 | Memuat modul tertentu. Bisa berupa modul Lua atau modul YueScript. |
| 437 | Rewrites the error line number to the original line number in the YueScript code if the module is a YueScript module and loading fails. | 437 | Menulis ulang nomor baris error ke nomor baris asli di kode YueScript jika modul adalah modul YueScript dan pemuatan gagal. |
| 438 | 438 | ||
| 439 | **Signature:** | 439 | **Signature:** |
| 440 | ```lua | 440 | ```lua |
| 441 | require: function(name: string): any... | 441 | require: function(name: string): any... |
| 442 | ``` | 442 | ``` |
| 443 | 443 | ||
| 444 | **Parameters:** | 444 | **Parameter:** |
| 445 | 445 | ||
| 446 | | Parameter | Type | Description | | 446 | | Parameter | Tipe | Deskripsi | |
| 447 | | --- | --- | --- | | 447 | | --- | --- | --- | |
| 448 | | modname | string | The name of the module to load. | | 448 | | modname | string | Nama modul yang akan dimuat. | |
| 449 | 449 | ||
| 450 | **Returns:** | 450 | **Return:** |
| 451 | 451 | ||
| 452 | | Return Type | Description | | 452 | | Tipe Return | Deskripsi | |
| 453 | | --- | --- | | 453 | | --- | --- | |
| 454 | | any | The value stored at package.loaded[modname] if the module is already loaded.Otherwise, tries to find a loader and returns the final value of package.loaded[modname] and a loader data as a second result. | | 454 | | 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. | |
| 455 | 455 | ||
| 456 | ### p | 456 | ### p |
| 457 | 457 | ||
| 458 | **Type:** Function. | 458 | **Tipe:** Function. |
| 459 | 459 | ||
| 460 | **Description:** | 460 | **Deskripsi:** |
| 461 | 461 | ||
| 462 | Inspects the structures of the passed values and prints string representations. | 462 | Memeriksa struktur nilai yang diteruskan dan mencetak representasi string. |
| 463 | 463 | ||
| 464 | **Signature:** | 464 | **Signature:** |
| 465 | ```lua | 465 | ```lua |
| 466 | p: function(...: any) | 466 | p: function(...: any) |
| 467 | ``` | 467 | ``` |
| 468 | 468 | ||
| 469 | **Parameters:** | 469 | **Parameter:** |
| 470 | 470 | ||
| 471 | | Parameter | Type | Description | | 471 | | Parameter | Tipe | Deskripsi | |
| 472 | | --- | --- | --- | | 472 | | --- | --- | --- | |
| 473 | | ... | any | The values to inspect. | | 473 | | ... | any | Nilai yang akan diperiksa. | |
| 474 | 474 | ||
| 475 | ### options | 475 | ### options |
| 476 | 476 | ||
| 477 | **Type:** Field. | 477 | **Tipe:** Field. |
| 478 | 478 | ||
| 479 | **Description:** | 479 | **Deskripsi:** |
| 480 | 480 | ||
| 481 | The current compiler options. | 481 | Opsi kompiler saat ini. |
| 482 | 482 | ||
| 483 | **Signature:** | 483 | **Signature:** |
| 484 | ```lua | 484 | ```lua |
| @@ -487,62 +487,62 @@ options: Config.Options | |||
| 487 | 487 | ||
| 488 | ### traceback | 488 | ### traceback |
| 489 | 489 | ||
| 490 | **Type:** Function. | 490 | **Tipe:** Function. |
| 491 | 491 | ||
| 492 | **Description:** | 492 | **Deskripsi:** |
| 493 | 493 | ||
| 494 | The traceback function that rewrites the stack trace line numbers to the original line numbers in the YueScript code. | 494 | Fungsi traceback yang menulis ulang nomor baris stack trace ke nomor baris asli di kode YueScript. |
| 495 | 495 | ||
| 496 | **Signature:** | 496 | **Signature:** |
| 497 | ```lua | 497 | ```lua |
| 498 | traceback: function(message: string): string | 498 | traceback: function(message: string): string |
| 499 | ``` | 499 | ``` |
| 500 | 500 | ||
| 501 | **Parameters:** | 501 | **Parameter:** |
| 502 | 502 | ||
| 503 | | Parameter | Type | Description | | 503 | | Parameter | Tipe | Deskripsi | |
| 504 | | --- | --- | --- | | 504 | | --- | --- | --- | |
| 505 | | message | string | The traceback message. | | 505 | | message | string | Pesan traceback. | |
| 506 | 506 | ||
| 507 | **Returns:** | 507 | **Return:** |
| 508 | 508 | ||
| 509 | | Return Type | Description | | 509 | | Tipe Return | Deskripsi | |
| 510 | | --- | --- | | 510 | | --- | --- | |
| 511 | | string | The rewritten traceback message. | | 511 | | string | Pesan traceback yang telah ditulis ulang. | |
| 512 | 512 | ||
| 513 | ### is_ast | 513 | ### is_ast |
| 514 | 514 | ||
| 515 | **Type:** Function. | 515 | **Tipe:** Function. |
| 516 | 516 | ||
| 517 | **Description:** | 517 | **Deskripsi:** |
| 518 | 518 | ||
| 519 | Checks whether the code matches the specified AST. | 519 | Memeriksa apakah kode cocok dengan AST yang ditentukan. |
| 520 | 520 | ||
| 521 | **Signature:** | 521 | **Signature:** |
| 522 | ```lua | 522 | ```lua |
| 523 | is_ast: function(astName: string, code: string): boolean | 523 | is_ast: function(astName: string, code: string): boolean |
| 524 | ``` | 524 | ``` |
| 525 | 525 | ||
| 526 | **Parameters:** | 526 | **Parameter:** |
| 527 | 527 | ||
| 528 | | Parameter | Type | Description | | 528 | | Parameter | Tipe | Deskripsi | |
| 529 | | --- | --- | --- | | 529 | | --- | --- | --- | |
| 530 | | astName | string | The AST name. | | 530 | | astName | string | Nama AST. | |
| 531 | | code | string | The code. | | 531 | | code | string | Kode. | |
| 532 | 532 | ||
| 533 | **Returns:** | 533 | **Return:** |
| 534 | 534 | ||
| 535 | | Return Type | Description | | 535 | | Tipe Return | Deskripsi | |
| 536 | | --- | --- | | 536 | | --- | --- | |
| 537 | | boolean | Whether the code matches the AST. | | 537 | | boolean | Apakah kode cocok dengan AST. | |
| 538 | 538 | ||
| 539 | ### AST | 539 | ### AST |
| 540 | 540 | ||
| 541 | **Type:** Field. | 541 | **Tipe:** Field. |
| 542 | 542 | ||
| 543 | **Description:** | 543 | **Deskripsi:** |
| 544 | 544 | ||
| 545 | The AST type definition with name, row, column and sub nodes. | 545 | Definisi tipe AST dengan nama, baris, kolom, dan sub-node. |
| 546 | 546 | ||
| 547 | **Signature:** | 547 | **Signature:** |
| 548 | ```lua | 548 | ```lua |
| @@ -551,11 +551,11 @@ type AST = {string, integer, integer, any} | |||
| 551 | 551 | ||
| 552 | ### to_ast | 552 | ### to_ast |
| 553 | 553 | ||
| 554 | **Type:** Function. | 554 | **Tipe:** Function. |
| 555 | 555 | ||
| 556 | **Description:** | 556 | **Deskripsi:** |
| 557 | 557 | ||
| 558 | Converts the code to the AST. | 558 | Mengonversi kode menjadi AST. |
| 559 | 559 | ||
| 560 | **Signature:** | 560 | **Signature:** |
| 561 | ```lua | 561 | ```lua |
| @@ -564,88 +564,88 @@ to_ast: function(code: string, flattenLevel?: number, astName?: string, reserveC | |||
| 564 | --[[error]] nil | string | 564 | --[[error]] nil | string |
| 565 | ``` | 565 | ``` |
| 566 | 566 | ||
| 567 | **Parameters:** | 567 | **Parameter:** |
| 568 | 568 | ||
| 569 | | Parameter | Type | Description | | 569 | | Parameter | Tipe | Deskripsi | |
| 570 | | --- | --- | --- | | 570 | | --- | --- | --- | |
| 571 | | code | string | The code. | | 571 | | code | string | Kode. | |
| 572 | | flattenLevel | integer | [Optional] The flatten level. Higher level means more flattening. Default is 0. Maximum is 2. | | 572 | | flattenLevel | integer | [Opsional] Tingkat perataan. Semakin tinggi berarti semakin rata. Default 0. Maksimum 2. | |
| 573 | | astName | string | [Optional] The AST name. Default is "File". | | 573 | | astName | string | [Opsional] Nama AST. Default "File". | |
| 574 | | reserveComment | boolean | [Optional] Whether to reserve the original comments. Default is false. | | 574 | | reserveComment | boolean | [Opsional] Apakah akan mempertahankan komentar asli. Default false. | |
| 575 | 575 | ||
| 576 | **Returns:** | 576 | **Return:** |
| 577 | 577 | ||
| 578 | | Return Type | Description | | 578 | | Tipe Return | Deskripsi | |
| 579 | | --- | --- | | 579 | | --- | --- | |
| 580 | | AST \| nil | The AST, or nil if the conversion failed. | | 580 | | AST \| nil | AST, atau nil jika konversi gagal. | |
| 581 | | string \| nil | The error message, or nil if the conversion succeeded. | | 581 | | string \| nil | Pesan error, atau nil jika konversi berhasil. | |
| 582 | 582 | ||
| 583 | ### format | 583 | ### format |
| 584 | 584 | ||
| 585 | **Type:** Function. | 585 | **Tipe:** Function. |
| 586 | 586 | ||
| 587 | **Description:** | 587 | **Deskripsi:** |
| 588 | 588 | ||
| 589 | Formats the YueScript code. | 589 | Memformat kode YueScript. |
| 590 | 590 | ||
| 591 | **Signature:** | 591 | **Signature:** |
| 592 | ```lua | 592 | ```lua |
| 593 | format: function(code: string, tabSize?: number, reserveComment?: boolean): string | 593 | format: function(code: string, tabSize?: number, reserveComment?: boolean): string |
| 594 | ``` | 594 | ``` |
| 595 | 595 | ||
| 596 | **Parameters:** | 596 | **Parameter:** |
| 597 | 597 | ||
| 598 | | Parameter | Type | Description | | 598 | | Parameter | Tipe | Deskripsi | |
| 599 | | --- | --- | --- | | 599 | | --- | --- | --- | |
| 600 | | code | string | The code. | | 600 | | code | string | Kode. | |
| 601 | | tabSize | integer | [Optional] The tab size. Default is 4. | | 601 | | tabSize | integer | [Opsional] Ukuran tab. Default 4. | |
| 602 | | reserveComment | boolean | [Optional] Whether to reserve the original comments. Default is true. | | 602 | | reserveComment | boolean | [Opsional] Apakah mempertahankan komentar asli. Default true. | |
| 603 | 603 | ||
| 604 | **Returns:** | 604 | **Return:** |
| 605 | 605 | ||
| 606 | | Return Type | Description | | 606 | | Tipe Return | Deskripsi | |
| 607 | | --- | --- | | 607 | | --- | --- | |
| 608 | | string | The formatted code. | | 608 | | string | Kode yang telah diformat. | |
| 609 | 609 | ||
| 610 | ### __call | 610 | ### __call |
| 611 | 611 | ||
| 612 | **Type:** Metamethod. | 612 | **Tipe:** Metamethod. |
| 613 | 613 | ||
| 614 | **Description:** | 614 | **Deskripsi:** |
| 615 | 615 | ||
| 616 | Requires the YueScript module. | 616 | Me-require modul YueScript. |
| 617 | Rewrites the error line number to the original line number in the YueScript code when loading fails. | 617 | Menulis ulang nomor baris error ke nomor baris asli di kode YueScript saat pemuatan gagal. |
| 618 | 618 | ||
| 619 | **Signature:** | 619 | **Signature:** |
| 620 | ```lua | 620 | ```lua |
| 621 | metamethod __call: function(self: yue, module: string): any... | 621 | metamethod __call: function(self: yue, module: string): any... |
| 622 | ``` | 622 | ``` |
| 623 | 623 | ||
| 624 | **Parameters:** | 624 | **Parameter:** |
| 625 | 625 | ||
| 626 | | Parameter | Type | Description | | 626 | | Parameter | Tipe | Deskripsi | |
| 627 | | --- | --- | --- | | 627 | | --- | --- | --- | |
| 628 | | module | string | The module name. | | 628 | | module | string | Nama modul. | |
| 629 | 629 | ||
| 630 | **Returns:** | 630 | **Return:** |
| 631 | 631 | ||
| 632 | | Return Type | Description | | 632 | | Tipe Return | Deskripsi | |
| 633 | | --- | --- | | 633 | | --- | --- | |
| 634 | | any | The module value. | | 634 | | any | Nilai modul. | |
| 635 | 635 | ||
| 636 | ## Config | 636 | ## Config |
| 637 | 637 | ||
| 638 | **Description:** | 638 | **Deskripsi:** |
| 639 | 639 | ||
| 640 | The compiler compile options. | 640 | Opsi kompilasi kompiler. |
| 641 | 641 | ||
| 642 | ### lint_global | 642 | ### lint_global |
| 643 | 643 | ||
| 644 | **Type:** Field. | 644 | **Tipe:** Field. |
| 645 | 645 | ||
| 646 | **Description:** | 646 | **Deskripsi:** |
| 647 | 647 | ||
| 648 | Whether the compiler should collect the global variables appearing in the code. | 648 | Apakah kompiler harus mengumpulkan variabel global yang muncul dalam kode. |
| 649 | 649 | ||
| 650 | **Signature:** | 650 | **Signature:** |
| 651 | ```lua | 651 | ```lua |
| @@ -654,11 +654,11 @@ lint_global: boolean | |||
| 654 | 654 | ||
| 655 | ### implicit_return_root | 655 | ### implicit_return_root |
| 656 | 656 | ||
| 657 | **Type:** Field. | 657 | **Tipe:** Field. |
| 658 | 658 | ||
| 659 | **Description:** | 659 | **Deskripsi:** |
| 660 | 660 | ||
| 661 | Whether the compiler should do an implicit return for the root code block. | 661 | Apakah kompiler harus melakukan return implisit untuk blok kode root. |
| 662 | 662 | ||
| 663 | **Signature:** | 663 | **Signature:** |
| 664 | ```lua | 664 | ```lua |
| @@ -667,11 +667,11 @@ implicit_return_root: boolean | |||
| 667 | 667 | ||
| 668 | ### reserve_line_number | 668 | ### reserve_line_number |
| 669 | 669 | ||
| 670 | **Type:** Field. | 670 | **Tipe:** Field. |
| 671 | 671 | ||
| 672 | **Description:** | 672 | **Deskripsi:** |
| 673 | 673 | ||
| 674 | Whether the compiler should reserve the original line number in the compiled code. | 674 | Apakah kompiler harus mempertahankan nomor baris asli di kode hasil kompilasi. |
| 675 | 675 | ||
| 676 | **Signature:** | 676 | **Signature:** |
| 677 | ```lua | 677 | ```lua |
| @@ -680,11 +680,11 @@ reserve_line_number: boolean | |||
| 680 | 680 | ||
| 681 | ### reserve_comment | 681 | ### reserve_comment |
| 682 | 682 | ||
| 683 | **Type:** Field. | 683 | **Tipe:** Field. |
| 684 | 684 | ||
| 685 | **Description:** | 685 | **Deskripsi:** |
| 686 | 686 | ||
| 687 | Whether the compiler should reserve the original comments in the compiled code. | 687 | Apakah kompiler harus mempertahankan komentar asli di kode hasil kompilasi. |
| 688 | 688 | ||
| 689 | **Signature:** | 689 | **Signature:** |
| 690 | ```lua | 690 | ```lua |
| @@ -693,11 +693,11 @@ reserve_comment: boolean | |||
| 693 | 693 | ||
| 694 | ### space_over_tab | 694 | ### space_over_tab |
| 695 | 695 | ||
| 696 | **Type:** Field. | 696 | **Tipe:** Field. |
| 697 | 697 | ||
| 698 | **Description:** | 698 | **Deskripsi:** |
| 699 | 699 | ||
| 700 | Whether the compiler should use the space character instead of the tab character in the compiled code. | 700 | Apakah kompiler harus menggunakan karakter spasi alih-alih tab di kode hasil kompilasi. |
| 701 | 701 | ||
| 702 | **Signature:** | 702 | **Signature:** |
| 703 | ```lua | 703 | ```lua |
| @@ -706,11 +706,11 @@ space_over_tab: boolean | |||
| 706 | 706 | ||
| 707 | ### same_module | 707 | ### same_module |
| 708 | 708 | ||
| 709 | **Type:** Field. | 709 | **Tipe:** Field. |
| 710 | 710 | ||
| 711 | **Description:** | 711 | **Deskripsi:** |
| 712 | 712 | ||
| 713 | Whether the compiler should treat the code to be compiled as the same currently being compiled module. For internal use only. | 713 | Apakah kompiler harus memperlakukan kode yang akan dikompilasi sebagai modul yang sama dengan modul yang sedang dikompilasi. Untuk penggunaan internal saja. |
| 714 | 714 | ||
| 715 | **Signature:** | 715 | **Signature:** |
| 716 | ```lua | 716 | ```lua |
| @@ -719,11 +719,11 @@ same_module: boolean | |||
| 719 | 719 | ||
| 720 | ### line_offset | 720 | ### line_offset |
| 721 | 721 | ||
| 722 | **Type:** Field. | 722 | **Tipe:** Field. |
| 723 | 723 | ||
| 724 | **Description:** | 724 | **Deskripsi:** |
| 725 | 725 | ||
| 726 | Whether the compiler error message should include the line number offset. For internal use only. | 726 | Apakah pesan error kompiler harus menyertakan offset nomor baris. Untuk penggunaan internal saja. |
| 727 | 727 | ||
| 728 | **Signature:** | 728 | **Signature:** |
| 729 | ```lua | 729 | ```lua |
| @@ -732,11 +732,11 @@ line_offset: integer | |||
| 732 | 732 | ||
| 733 | ### yue.Config.LuaTarget | 733 | ### yue.Config.LuaTarget |
| 734 | 734 | ||
| 735 | **Type:** Enumeration. | 735 | **Tipe:** Enumeration. |
| 736 | 736 | ||
| 737 | **Description:** | 737 | **Deskripsi:** |
| 738 | 738 | ||
| 739 | The target Lua version enumeration. | 739 | Enumerasi versi Lua target. |
| 740 | 740 | ||
| 741 | **Signature:** | 741 | **Signature:** |
| 742 | ```lua | 742 | ```lua |
| @@ -751,11 +751,11 @@ end | |||
| 751 | 751 | ||
| 752 | ### options | 752 | ### options |
| 753 | 753 | ||
| 754 | **Type:** Field. | 754 | **Tipe:** Field. |
| 755 | 755 | ||
| 756 | **Description:** | 756 | **Deskripsi:** |
| 757 | 757 | ||
| 758 | The extra options to be passed to the compilation function. | 758 | Opsi tambahan untuk diteruskan ke fungsi kompilasi. |
| 759 | 759 | ||
| 760 | **Signature:** | 760 | **Signature:** |
| 761 | ```lua | 761 | ```lua |
| @@ -764,17 +764,17 @@ options: Options | |||
| 764 | 764 | ||
| 765 | ## Options | 765 | ## Options |
| 766 | 766 | ||
| 767 | **Description:** | 767 | **Deskripsi:** |
| 768 | 768 | ||
| 769 | The extra compiler options definition. | 769 | Definisi opsi kompiler tambahan. |
| 770 | 770 | ||
| 771 | ### target | 771 | ### target |
| 772 | 772 | ||
| 773 | **Type:** Field. | 773 | **Tipe:** Field. |
| 774 | 774 | ||
| 775 | **Description:** | 775 | **Deskripsi:** |
| 776 | 776 | ||
| 777 | The target Lua version for the compilation. | 777 | Versi Lua target untuk kompilasi. |
| 778 | 778 | ||
| 779 | **Signature:** | 779 | **Signature:** |
| 780 | ```lua | 780 | ```lua |
| @@ -783,11 +783,11 @@ target: LuaTarget | |||
| 783 | 783 | ||
| 784 | ### path | 784 | ### path |
| 785 | 785 | ||
| 786 | **Type:** Field. | 786 | **Tipe:** Field. |
| 787 | 787 | ||
| 788 | **Description:** | 788 | **Deskripsi:** |
| 789 | 789 | ||
| 790 | The extra module search path. | 790 | Path pencarian modul tambahan. |
| 791 | 791 | ||
| 792 | **Signature:** | 792 | **Signature:** |
| 793 | ```lua | 793 | ```lua |
| @@ -796,11 +796,11 @@ path: string | |||
| 796 | 796 | ||
| 797 | ### dump_locals | 797 | ### dump_locals |
| 798 | 798 | ||
| 799 | **Type:** Field. | 799 | **Tipe:** Field. |
| 800 | 800 | ||
| 801 | **Description:** | 801 | **Deskripsi:** |
| 802 | 802 | ||
| 803 | Whether to dump the local variables in the traceback error message. Default is false. | 803 | Apakah akan menampilkan variabel local dalam pesan error traceback. Default false. |
| 804 | 804 | ||
| 805 | **Signature:** | 805 | **Signature:** |
| 806 | ```lua | 806 | ```lua |
| @@ -809,11 +809,11 @@ dump_locals: boolean | |||
| 809 | 809 | ||
| 810 | ### simplified | 810 | ### simplified |
| 811 | 811 | ||
| 812 | **Type:** Field. | 812 | **Tipe:** Field. |
| 813 | 813 | ||
| 814 | **Description:** | 814 | **Deskripsi:** |
| 815 | 815 | ||
| 816 | Whether to simplify the error message. Default is true. | 816 | Apakah akan menyederhanakan pesan error. Default true. |
| 817 | 817 | ||
| 818 | **Signature:** | 818 | **Signature:** |
| 819 | ```lua | 819 | ```lua |
diff --git a/doc/docs/id-id/index.md b/doc/docs/id-id/index.md index 016b688..c8b5fab 100644 --- a/doc/docs/id-id/index.md +++ b/doc/docs/id-id/index.md | |||
| @@ -2,22 +2,22 @@ | |||
| 2 | layout: home | 2 | layout: home |
| 3 | hero: | 3 | hero: |
| 4 | name: YueScript | 4 | name: YueScript |
| 5 | tagline: A language that compiles to Lua | 5 | tagline: Bahasa yang dikompilasi ke Lua |
| 6 | image: | 6 | image: |
| 7 | src: /image/yuescript.svg | 7 | src: /image/yuescript.svg |
| 8 | alt: YueScript | 8 | alt: YueScript |
| 9 | actions: | 9 | actions: |
| 10 | - theme: brand | 10 | - theme: brand |
| 11 | text: Quick Start → | 11 | text: Mulai Cepat → |
| 12 | link: /doc/ | 12 | link: /doc/ |
| 13 | features: | 13 | features: |
| 14 | - title: Familiar Lua workflows | 14 | - title: Alur kerja Lua yang familiar |
| 15 | details: Write concise syntax that compiles to readable Lua, with predictable output. | 15 | details: Tulis sintaks ringkas yang dikompilasi ke Lua yang mudah dibaca, dengan output yang dapat diprediksi. |
| 16 | - title: Modern language features | 16 | - title: Fitur bahasa modern |
| 17 | details: Pipe, pattern matching, slicing, and destructuring without giving up Lua interop. | 17 | details: Pipe, pattern matching, slicing, dan destrukturisasi tanpa mengorbankan interoperabilitas Lua. |
| 18 | - title: Rapid Iteration | 18 | - title: Iterasi Cepat |
| 19 | details: Any feedback is welcome to help accelerate the language development and evolution! | 19 | details: Setiap masukan sangat diterima untuk membantu mempercepat pengembangan dan evolusi bahasa! |
| 20 | footer: | 20 | footer: |
| 21 | message: MIT License. | 21 | message: Lisensi MIT. |
| 22 | copyright: Copyright © 2017-2026 Li Jin. All rights reserved. | 22 | copyright: Hak cipta © 2017-2026 Li Jin. Semua hak dilindungi. |
| 23 | --- | 23 | --- |
diff --git a/doc/docs/id-id/try/index.md b/doc/docs/id-id/try/index.md index 85a903b..c31dc1c 100755 --- a/doc/docs/id-id/try/index.md +++ b/doc/docs/id-id/try/index.md | |||
| @@ -4,9 +4,9 @@ prev: false | |||
| 4 | next: false | 4 | next: false |
| 5 | --- | 5 | --- |
| 6 | 6 | ||
| 7 | # YueScript Online Compiler | 7 | # Kompiler Online YueScript |
| 8 | --- | 8 | --- |
| 9 | 9 | ||
| 10 | Try YueScript in the browser with WASM. | 10 | Coba YueScript di browser dengan WASM. |
| 11 | 11 | ||
| 12 | <YueCompiler /> | 12 | <YueCompiler /> |
diff --git a/doc/docs/pt-br/doc/advanced/do.md b/doc/docs/pt-br/doc/advanced/do.md index 4990d6f..f13d8aa 100644 --- a/doc/docs/pt-br/doc/advanced/do.md +++ b/doc/docs/pt-br/doc/advanced/do.md | |||
| @@ -1,12 +1,12 @@ | |||
| 1 | # Do | 1 | # Do |
| 2 | 2 | ||
| 3 | When used as a statement, do works just like it does in Lua. | 3 | Quando usado como instrução, do funciona exatamente como no Lua. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | do | 6 | do |
| 7 | var = "hello" | 7 | var = "hello" |
| 8 | print var | 8 | print var |
| 9 | print var -- nil here | 9 | print var -- nil aqui |
| 10 | ``` | 10 | ``` |
| 11 | <YueDisplay> | 11 | <YueDisplay> |
| 12 | 12 | ||
| @@ -14,12 +14,12 @@ print var -- nil here | |||
| 14 | do | 14 | do |
| 15 | var = "hello" | 15 | var = "hello" |
| 16 | print var | 16 | print var |
| 17 | print var -- nil here | 17 | print var -- nil aqui |
| 18 | ``` | 18 | ``` |
| 19 | 19 | ||
| 20 | </YueDisplay> | 20 | </YueDisplay> |
| 21 | 21 | ||
| 22 | YueScript's **do** can also be used an expression . Allowing you to combine multiple lines into one. The result of the do expression is the last statement in its body. | 22 | O **do** do YueScript também pode ser usado como expressão. Permitindo combinar múltiplas linhas em uma. O resultado da expressão do é a última instrução em seu corpo. |
| 23 | 23 | ||
| 24 | ```yuescript | 24 | ```yuescript |
| 25 | counter = do | 25 | counter = do |
diff --git a/doc/docs/pt-br/doc/advanced/line-decorators.md b/doc/docs/pt-br/doc/advanced/line-decorators.md index 292bc77..94d1004 100644 --- a/doc/docs/pt-br/doc/advanced/line-decorators.md +++ b/doc/docs/pt-br/doc/advanced/line-decorators.md | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | # Line Decorators | 1 | # Decoradores de linha |
| 2 | 2 | ||
| 3 | For convenience, the for loop and if statement can be applied to single statements at the end of the line: | 3 | Por conveniência, o loop for e a instrução if podem ser aplicados a instruções únicas no final da linha: |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | print "hello world" if name == "Rob" | 6 | print "hello world" if name == "Rob" |
| @@ -13,7 +13,7 @@ print "hello world" if name == "Rob" | |||
| 13 | 13 | ||
| 14 | </YueDisplay> | 14 | </YueDisplay> |
| 15 | 15 | ||
| 16 | And with basic loops: | 16 | E com loops básicos: |
| 17 | 17 | ||
| 18 | ```yuescript | 18 | ```yuescript |
| 19 | print "item: ", item for item in *items | 19 | print "item: ", item for item in *items |
| @@ -26,7 +26,7 @@ print "item: ", item for item in *items | |||
| 26 | 26 | ||
| 27 | </YueDisplay> | 27 | </YueDisplay> |
| 28 | 28 | ||
| 29 | And with while loops: | 29 | E com loops while: |
| 30 | 30 | ||
| 31 | ```yuescript | 31 | ```yuescript |
| 32 | game\update! while game\isRunning! | 32 | game\update! while game\isRunning! |
diff --git a/doc/docs/pt-br/doc/advanced/macro.md b/doc/docs/pt-br/doc/advanced/macro.md index 6d194c3..846d506 100644 --- a/doc/docs/pt-br/doc/advanced/macro.md +++ b/doc/docs/pt-br/doc/advanced/macro.md | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | # Macro | 1 | # Macro |
| 2 | 2 | ||
| 3 | ## Common Usage | 3 | ## Uso comum |
| 4 | 4 | ||
| 5 | Macro function is used for evaluating a string in the compile time and insert the generated codes into final compilation. | 5 | A função macro é usada para avaliar uma string em tempo de compilação e inserir os códigos gerados na compilação final. |
| 6 | 6 | ||
| 7 | ```yuescript | 7 | ```yuescript |
| 8 | macro PI2 = -> math.pi * 2 | 8 | macro PI2 = -> math.pi * 2 |
| @@ -27,7 +27,7 @@ $asserts item ~= nil | |||
| 27 | $config false | 27 | $config false |
| 28 | value = $assert item | 28 | value = $assert item |
| 29 | 29 | ||
| 30 | -- the passed expressions are treated as strings | 30 | -- as expressões passadas são tratadas como strings |
| 31 | macro and = (...) -> "#{ table.concat {...}, ' and ' }" | 31 | macro and = (...) -> "#{ table.concat {...}, ' and ' }" |
| 32 | if $and f1!, f2!, f3! | 32 | if $and f1!, f2!, f3! |
| 33 | print "OK" | 33 | print "OK" |
| @@ -57,7 +57,7 @@ $asserts item ~= nil | |||
| 57 | $config false | 57 | $config false |
| 58 | value = $assert item | 58 | value = $assert item |
| 59 | 59 | ||
| 60 | -- the passed expressions are treated as strings | 60 | -- as expressões passadas são tratadas como strings |
| 61 | macro and = (...) -> "#{ table.concat {...}, ' and ' }" | 61 | macro and = (...) -> "#{ table.concat {...}, ' and ' }" |
| 62 | if $and f1!, f2!, f3! | 62 | if $and f1!, f2!, f3! |
| 63 | print "OK" | 63 | print "OK" |
| @@ -65,9 +65,9 @@ if $and f1!, f2!, f3! | |||
| 65 | 65 | ||
| 66 | </YueDisplay> | 66 | </YueDisplay> |
| 67 | 67 | ||
| 68 | ## Insert Raw Codes | 68 | ## Inserir códigos brutos |
| 69 | 69 | ||
| 70 | A macro function can either return a YueScript string or a config table containing Lua codes. | 70 | Uma função macro pode retornar uma string YueScript ou uma tabela de configuração contendo códigos Lua. |
| 71 | ```yuescript | 71 | ```yuescript |
| 72 | macro yueFunc = (var) -> "local #{var} = ->" | 72 | macro yueFunc = (var) -> "local #{var} = ->" |
| 73 | $yueFunc funcA | 73 | $yueFunc funcA |
| @@ -85,9 +85,9 @@ macro lua = (code) -> { | |||
| 85 | type: "lua" | 85 | type: "lua" |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | -- the raw string leading and ending symbols are auto trimed | 88 | -- os símbolos inicial e final da string bruta são aparados automaticamente |
| 89 | $lua[==[ | 89 | $lua[==[ |
| 90 | -- raw Lua codes insertion | 90 | -- inserção de códigos Lua brutos |
| 91 | if cond then | 91 | if cond then |
| 92 | print("output") | 92 | print("output") |
| 93 | end | 93 | end |
| @@ -112,9 +112,9 @@ macro lua = (code) -> { | |||
| 112 | type: "lua" | 112 | type: "lua" |
| 113 | } | 113 | } |
| 114 | 114 | ||
| 115 | -- the raw string leading and ending symbols are auto trimed | 115 | -- os símbolos inicial e final da string bruta são aparados automaticamente |
| 116 | $lua[==[ | 116 | $lua[==[ |
| 117 | -- raw Lua codes insertion | 117 | -- inserção de códigos Lua brutos |
| 118 | if cond then | 118 | if cond then |
| 119 | print("output") | 119 | print("output") |
| 120 | end | 120 | end |
| @@ -123,38 +123,37 @@ end | |||
| 123 | 123 | ||
| 124 | </YueDisplay> | 124 | </YueDisplay> |
| 125 | 125 | ||
| 126 | ## Export Macro | 126 | ## Exportar macro |
| 127 | 127 | ||
| 128 | Macro functions can be exported from a module and get imported in another module. You have to put export macro functions in a single file to be used, and only macro definition, macro importing and macro expansion in place can be put into the macro exporting module. | 128 | Funções macro podem ser exportadas de um módulo e importadas em outro módulo. Você deve colocar funções export macro em um único arquivo para uso, e apenas definição de macro, importação de macro e expansão de macro inline podem ser colocadas no módulo exportador de macro. |
| 129 | ```yuescript | 129 | ```yuescript |
| 130 | -- file: utils.yue | 130 | -- arquivo: utils.yue |
| 131 | export macro map = (items, action) -> "[#{action} for _ in *#{items}]" | 131 | export macro map = (items, action) -> "[#{action} for _ in *#{items}]" |
| 132 | export macro filter = (items, action) -> "[_ for _ in *#{items} when #{action}]" | 132 | export macro filter = (items, action) -> "[_ for _ in *#{items} when #{action}]" |
| 133 | export macro foreach = (items, action) -> "for _ in *#{items} | 133 | export macro foreach = (items, action) -> "for _ in *#{items} |
| 134 | #{action}" | 134 | #{action}" |
| 135 | 135 | ||
| 136 | -- file main.yue | 136 | -- arquivo main.yue |
| 137 | import "utils" as { | 137 | import "utils" as { |
| 138 | $, -- symbol to import all macros | 138 | $, -- símbolo para importar todas as macros |
| 139 | $foreach: $each -- rename macro $foreach to $each | 139 | $foreach: $each -- renomear macro $foreach para $each |
| 140 | } | 140 | } |
| 141 | [1, 2, 3] |> $map(_ * 2) |> $filter(_ > 4) |> $each print _ | 141 | [1, 2, 3] |> $map(_ * 2) |> $filter(_ > 4) |> $each print _ |
| 142 | ``` | 142 | ``` |
| 143 | <YueDisplay> | 143 | <YueDisplay> |
| 144 | 144 | ||
| 145 | ```yue | 145 | ```yue |
| 146 | -- file: utils.yue | 146 | -- arquivo: utils.yue |
| 147 | export macro map = (items, action) -> "[#{action} for _ in *#{items}]" | 147 | export macro map = (items, action) -> "[#{action} for _ in *#{items}]" |
| 148 | export macro filter = (items, action) -> "[_ for _ in *#{items} when #{action}]" | 148 | export macro filter = (items, action) -> "[_ for _ in *#{items} when #{action}]" |
| 149 | export macro foreach = (items, action) -> "for _ in *#{items} | 149 | export macro foreach = (items, action) -> "for _ in *#{items} |
| 150 | #{action}" | 150 | #{action}" |
| 151 | 151 | ||
| 152 | -- file main.yue | 152 | -- arquivo main.yue |
| 153 | -- import function is not available in browser, try it in a real environment | ||
| 154 | --[[ | 153 | --[[ |
| 155 | import "utils" as { | 154 | import "utils" as { |
| 156 | $, -- symbol to import all macros | 155 | $, -- símbolo para importar todas as macros |
| 157 | $foreach: $each -- rename macro $foreach to $each | 156 | $foreach: $each -- renomear macro $foreach para $each |
| 158 | } | 157 | } |
| 159 | [1, 2, 3] |> $map(_ * 2) |> $filter(_ > 4) |> $each print _ | 158 | [1, 2, 3] |> $map(_ * 2) |> $filter(_ > 4) |> $each print _ |
| 160 | ]] | 159 | ]] |
| @@ -162,25 +161,25 @@ import "utils" as { | |||
| 162 | 161 | ||
| 163 | </YueDisplay> | 162 | </YueDisplay> |
| 164 | 163 | ||
| 165 | ## Builtin Macro | 164 | ## Macro embutida |
| 166 | 165 | ||
| 167 | There are some builtin macros but you can override them by declaring macros with the same names. | 166 | Existem algumas macros embutidas, mas você pode sobrescrevê-las declarando macros com os mesmos nomes. |
| 168 | ```yuescript | 167 | ```yuescript |
| 169 | print $FILE -- get string of current module name | 168 | print $FILE -- obtém string do nome do módulo atual |
| 170 | print $LINE -- get number 2 | 169 | print $LINE -- obtém número 2 |
| 171 | ``` | 170 | ``` |
| 172 | <YueDisplay> | 171 | <YueDisplay> |
| 173 | 172 | ||
| 174 | ```yue | 173 | ```yue |
| 175 | print $FILE -- get string of current module name | 174 | print $FILE -- obtém string do nome do módulo atual |
| 176 | print $LINE -- get number 2 | 175 | print $LINE -- obtém número 2 |
| 177 | ``` | 176 | ``` |
| 178 | 177 | ||
| 179 | </YueDisplay> | 178 | </YueDisplay> |
| 180 | 179 | ||
| 181 | ## Generating Macros with Macros | 180 | ## Gerando macros com macros |
| 182 | 181 | ||
| 183 | In YueScript, macro functions allow you to generate code at compile time. By nesting macro functions, you can create more complex generation patterns. This feature enables you to define a macro function that generates another macro function, allowing for more dynamic code generation. | 182 | No YueScript, as funções macro permitem que você gere código em tempo de compilação. Aninhando funções macro, você pode criar padrões de geração mais complexos. Este recurso permite que você defina uma função macro que gera outra função macro, permitindo geração de código mais dinâmica. |
| 184 | 183 | ||
| 185 | ```yuescript | 184 | ```yuescript |
| 186 | macro Enum = (...) -> | 185 | macro Enum = (...) -> |
| @@ -222,9 +221,9 @@ print "Valid enum type:", $BodyType Static | |||
| 222 | 221 | ||
| 223 | </YueDisplay> | 222 | </YueDisplay> |
| 224 | 223 | ||
| 225 | ## Argument Validation | 224 | ## Validação de argumentos |
| 226 | 225 | ||
| 227 | You can declare the expected AST node types in the argument list, and check whether the incoming macro arguments meet the expectations at compile time. | 226 | Você pode declarar os tipos de nós AST esperados na lista de argumentos e verificar se os argumentos da macro recebidos atendem às expectativas em tempo de compilação. |
| 228 | 227 | ||
| 229 | ```yuescript | 228 | ```yuescript |
| 230 | macro printNumAndStr = (num `Num, str `String) -> | | 229 | macro printNumAndStr = (num `Num, str `String) -> | |
| @@ -249,7 +248,7 @@ $printNumAndStr 123, "hello" | |||
| 249 | 248 | ||
| 250 | </YueDisplay> | 249 | </YueDisplay> |
| 251 | 250 | ||
| 252 | If you need more flexible argument checking, you can use the built-in `$is_ast` macro function to manually check at the appropriate place. | 251 | Se você precisar de verificação de argumentos mais flexível, pode usar a função macro embutida `$is_ast` para verificar manualmente no lugar apropriado. |
| 253 | 252 | ||
| 254 | ```yuescript | 253 | ```yuescript |
| 255 | macro printNumAndStr = (num, str) -> | 254 | macro printNumAndStr = (num, str) -> |
| @@ -272,4 +271,4 @@ $printNumAndStr 123, "hello" | |||
| 272 | 271 | ||
| 273 | </YueDisplay> | 272 | </YueDisplay> |
| 274 | 273 | ||
| 275 | For more details about available AST nodes, please refer to the uppercased definitions in [yue_parser.cpp](https://github.com/IppClub/YueScript/blob/main/src/yuescript/yue_parser.cpp). | 274 | Para mais detalhes sobre os nós AST disponíveis, consulte as definições em maiúsculas em [yue_parser.cpp](https://github.com/IppClub/YueScript/blob/main/src/yuescript/yue_parser.cpp). |
diff --git a/doc/docs/pt-br/doc/advanced/module.md b/doc/docs/pt-br/doc/advanced/module.md index c955092..34fd106 100644 --- a/doc/docs/pt-br/doc/advanced/module.md +++ b/doc/docs/pt-br/doc/advanced/module.md | |||
| @@ -1,28 +1,28 @@ | |||
| 1 | # Module | 1 | # Módulo |
| 2 | 2 | ||
| 3 | ## Import | 3 | ## Import |
| 4 | 4 | ||
| 5 | The import statement is a syntax sugar for requiring a module or help extracting items from an imported module. The imported items are const by default. | 5 | A instrução import é um açúcar sintático para requerer um módulo ou ajudar a extrair itens de um módulo importado. Os itens importados são const por padrão. |
| 6 | 6 | ||
| 7 | ```yuescript | 7 | ```yuescript |
| 8 | -- used as table destructuring | 8 | -- usado como desestruturação de tabela |
| 9 | do | 9 | do |
| 10 | import insert, concat from table | 10 | import insert, concat from table |
| 11 | -- report error when assigning to insert, concat | 11 | -- reporta erro ao atribuir a insert, concat |
| 12 | import C, Ct, Cmt from require "lpeg" | 12 | import C, Ct, Cmt from require "lpeg" |
| 13 | -- shortcut for implicit requiring | 13 | -- atalho para require implícito |
| 14 | import x, y, z from 'mymodule' | 14 | import x, y, z from 'mymodule' |
| 15 | -- import with Python style | 15 | -- import com estilo Python |
| 16 | from 'module' import a, b, c | 16 | from 'module' import a, b, c |
| 17 | 17 | ||
| 18 | -- shortcut for requring a module | 18 | -- atalho para requerer um módulo |
| 19 | do | 19 | do |
| 20 | import 'module' | 20 | import 'module' |
| 21 | import 'module_x' | 21 | import 'module_x' |
| 22 | import "d-a-s-h-e-s" | 22 | import "d-a-s-h-e-s" |
| 23 | import "module.part" | 23 | import "module.part" |
| 24 | 24 | ||
| 25 | -- requring module with aliasing or table destructuring | 25 | -- requerer módulo com aliasing ou desestruturação de tabela |
| 26 | do | 26 | do |
| 27 | import "player" as PlayerModule | 27 | import "player" as PlayerModule |
| 28 | import "lpeg" as :C, :Ct, :Cmt | 28 | import "lpeg" as :C, :Ct, :Cmt |
| @@ -31,24 +31,24 @@ do | |||
| 31 | <YueDisplay> | 31 | <YueDisplay> |
| 32 | 32 | ||
| 33 | ```yue | 33 | ```yue |
| 34 | -- used as table destructuring | 34 | -- usado como desestruturação de tabela |
| 35 | do | 35 | do |
| 36 | import insert, concat from table | 36 | import insert, concat from table |
| 37 | -- report error when assigning to insert, concat | 37 | -- reporta erro ao atribuir a insert, concat |
| 38 | import C, Ct, Cmt from require "lpeg" | 38 | import C, Ct, Cmt from require "lpeg" |
| 39 | -- shortcut for implicit requiring | 39 | -- atalho para require implícito |
| 40 | import x, y, z from 'mymodule' | 40 | import x, y, z from 'mymodule' |
| 41 | -- import with Python style | 41 | -- import com estilo Python |
| 42 | from 'module' import a, b, c | 42 | from 'module' import a, b, c |
| 43 | 43 | ||
| 44 | -- shortcut for requring a module | 44 | -- atalho para requerer um módulo |
| 45 | do | 45 | do |
| 46 | import 'module' | 46 | import 'module' |
| 47 | import 'module_x' | 47 | import 'module_x' |
| 48 | import "d-a-s-h-e-s" | 48 | import "d-a-s-h-e-s" |
| 49 | import "module.part" | 49 | import "module.part" |
| 50 | 50 | ||
| 51 | -- requring module with aliasing or table destructuring | 51 | -- requerer módulo com aliasing ou desestruturação de tabela |
| 52 | do | 52 | do |
| 53 | import "player" as PlayerModule | 53 | import "player" as PlayerModule |
| 54 | import "lpeg" as :C, :Ct, :Cmt | 54 | import "lpeg" as :C, :Ct, :Cmt |
| @@ -59,7 +59,7 @@ do | |||
| 59 | 59 | ||
| 60 | ## Import Global | 60 | ## Import Global |
| 61 | 61 | ||
| 62 | You can import specific globals into local variables with `import`. When importing a chain of global variable accessings, the last field will be assigned to the local variable. | 62 | Você pode importar globais específicos para variáveis locais com `import`. Ao importar uma cadeia de acessos a variáveis globais, o último campo será atribuído à variável local. |
| 63 | 63 | ||
| 64 | ```yuescript | 64 | ```yuescript |
| 65 | do | 65 | do |
| @@ -78,21 +78,21 @@ do | |||
| 78 | 78 | ||
| 79 | </YueDisplay> | 79 | </YueDisplay> |
| 80 | 80 | ||
| 81 | ### Automatic Global Variable Import | 81 | ### Importação automática de variável global |
| 82 | 82 | ||
| 83 | You can place `import global` at the top of a block to automatically import all names that have not been explicitly declared or assigned in the current scope as globals. These implicit imports are treated as local consts that reference the corresponding globals at the position of the statement. | 83 | Você pode colocar `import global` no topo de um bloco para importar automaticamente todos os nomes que não foram explicitamente declarados ou atribuídos no escopo atual como globais. Essas importações implícitas são tratadas como consts locais que referenciam os globais correspondentes na posição da instrução. |
| 84 | 84 | ||
| 85 | Names that are explicitly declared as globals in the same scope will not be imported, so you can still assign to them. | 85 | Nomes que foram explicitamente declarados como globais no mesmo escopo não serão importados, então você ainda pode atribuir a eles. |
| 86 | 86 | ||
| 87 | ```yuescript | 87 | ```yuescript |
| 88 | do | 88 | do |
| 89 | import global | 89 | import global |
| 90 | print "hello" | 90 | print "hello" |
| 91 | math.random 3 | 91 | math.random 3 |
| 92 | -- print = nil -- error: imported globals are const | 92 | -- print = nil -- erro: globais importados são const |
| 93 | 93 | ||
| 94 | do | 94 | do |
| 95 | -- explicit global variable will not be imported | 95 | -- variável global explícita não será importada |
| 96 | import global | 96 | import global |
| 97 | global FLAG | 97 | global FLAG |
| 98 | print FLAG | 98 | print FLAG |
| @@ -105,10 +105,10 @@ do | |||
| 105 | import global | 105 | import global |
| 106 | print "hello" | 106 | print "hello" |
| 107 | math.random 3 | 107 | math.random 3 |
| 108 | -- print = nil -- error: imported globals are const | 108 | -- print = nil -- erro: globais importados são const |
| 109 | 109 | ||
| 110 | do | 110 | do |
| 111 | -- explicit global variable will not be imported | 111 | -- variável global explícita não será importada |
| 112 | import global | 112 | import global |
| 113 | global FLAG | 113 | global FLAG |
| 114 | print FLAG | 114 | print FLAG |
| @@ -119,11 +119,11 @@ do | |||
| 119 | 119 | ||
| 120 | ## Export | 120 | ## Export |
| 121 | 121 | ||
| 122 | The export statement offers a concise way to define modules. | 122 | A instrução export oferece uma forma concisa de definir módulos. |
| 123 | 123 | ||
| 124 | ### Named Export | 124 | ### Export nomeado |
| 125 | 125 | ||
| 126 | Named export will define a local variable as well as adding a field in the exported table. | 126 | Export nomeado definirá uma variável local e também adicionará um campo na tabela exportada. |
| 127 | 127 | ||
| 128 | ```yuescript | 128 | ```yuescript |
| 129 | export a, b, c = 1, 2, 3 | 129 | export a, b, c = 1, 2, 3 |
| @@ -160,7 +160,7 @@ export class Something | |||
| 160 | 160 | ||
| 161 | </YueDisplay> | 161 | </YueDisplay> |
| 162 | 162 | ||
| 163 | Doing named export with destructuring. | 163 | Fazendo export nomeado com desestruturação. |
| 164 | 164 | ||
| 165 | ```yuescript | 165 | ```yuescript |
| 166 | export :loadstring, to_lua: tolua = yue | 166 | export :loadstring, to_lua: tolua = yue |
| @@ -175,7 +175,7 @@ export {itemA: {:fieldA = 'default'}} = tb | |||
| 175 | 175 | ||
| 176 | </YueDisplay> | 176 | </YueDisplay> |
| 177 | 177 | ||
| 178 | Export named items from module without creating local variables. | 178 | Exportar itens nomeados do módulo sem criar variáveis locais. |
| 179 | 179 | ||
| 180 | ```yuescript | 180 | ```yuescript |
| 181 | export.itemA = tb | 181 | export.itemA = tb |
| @@ -192,9 +192,9 @@ export["a-b-c"] = 123 | |||
| 192 | 192 | ||
| 193 | </YueDisplay> | 193 | </YueDisplay> |
| 194 | 194 | ||
| 195 | ### Unnamed Export | 195 | ### Export sem nome |
| 196 | 196 | ||
| 197 | Unnamed export will add the target item into the array part of the exported table. | 197 | Export sem nome adicionará o item alvo na parte array da tabela exportada. |
| 198 | 198 | ||
| 199 | ```yuescript | 199 | ```yuescript |
| 200 | d, e, f = 3, 2, 1 | 200 | d, e, f = 3, 2, 1 |
| @@ -225,9 +225,9 @@ export with tmp | |||
| 225 | 225 | ||
| 226 | </YueDisplay> | 226 | </YueDisplay> |
| 227 | 227 | ||
| 228 | ### Default Export | 228 | ### Export padrão |
| 229 | 229 | ||
| 230 | Using the **default** keyword in export statement to replace the exported table with any thing. | 230 | Usar a palavra-chave **default** na instrução export para substituir a tabela exportada por qualquer coisa. |
| 231 | 231 | ||
| 232 | ```yuescript | 232 | ```yuescript |
| 233 | export default -> | 233 | export default -> |
diff --git a/doc/docs/pt-br/doc/advanced/try.md b/doc/docs/pt-br/doc/advanced/try.md index 23c7877..fbb4e87 100644 --- a/doc/docs/pt-br/doc/advanced/try.md +++ b/doc/docs/pt-br/doc/advanced/try.md | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | # Try | 1 | # Try |
| 2 | 2 | ||
| 3 | The syntax for Lua error handling in a common form. | 3 | A sintaxe para tratamento de erros do Lua em uma forma comum. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | try | 6 | try |
| @@ -23,7 +23,7 @@ try | |||
| 23 | print "trying" | 23 | print "trying" |
| 24 | func 1, 2, 3 | 24 | func 1, 2, 3 |
| 25 | 25 | ||
| 26 | -- working with if assignment pattern | 26 | -- funcionando com padrão de atribuição em if |
| 27 | if success, result := try func 1, 2, 3 | 27 | if success, result := try func 1, 2, 3 |
| 28 | catch err | 28 | catch err |
| 29 | print yue.traceback err | 29 | print yue.traceback err |
| @@ -52,7 +52,7 @@ try | |||
| 52 | print "trying" | 52 | print "trying" |
| 53 | func 1, 2, 3 | 53 | func 1, 2, 3 |
| 54 | 54 | ||
| 55 | -- working with if assignment pattern | 55 | -- funcionando com padrão de atribuição em if |
| 56 | if success, result := try func 1, 2, 3 | 56 | if success, result := try func 1, 2, 3 |
| 57 | catch err | 57 | catch err |
| 58 | print yue.traceback err | 58 | print yue.traceback err |
| @@ -63,18 +63,18 @@ catch err | |||
| 63 | 63 | ||
| 64 | ## Try? | 64 | ## Try? |
| 65 | 65 | ||
| 66 | `try?` is a simplified use for error handling syntax that omit the boolean status from the `try` statement, and it will return the result from the try block when success, return nil instead of error object otherwise. | 66 | `try?` é um uso simplificado para sintaxe de tratamento de erros que omite o status booleano da instrução `try`, e retornará o resultado do bloco try quando tiver sucesso, retornando nil em vez do objeto de erro caso contrário. |
| 67 | 67 | ||
| 68 | ```yuescript | 68 | ```yuescript |
| 69 | a, b, c = try? func! | 69 | a, b, c = try? func! |
| 70 | 70 | ||
| 71 | -- with nil coalescing operator | 71 | -- com operador de coalescência de nil |
| 72 | a = (try? func!) ?? "default" | 72 | a = (try? func!) ?? "default" |
| 73 | 73 | ||
| 74 | -- as function argument | 74 | -- como argumento de função |
| 75 | f try? func! | 75 | f try? func! |
| 76 | 76 | ||
| 77 | -- with catch block | 77 | -- com bloco catch |
| 78 | f try? | 78 | f try? |
| 79 | print 123 | 79 | print 123 |
| 80 | func! | 80 | func! |
| @@ -87,13 +87,13 @@ catch e | |||
| 87 | ```yue | 87 | ```yue |
| 88 | a, b, c = try? func! | 88 | a, b, c = try? func! |
| 89 | 89 | ||
| 90 | -- with nil coalescing operator | 90 | -- com operador de coalescência de nil |
| 91 | a = (try? func!) ?? "default" | 91 | a = (try? func!) ?? "default" |
| 92 | 92 | ||
| 93 | -- as function argument | 93 | -- como argumento de função |
| 94 | f try? func! | 94 | f try? func! |
| 95 | 95 | ||
| 96 | -- with catch block | 96 | -- com bloco catch |
| 97 | f try? | 97 | f try? |
| 98 | print 123 | 98 | print 123 |
| 99 | func! | 99 | func! |
diff --git a/doc/docs/pt-br/doc/assignment/assignment.md b/doc/docs/pt-br/doc/assignment/assignment.md index 4dac6f4..1da6bb0 100644 --- a/doc/docs/pt-br/doc/assignment/assignment.md +++ b/doc/docs/pt-br/doc/assignment/assignment.md | |||
| @@ -1,25 +1,25 @@ | |||
| 1 | # Assignment | 1 | # Atribuição |
| 2 | 2 | ||
| 3 | The variable is dynamic typed and is defined as local by default. But you can change the scope of declaration by **local** and **global** statement. | 3 | A variável é tipada dinamicamente e é definida como local por padrão. Mas você pode alterar o escopo da declaração pelas instruções **local** e **global**. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | hello = "world" | 6 | hello = "world" |
| 7 | a, b, c = 1, 2, 3 | 7 | a, b, c = 1, 2, 3 |
| 8 | hello = 123 -- uses the existing variable | 8 | hello = 123 -- usa a variável existente |
| 9 | ``` | 9 | ``` |
| 10 | <YueDisplay> | 10 | <YueDisplay> |
| 11 | 11 | ||
| 12 | ```yue | 12 | ```yue |
| 13 | hello = "world" | 13 | hello = "world" |
| 14 | a, b, c = 1, 2, 3 | 14 | a, b, c = 1, 2, 3 |
| 15 | hello = 123 -- uses the existing variable | 15 | hello = 123 -- usa a variável existente |
| 16 | ``` | 16 | ``` |
| 17 | 17 | ||
| 18 | </YueDisplay> | 18 | </YueDisplay> |
| 19 | 19 | ||
| 20 | ## Perform Update | 20 | ## Atualização |
| 21 | 21 | ||
| 22 | You can perform update assignment with many binary operators. | 22 | Você pode realizar atribuição de atualização com muitos operadores binários. |
| 23 | ```yuescript | 23 | ```yuescript |
| 24 | x = 1 | 24 | x = 1 |
| 25 | x += 1 | 25 | x += 1 |
| @@ -27,8 +27,8 @@ x -= 1 | |||
| 27 | x *= 10 | 27 | x *= 10 |
| 28 | x /= 10 | 28 | x /= 10 |
| 29 | x %= 10 | 29 | x %= 10 |
| 30 | s ..= "world" -- will add a new local if local variable is not exist | 30 | s ..= "world" -- adiciona um novo local se a variável local não existir |
| 31 | arg or= "default value" | 31 | arg or= "valor padrão" |
| 32 | ``` | 32 | ``` |
| 33 | <YueDisplay> | 33 | <YueDisplay> |
| 34 | 34 | ||
| @@ -39,15 +39,15 @@ x -= 1 | |||
| 39 | x *= 10 | 39 | x *= 10 |
| 40 | x /= 10 | 40 | x /= 10 |
| 41 | x %= 10 | 41 | x %= 10 |
| 42 | s ..= "world" -- will add a new local if local variable is not exist | 42 | s ..= "world" -- adiciona um novo local se a variável local não existir |
| 43 | arg or= "default value" | 43 | arg or= "valor padrão" |
| 44 | ``` | 44 | ``` |
| 45 | 45 | ||
| 46 | </YueDisplay> | 46 | </YueDisplay> |
| 47 | 47 | ||
| 48 | ## Chaining Assignment | 48 | ## Atribuição encadeada |
| 49 | 49 | ||
| 50 | You can do chaining assignment to assign multiple items to hold the same value. | 50 | Você pode fazer atribuição encadeada para atribuir múltiplos itens ao mesmo valor. |
| 51 | ```yuescript | 51 | ```yuescript |
| 52 | a = b = c = d = e = 0 | 52 | a = b = c = d = e = 0 |
| 53 | x = y = z = f! | 53 | x = y = z = f! |
| @@ -61,12 +61,12 @@ x = y = z = f! | |||
| 61 | 61 | ||
| 62 | </YueDisplay> | 62 | </YueDisplay> |
| 63 | 63 | ||
| 64 | ## Explicit Locals | 64 | ## Locais explícitos |
| 65 | ```yuescript | 65 | ```yuescript |
| 66 | do | 66 | do |
| 67 | local a = 1 | 67 | local a = 1 |
| 68 | local * | 68 | local * |
| 69 | print "forward declare all variables as locals" | 69 | print "declarar antecipadamente todas as variáveis como locais" |
| 70 | x = -> 1 + y + z | 70 | x = -> 1 + y + z |
| 71 | y, z = 2, 3 | 71 | y, z = 2, 3 |
| 72 | global instance = Item\new! | 72 | global instance = Item\new! |
| @@ -74,7 +74,7 @@ do | |||
| 74 | do | 74 | do |
| 75 | local X = 1 | 75 | local X = 1 |
| 76 | local ^ | 76 | local ^ |
| 77 | print "only forward declare upper case variables" | 77 | print "declarar antecipadamente apenas variáveis em maiúsculas" |
| 78 | a = 1 | 78 | a = 1 |
| 79 | B = 2 | 79 | B = 2 |
| 80 | ``` | 80 | ``` |
| @@ -84,7 +84,7 @@ do | |||
| 84 | do | 84 | do |
| 85 | local a = 1 | 85 | local a = 1 |
| 86 | local * | 86 | local * |
| 87 | print "forward declare all variables as locals" | 87 | print "declarar antecipadamente todas as variáveis como locais" |
| 88 | x = -> 1 + y + z | 88 | x = -> 1 + y + z |
| 89 | y, z = 2, 3 | 89 | y, z = 2, 3 |
| 90 | global instance = Item\new! | 90 | global instance = Item\new! |
| @@ -92,29 +92,29 @@ do | |||
| 92 | do | 92 | do |
| 93 | local X = 1 | 93 | local X = 1 |
| 94 | local ^ | 94 | local ^ |
| 95 | print "only forward declare upper case variables" | 95 | print "declarar antecipadamente apenas variáveis em maiúsculas" |
| 96 | a = 1 | 96 | a = 1 |
| 97 | B = 2 | 97 | B = 2 |
| 98 | ``` | 98 | ``` |
| 99 | 99 | ||
| 100 | </YueDisplay> | 100 | </YueDisplay> |
| 101 | 101 | ||
| 102 | ## Explicit Globals | 102 | ## Globais explícitos |
| 103 | ```yuescript | 103 | ```yuescript |
| 104 | do | 104 | do |
| 105 | global a = 1 | 105 | global a = 1 |
| 106 | global * | 106 | global * |
| 107 | print "declare all variables as globals" | 107 | print "declarar todas as variáveis como globais" |
| 108 | x = -> 1 + y + z | 108 | x = -> 1 + y + z |
| 109 | y, z = 2, 3 | 109 | y, z = 2, 3 |
| 110 | 110 | ||
| 111 | do | 111 | do |
| 112 | global X = 1 | 112 | global X = 1 |
| 113 | global ^ | 113 | global ^ |
| 114 | print "only declare upper case variables as globals" | 114 | print "declarar apenas variáveis em maiúsculas como globais" |
| 115 | a = 1 | 115 | a = 1 |
| 116 | B = 2 | 116 | B = 2 |
| 117 | local Temp = "a local value" | 117 | local Temp = "um valor local" |
| 118 | ``` | 118 | ``` |
| 119 | <YueDisplay> | 119 | <YueDisplay> |
| 120 | 120 | ||
| @@ -122,17 +122,17 @@ do | |||
| 122 | do | 122 | do |
| 123 | global a = 1 | 123 | global a = 1 |
| 124 | global * | 124 | global * |
| 125 | print "declare all variables as globals" | 125 | print "declarar todas as variáveis como globais" |
| 126 | x = -> 1 + y + z | 126 | x = -> 1 + y + z |
| 127 | y, z = 2, 3 | 127 | y, z = 2, 3 |
| 128 | 128 | ||
| 129 | do | 129 | do |
| 130 | global X = 1 | 130 | global X = 1 |
| 131 | global ^ | 131 | global ^ |
| 132 | print "only declare upper case variables as globals" | 132 | print "declarar apenas variáveis em maiúsculas como globais" |
| 133 | a = 1 | 133 | a = 1 |
| 134 | B = 2 | 134 | B = 2 |
| 135 | local Temp = "a local value" | 135 | local Temp = "um valor local" |
| 136 | ``` | 136 | ``` |
| 137 | 137 | ||
| 138 | </YueDisplay> | 138 | </YueDisplay> |
diff --git a/doc/docs/pt-br/doc/assignment/destructuring-assignment.md b/doc/docs/pt-br/doc/assignment/destructuring-assignment.md index e7b8046..7692885 100644 --- a/doc/docs/pt-br/doc/assignment/destructuring-assignment.md +++ b/doc/docs/pt-br/doc/assignment/destructuring-assignment.md | |||
| @@ -1,10 +1,10 @@ | |||
| 1 | # Destructuring Assignment | 1 | # Atribuição por desestruturação |
| 2 | 2 | ||
| 3 | Destructuring assignment is a way to quickly extract values from a table by their name or position in array based tables. | 3 | A atribuição por desestruturação é uma forma de extrair rapidamente valores de uma tabela por seu nome ou posição em tabelas baseadas em array. |
| 4 | 4 | ||
| 5 | Typically when you see a table literal, {1,2,3}, it is on the right hand side of an assignment because it is a value. Destructuring assignment swaps the role of the table literal, and puts it on the left hand side of an assign statement. | 5 | Tipicamente, quando você vê um literal de tabela, {1,2,3}, ele está no lado direito de uma atribuição porque é um valor. A atribuição por desestruturação troca o papel do literal de tabela e o coloca no lado esquerdo de uma instrução de atribuição. |
| 6 | 6 | ||
| 7 | This is best explained with examples. Here is how you would unpack the first two values from a table: | 7 | Isso é melhor explicado com exemplos. Assim você extrairia os dois primeiros valores de uma tabela: |
| 8 | 8 | ||
| 9 | ```yuescript | 9 | ```yuescript |
| 10 | thing = [1, 2] | 10 | thing = [1, 2] |
| @@ -23,7 +23,7 @@ print a, b | |||
| 23 | 23 | ||
| 24 | </YueDisplay> | 24 | </YueDisplay> |
| 25 | 25 | ||
| 26 | In the destructuring table literal, the key represents the key to read from the right hand side, and the value represents the name the read value will be assigned to. | 26 | No literal de tabela de desestruturação, a chave representa a chave para ler do lado direito, e o valor representa o nome ao qual o valor lido será atribuído. |
| 27 | 27 | ||
| 28 | ```yuescript | 28 | ```yuescript |
| 29 | obj = { | 29 | obj = { |
| @@ -35,7 +35,7 @@ obj = { | |||
| 35 | {hello: hello, day: the_day} = obj | 35 | {hello: hello, day: the_day} = obj |
| 36 | print hello, the_day | 36 | print hello, the_day |
| 37 | 37 | ||
| 38 | :day = obj -- OK to do simple destructuring without braces | 38 | :day = obj -- OK fazer desestruturação simples sem chaves |
| 39 | ``` | 39 | ``` |
| 40 | <YueDisplay> | 40 | <YueDisplay> |
| 41 | 41 | ||
| @@ -49,12 +49,12 @@ obj = { | |||
| 49 | {hello: hello, day: the_day} = obj | 49 | {hello: hello, day: the_day} = obj |
| 50 | print hello, the_day | 50 | print hello, the_day |
| 51 | 51 | ||
| 52 | :day = obj -- OK to do simple destructuring without braces | 52 | :day = obj -- OK fazer desestruturação simples sem chaves |
| 53 | ``` | 53 | ``` |
| 54 | 54 | ||
| 55 | </YueDisplay> | 55 | </YueDisplay> |
| 56 | 56 | ||
| 57 | This also works with nested data structures as well: | 57 | Isso também funciona com estruturas de dados aninhadas: |
| 58 | 58 | ||
| 59 | ```yuescript | 59 | ```yuescript |
| 60 | obj2 = { | 60 | obj2 = { |
| @@ -85,7 +85,7 @@ print first, second, color | |||
| 85 | 85 | ||
| 86 | </YueDisplay> | 86 | </YueDisplay> |
| 87 | 87 | ||
| 88 | If the destructuring statement is complicated, feel free to spread it out over a few lines. A slightly more complicated example: | 88 | Se a instrução de desestruturação for complicada, sinta-se à vontade para espalhá-la em várias linhas. Um exemplo um pouco mais complicado: |
| 89 | 89 | ||
| 90 | ```yuescript | 90 | ```yuescript |
| 91 | { | 91 | { |
| @@ -108,7 +108,7 @@ If the destructuring statement is complicated, feel free to spread it out over a | |||
| 108 | 108 | ||
| 109 | </YueDisplay> | 109 | </YueDisplay> |
| 110 | 110 | ||
| 111 | It's common to extract values from at table and assign them the local variables that have the same name as the key. In order to avoid repetition we can use the **:** prefix operator: | 111 | É comum extrair valores de uma tabela e atribuí-los a variáveis locais que têm o mesmo nome da chave. Para evitar repetição, podemos usar o operador de prefixo **:**: |
| 112 | 112 | ||
| 113 | ```yuescript | 113 | ```yuescript |
| 114 | {:concat, :insert} = table | 114 | {:concat, :insert} = table |
| @@ -121,7 +121,7 @@ It's common to extract values from at table and assign them the local variables | |||
| 121 | 121 | ||
| 122 | </YueDisplay> | 122 | </YueDisplay> |
| 123 | 123 | ||
| 124 | This is effectively the same as import, but we can rename fields we want to extract by mixing the syntax: | 124 | Isso é efetivamente o mesmo que import, mas podemos renomear campos que queremos extrair misturando a sintaxe: |
| 125 | 125 | ||
| 126 | ```yuescript | 126 | ```yuescript |
| 127 | {:mix, :max, random: rand} = math | 127 | {:mix, :max, random: rand} = math |
| @@ -134,20 +134,20 @@ This is effectively the same as import, but we can rename fields we want to extr | |||
| 134 | 134 | ||
| 135 | </YueDisplay> | 135 | </YueDisplay> |
| 136 | 136 | ||
| 137 | You can write default values while doing destructuring like: | 137 | Você pode escrever valores padrão ao fazer desestruturação: |
| 138 | 138 | ||
| 139 | ```yuescript | 139 | ```yuescript |
| 140 | {:name = "nameless", :job = "jobless"} = person | 140 | {:name = "sem nome", :job = "sem emprego"} = person |
| 141 | ``` | 141 | ``` |
| 142 | <YueDisplay> | 142 | <YueDisplay> |
| 143 | 143 | ||
| 144 | ```yue | 144 | ```yue |
| 145 | {:name = "nameless", :job = "jobless"} = person | 145 | {:name = "sem nome", :job = "sem emprego"} = person |
| 146 | ``` | 146 | ``` |
| 147 | 147 | ||
| 148 | </YueDisplay> | 148 | </YueDisplay> |
| 149 | 149 | ||
| 150 | You can use `_` as placeholder when doing a list destructuring: | 150 | Você pode usar `_` como placeholder ao fazer desestruturação de lista: |
| 151 | 151 | ||
| 152 | ```yuescript | 152 | ```yuescript |
| 153 | [_, two, _, four] = items | 153 | [_, two, _, four] = items |
| @@ -160,59 +160,59 @@ You can use `_` as placeholder when doing a list destructuring: | |||
| 160 | 160 | ||
| 161 | </YueDisplay> | 161 | </YueDisplay> |
| 162 | 162 | ||
| 163 | ## Range Destructuring | 163 | ## Desestruturação por intervalo |
| 164 | 164 | ||
| 165 | You can use the spread operator `...` in list destructuring to capture a range of values. This is useful when you want to extract specific elements from the beginning and end of a list while collecting the rest in between. | 165 | Você pode usar o operador spread `...` na desestruturação de lista para capturar um intervalo de valores. Isso é útil quando você quer extrair elementos específicos do início e do fim de uma lista enquanto coleta o restante entre eles. |
| 166 | 166 | ||
| 167 | ```yuescript | 167 | ```yuescript |
| 168 | orders = ["first", "second", "third", "fourth", "last"] | 168 | orders = ["first", "second", "third", "fourth", "last"] |
| 169 | [first, ...bulk, last] = orders | 169 | [first, ...bulk, last] = orders |
| 170 | print first -- prints: first | 170 | print first -- imprime: first |
| 171 | print bulk -- prints: {"second", "third", "fourth"} | 171 | print bulk -- imprime: {"second", "third", "fourth"} |
| 172 | print last -- prints: last | 172 | print last -- imprime: last |
| 173 | ``` | 173 | ``` |
| 174 | <YueDisplay> | 174 | <YueDisplay> |
| 175 | 175 | ||
| 176 | ```yue | 176 | ```yue |
| 177 | orders = ["first", "second", "third", "fourth", "last"] | 177 | orders = ["first", "second", "third", "fourth", "last"] |
| 178 | [first, ...bulk, last] = orders | 178 | [first, ...bulk, last] = orders |
| 179 | print first -- prints: first | 179 | print first -- imprime: first |
| 180 | print bulk -- prints: {"second", "third", "fourth"} | 180 | print bulk -- imprime: {"second", "third", "fourth"} |
| 181 | print last -- prints: last | 181 | print last -- imprime: last |
| 182 | ``` | 182 | ``` |
| 183 | 183 | ||
| 184 | </YueDisplay> | 184 | </YueDisplay> |
| 185 | 185 | ||
| 186 | The spread operator can be used in different positions to capture different ranges, and you can use `_` as a placeholder for the values you don't want to capture: | 186 | O operador spread pode ser usado em diferentes posições para capturar diferentes intervalos, e você pode usar `_` como placeholder para os valores que não quer capturar: |
| 187 | 187 | ||
| 188 | ```yuescript | 188 | ```yuescript |
| 189 | -- Capture everything after first element | 189 | -- Capturar tudo após o primeiro elemento |
| 190 | [first, ...rest] = orders | 190 | [first, ...rest] = orders |
| 191 | 191 | ||
| 192 | -- Capture everything before last element | 192 | -- Capturar tudo antes do último elemento |
| 193 | [...start, last] = orders | 193 | [...start, last] = orders |
| 194 | 194 | ||
| 195 | -- Capture things except the middle elements | 195 | -- Capturar tudo exceto os elementos do meio |
| 196 | [first, ..._, last] = orders | 196 | [first, ..._, last] = orders |
| 197 | ``` | 197 | ``` |
| 198 | <YueDisplay> | 198 | <YueDisplay> |
| 199 | 199 | ||
| 200 | ```yue | 200 | ```yue |
| 201 | -- Capture everything after first element | 201 | -- Capturar tudo após o primeiro elemento |
| 202 | [first, ...rest] = orders | 202 | [first, ...rest] = orders |
| 203 | 203 | ||
| 204 | -- Capture everything before last element | 204 | -- Capturar tudo antes do último elemento |
| 205 | [...start, last] = orders | 205 | [...start, last] = orders |
| 206 | 206 | ||
| 207 | -- Capture things except the middle elements | 207 | -- Capturar tudo exceto os elementos do meio |
| 208 | [first, ..._, last] = orders | 208 | [first, ..._, last] = orders |
| 209 | ``` | 209 | ``` |
| 210 | 210 | ||
| 211 | </YueDisplay> | 211 | </YueDisplay> |
| 212 | 212 | ||
| 213 | ## Destructuring In Other Places | 213 | ## Desestruturação em outros lugares |
| 214 | 214 | ||
| 215 | Destructuring can also show up in places where an assignment implicitly takes place. An example of this is a for loop: | 215 | A desestruturação também pode aparecer em lugares onde uma atribuição ocorre implicitamente. Um exemplo disso é um loop for: |
| 216 | 216 | ||
| 217 | ```yuescript | 217 | ```yuescript |
| 218 | tuples = [ | 218 | tuples = [ |
| @@ -237,4 +237,4 @@ for [left, right] in *tuples | |||
| 237 | 237 | ||
| 238 | </YueDisplay> | 238 | </YueDisplay> |
| 239 | 239 | ||
| 240 | We know each element in the array table is a two item tuple, so we can unpack it directly in the names clause of the for statement using a destructure. | 240 | Sabemos que cada elemento na tabela array é uma tupla de dois itens, então podemos desempacotá-lo diretamente na cláusula de nomes da instrução for usando desestruturação. |
diff --git a/doc/docs/pt-br/doc/assignment/if-assignment.md b/doc/docs/pt-br/doc/assignment/if-assignment.md index 02984e8..84094ed 100644 --- a/doc/docs/pt-br/doc/assignment/if-assignment.md +++ b/doc/docs/pt-br/doc/assignment/if-assignment.md | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | # If Assignment | 1 | # Atribuição em if |
| 2 | 2 | ||
| 3 | `if` and `elseif` blocks can take an assignment in place of a conditional expression. Upon evaluating the conditional, the assignment will take place and the value that was assigned to will be used as the conditional expression. The assigned variable is only in scope for the body of the conditional, meaning it is never available if the value is not truthy. And you have to use "the walrus operator" `:=` instead of `=` to do assignment. | 3 | Os blocos `if` e `elseif` podem receber uma atribuição no lugar de uma expressão condicional. Ao avaliar o condicional, a atribuição será realizada e o valor que foi atribuído será usado como expressão condicional. A variável atribuída está no escopo apenas para o corpo do condicional, ou seja, nunca está disponível se o valor não for truthy. E você precisa usar o "operador walrus" `:=` em vez de `=` para fazer a atribuição. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | if user := database.find_user "moon" | 6 | if user := database.find_user "moon" |
| @@ -17,55 +17,55 @@ if user := database.find_user "moon" | |||
| 17 | 17 | ||
| 18 | ```yuescript | 18 | ```yuescript |
| 19 | if hello := os.getenv "hello" | 19 | if hello := os.getenv "hello" |
| 20 | print "You have hello", hello | 20 | print "Você tem hello", hello |
| 21 | elseif world := os.getenv "world" | 21 | elseif world := os.getenv "world" |
| 22 | print "you have world", world | 22 | print "você tem world", world |
| 23 | else | 23 | else |
| 24 | print "nothing :(" | 24 | print "nada :(" |
| 25 | ``` | 25 | ``` |
| 26 | <YueDisplay> | 26 | <YueDisplay> |
| 27 | 27 | ||
| 28 | ```yue | 28 | ```yue |
| 29 | if hello := os.getenv "hello" | 29 | if hello := os.getenv "hello" |
| 30 | print "You have hello", hello | 30 | print "Você tem hello", hello |
| 31 | elseif world := os.getenv "world" | 31 | elseif world := os.getenv "world" |
| 32 | print "you have world", world | 32 | print "você tem world", world |
| 33 | else | 33 | else |
| 34 | print "nothing :(" | 34 | print "nada :(" |
| 35 | ``` | 35 | ``` |
| 36 | 36 | ||
| 37 | </YueDisplay> | 37 | </YueDisplay> |
| 38 | 38 | ||
| 39 | If assignment with multiple return values. Only the first value is getting checked, other values are scoped. | 39 | Atribuição em if com múltiplos valores de retorno. Apenas o primeiro valor é verificado, os outros valores estão no escopo. |
| 40 | ```yuescript | 40 | ```yuescript |
| 41 | if success, result := pcall -> "get result without problems" | 41 | if success, result := pcall -> "obter resultado sem problemas" |
| 42 | print result -- variable result is scoped | 42 | print result -- variável result está no escopo |
| 43 | print "OK" | 43 | print "OK" |
| 44 | ``` | 44 | ``` |
| 45 | <YueDisplay> | 45 | <YueDisplay> |
| 46 | 46 | ||
| 47 | ```yue | 47 | ```yue |
| 48 | if success, result := pcall -> "get result without problems" | 48 | if success, result := pcall -> "obter resultado sem problemas" |
| 49 | print result -- variable result is scoped | 49 | print result -- variável result está no escopo |
| 50 | print "OK" | 50 | print "OK" |
| 51 | ``` | 51 | ``` |
| 52 | 52 | ||
| 53 | </YueDisplay> | 53 | </YueDisplay> |
| 54 | 54 | ||
| 55 | ## While Assignment | 55 | ## Atribuição em while |
| 56 | 56 | ||
| 57 | You can also use if assignment in a while loop to get the value as the loop condition. | 57 | Você também pode usar atribuição em if em um loop while para obter o valor como condição do loop. |
| 58 | 58 | ||
| 59 | ```yuescript | 59 | ```yuescript |
| 60 | while byte := stream\read_one! | 60 | while byte := stream\read_one! |
| 61 | -- do something with the byte | 61 | -- fazer algo com o byte |
| 62 | print byte | 62 | print byte |
| 63 | ``` | 63 | ``` |
| 64 | <YueDisplay> | 64 | <YueDisplay> |
| 65 | 65 | ||
| 66 | ```yue | 66 | ```yue |
| 67 | while byte := stream\read_one! | 67 | while byte := stream\read_one! |
| 68 | -- do something with the byte | 68 | -- fazer algo com o byte |
| 69 | print byte | 69 | print byte |
| 70 | ``` | 70 | ``` |
| 71 | 71 | ||
diff --git a/doc/docs/pt-br/doc/assignment/the-using-clause-controlling-destructive-assignment.md b/doc/docs/pt-br/doc/assignment/the-using-clause-controlling-destructive-assignment.md index fb9b740..02d4162 100644 --- a/doc/docs/pt-br/doc/assignment/the-using-clause-controlling-destructive-assignment.md +++ b/doc/docs/pt-br/doc/assignment/the-using-clause-controlling-destructive-assignment.md | |||
| @@ -1,11 +1,11 @@ | |||
| 1 | # The Using Clause; Controlling Destructive Assignment | 1 | # A cláusula Using; controlando atribuição destrutiva |
| 2 | 2 | ||
| 3 | While lexical scoping can be a great help in reducing the complexity of the code we write, things can get unwieldy as the code size increases. Consider the following snippet: | 3 | Embora o escopo léxico possa ser uma grande ajuda na redução da complexidade do código que escrevemos, as coisas podem ficar difíceis de gerenciar conforme o tamanho do código aumenta. Considere o seguinte trecho: |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | i = 100 | 6 | i = 100 |
| 7 | 7 | ||
| 8 | -- many lines of code... | 8 | -- muitas linhas de código... |
| 9 | 9 | ||
| 10 | my_func = -> | 10 | my_func = -> |
| 11 | i = 10 | 11 | i = 10 |
| @@ -15,14 +15,14 @@ my_func = -> | |||
| 15 | 15 | ||
| 16 | my_func! | 16 | my_func! |
| 17 | 17 | ||
| 18 | print i -- will print 0 | 18 | print i -- vai imprimir 0 |
| 19 | ``` | 19 | ``` |
| 20 | <YueDisplay> | 20 | <YueDisplay> |
| 21 | 21 | ||
| 22 | ```yue | 22 | ```yue |
| 23 | i = 100 | 23 | i = 100 |
| 24 | 24 | ||
| 25 | -- many lines of code... | 25 | -- muitas linhas de código... |
| 26 | 26 | ||
| 27 | my_func = -> | 27 | my_func = -> |
| 28 | i = 10 | 28 | i = 10 |
| @@ -32,25 +32,25 @@ my_func = -> | |||
| 32 | 32 | ||
| 33 | my_func! | 33 | my_func! |
| 34 | 34 | ||
| 35 | print i -- will print 0 | 35 | print i -- vai imprimir 0 |
| 36 | ``` | 36 | ``` |
| 37 | 37 | ||
| 38 | </YueDisplay> | 38 | </YueDisplay> |
| 39 | 39 | ||
| 40 | In my_func, we've overwritten the value of i mistakenly. In this example it is quite obvious, but consider a large, or foreign code base where it isn't clear what names have already been declared. | 40 | Em my_func, sobrescrevemos o valor de i por engano. Neste exemplo é bem óbvio, mas considere uma base de código grande ou estrangeira onde não está claro quais nomes já foram declarados. |
| 41 | 41 | ||
| 42 | It would be helpful to say which variables from the enclosing scope we intend on change, in order to prevent us from changing others by accident. | 42 | Seria útil dizer quais variáveis do escopo envolvente pretendemos alterar, para evitar que alteremos outras por acidente. |
| 43 | 43 | ||
| 44 | The using keyword lets us do that. using nil makes sure that no closed variables are overwritten in assignment. The using clause is placed after the argument list in a function, or in place of it if there are no arguments. | 44 | A palavra-chave using nos permite fazer isso. using nil garante que nenhuma variável fechada seja sobrescrita na atribuição. A cláusula using é colocada após a lista de argumentos em uma função, ou no lugar dela se não houver argumentos. |
| 45 | 45 | ||
| 46 | ```yuescript | 46 | ```yuescript |
| 47 | i = 100 | 47 | i = 100 |
| 48 | 48 | ||
| 49 | my_func = (using nil) -> | 49 | my_func = (using nil) -> |
| 50 | i = "hello" -- a new local variable is created here | 50 | i = "hello" -- uma nova variável local é criada aqui |
| 51 | 51 | ||
| 52 | my_func! | 52 | my_func! |
| 53 | print i -- prints 100, i is unaffected | 53 | print i -- imprime 100, i não é afetado |
| 54 | ``` | 54 | ``` |
| 55 | <YueDisplay> | 55 | <YueDisplay> |
| 56 | 56 | ||
| @@ -58,27 +58,27 @@ print i -- prints 100, i is unaffected | |||
| 58 | i = 100 | 58 | i = 100 |
| 59 | 59 | ||
| 60 | my_func = (using nil) -> | 60 | my_func = (using nil) -> |
| 61 | i = "hello" -- a new local variable is created here | 61 | i = "hello" -- uma nova variável local é criada aqui |
| 62 | 62 | ||
| 63 | my_func! | 63 | my_func! |
| 64 | print i -- prints 100, i is unaffected | 64 | print i -- imprime 100, i não é afetado |
| 65 | ``` | 65 | ``` |
| 66 | 66 | ||
| 67 | </YueDisplay> | 67 | </YueDisplay> |
| 68 | 68 | ||
| 69 | Multiple names can be separated by commas. Closure values can still be accessed, they just cant be modified: | 69 | Múltiplos nomes podem ser separados por vírgulas. Os valores do closure ainda podem ser acessados, apenas não podem ser modificados: |
| 70 | 70 | ||
| 71 | ```yuescript | 71 | ```yuescript |
| 72 | tmp = 1213 | 72 | tmp = 1213 |
| 73 | i, k = 100, 50 | 73 | i, k = 100, 50 |
| 74 | 74 | ||
| 75 | my_func = (add using k, i) -> | 75 | my_func = (add using k, i) -> |
| 76 | tmp = tmp + add -- a new local tmp is created | 76 | tmp = tmp + add -- uma nova variável local tmp é criada |
| 77 | i += tmp | 77 | i += tmp |
| 78 | k += tmp | 78 | k += tmp |
| 79 | 79 | ||
| 80 | my_func(22) | 80 | my_func(22) |
| 81 | print i, k -- these have been updated | 81 | print i, k -- estes foram atualizados |
| 82 | ``` | 82 | ``` |
| 83 | <YueDisplay> | 83 | <YueDisplay> |
| 84 | 84 | ||
| @@ -87,12 +87,12 @@ tmp = 1213 | |||
| 87 | i, k = 100, 50 | 87 | i, k = 100, 50 |
| 88 | 88 | ||
| 89 | my_func = (add using k, i) -> | 89 | my_func = (add using k, i) -> |
| 90 | tmp = tmp + add -- a new local tmp is created | 90 | tmp = tmp + add -- uma nova variável local tmp é criada |
| 91 | i += tmp | 91 | i += tmp |
| 92 | k += tmp | 92 | k += tmp |
| 93 | 93 | ||
| 94 | my_func(22) | 94 | my_func(22) |
| 95 | print i, k -- these have been updated | 95 | print i, k -- estes foram atualizados |
| 96 | ``` | 96 | ``` |
| 97 | 97 | ||
| 98 | </YueDisplay> | 98 | </YueDisplay> |
diff --git a/doc/docs/pt-br/doc/assignment/varargs-assignment.md b/doc/docs/pt-br/doc/assignment/varargs-assignment.md index 1d66680..0aab540 100644 --- a/doc/docs/pt-br/doc/assignment/varargs-assignment.md +++ b/doc/docs/pt-br/doc/assignment/varargs-assignment.md | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | # Varargs Assignment | 1 | # Atribuição de varargs |
| 2 | 2 | ||
| 3 | You can assign the results returned from a function to a varargs symbol `...`. And then access its content using the Lua way. | 3 | Você pode atribuir os resultados retornados de uma função a um símbolo varargs `...`. E então acessar seu conteúdo da forma Lua. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | list = [1, 2, 3, 4, 5] | 6 | list = [1, 2, 3, 4, 5] |
diff --git a/doc/docs/pt-br/doc/control-flow/conditionals.md b/doc/docs/pt-br/doc/control-flow/conditionals.md index 5ba81cf..94e41ec 100644 --- a/doc/docs/pt-br/doc/control-flow/conditionals.md +++ b/doc/docs/pt-br/doc/control-flow/conditionals.md | |||
| @@ -1,55 +1,55 @@ | |||
| 1 | # Conditionals | 1 | # Condicionais |
| 2 | 2 | ||
| 3 | ```yuescript | 3 | ```yuescript |
| 4 | have_coins = false | 4 | have_coins = false |
| 5 | if have_coins | 5 | if have_coins |
| 6 | print "Got coins" | 6 | print "Tem moedas" |
| 7 | else | 7 | else |
| 8 | print "No coins" | 8 | print "Sem moedas" |
| 9 | ``` | 9 | ``` |
| 10 | <YueDisplay> | 10 | <YueDisplay> |
| 11 | 11 | ||
| 12 | ```yue | 12 | ```yue |
| 13 | have_coins = false | 13 | have_coins = false |
| 14 | if have_coins | 14 | if have_coins |
| 15 | print "Got coins" | 15 | print "Tem moedas" |
| 16 | else | 16 | else |
| 17 | print "No coins" | 17 | print "Sem moedas" |
| 18 | ``` | 18 | ``` |
| 19 | 19 | ||
| 20 | </YueDisplay> | 20 | </YueDisplay> |
| 21 | 21 | ||
| 22 | A short syntax for single statements can also be used: | 22 | Uma sintaxe curta para instruções únicas também pode ser usada: |
| 23 | 23 | ||
| 24 | ```yuescript | 24 | ```yuescript |
| 25 | have_coins = false | 25 | have_coins = false |
| 26 | if have_coins then print "Got coins" else print "No coins" | 26 | if have_coins then print "Tem moedas" else print "Sem moedas" |
| 27 | ``` | 27 | ``` |
| 28 | <YueDisplay> | 28 | <YueDisplay> |
| 29 | 29 | ||
| 30 | ```yue | 30 | ```yue |
| 31 | have_coins = false | 31 | have_coins = false |
| 32 | if have_coins then print "Got coins" else print "No coins" | 32 | if have_coins then print "Tem moedas" else print "Sem moedas" |
| 33 | ``` | 33 | ``` |
| 34 | 34 | ||
| 35 | </YueDisplay> | 35 | </YueDisplay> |
| 36 | 36 | ||
| 37 | Because if statements can be used as expressions, this can also be written as: | 37 | Como instruções if podem ser usadas como expressões, isso também pode ser escrito como: |
| 38 | 38 | ||
| 39 | ```yuescript | 39 | ```yuescript |
| 40 | have_coins = false | 40 | have_coins = false |
| 41 | print if have_coins then "Got coins" else "No coins" | 41 | print if have_coins then "Tem moedas" else "Sem moedas" |
| 42 | ``` | 42 | ``` |
| 43 | <YueDisplay> | 43 | <YueDisplay> |
| 44 | 44 | ||
| 45 | ```yue | 45 | ```yue |
| 46 | have_coins = false | 46 | have_coins = false |
| 47 | print if have_coins then "Got coins" else "No coins" | 47 | print if have_coins then "Tem moedas" else "Sem moedas" |
| 48 | ``` | 48 | ``` |
| 49 | 49 | ||
| 50 | </YueDisplay> | 50 | </YueDisplay> |
| 51 | 51 | ||
| 52 | Conditionals can also be used in return statements and assignments: | 52 | Condicionais também podem ser usados em instruções de retorno e atribuições: |
| 53 | 53 | ||
| 54 | ```yuescript | 54 | ```yuescript |
| 55 | is_tall = (name) -> | 55 | is_tall = (name) -> |
| @@ -59,11 +59,11 @@ is_tall = (name) -> | |||
| 59 | false | 59 | false |
| 60 | 60 | ||
| 61 | message = if is_tall "Rob" | 61 | message = if is_tall "Rob" |
| 62 | "I am very tall" | 62 | "Sou muito alto" |
| 63 | else | 63 | else |
| 64 | "I am not so tall" | 64 | "Não sou tão alto" |
| 65 | 65 | ||
| 66 | print message -- prints: I am very tall | 66 | print message -- imprime: Sou muito alto |
| 67 | ``` | 67 | ``` |
| 68 | <YueDisplay> | 68 | <YueDisplay> |
| 69 | 69 | ||
| @@ -75,53 +75,53 @@ is_tall = (name) -> | |||
| 75 | false | 75 | false |
| 76 | 76 | ||
| 77 | message = if is_tall "Rob" | 77 | message = if is_tall "Rob" |
| 78 | "I am very tall" | 78 | "Sou muito alto" |
| 79 | else | 79 | else |
| 80 | "I am not so tall" | 80 | "Não sou tão alto" |
| 81 | 81 | ||
| 82 | print message -- prints: I am very tall | 82 | print message -- imprime: Sou muito alto |
| 83 | ``` | 83 | ``` |
| 84 | 84 | ||
| 85 | </YueDisplay> | 85 | </YueDisplay> |
| 86 | 86 | ||
| 87 | The opposite of if is unless: | 87 | O oposto de if é unless: |
| 88 | 88 | ||
| 89 | ```yuescript | 89 | ```yuescript |
| 90 | unless os.date("%A") == "Monday" | 90 | unless os.date("%A") == "Monday" |
| 91 | print "it is not Monday!" | 91 | print "não é segunda-feira!" |
| 92 | ``` | 92 | ``` |
| 93 | <YueDisplay> | 93 | <YueDisplay> |
| 94 | 94 | ||
| 95 | ```yue | 95 | ```yue |
| 96 | unless os.date("%A") == "Monday" | 96 | unless os.date("%A") == "Monday" |
| 97 | print "it is not Monday!" | 97 | print "não é segunda-feira!" |
| 98 | ``` | 98 | ``` |
| 99 | 99 | ||
| 100 | </YueDisplay> | 100 | </YueDisplay> |
| 101 | 101 | ||
| 102 | ```yuescript | 102 | ```yuescript |
| 103 | print "You're lucky!" unless math.random! > 0.1 | 103 | print "Você tem sorte!" unless math.random! > 0.1 |
| 104 | ``` | 104 | ``` |
| 105 | <YueDisplay> | 105 | <YueDisplay> |
| 106 | 106 | ||
| 107 | ```yue | 107 | ```yue |
| 108 | print "You're lucky!" unless math.random! > 0.1 | 108 | print "Você tem sorte!" unless math.random! > 0.1 |
| 109 | ``` | 109 | ``` |
| 110 | 110 | ||
| 111 | </YueDisplay> | 111 | </YueDisplay> |
| 112 | 112 | ||
| 113 | ## In Expression | 113 | ## Em expressão |
| 114 | 114 | ||
| 115 | You can write range checking code with an `in-expression`. | 115 | Você pode escrever código de verificação de intervalo com uma `in-expression`. |
| 116 | 116 | ||
| 117 | ```yuescript | 117 | ```yuescript |
| 118 | a = 5 | 118 | a = 5 |
| 119 | 119 | ||
| 120 | if a in [1, 3, 5, 7] | 120 | if a in [1, 3, 5, 7] |
| 121 | print "checking equality with discrete values" | 121 | print "verificando igualdade com valores discretos" |
| 122 | 122 | ||
| 123 | if a in list | 123 | if a in list |
| 124 | print "checking if `a` is in a list" | 124 | print "verificando se `a` está na lista" |
| 125 | ``` | 125 | ``` |
| 126 | <YueDisplay> | 126 | <YueDisplay> |
| 127 | 127 | ||
| @@ -129,21 +129,10 @@ if a in list | |||
| 129 | a = 5 | 129 | a = 5 |
| 130 | 130 | ||
| 131 | if a in [1, 3, 5, 7] | 131 | if a in [1, 3, 5, 7] |
| 132 | print "checking equality with discrete values" | 132 | print "verificando igualdade com valores discretos" |
| 133 | 133 | ||
| 134 | if a in list | 134 | if a in list |
| 135 | print "checking if `a` is in a list" | 135 | print "verificando se `a` está na lista" |
| 136 | ``` | ||
| 137 | |||
| 138 | </YueDisplay> | ||
| 139 | |||
| 140 | ```yuescript | ||
| 141 | print "You're lucky!" unless math.random! > 0.1 | ||
| 142 | ``` | ||
| 143 | <YueDisplay> | ||
| 144 | |||
| 145 | ```yue | ||
| 146 | print "You're lucky!" unless math.random! > 0.1 | ||
| 147 | ``` | 136 | ``` |
| 148 | 137 | ||
| 149 | </YueDisplay> | 138 | </YueDisplay> |
diff --git a/doc/docs/pt-br/doc/control-flow/continue.md b/doc/docs/pt-br/doc/control-flow/continue.md index b000765..8a3cdff 100644 --- a/doc/docs/pt-br/doc/control-flow/continue.md +++ b/doc/docs/pt-br/doc/control-flow/continue.md | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | # Continue | 1 | # Continue |
| 2 | 2 | ||
| 3 | A continue statement can be used to skip the current iteration in a loop. | 3 | Uma instrução continue pode ser usada para pular a iteração atual em um loop. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | i = 0 | 6 | i = 0 |
| @@ -21,7 +21,7 @@ while i < 10 | |||
| 21 | 21 | ||
| 22 | </YueDisplay> | 22 | </YueDisplay> |
| 23 | 23 | ||
| 24 | continue can also be used with loop expressions to prevent that iteration from accumulating into the result. This examples filters the array table into just even numbers: | 24 | continue também pode ser usado com expressões de loop para impedir que essa iteração seja acumulada no resultado. Este exemplo filtra a tabela array para apenas números pares: |
| 25 | 25 | ||
| 26 | ```yuescript | 26 | ```yuescript |
| 27 | my_numbers = [1, 2, 3, 4, 5, 6] | 27 | my_numbers = [1, 2, 3, 4, 5, 6] |
diff --git a/doc/docs/pt-br/doc/control-flow/for-loop.md b/doc/docs/pt-br/doc/control-flow/for-loop.md index cabcde5..dfd8285 100644 --- a/doc/docs/pt-br/doc/control-flow/for-loop.md +++ b/doc/docs/pt-br/doc/control-flow/for-loop.md | |||
| @@ -1,12 +1,12 @@ | |||
| 1 | # For Loop | 1 | # Loop For |
| 2 | 2 | ||
| 3 | There are two for loop forms, just like in Lua. A numeric one and a generic one: | 3 | Existem duas formas de loop for, assim como no Lua. Uma numérica e uma genérica: |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | for i = 10, 20 | 6 | for i = 10, 20 |
| 7 | print i | 7 | print i |
| 8 | 8 | ||
| 9 | for k = 1, 15, 2 -- an optional step provided | 9 | for k = 1, 15, 2 -- um passo opcional fornecido |
| 10 | print k | 10 | print k |
| 11 | 11 | ||
| 12 | for key, value in pairs object | 12 | for key, value in pairs object |
| @@ -18,7 +18,7 @@ for key, value in pairs object | |||
| 18 | for i = 10, 20 | 18 | for i = 10, 20 |
| 19 | print i | 19 | print i |
| 20 | 20 | ||
| 21 | for k = 1, 15, 2 -- an optional step provided | 21 | for k = 1, 15, 2 -- um passo opcional fornecido |
| 22 | print k | 22 | print k |
| 23 | 23 | ||
| 24 | for key, value in pairs object | 24 | for key, value in pairs object |
| @@ -27,7 +27,7 @@ for key, value in pairs object | |||
| 27 | 27 | ||
| 28 | </YueDisplay> | 28 | </YueDisplay> |
| 29 | 29 | ||
| 30 | The slicing and **\*** operators can be used, just like with comprehensions: | 30 | Os operadores de slicing e **\*** podem ser usados, assim como com compreensões: |
| 31 | 31 | ||
| 32 | ```yuescript | 32 | ```yuescript |
| 33 | for item in *items[2, 4] | 33 | for item in *items[2, 4] |
| @@ -42,7 +42,7 @@ for item in *items[2, 4] | |||
| 42 | 42 | ||
| 43 | </YueDisplay> | 43 | </YueDisplay> |
| 44 | 44 | ||
| 45 | A shorter syntax is also available for all variations when the body is only a single line: | 45 | Uma sintaxe mais curta também está disponível para todas as variações quando o corpo é apenas uma linha: |
| 46 | 46 | ||
| 47 | ```yuescript | 47 | ```yuescript |
| 48 | for item in *items do print item | 48 | for item in *items do print item |
| @@ -59,9 +59,9 @@ for j = 1, 10, 3 do print j | |||
| 59 | 59 | ||
| 60 | </YueDisplay> | 60 | </YueDisplay> |
| 61 | 61 | ||
| 62 | A for loop can also be used as an expression. The last statement in the body of the for loop is coerced into an expression and appended to an accumulating array table. | 62 | Um loop for também pode ser usado como expressão. A última instrução no corpo do loop for é convertida em expressão e anexada a uma tabela array acumuladora. |
| 63 | 63 | ||
| 64 | Doubling every even number: | 64 | Dobrando cada número par: |
| 65 | 65 | ||
| 66 | ```yuescript | 66 | ```yuescript |
| 67 | doubled_evens = for i = 1, 20 | 67 | doubled_evens = for i = 1, 20 |
| @@ -82,9 +82,9 @@ doubled_evens = for i = 1, 20 | |||
| 82 | 82 | ||
| 83 | </YueDisplay> | 83 | </YueDisplay> |
| 84 | 84 | ||
| 85 | In addition, for loops support break with a return value, allowing the loop itself to be used as an expression that exits early with a meaningful result. | 85 | Além disso, os loops for suportam break com valor de retorno, permitindo que o próprio loop seja usado como expressão que sai antecipadamente com um resultado significativo. |
| 86 | 86 | ||
| 87 | For example, to find the first number greater than 10: | 87 | Por exemplo, para encontrar o primeiro número maior que 10: |
| 88 | 88 | ||
| 89 | ```yuescript | 89 | ```yuescript |
| 90 | first_large = for n in *numbers | 90 | first_large = for n in *numbers |
| @@ -99,18 +99,18 @@ first_large = for n in *numbers | |||
| 99 | 99 | ||
| 100 | </YueDisplay> | 100 | </YueDisplay> |
| 101 | 101 | ||
| 102 | This break-with-value syntax enables concise and expressive search or early-exit patterns directly within loop expressions. | 102 | Esta sintaxe de break-com-valor permite padrões concisos e expressivos de busca ou saída antecipada diretamente em expressões de loop. |
| 103 | 103 | ||
| 104 | You can also filter values by combining the for loop expression with the continue statement. | 104 | Você também pode filtrar valores combinando a expressão do loop for com a instrução continue. |
| 105 | 105 | ||
| 106 | For loops at the end of a function body are not accumulated into a table for a return value (Instead the function will return nil). Either an explicit return statement can be used, or the loop can be converted into a list comprehension. | 106 | Loops for no final do corpo de uma função não são acumulados em uma tabela para valor de retorno (em vez disso, a função retornará nil). Uma instrução return explícita pode ser usada, ou o loop pode ser convertido em compreensão de lista. |
| 107 | 107 | ||
| 108 | ```yuescript | 108 | ```yuescript |
| 109 | func_a = -> for i = 1, 10 do print i | 109 | func_a = -> for i = 1, 10 do print i |
| 110 | func_b = -> return for i = 1, 10 do i | 110 | func_b = -> return for i = 1, 10 do i |
| 111 | 111 | ||
| 112 | print func_a! -- prints nil | 112 | print func_a! -- imprime nil |
| 113 | print func_b! -- prints table object | 113 | print func_b! -- imprime objeto table |
| 114 | ``` | 114 | ``` |
| 115 | <YueDisplay> | 115 | <YueDisplay> |
| 116 | 116 | ||
| @@ -118,10 +118,10 @@ print func_b! -- prints table object | |||
| 118 | func_a = -> for i = 1, 10 do print i | 118 | func_a = -> for i = 1, 10 do print i |
| 119 | func_b = -> return for i = 1, 10 do i | 119 | func_b = -> return for i = 1, 10 do i |
| 120 | 120 | ||
| 121 | print func_a! -- prints nil | 121 | print func_a! -- imprime nil |
| 122 | print func_b! -- prints table object | 122 | print func_b! -- imprime objeto table |
| 123 | ``` | 123 | ``` |
| 124 | 124 | ||
| 125 | </YueDisplay> | 125 | </YueDisplay> |
| 126 | 126 | ||
| 127 | This is done to avoid the needless creation of tables for functions that don't need to return the results of the loop. | 127 | Isso é feito para evitar a criação desnecessária de tabelas para funções que não precisam retornar os resultados do loop. |
diff --git a/doc/docs/pt-br/doc/control-flow/switch.md b/doc/docs/pt-br/doc/control-flow/switch.md index f503a80..5c87327 100644 --- a/doc/docs/pt-br/doc/control-flow/switch.md +++ b/doc/docs/pt-br/doc/control-flow/switch.md | |||
| @@ -1,33 +1,33 @@ | |||
| 1 | # Switch | 1 | # Switch |
| 2 | 2 | ||
| 3 | The switch statement is shorthand for writing a series of if statements that check against the same value. Note that the value is only evaluated once. Like if statements, switches can have an else block to handle no matches. Comparison is done with the == operator. In switch statement, you can also use assignment expression to store temporary variable value. | 3 | A instrução switch é uma forma abreviada de escrever uma série de instruções if que verificam o mesmo valor. Observe que o valor é avaliado apenas uma vez. Como as instruções if, os switches podem ter um bloco else para tratar ausência de correspondências. A comparação é feita com o operador ==. Na instrução switch, você também pode usar expressão de atribuição para armazenar valor de variável temporária. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | switch name := "Dan" | 6 | switch name := "Dan" |
| 7 | when "Robert" | 7 | when "Robert" |
| 8 | print "You are Robert" | 8 | print "Você é Robert" |
| 9 | when "Dan", "Daniel" | 9 | when "Dan", "Daniel" |
| 10 | print "Your name, it's Dan" | 10 | print "Seu nome é Dan" |
| 11 | else | 11 | else |
| 12 | print "I don't know about you with name #{name}" | 12 | print "Não sei quem você é com o nome #{name}" |
| 13 | ``` | 13 | ``` |
| 14 | <YueDisplay> | 14 | <YueDisplay> |
| 15 | 15 | ||
| 16 | ```yue | 16 | ```yue |
| 17 | switch name := "Dan" | 17 | switch name := "Dan" |
| 18 | when "Robert" | 18 | when "Robert" |
| 19 | print "You are Robert" | 19 | print "Você é Robert" |
| 20 | when "Dan", "Daniel" | 20 | when "Dan", "Daniel" |
| 21 | print "Your name, it's Dan" | 21 | print "Seu nome é Dan" |
| 22 | else | 22 | else |
| 23 | print "I don't know about you with name #{name}" | 23 | print "Não sei quem você é com o nome #{name}" |
| 24 | ``` | 24 | ``` |
| 25 | 25 | ||
| 26 | </YueDisplay> | 26 | </YueDisplay> |
| 27 | 27 | ||
| 28 | A switch when clause can match against multiple values by listing them out comma separated. | 28 | Uma cláusula when de um switch pode corresponder a múltiplos valores listando-os separados por vírgula. |
| 29 | 29 | ||
| 30 | Switches can be used as expressions as well, here we can assign the result of the switch to a variable: | 30 | Os switches também podem ser usados como expressões; aqui podemos atribuir o resultado do switch a uma variável: |
| 31 | 31 | ||
| 32 | ```yuescript | 32 | ```yuescript |
| 33 | b = 1 | 33 | b = 1 |
| @@ -37,7 +37,7 @@ next_number = switch b | |||
| 37 | when 2 | 37 | when 2 |
| 38 | 3 | 38 | 3 |
| 39 | else | 39 | else |
| 40 | error "can't count that high!" | 40 | error "não consigo contar tão alto!" |
| 41 | ``` | 41 | ``` |
| 42 | <YueDisplay> | 42 | <YueDisplay> |
| 43 | 43 | ||
| @@ -49,66 +49,66 @@ next_number = switch b | |||
| 49 | when 2 | 49 | when 2 |
| 50 | 3 | 50 | 3 |
| 51 | else | 51 | else |
| 52 | error "can't count that high!" | 52 | error "não consigo contar tão alto!" |
| 53 | ``` | 53 | ``` |
| 54 | 54 | ||
| 55 | </YueDisplay> | 55 | </YueDisplay> |
| 56 | 56 | ||
| 57 | We can use the then keyword to write a switch's when block on a single line. No extra keyword is needed to write the else block on a single line. | 57 | Podemos usar a palavra-chave then para escrever o bloco when de um switch em uma única linha. Nenhuma palavra-chave extra é necessária para escrever o bloco else em uma única linha. |
| 58 | 58 | ||
| 59 | ```yuescript | 59 | ```yuescript |
| 60 | msg = switch math.random(1, 5) | 60 | msg = switch math.random(1, 5) |
| 61 | when 1 then "you are lucky" | 61 | when 1 then "você tem sorte" |
| 62 | when 2 then "you are almost lucky" | 62 | when 2 then "você quase tem sorte" |
| 63 | else "not so lucky" | 63 | else "não tão sortudo" |
| 64 | ``` | 64 | ``` |
| 65 | <YueDisplay> | 65 | <YueDisplay> |
| 66 | 66 | ||
| 67 | ```yue | 67 | ```yue |
| 68 | msg = switch math.random(1, 5) | 68 | msg = switch math.random(1, 5) |
| 69 | when 1 then "you are lucky" | 69 | when 1 then "você tem sorte" |
| 70 | when 2 then "you are almost lucky" | 70 | when 2 then "você quase tem sorte" |
| 71 | else "not so lucky" | 71 | else "não tão sortudo" |
| 72 | ``` | 72 | ``` |
| 73 | 73 | ||
| 74 | </YueDisplay> | 74 | </YueDisplay> |
| 75 | 75 | ||
| 76 | If you want to write code with one less indent when writing a switch statement, you can put the first when clause on the statement start line, and then all other clauses can be written with one less indent. | 76 | Se você quiser escrever código com uma indentação a menos ao escrever uma instrução switch, pode colocar a primeira cláusula when na linha de início da instrução, e então todas as outras cláusulas podem ser escritas com uma indentação a menos. |
| 77 | 77 | ||
| 78 | ```yuescript | 78 | ```yuescript |
| 79 | switch math.random(1, 5) | 79 | switch math.random(1, 5) |
| 80 | when 1 | 80 | when 1 |
| 81 | print "you are lucky" -- two indents | 81 | print "você tem sorte" -- duas indentações |
| 82 | else | 82 | else |
| 83 | print "not so lucky" | 83 | print "não tão sortudo" |
| 84 | 84 | ||
| 85 | switch math.random(1, 5) when 1 | 85 | switch math.random(1, 5) when 1 |
| 86 | print "you are lucky" -- one indent | 86 | print "você tem sorte" -- uma indentação |
| 87 | else | 87 | else |
| 88 | print "not so lucky" | 88 | print "não tão sortudo" |
| 89 | ``` | 89 | ``` |
| 90 | <YueDisplay> | 90 | <YueDisplay> |
| 91 | 91 | ||
| 92 | ```yue | 92 | ```yue |
| 93 | switch math.random(1, 5) | 93 | switch math.random(1, 5) |
| 94 | when 1 | 94 | when 1 |
| 95 | print "you are lucky" -- two indents | 95 | print "você tem sorte" -- duas indentações |
| 96 | else | 96 | else |
| 97 | print "not so lucky" | 97 | print "não tão sortudo" |
| 98 | 98 | ||
| 99 | switch math.random(1, 5) when 1 | 99 | switch math.random(1, 5) when 1 |
| 100 | print "you are lucky" -- one indent | 100 | print "você tem sorte" -- uma indentação |
| 101 | else | 101 | else |
| 102 | print "not so lucky" | 102 | print "não tão sortudo" |
| 103 | ``` | 103 | ``` |
| 104 | 104 | ||
| 105 | </YueDisplay> | 105 | </YueDisplay> |
| 106 | 106 | ||
| 107 | It is worth noting the order of the case comparison expression. The case's expression is on the left hand side. This can be useful if the case's expression wants to overwrite how the comparison is done by defining an eq metamethod. | 107 | Vale notar a ordem da expressão de comparação do case. A expressão do case está no lado esquerdo. Isso pode ser útil se a expressão do case quiser sobrescrever como a comparação é feita definindo um metamétodo eq. |
| 108 | 108 | ||
| 109 | ## Table Matching | 109 | ## Correspondência de tabela |
| 110 | 110 | ||
| 111 | You can do table matching in a switch when clause, if the table can be destructured by a specific structure and get non-nil values. | 111 | Você pode fazer correspondência de tabela em uma cláusula when de switch, se a tabela puder ser desestruturada por uma estrutura específica e obter valores não-nil. |
| 112 | 112 | ||
| 113 | ```yuescript | 113 | ```yuescript |
| 114 | items = | 114 | items = |
| @@ -122,7 +122,7 @@ for item in *items | |||
| 122 | when :x, :y | 122 | when :x, :y |
| 123 | print "Vec2 #{x}, #{y}" | 123 | print "Vec2 #{x}, #{y}" |
| 124 | when :width, :height | 124 | when :width, :height |
| 125 | print "size #{width}, #{height}" | 125 | print "tamanho #{width}, #{height}" |
| 126 | ``` | 126 | ``` |
| 127 | <YueDisplay> | 127 | <YueDisplay> |
| 128 | 128 | ||
| @@ -138,39 +138,39 @@ for item in *items | |||
| 138 | when :x, :y | 138 | when :x, :y |
| 139 | print "Vec2 #{x}, #{y}" | 139 | print "Vec2 #{x}, #{y}" |
| 140 | when :width, :height | 140 | when :width, :height |
| 141 | print "size #{width}, #{height}" | 141 | print "tamanho #{width}, #{height}" |
| 142 | ``` | 142 | ``` |
| 143 | 143 | ||
| 144 | </YueDisplay> | 144 | </YueDisplay> |
| 145 | 145 | ||
| 146 | You can use default values to optionally destructure the table for some fields. | 146 | Você pode usar valores padrão para opcionalmente desestruturar a tabela para alguns campos. |
| 147 | 147 | ||
| 148 | ```yuescript | 148 | ```yuescript |
| 149 | item = {} | 149 | item = {} |
| 150 | 150 | ||
| 151 | {pos: {:x = 50, :y = 200}} = item -- get error: attempt to index a nil value (field 'pos') | 151 | {pos: {:x = 50, :y = 200}} = item -- obtém erro: attempt to index a nil value (field 'pos') |
| 152 | 152 | ||
| 153 | switch item | 153 | switch item |
| 154 | when {pos: {:x = 50, :y = 200}} | 154 | when {pos: {:x = 50, :y = 200}} |
| 155 | print "Vec2 #{x}, #{y}" -- table destructuring will still pass | 155 | print "Vec2 #{x}, #{y}" -- a desestruturação de tabela ainda passará |
| 156 | ``` | 156 | ``` |
| 157 | <YueDisplay> | 157 | <YueDisplay> |
| 158 | 158 | ||
| 159 | ```yue | 159 | ```yue |
| 160 | item = {} | 160 | item = {} |
| 161 | 161 | ||
| 162 | {pos: {:x = 50, :y = 200}} = item -- get error: attempt to index a nil value (field 'pos') | 162 | {pos: {:x = 50, :y = 200}} = item -- obtém erro: attempt to index a nil value (field 'pos') |
| 163 | 163 | ||
| 164 | switch item | 164 | switch item |
| 165 | when {pos: {:x = 50, :y = 200}} | 165 | when {pos: {:x = 50, :y = 200}} |
| 166 | print "Vec2 #{x}, #{y}" -- table destructuring will still pass | 166 | print "Vec2 #{x}, #{y}" -- a desestruturação de tabela ainda passará |
| 167 | ``` | 167 | ``` |
| 168 | 168 | ||
| 169 | </YueDisplay> | 169 | </YueDisplay> |
| 170 | 170 | ||
| 171 | You can also match against array elements, table fields, and even nested structures with array or table literals. | 171 | Você também pode corresponder contra elementos de array, campos de tabela, e até estruturas aninhadas com literais de array ou tabela. |
| 172 | 172 | ||
| 173 | Match against array elements. | 173 | Corresponder contra elementos de array. |
| 174 | 174 | ||
| 175 | ```yuescript | 175 | ```yuescript |
| 176 | switch tb | 176 | switch tb |
| @@ -178,7 +178,7 @@ switch tb | |||
| 178 | print "1, 2, 3" | 178 | print "1, 2, 3" |
| 179 | when [1, b, 3] | 179 | when [1, b, 3] |
| 180 | print "1, #{b}, 3" | 180 | print "1, #{b}, 3" |
| 181 | when [1, 2, b = 3] -- b has a default value | 181 | when [1, 2, b = 3] -- b tem valor padrão |
| 182 | print "1, 2, #{b}" | 182 | print "1, 2, #{b}" |
| 183 | ``` | 183 | ``` |
| 184 | <YueDisplay> | 184 | <YueDisplay> |
| @@ -189,63 +189,63 @@ switch tb | |||
| 189 | print "1, 2, 3" | 189 | print "1, 2, 3" |
| 190 | when [1, b, 3] | 190 | when [1, b, 3] |
| 191 | print "1, #{b}, 3" | 191 | print "1, #{b}, 3" |
| 192 | when [1, 2, b = 3] -- b has a default value | 192 | when [1, 2, b = 3] -- b tem valor padrão |
| 193 | print "1, 2, #{b}" | 193 | print "1, 2, #{b}" |
| 194 | ``` | 194 | ``` |
| 195 | 195 | ||
| 196 | </YueDisplay> | 196 | </YueDisplay> |
| 197 | 197 | ||
| 198 | Match against table fields with destructuring. | 198 | Corresponder contra campos de tabela com desestruturação. |
| 199 | 199 | ||
| 200 | ```yuescript | 200 | ```yuescript |
| 201 | switch tb | 201 | switch tb |
| 202 | when success: true, :result | 202 | when success: true, :result |
| 203 | print "success", result | 203 | print "sucesso", result |
| 204 | when success: false | 204 | when success: false |
| 205 | print "failed", result | 205 | print "falhou", result |
| 206 | else | 206 | else |
| 207 | print "invalid" | 207 | print "inválido" |
| 208 | ``` | 208 | ``` |
| 209 | <YueDisplay> | 209 | <YueDisplay> |
| 210 | 210 | ||
| 211 | ```yue | 211 | ```yue |
| 212 | switch tb | 212 | switch tb |
| 213 | when success: true, :result | 213 | when success: true, :result |
| 214 | print "success", result | 214 | print "sucesso", result |
| 215 | when success: false | 215 | when success: false |
| 216 | print "failed", result | 216 | print "falhou", result |
| 217 | else | 217 | else |
| 218 | print "invalid" | 218 | print "inválido" |
| 219 | ``` | 219 | ``` |
| 220 | 220 | ||
| 221 | </YueDisplay> | 221 | </YueDisplay> |
| 222 | 222 | ||
| 223 | Match against nested table structures. | 223 | Corresponder contra estruturas de tabela aninhadas. |
| 224 | 224 | ||
| 225 | ```yuescript | 225 | ```yuescript |
| 226 | switch tb | 226 | switch tb |
| 227 | when data: {type: "success", :content} | 227 | when data: {type: "success", :content} |
| 228 | print "success", content | 228 | print "sucesso", content |
| 229 | when data: {type: "error", :content} | 229 | when data: {type: "error", :content} |
| 230 | print "failed", content | 230 | print "erro", content |
| 231 | else | 231 | else |
| 232 | print "invalid" | 232 | print "inválido" |
| 233 | ``` | 233 | ``` |
| 234 | <YueDisplay> | 234 | <YueDisplay> |
| 235 | 235 | ||
| 236 | ```yue | 236 | ```yue |
| 237 | switch tb | 237 | switch tb |
| 238 | when data: {type: "success", :content} | 238 | when data: {type: "success", :content} |
| 239 | print "success", content | 239 | print "sucesso", content |
| 240 | when data: {type: "error", :content} | 240 | when data: {type: "error", :content} |
| 241 | print "failed", content | 241 | print "erro", content |
| 242 | else | 242 | else |
| 243 | print "invalid" | 243 | print "inválido" |
| 244 | ``` | 244 | ``` |
| 245 | 245 | ||
| 246 | </YueDisplay> | 246 | </YueDisplay> |
| 247 | 247 | ||
| 248 | Match against array of tables. | 248 | Corresponder contra array de tabelas. |
| 249 | 249 | ||
| 250 | ```yuescript | 250 | ```yuescript |
| 251 | switch tb | 251 | switch tb |
| @@ -255,7 +255,7 @@ switch tb | |||
| 255 | {a: 5, b: 6} | 255 | {a: 5, b: 6} |
| 256 | fourth | 256 | fourth |
| 257 | ] | 257 | ] |
| 258 | print "matched", fourth | 258 | print "correspondido", fourth |
| 259 | ``` | 259 | ``` |
| 260 | <YueDisplay> | 260 | <YueDisplay> |
| 261 | 261 | ||
| @@ -267,20 +267,20 @@ switch tb | |||
| 267 | {a: 5, b: 6} | 267 | {a: 5, b: 6} |
| 268 | fourth | 268 | fourth |
| 269 | ] | 269 | ] |
| 270 | print "matched", fourth | 270 | print "correspondido", fourth |
| 271 | ``` | 271 | ``` |
| 272 | 272 | ||
| 273 | </YueDisplay> | 273 | </YueDisplay> |
| 274 | 274 | ||
| 275 | Match against a list and capture a range of elements. | 275 | Corresponder contra uma lista e capturar um intervalo de elementos. |
| 276 | 276 | ||
| 277 | ```yuescript | 277 | ```yuescript |
| 278 | segments = ["admin", "users", "logs", "view"] | 278 | segments = ["admin", "users", "logs", "view"] |
| 279 | switch segments | 279 | switch segments |
| 280 | when [...groups, resource, action] | 280 | when [...groups, resource, action] |
| 281 | print "Group:", groups -- prints: {"admin", "users"} | 281 | print "Grupo:", groups -- imprime: {"admin", "users"} |
| 282 | print "Resource:", resource -- prints: "logs" | 282 | print "Recurso:", resource -- imprime: "logs" |
| 283 | print "Action:", action -- prints: "view" | 283 | print "Ação:", action -- imprime: "view" |
| 284 | ``` | 284 | ``` |
| 285 | <YueDisplay> | 285 | <YueDisplay> |
| 286 | 286 | ||
| @@ -288,9 +288,9 @@ switch segments | |||
| 288 | segments = ["admin", "users", "logs", "view"] | 288 | segments = ["admin", "users", "logs", "view"] |
| 289 | switch segments | 289 | switch segments |
| 290 | when [...groups, resource, action] | 290 | when [...groups, resource, action] |
| 291 | print "Group:", groups -- prints: {"admin", "users"} | 291 | print "Grupo:", groups -- imprime: {"admin", "users"} |
| 292 | print "Resource:", resource -- prints: "logs" | 292 | print "Recurso:", resource -- imprime: "logs" |
| 293 | print "Action:", action -- prints: "view" | 293 | print "Ação:", action -- imprime: "view" |
| 294 | ``` | 294 | ``` |
| 295 | 295 | ||
| 296 | </YueDisplay> | 296 | </YueDisplay> |
diff --git a/doc/docs/pt-br/doc/control-flow/while-loop.md b/doc/docs/pt-br/doc/control-flow/while-loop.md index 502935e..f47f00c 100644 --- a/doc/docs/pt-br/doc/control-flow/while-loop.md +++ b/doc/docs/pt-br/doc/control-flow/while-loop.md | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | # While Loop | 1 | # Loop While |
| 2 | 2 | ||
| 3 | The while loop also comes in four variations: | 3 | O loop while também vem em quatro variações: |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | i = 10 | 6 | i = 10 |
| @@ -43,11 +43,11 @@ until running == false do my_function! | |||
| 43 | 43 | ||
| 44 | </YueDisplay> | 44 | </YueDisplay> |
| 45 | 45 | ||
| 46 | Like for loops, the while loop can also be used an expression. Additionally, for a function to return the accumulated value of a while loop, the statement must be explicitly returned. | 46 | Como os loops for, o loop while também pode ser usado como expressão. Além disso, para uma função retornar o valor acumulado de um loop while, a instrução deve ser explicitamente retornada. |
| 47 | 47 | ||
| 48 | ## Repeat Loop | 48 | ## Loop Repeat |
| 49 | 49 | ||
| 50 | The repeat loop comes from Lua: | 50 | O loop repeat vem do Lua: |
| 51 | 51 | ||
| 52 | ```yuescript | 52 | ```yuescript |
| 53 | i = 10 | 53 | i = 10 |
diff --git a/doc/docs/pt-br/doc/data-structures/comprehensions.md b/doc/docs/pt-br/doc/data-structures/comprehensions.md index 3a92167..1694813 100644 --- a/doc/docs/pt-br/doc/data-structures/comprehensions.md +++ b/doc/docs/pt-br/doc/data-structures/comprehensions.md | |||
| @@ -1,10 +1,10 @@ | |||
| 1 | # Comprehensions | 1 | # Compreensões |
| 2 | 2 | ||
| 3 | Comprehensions provide a convenient syntax for constructing a new table by iterating over some existing object and applying an expression to its values. There are two kinds of comprehensions: list comprehensions and table comprehensions. They both produce Lua tables; list comprehensions accumulate values into an array-like table, and table comprehensions let you set both the key and the value on each iteration. | 3 | As compreensões fornecem uma sintaxe conveniente para construir uma nova tabela iterando sobre algum objeto existente e aplicando uma expressão a seus valores. Existem dois tipos de compreensões: compreensões de lista e compreensões de tabela. Ambas produzem tabelas Lua; as compreensões de lista acumulam valores em uma tabela semelhante a array, e as compreensões de tabela permitem definir tanto a chave quanto o valor em cada iteração. |
| 4 | 4 | ||
| 5 | ## List Comprehensions | 5 | ## Compreensões de lista |
| 6 | 6 | ||
| 7 | The following creates a copy of the items table but with all the values doubled. | 7 | O seguinte cria uma cópia da tabela items mas com todos os valores dobrados. |
| 8 | 8 | ||
| 9 | ```yuescript | 9 | ```yuescript |
| 10 | items = [ 1, 2, 3, 4 ] | 10 | items = [ 1, 2, 3, 4 ] |
| @@ -19,7 +19,7 @@ doubled = [item * 2 for i, item in ipairs items] | |||
| 19 | 19 | ||
| 20 | </YueDisplay> | 20 | </YueDisplay> |
| 21 | 21 | ||
| 22 | The items included in the new table can be restricted with a when clause: | 22 | Os itens incluídos na nova tabela podem ser restringidos com uma cláusula when: |
| 23 | 23 | ||
| 24 | ```yuescript | 24 | ```yuescript |
| 25 | slice = [item for i, item in ipairs items when i > 1 and i < 3] | 25 | slice = [item for i, item in ipairs items when i > 1 and i < 3] |
| @@ -32,7 +32,7 @@ slice = [item for i, item in ipairs items when i > 1 and i < 3] | |||
| 32 | 32 | ||
| 33 | </YueDisplay> | 33 | </YueDisplay> |
| 34 | 34 | ||
| 35 | Because it is common to iterate over the values of a numerically indexed table, an **\*** operator is introduced. The doubled example can be rewritten as: | 35 | Como é comum iterar sobre os valores de uma tabela indexada numericamente, um operador **\*** é introduzido. O exemplo doubled pode ser reescrito como: |
| 36 | 36 | ||
| 37 | ```yuescript | 37 | ```yuescript |
| 38 | doubled = [item * 2 for item in *items] | 38 | doubled = [item * 2 for item in *items] |
| @@ -45,7 +45,7 @@ doubled = [item * 2 for item in *items] | |||
| 45 | 45 | ||
| 46 | </YueDisplay> | 46 | </YueDisplay> |
| 47 | 47 | ||
| 48 | In list comprehensions, you can also use the spread operator `...` to flatten nested lists, achieving a flat map effect: | 48 | Nas compreensões de lista, você também pode usar o operador spread `...` para achatar listas aninhadas, alcançando um efeito de flat map: |
| 49 | 49 | ||
| 50 | ```yuescript | 50 | ```yuescript |
| 51 | data = | 51 | data = |
| @@ -53,7 +53,7 @@ data = | |||
| 53 | b: [4, 5, 6] | 53 | b: [4, 5, 6] |
| 54 | 54 | ||
| 55 | flat = [...v for k,v in pairs data] | 55 | flat = [...v for k,v in pairs data] |
| 56 | -- flat is now [1, 2, 3, 4, 5, 6] | 56 | -- flat agora é [1, 2, 3, 4, 5, 6] |
| 57 | ``` | 57 | ``` |
| 58 | <YueDisplay> | 58 | <YueDisplay> |
| 59 | 59 | ||
| @@ -63,14 +63,14 @@ data = | |||
| 63 | b: [4, 5, 6] | 63 | b: [4, 5, 6] |
| 64 | 64 | ||
| 65 | flat = [...v for k,v in pairs data] | 65 | flat = [...v for k,v in pairs data] |
| 66 | -- flat is now [1, 2, 3, 4, 5, 6] | 66 | -- flat agora é [1, 2, 3, 4, 5, 6] |
| 67 | ``` | 67 | ``` |
| 68 | 68 | ||
| 69 | </YueDisplay> | 69 | </YueDisplay> |
| 70 | 70 | ||
| 71 | The for and when clauses can be chained as much as desired. The only requirement is that a comprehension has at least one for clause. | 71 | As cláusulas for e when podem ser encadeadas tanto quanto desejado. O único requisito é que uma compreensão tenha pelo menos uma cláusula for. |
| 72 | 72 | ||
| 73 | Using multiple for clauses is the same as using nested loops: | 73 | Usar múltiplas cláusulas for é o mesmo que usar loops aninhados: |
| 74 | 74 | ||
| 75 | ```yuescript | 75 | ```yuescript |
| 76 | x_coords = [4, 5, 6, 7] | 76 | x_coords = [4, 5, 6, 7] |
| @@ -91,7 +91,7 @@ for y in *y_coords] | |||
| 91 | 91 | ||
| 92 | </YueDisplay> | 92 | </YueDisplay> |
| 93 | 93 | ||
| 94 | Numeric for loops can also be used in comprehensions: | 94 | Loops for numéricos também podem ser usados em compreensões: |
| 95 | 95 | ||
| 96 | ```yuescript | 96 | ```yuescript |
| 97 | evens = [i for i = 1, 100 when i % 2 == 0] | 97 | evens = [i for i = 1, 100 when i % 2 == 0] |
| @@ -104,11 +104,11 @@ evens = [i for i = 1, 100 when i % 2 == 0] | |||
| 104 | 104 | ||
| 105 | </YueDisplay> | 105 | </YueDisplay> |
| 106 | 106 | ||
| 107 | ## Table Comprehensions | 107 | ## Compreensões de tabela |
| 108 | 108 | ||
| 109 | The syntax for table comprehensions is very similar, only differing by using **{** and **}** and taking two values from each iteration. | 109 | A sintaxe para compreensões de tabela é muito semelhante, diferindo apenas por usar **{** e **}** e receber dois valores de cada iteração. |
| 110 | 110 | ||
| 111 | This example makes a copy of the tablething: | 111 | Este exemplo faz uma cópia da tabela thing: |
| 112 | 112 | ||
| 113 | ```yuescript | 113 | ```yuescript |
| 114 | thing = { | 114 | thing = { |
| @@ -144,7 +144,7 @@ no_color = {k, v for k, v in pairs thing when k != "color"} | |||
| 144 | 144 | ||
| 145 | </YueDisplay> | 145 | </YueDisplay> |
| 146 | 146 | ||
| 147 | The **\*** operator is also supported. Here we create a square root look up table for a few numbers. | 147 | O operador **\*** também é suportado. Aqui criamos uma tabela de consulta de raiz quadrada para alguns números. |
| 148 | 148 | ||
| 149 | ```yuescript | 149 | ```yuescript |
| 150 | numbers = [1, 2, 3, 4] | 150 | numbers = [1, 2, 3, 4] |
| @@ -159,9 +159,9 @@ sqrts = {i, math.sqrt i for i in *numbers} | |||
| 159 | 159 | ||
| 160 | </YueDisplay> | 160 | </YueDisplay> |
| 161 | 161 | ||
| 162 | The key-value tuple in a table comprehension can also come from a single expression, in which case the expression should return two values. The first is used as the key and the second is used as the value: | 162 | A tupla chave-valor em uma compreensão de tabela também pode vir de uma única expressão, caso em que a expressão deve retornar dois valores. O primeiro é usado como chave e o segundo é usado como valor: |
| 163 | 163 | ||
| 164 | In this example we convert an array of pairs to a table where the first item in the pair is the key and the second is the value. | 164 | Neste exemplo convertemos um array de pares em uma tabela onde o primeiro item do par é a chave e o segundo é o valor. |
| 165 | 165 | ||
| 166 | ```yuescript | 166 | ```yuescript |
| 167 | tuples = [ ["hello", "world"], ["foo", "bar"]] | 167 | tuples = [ ["hello", "world"], ["foo", "bar"]] |
| @@ -178,9 +178,9 @@ tbl = {unpack tuple for tuple in *tuples} | |||
| 178 | 178 | ||
| 179 | ## Slicing | 179 | ## Slicing |
| 180 | 180 | ||
| 181 | A special syntax is provided to restrict the items that are iterated over when using the **\*** operator. This is equivalent to setting the iteration bounds and a step size in a for loop. | 181 | Uma sintaxe especial é fornecida para restringir os itens sobre os quais se itera ao usar o operador **\***. Isso é equivalente a definir os limites de iteração e um tamanho de passo em um loop for. |
| 182 | 182 | ||
| 183 | Here we can set the minimum and maximum bounds, taking all items with indexes between 1 and 5 inclusive: | 183 | Aqui podemos definir os limites mínimo e máximo, pegando todos os itens com índices entre 1 e 5 inclusive: |
| 184 | 184 | ||
| 185 | ```yuescript | 185 | ```yuescript |
| 186 | slice = [item for item in *items[1, 5]] | 186 | slice = [item for item in *items[1, 5]] |
| @@ -193,7 +193,7 @@ slice = [item for item in *items[1, 5]] | |||
| 193 | 193 | ||
| 194 | </YueDisplay> | 194 | </YueDisplay> |
| 195 | 195 | ||
| 196 | Any of the slice arguments can be left off to use a sensible default. In this example, if the max index is left off it defaults to the length of the table. This will take everything but the first element: | 196 | Qualquer um dos argumentos do slice pode ser omitido para usar um padrão sensato. Neste exemplo, se o índice máximo for omitido, ele usa como padrão o comprimento da tabela. Isso pegará tudo exceto o primeiro elemento: |
| 197 | 197 | ||
| 198 | ```yuescript | 198 | ```yuescript |
| 199 | slice = [item for item in *items[2,]] | 199 | slice = [item for item in *items[2,]] |
| @@ -206,7 +206,7 @@ slice = [item for item in *items[2,]] | |||
| 206 | 206 | ||
| 207 | </YueDisplay> | 207 | </YueDisplay> |
| 208 | 208 | ||
| 209 | If the minimum bound is left out, it defaults to 1. Here we only provide a step size and leave the other bounds blank. This takes all odd indexed items: (1, 3, 5, …) | 209 | Se o limite mínimo for omitido, ele usa como padrão 1. Aqui fornecemos apenas um tamanho de passo e deixamos os outros limites em branco. Isso pega todos os itens com índice ímpar: (1, 3, 5, …) |
| 210 | 210 | ||
| 211 | ```yuescript | 211 | ```yuescript |
| 212 | slice = [item for item in *items[,,2]] | 212 | slice = [item for item in *items[,,2]] |
| @@ -219,22 +219,22 @@ slice = [item for item in *items[,,2]] | |||
| 219 | 219 | ||
| 220 | </YueDisplay> | 220 | </YueDisplay> |
| 221 | 221 | ||
| 222 | Both the minimum and maximum bounds can be negative, which means that the bounds are counted from the end of the table. | 222 | Tanto o limite mínimo quanto o máximo podem ser negativos, o que significa que os limites são contados a partir do fim da tabela. |
| 223 | 223 | ||
| 224 | ```yuescript | 224 | ```yuescript |
| 225 | -- take the last 4 items | 225 | -- pegar os últimos 4 itens |
| 226 | slice = [item for item in *items[-4,-1]] | 226 | slice = [item for item in *items[-4,-1]] |
| 227 | ``` | 227 | ``` |
| 228 | <YueDisplay> | 228 | <YueDisplay> |
| 229 | 229 | ||
| 230 | ```yue | 230 | ```yue |
| 231 | -- take the last 4 items | 231 | -- pegar os últimos 4 itens |
| 232 | slice = [item for item in *items[-4,-1]] | 232 | slice = [item for item in *items[-4,-1]] |
| 233 | ``` | 233 | ``` |
| 234 | 234 | ||
| 235 | </YueDisplay> | 235 | </YueDisplay> |
| 236 | 236 | ||
| 237 | The step size can also be negative, which means that the items are taken in reverse order. | 237 | O tamanho do passo também pode ser negativo, o que significa que os itens são tomados em ordem reversa. |
| 238 | 238 | ||
| 239 | ```yuescript | 239 | ```yuescript |
| 240 | reverse_slice = [item for item in *items[-1,1,-1]] | 240 | reverse_slice = [item for item in *items[-1,1,-1]] |
| @@ -247,24 +247,24 @@ reverse_slice = [item for item in *items[-1,1,-1]] | |||
| 247 | 247 | ||
| 248 | </YueDisplay> | 248 | </YueDisplay> |
| 249 | 249 | ||
| 250 | ### Slicing Expression | 250 | ### Expressão de slicing |
| 251 | 251 | ||
| 252 | Slicing can also be used as an expression. This is useful for getting a sub-list of a table. | 252 | O slicing também pode ser usado como expressão. Isso é útil para obter uma sublista de uma tabela. |
| 253 | 253 | ||
| 254 | ```yuescript | 254 | ```yuescript |
| 255 | -- take the 2nd and 4th items as a new list | 255 | -- pegar o 2º e 4º itens como nova lista |
| 256 | sub_list = items[2, 4] | 256 | sub_list = items[2, 4] |
| 257 | 257 | ||
| 258 | -- take the last 4 items | 258 | -- pegar os últimos 4 itens |
| 259 | last_four_items = items[-4, -1] | 259 | last_four_items = items[-4, -1] |
| 260 | ``` | 260 | ``` |
| 261 | <YueDisplay> | 261 | <YueDisplay> |
| 262 | 262 | ||
| 263 | ```yue | 263 | ```yue |
| 264 | -- take the 2nd and 4th items as a new list | 264 | -- pegar o 2º e 4º itens como nova lista |
| 265 | sub_list = items[2, 4] | 265 | sub_list = items[2, 4] |
| 266 | 266 | ||
| 267 | -- take the last 4 items | 267 | -- pegar os últimos 4 itens |
| 268 | last_four_items = items[-4, -1] | 268 | last_four_items = items[-4, -1] |
| 269 | ``` | 269 | ``` |
| 270 | 270 | ||
diff --git a/doc/docs/pt-br/doc/data-structures/table-literals.md b/doc/docs/pt-br/doc/data-structures/table-literals.md index c1adcab..f0fbdc5 100644 --- a/doc/docs/pt-br/doc/data-structures/table-literals.md +++ b/doc/docs/pt-br/doc/data-structures/table-literals.md | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | # Table Literals | 1 | # Literais de tabela |
| 2 | 2 | ||
| 3 | Like in Lua, tables are delimited in curly braces. | 3 | Como no Lua, as tabelas são delimitadas por chaves. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | some_values = [1, 2, 3, 4] | 6 | some_values = [1, 2, 3, 4] |
| @@ -13,7 +13,7 @@ some_values = [1, 2, 3, 4] | |||
| 13 | 13 | ||
| 14 | </YueDisplay> | 14 | </YueDisplay> |
| 15 | 15 | ||
| 16 | Unlike Lua, assigning a value to a key in a table is done with **:** (instead of **=**). | 16 | Diferente do Lua, atribuir um valor a uma chave em uma tabela é feito com **:** (em vez de **=**). |
| 17 | 17 | ||
| 18 | ```yuescript | 18 | ```yuescript |
| 19 | some_values = { | 19 | some_values = { |
| @@ -34,7 +34,7 @@ some_values = { | |||
| 34 | 34 | ||
| 35 | </YueDisplay> | 35 | </YueDisplay> |
| 36 | 36 | ||
| 37 | The curly braces can be left off if a single table of key value pairs is being assigned. | 37 | As chaves podem ser omitidas se uma única tabela de pares chave-valor está sendo atribuída. |
| 38 | 38 | ||
| 39 | ```yuescript | 39 | ```yuescript |
| 40 | profile = | 40 | profile = |
| @@ -53,7 +53,7 @@ profile = | |||
| 53 | 53 | ||
| 54 | </YueDisplay> | 54 | </YueDisplay> |
| 55 | 55 | ||
| 56 | Newlines can be used to delimit values instead of a comma (or both): | 56 | Quebras de linha podem ser usadas para delimitar valores em vez de vírgula (ou ambos): |
| 57 | 57 | ||
| 58 | ```yuescript | 58 | ```yuescript |
| 59 | values = { | 59 | values = { |
| @@ -76,7 +76,7 @@ values = { | |||
| 76 | 76 | ||
| 77 | </YueDisplay> | 77 | </YueDisplay> |
| 78 | 78 | ||
| 79 | When creating a single line table literal, the curly braces can also be left off: | 79 | Ao criar um literal de tabela em uma única linha, as chaves também podem ser omitidas: |
| 80 | 80 | ||
| 81 | ```yuescript | 81 | ```yuescript |
| 82 | my_function dance: "Tango", partner: "none" | 82 | my_function dance: "Tango", partner: "none" |
| @@ -93,7 +93,7 @@ y = type: "dog", legs: 4, tails: 1 | |||
| 93 | 93 | ||
| 94 | </YueDisplay> | 94 | </YueDisplay> |
| 95 | 95 | ||
| 96 | The keys of a table literal can be language keywords without being escaped: | 96 | As chaves de um literal de tabela podem ser palavras-chave da linguagem sem precisar escapar: |
| 97 | 97 | ||
| 98 | ```yuescript | 98 | ```yuescript |
| 99 | tbl = { | 99 | tbl = { |
| @@ -112,7 +112,7 @@ tbl = { | |||
| 112 | 112 | ||
| 113 | </YueDisplay> | 113 | </YueDisplay> |
| 114 | 114 | ||
| 115 | If you are constructing a table out of variables and wish the keys to be the same as the variable names, then the **:** prefix operator can be used: | 115 | Se você está construindo uma tabela a partir de variáveis e deseja que as chaves sejam iguais aos nomes das variáveis, então o operador de prefixo **:** pode ser usado: |
| 116 | 116 | ||
| 117 | ```yuescript | 117 | ```yuescript |
| 118 | hair = "golden" | 118 | hair = "golden" |
| @@ -133,7 +133,7 @@ print_table :hair, :height | |||
| 133 | 133 | ||
| 134 | </YueDisplay> | 134 | </YueDisplay> |
| 135 | 135 | ||
| 136 | If you want the key of a field in the table to to be result of an expression, then you can wrap it in **[ ]**, just like in Lua. You can also use a string literal directly as a key, leaving out the square brackets. This is useful if your key has any special characters. | 136 | Se você quiser que a chave de um campo na tabela seja o resultado de uma expressão, então pode envolvê-la em **[ ]**, assim como no Lua. Você também pode usar um literal de string diretamente como chave, omitindo os colchetes. Isso é útil se sua chave tiver caracteres especiais. |
| 137 | 137 | ||
| 138 | ```yuescript | 138 | ```yuescript |
| 139 | t = { | 139 | t = { |
| @@ -152,7 +152,7 @@ t = { | |||
| 152 | 152 | ||
| 153 | </YueDisplay> | 153 | </YueDisplay> |
| 154 | 154 | ||
| 155 | Lua tables have both an array part and a hash part, but sometimes you want to make a semantic distinction between array and hash usage when writing Lua tables. Then you can write Lua table with **[ ]** instead of **{ }** to represent an array table and writing any key value pair in a list table won't be allowed. | 155 | As tabelas Lua têm tanto uma parte array quanto uma parte hash, mas às vezes você quer fazer uma distinção semântica entre uso de array e hash ao escrever tabelas Lua. Então você pode escrever tabela Lua com **[ ]** em vez de **{ }** para representar uma tabela array, e escrever qualquer par chave-valor em uma tabela lista não será permitido. |
| 156 | 156 | ||
| 157 | ```yuescript | 157 | ```yuescript |
| 158 | some_values = [1, 2, 3, 4] | 158 | some_values = [1, 2, 3, 4] |
diff --git a/doc/docs/pt-br/doc/functions/backcalls.md b/doc/docs/pt-br/doc/functions/backcalls.md index e34331e..924c10a 100644 --- a/doc/docs/pt-br/doc/functions/backcalls.md +++ b/doc/docs/pt-br/doc/functions/backcalls.md | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | # Backcalls | 1 | # Backcalls |
| 2 | 2 | ||
| 3 | Backcalls are used for unnesting callbacks. They are defined using arrows pointed to the left as the last parameter by default filling in a function call. All the syntax is mostly the same as regular arrow functions except that it is just pointing the other way and the function body does not require indent. | 3 | Backcalls são usados para desaninhar callbacks. Eles são definidos usando setas apontando para a esquerda como o último parâmetro, preenchendo por padrão uma chamada de função. Toda a sintaxe é basicamente a mesma das funções seta regulares, exceto que apenas aponta para o outro lado e o corpo da função não requer indentação. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | x <- f | 6 | x <- f |
| @@ -15,7 +15,7 @@ print "hello" .. x | |||
| 15 | 15 | ||
| 16 | </YueDisplay> | 16 | </YueDisplay> |
| 17 | 17 | ||
| 18 | Fat arrow functions are also available. | 18 | Funções seta "fat" também estão disponíveis. |
| 19 | 19 | ||
| 20 | ```yuescript | 20 | ```yuescript |
| 21 | <= f | 21 | <= f |
| @@ -30,7 +30,7 @@ print @value | |||
| 30 | 30 | ||
| 31 | </YueDisplay> | 31 | </YueDisplay> |
| 32 | 32 | ||
| 33 | You can specify a placeholder for where you want the backcall function to go as a parameter. | 33 | Você pode especificar um placeholder para onde deseja que a função backcall vá como parâmetro. |
| 34 | 34 | ||
| 35 | ```yuescript | 35 | ```yuescript |
| 36 | (x) <- map _, [1, 2, 3] | 36 | (x) <- map _, [1, 2, 3] |
| @@ -45,7 +45,7 @@ x * 2 | |||
| 45 | 45 | ||
| 46 | </YueDisplay> | 46 | </YueDisplay> |
| 47 | 47 | ||
| 48 | If you wish to have further code after your backcalls, you can set them aside with a do statement. And the parentheses can be omitted with non-fat arrow functions. | 48 | Se você desejar ter mais código após seus backcalls, pode colocá-los em uma instrução do. E os parênteses podem ser omitidos com funções seta não-fat. |
| 49 | 49 | ||
| 50 | ```yuescript | 50 | ```yuescript |
| 51 | result, msg = do | 51 | result, msg = do |
diff --git a/doc/docs/pt-br/doc/functions/function-literals.md b/doc/docs/pt-br/doc/functions/function-literals.md index 316e07c..e63888f 100644 --- a/doc/docs/pt-br/doc/functions/function-literals.md +++ b/doc/docs/pt-br/doc/functions/function-literals.md | |||
| @@ -1,21 +1,21 @@ | |||
| 1 | # Function Literals | 1 | # Literais de função |
| 2 | 2 | ||
| 3 | All functions are created using a function expression. A simple function is denoted using the arrow: **->**. | 3 | Todas as funções são criadas usando uma expressão de função. Uma função simples é denotada usando a seta: **->**. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | my_function = -> | 6 | my_function = -> |
| 7 | my_function() -- call the empty function | 7 | my_function() -- chama a função vazia |
| 8 | ``` | 8 | ``` |
| 9 | <YueDisplay> | 9 | <YueDisplay> |
| 10 | 10 | ||
| 11 | ```yue | 11 | ```yue |
| 12 | my_function = -> | 12 | my_function = -> |
| 13 | my_function() -- call the empty function | 13 | my_function() -- chama a função vazia |
| 14 | ``` | 14 | ``` |
| 15 | 15 | ||
| 16 | </YueDisplay> | 16 | </YueDisplay> |
| 17 | 17 | ||
| 18 | The body of the function can either be one statement placed directly after the arrow, or it can be a series of statements indented on the following lines: | 18 | O corpo da função pode ser uma instrução colocada diretamente após a seta, ou pode ser uma série de instruções indentadas nas linhas seguintes: |
| 19 | 19 | ||
| 20 | ```yuescript | 20 | ```yuescript |
| 21 | func_a = -> print "hello world" | 21 | func_a = -> print "hello world" |
| @@ -36,7 +36,7 @@ func_b = -> | |||
| 36 | 36 | ||
| 37 | </YueDisplay> | 37 | </YueDisplay> |
| 38 | 38 | ||
| 39 | If a function has no arguments, it can be called using the ! operator, instead of empty parentheses. The ! invocation is the preferred way to call functions with no arguments. | 39 | Se uma função não tem argumentos, ela pode ser chamada usando o operador !, em vez de parênteses vazios. A invocação ! é a forma preferida de chamar funções sem argumentos. |
| 40 | 40 | ||
| 41 | ```yuescript | 41 | ```yuescript |
| 42 | func_a! | 42 | func_a! |
| @@ -51,7 +51,7 @@ func_b() | |||
| 51 | 51 | ||
| 52 | </YueDisplay> | 52 | </YueDisplay> |
| 53 | 53 | ||
| 54 | Functions with arguments can be created by preceding the arrow with a list of argument names in parentheses: | 54 | Funções com argumentos podem ser criadas precedendo a seta com uma lista de nomes de argumentos entre parênteses: |
| 55 | 55 | ||
| 56 | ```yuescript | 56 | ```yuescript |
| 57 | sum = (x, y) -> print "sum", x + y | 57 | sum = (x, y) -> print "sum", x + y |
| @@ -64,7 +64,7 @@ sum = (x, y) -> print "sum", x + y | |||
| 64 | 64 | ||
| 65 | </YueDisplay> | 65 | </YueDisplay> |
| 66 | 66 | ||
| 67 | Functions can be called by listing the arguments after the name of an expression that evaluates to a function. When chaining together function calls, the arguments are applied to the closest function to the left. | 67 | Funções podem ser chamadas listando os argumentos após o nome de uma expressão que avalia para uma função. Ao encadear chamadas de função, os argumentos são aplicados à função mais próxima à esquerda. |
| 68 | 68 | ||
| 69 | ```yuescript | 69 | ```yuescript |
| 70 | sum 10, 20 | 70 | sum 10, 20 |
| @@ -83,7 +83,7 @@ a b c "a", "b", "c" | |||
| 83 | 83 | ||
| 84 | </YueDisplay> | 84 | </YueDisplay> |
| 85 | 85 | ||
| 86 | In order to avoid ambiguity in when calling functions, parentheses can also be used to surround the arguments. This is required here in order to make sure the right arguments get sent to the right functions. | 86 | Para evitar ambiguidade ao chamar funções, parênteses também podem ser usados para envolver os argumentos. Isso é necessário aqui para garantir que os argumentos certos sejam enviados às funções certas. |
| 87 | 87 | ||
| 88 | ```yuescript | 88 | ```yuescript |
| 89 | print "x:", sum(10, 20), "y:", sum(30, 40) | 89 | print "x:", sum(10, 20), "y:", sum(30, 40) |
| @@ -96,9 +96,9 @@ print "x:", sum(10, 20), "y:", sum(30, 40) | |||
| 96 | 96 | ||
| 97 | </YueDisplay> | 97 | </YueDisplay> |
| 98 | 98 | ||
| 99 | There must not be any space between the opening parenthesis and the function. | 99 | Não deve haver espaço entre o parêntese de abertura e a função. |
| 100 | 100 | ||
| 101 | Functions will coerce the last statement in their body into a return statement, this is called implicit return: | 101 | As funções convertem a última instrução em seu corpo em uma instrução de retorno, isso é chamado de retorno implícito: |
| 102 | 102 | ||
| 103 | ```yuescript | 103 | ```yuescript |
| 104 | sum = (x, y) -> x + y | 104 | sum = (x, y) -> x + y |
| @@ -113,7 +113,7 @@ print "The sum is ", sum 10, 20 | |||
| 113 | 113 | ||
| 114 | </YueDisplay> | 114 | </YueDisplay> |
| 115 | 115 | ||
| 116 | And if you need to explicitly return, you can use the return keyword: | 116 | E se você precisar retornar explicitamente, pode usar a palavra-chave return: |
| 117 | 117 | ||
| 118 | ```yuescript | 118 | ```yuescript |
| 119 | sum = (x, y) -> return x + y | 119 | sum = (x, y) -> return x + y |
| @@ -126,7 +126,7 @@ sum = (x, y) -> return x + y | |||
| 126 | 126 | ||
| 127 | </YueDisplay> | 127 | </YueDisplay> |
| 128 | 128 | ||
| 129 | Just like in Lua, functions can return multiple values. The last statement must be a list of values separated by commas: | 129 | Assim como no Lua, as funções podem retornar múltiplos valores. A última instrução deve ser uma lista de valores separados por vírgulas: |
| 130 | 130 | ||
| 131 | ```yuescript | 131 | ```yuescript |
| 132 | mystery = (x, y) -> x + y, x - y | 132 | mystery = (x, y) -> x + y, x - y |
| @@ -141,9 +141,9 @@ a, b = mystery 10, 20 | |||
| 141 | 141 | ||
| 142 | </YueDisplay> | 142 | </YueDisplay> |
| 143 | 143 | ||
| 144 | ## Fat Arrows | 144 | ## Setas fat |
| 145 | 145 | ||
| 146 | Because it is an idiom in Lua to send an object as the first argument when calling a method, a special syntax is provided for creating functions which automatically includes a self argument. | 146 | Como é um idioma em Lua enviar um objeto como primeiro argumento ao chamar um método, uma sintaxe especial é fornecida para criar funções que incluem automaticamente um argumento self. |
| 147 | 147 | ||
| 148 | ```yuescript | 148 | ```yuescript |
| 149 | func = (num) => @value + num | 149 | func = (num) => @value + num |
| @@ -156,9 +156,9 @@ func = (num) => @value + num | |||
| 156 | 156 | ||
| 157 | </YueDisplay> | 157 | </YueDisplay> |
| 158 | 158 | ||
| 159 | ## Argument Defaults | 159 | ## Valores padrão de argumentos |
| 160 | 160 | ||
| 161 | It is possible to provide default values for the arguments of a function. An argument is determined to be empty if its value is nil. Any nil arguments that have a default value will be replace before the body of the function is run. | 161 | É possível fornecer valores padrão para os argumentos de uma função. Um argumento é determinado como vazio se seu valor for nil. Qualquer argumento nil que tenha valor padrão será substituído antes da execução do corpo da função. |
| 162 | 162 | ||
| 163 | ```yuescript | 163 | ```yuescript |
| 164 | my_function = (name = "something", height = 100) -> | 164 | my_function = (name = "something", height = 100) -> |
| @@ -175,7 +175,7 @@ my_function = (name = "something", height = 100) -> | |||
| 175 | 175 | ||
| 176 | </YueDisplay> | 176 | </YueDisplay> |
| 177 | 177 | ||
| 178 | An argument default value expression is evaluated in the body of the function in the order of the argument declarations. For this reason default values have access to previously declared arguments. | 178 | Uma expressão de valor padrão de argumento é avaliada no corpo da função na ordem das declarações de argumentos. Por esse motivo, os valores padrão têm acesso aos argumentos declarados anteriormente. |
| 179 | 179 | ||
| 180 | ```yuescript | 180 | ```yuescript |
| 181 | some_args = (x = 100, y = x + 1000) -> | 181 | some_args = (x = 100, y = x + 1000) -> |
| @@ -190,11 +190,11 @@ some_args = (x = 100, y = x + 1000) -> | |||
| 190 | 190 | ||
| 191 | </YueDisplay> | 191 | </YueDisplay> |
| 192 | 192 | ||
| 193 | ## Considerations | 193 | ## Considerações |
| 194 | 194 | ||
| 195 | Because of the expressive parentheses-less way of calling functions, some restrictions must be put in place to avoid parsing ambiguity involving whitespace. | 195 | Devido à forma expressiva de chamar funções sem parênteses, algumas restrições devem ser colocadas para evitar ambiguidade de análise envolvendo espaço em branco. |
| 196 | 196 | ||
| 197 | The minus sign plays two roles, a unary negation operator and a binary subtraction operator. Consider how the following examples compile: | 197 | O sinal de menos desempenha dois papéis: um operador de negação unário e um operador de subtração binário. Considere como os seguintes exemplos compilam: |
| 198 | 198 | ||
| 199 | ```yuescript | 199 | ```yuescript |
| 200 | a = x - 10 | 200 | a = x - 10 |
| @@ -213,11 +213,11 @@ d = x- z | |||
| 213 | 213 | ||
| 214 | </YueDisplay> | 214 | </YueDisplay> |
| 215 | 215 | ||
| 216 | The precedence of the first argument of a function call can be controlled using whitespace if the argument is a literal string. In Lua, it is common to leave off parentheses when calling a function with a single string or table literal. | 216 | A precedência do primeiro argumento de uma chamada de função pode ser controlada usando espaço em branco se o argumento for um literal de string. Em Lua, é comum omitir parênteses ao chamar uma função com uma única string ou literal de tabela. |
| 217 | 217 | ||
| 218 | When there is no space between a variable and a string literal, the function call takes precedence over any following expressions. No other arguments can be passed to the function when it is called this way. | 218 | Quando não há espaço entre uma variável e um literal de string, a chamada de função tem precedência sobre quaisquer expressões seguintes. Nenhum outro argumento pode ser passado para a função quando ela é chamada dessa forma. |
| 219 | 219 | ||
| 220 | Where there is a space following a variable and a string literal, the function call acts as show above. The string literal belongs to any following expressions (if they exist), which serves as the argument list. | 220 | Quando há um espaço após uma variável e um literal de string, a chamada de função age como mostrado acima. O literal de string pertence a quaisquer expressões seguintes (se existirem), que servem como lista de argumentos. |
| 221 | 221 | ||
| 222 | ```yuescript | 222 | ```yuescript |
| 223 | x = func"hello" + 100 | 223 | x = func"hello" + 100 |
| @@ -232,11 +232,11 @@ y = func "hello" + 100 | |||
| 232 | 232 | ||
| 233 | </YueDisplay> | 233 | </YueDisplay> |
| 234 | 234 | ||
| 235 | ## Multi-line arguments | 235 | ## Argumentos multilinha |
| 236 | 236 | ||
| 237 | When calling functions that take a large number of arguments, it is convenient to split the argument list over multiple lines. Because of the white-space sensitive nature of the language, care must be taken when splitting up the argument list. | 237 | Ao chamar funções que recebem um grande número de argumentos, é conveniente dividir a lista de argumentos em várias linhas. Devido à natureza sensível a espaço em branco da linguagem, deve-se ter cuidado ao dividir a lista de argumentos. |
| 238 | 238 | ||
| 239 | If an argument list is to be continued onto the next line, the current line must end in a comma. And the following line must be indented more than the current indentation. Once indented, all other argument lines must be at the same level of indentation to be part of the argument list | 239 | Se uma lista de argumentos for continuada na próxima linha, a linha atual deve terminar em vírgula. E a linha seguinte deve estar mais indentada que a indentação atual. Uma vez indentada, todas as outras linhas de argumentos devem estar no mesmo nível de indentação para fazer parte da lista de argumentos. |
| 240 | 240 | ||
| 241 | ```yuescript | 241 | ```yuescript |
| 242 | my_func 5, 4, 3, | 242 | my_func 5, 4, 3, |
| @@ -261,7 +261,7 @@ cool_func 1, 2, | |||
| 261 | 261 | ||
| 262 | </YueDisplay> | 262 | </YueDisplay> |
| 263 | 263 | ||
| 264 | This type of invocation can be nested. The level of indentation is used to determine to which function the arguments belong to. | 264 | Este tipo de invocação pode ser aninhado. O nível de indentação é usado para determinar a qual função os argumentos pertencem. |
| 265 | 265 | ||
| 266 | ```yuescript | 266 | ```yuescript |
| 267 | my_func 5, 6, 7, | 267 | my_func 5, 6, 7, |
| @@ -280,7 +280,7 @@ my_func 5, 6, 7, | |||
| 280 | 280 | ||
| 281 | </YueDisplay> | 281 | </YueDisplay> |
| 282 | 282 | ||
| 283 | Because tables also use the comma as a delimiter, this indentation syntax is helpful for letting values be part of the argument list instead of being part of the table. | 283 | Como as tabelas também usam vírgula como delimitador, esta sintaxe de indentação ajuda a deixar os valores fazerem parte da lista de argumentos em vez de fazerem parte da tabela. |
| 284 | 284 | ||
| 285 | ```yuescript | 285 | ```yuescript |
| 286 | x = [ | 286 | x = [ |
| @@ -301,7 +301,7 @@ x = [ | |||
| 301 | 301 | ||
| 302 | </YueDisplay> | 302 | </YueDisplay> |
| 303 | 303 | ||
| 304 | Although uncommon, notice how we can give a deeper indentation for function arguments if we know we will be using a lower indentation further on. | 304 | Embora incomum, observe como podemos dar uma indentação mais profunda para argumentos de função se soubermos que usaremos uma indentação menor mais adiante. |
| 305 | 305 | ||
| 306 | ```yuescript | 306 | ```yuescript |
| 307 | y = [ my_func 1, 2, 3, | 307 | y = [ my_func 1, 2, 3, |
| @@ -320,7 +320,7 @@ y = [ my_func 1, 2, 3, | |||
| 320 | 320 | ||
| 321 | </YueDisplay> | 321 | </YueDisplay> |
| 322 | 322 | ||
| 323 | The same thing can be done with other block level statements like conditionals. We can use indentation level to determine what statement a value belongs to: | 323 | A mesma coisa pode ser feita com outras instruções em nível de bloco como condicionais. Podemos usar o nível de indentação para determinar a qual instrução um valor pertence: |
| 324 | 324 | ||
| 325 | ```yuescript | 325 | ```yuescript |
| 326 | if func 1, 2, 3, | 326 | if func 1, 2, 3, |
| @@ -353,13 +353,13 @@ if func 1, 2, 3, | |||
| 353 | 353 | ||
| 354 | </YueDisplay> | 354 | </YueDisplay> |
| 355 | 355 | ||
| 356 | ## Parameter Destructuring | 356 | ## Desestruturação de parâmetros |
| 357 | 357 | ||
| 358 | YueScript now supports destructuring function parameters when the argument is an object. Two forms of destructuring table literals are available: | 358 | YueScript agora suporta desestruturação de parâmetros de função quando o argumento é um objeto. Duas formas de literais de tabela de desestruturação estão disponíveis: |
| 359 | 359 | ||
| 360 | * **Curly-brace wrapped literals/object parameters**, allowing optional default values when fields are missing (e.g., `{:a, :b}`, `{a: a1 = 123}`). | 360 | * **Literais/parâmetros de objeto envolvidos em chaves**, permitindo valores padrão opcionais quando os campos estão ausentes (ex.: `{:a, :b}`, `{a: a1 = 123}`). |
| 361 | 361 | ||
| 362 | * **Unwrapped simple table syntax**, starting with a sequence of key-value or shorthand bindings and continuing until another expression terminates it (e.g., `:a, b: b1, :c`). This form extracts multiple fields from the same object. | 362 | * **Sintaxe de tabela simples não envolvida**, começando com uma sequência de ligações chave-valor ou abreviadas e continuando até outra expressão terminá-la (ex.: `:a, b: b1, :c`). Esta forma extrai múltiplos campos do mesmo objeto. |
| 363 | 363 | ||
| 364 | ```yuescript | 364 | ```yuescript |
| 365 | f1 = (:a, :b, :c) -> | 365 | f1 = (:a, :b, :c) -> |
| @@ -390,9 +390,9 @@ f2 arg1, arg2 | |||
| 390 | 390 | ||
| 391 | </YueDisplay> | 391 | </YueDisplay> |
| 392 | 392 | ||
| 393 | ## Prefixed Return Expression | 393 | ## Expressão de retorno prefixada |
| 394 | 394 | ||
| 395 | When working with deeply nested function bodies, it can be tedious to maintain readability and consistency of the return value. To address this, YueScript introduces the **Prefixed Return Expression** syntax. Its form is as follows: | 395 | Ao trabalhar com corpos de função profundamente aninhados, pode ser tedioso manter a legibilidade e consistência do valor de retorno. Para resolver isso, YueScript introduz a sintaxe **Expressão de Retorno Prefixada**. Sua forma é a seguinte: |
| 396 | 396 | ||
| 397 | ```yuescript | 397 | ```yuescript |
| 398 | findFirstEven = (list): nil -> | 398 | findFirstEven = (list): nil -> |
| @@ -415,7 +415,7 @@ findFirstEven = (list): nil -> | |||
| 415 | 415 | ||
| 416 | </YueDisplay> | 416 | </YueDisplay> |
| 417 | 417 | ||
| 418 | This is equivalent to: | 418 | Isso é equivalente a: |
| 419 | 419 | ||
| 420 | ```yuescript | 420 | ```yuescript |
| 421 | findFirstEven = (list) -> | 421 | findFirstEven = (list) -> |
| @@ -440,16 +440,16 @@ findFirstEven = (list) -> | |||
| 440 | 440 | ||
| 441 | </YueDisplay> | 441 | </YueDisplay> |
| 442 | 442 | ||
| 443 | The only difference is that you can move the final return expression before the `->` or `=>` token to indicate the function’s implicit return value as the last statement. This way, even in functions with multiple nested loops or conditional branches, you no longer need to write a trailing return expression at the end of the function body, making the logic structure more straightforward and easier to follow. | 443 | A única diferença é que você pode mover a expressão de retorno final antes do token `->` ou `=>` para indicar o valor de retorno implícito da função como última instrução. Dessa forma, mesmo em funções com múltiplos loops aninhados ou ramificações condicionais, você não precisa mais escrever uma expressão de retorno no final do corpo da função, tornando a estrutura lógica mais direta e fácil de seguir. |
| 444 | 444 | ||
| 445 | ## Named Varargs | 445 | ## Varargs nomeados |
| 446 | 446 | ||
| 447 | You can use the `(...t) ->` syntax to automatically store varargs into a named table. This table will contain all passed arguments (including `nil` values), and the `n` field of the table will store the actual number of arguments passed (including `nil` values). | 447 | Você pode usar a sintaxe `(...t) ->` para armazenar automaticamente varargs em uma tabela nomeada. Esta tabela conterá todos os argumentos passados (incluindo valores `nil`), e o campo `n` da tabela armazenará o número real de argumentos passados (incluindo valores `nil`). |
| 448 | 448 | ||
| 449 | ```yuescript | 449 | ```yuescript |
| 450 | f = (...t) -> | 450 | f = (...t) -> |
| 451 | print "argument count:", t.n | 451 | print "contagem de argumentos:", t.n |
| 452 | print "table length:", #t | 452 | print "comprimento da tabela:", #t |
| 453 | for i = 1, t.n | 453 | for i = 1, t.n |
| 454 | print t[i] | 454 | print t[i] |
| 455 | 455 | ||
| @@ -457,7 +457,7 @@ f 1, 2, 3 | |||
| 457 | f "a", "b", "c", "d" | 457 | f "a", "b", "c", "d" |
| 458 | f! | 458 | f! |
| 459 | 459 | ||
| 460 | -- Handling cases with nil values | 460 | -- Tratando casos com valores nil |
| 461 | process = (...args) -> | 461 | process = (...args) -> |
| 462 | sum = 0 | 462 | sum = 0 |
| 463 | for i = 1, args.n | 463 | for i = 1, args.n |
| @@ -471,8 +471,8 @@ process 1, nil, 3, nil, 5 | |||
| 471 | 471 | ||
| 472 | ```yue | 472 | ```yue |
| 473 | f = (...t) -> | 473 | f = (...t) -> |
| 474 | print "argument count:", t.n | 474 | print "contagem de argumentos:", t.n |
| 475 | print "table length:", #t | 475 | print "comprimento da tabela:", #t |
| 476 | for i = 1, t.n | 476 | for i = 1, t.n |
| 477 | print t[i] | 477 | print t[i] |
| 478 | 478 | ||
| @@ -480,7 +480,7 @@ f 1, 2, 3 | |||
| 480 | f "a", "b", "c", "d" | 480 | f "a", "b", "c", "d" |
| 481 | f! | 481 | f! |
| 482 | 482 | ||
| 483 | -- Handling cases with nil values | 483 | -- Tratando casos com valores nil |
| 484 | process = (...args) -> | 484 | process = (...args) -> |
| 485 | sum = 0 | 485 | sum = 0 |
| 486 | for i = 1, args.n | 486 | for i = 1, args.n |
diff --git a/doc/docs/pt-br/doc/functions/function-stubs.md b/doc/docs/pt-br/doc/functions/function-stubs.md index 57a8b0c..d13f8ed 100644 --- a/doc/docs/pt-br/doc/functions/function-stubs.md +++ b/doc/docs/pt-br/doc/functions/function-stubs.md | |||
| @@ -1,10 +1,10 @@ | |||
| 1 | # Function Stubs | 1 | # Stubs de função |
| 2 | 2 | ||
| 3 | It is common to pass a function from an object around as a value, for example, passing an instance method into a function as a callback. If the function expects the object it is operating on as the first argument then you must somehow bundle that object with the function so it can be called properly. | 3 | É comum passar uma função de um objeto como valor, por exemplo, passando um método de instância para uma função como callback. Se a função espera o objeto em que está operando como primeiro argumento, então você deve de alguma forma empacotar esse objeto com a função para que ela possa ser chamada corretamente. |
| 4 | 4 | ||
| 5 | The function stub syntax is a shorthand for creating a new closure function that bundles both the object and function. This new function calls the wrapped function in the correct context of the object. | 5 | A sintaxe de function stub é uma forma abreviada de criar uma nova função closure que empacota tanto o objeto quanto a função. Esta nova função chama a função empacotada no contexto correto do objeto. |
| 6 | 6 | ||
| 7 | Its syntax is the same as calling an instance method with the \ operator but with no argument list provided. | 7 | Sua sintaxe é a mesma que chamar um método de instância com o operador \, mas sem lista de argumentos fornecida. |
| 8 | 8 | ||
| 9 | ```yuescript | 9 | ```yuescript |
| 10 | my_object = { | 10 | my_object = { |
| @@ -16,12 +16,12 @@ run_callback = (func) -> | |||
| 16 | print "running callback..." | 16 | print "running callback..." |
| 17 | func! | 17 | func! |
| 18 | 18 | ||
| 19 | -- this will not work: | 19 | -- isso não funcionará: |
| 20 | -- the function has to no reference to my_object | 20 | -- a função não tem referência a my_object |
| 21 | run_callback my_object.write | 21 | run_callback my_object.write |
| 22 | 22 | ||
| 23 | -- function stub syntax | 23 | -- sintaxe de function stub |
| 24 | -- lets us bundle the object into a new function | 24 | -- nos permite empacotar o objeto em uma nova função |
| 25 | run_callback my_object\write | 25 | run_callback my_object\write |
| 26 | ``` | 26 | ``` |
| 27 | <YueDisplay> | 27 | <YueDisplay> |
| @@ -36,12 +36,12 @@ run_callback = (func) -> | |||
| 36 | print "running callback..." | 36 | print "running callback..." |
| 37 | func! | 37 | func! |
| 38 | 38 | ||
| 39 | -- this will not work: | 39 | -- isso não funcionará: |
| 40 | -- the function has to no reference to my_object | 40 | -- a função não tem referência a my_object |
| 41 | run_callback my_object.write | 41 | run_callback my_object.write |
| 42 | 42 | ||
| 43 | -- function stub syntax | 43 | -- sintaxe de function stub |
| 44 | -- lets us bundle the object into a new function | 44 | -- nos permite empacotar o objeto em uma nova função |
| 45 | run_callback my_object\write | 45 | run_callback my_object\write |
| 46 | ``` | 46 | ``` |
| 47 | 47 | ||
diff --git a/doc/docs/pt-br/doc/getting-started/installation.md b/doc/docs/pt-br/doc/getting-started/installation.md index a93ddfd..c5ee875 100644 --- a/doc/docs/pt-br/doc/getting-started/installation.md +++ b/doc/docs/pt-br/doc/getting-started/installation.md | |||
| @@ -1,43 +1,43 @@ | |||
| 1 | # Installation | 1 | # Instalação |
| 2 | 2 | ||
| 3 | ## Lua Module | 3 | ## Módulo Lua |
| 4 | 4 | ||
| 5 | Install [luarocks](https://luarocks.org), a package manager for Lua modules. Then install it as a Lua module and executable with: | 5 | Instale o [luarocks](https://luarocks.org), um gerenciador de pacotes para módulos Lua. Em seguida, instale-o como módulo Lua e executável com: |
| 6 | 6 | ||
| 7 | ```shell | 7 | ```shell |
| 8 | luarocks install yuescript | 8 | luarocks install yuescript |
| 9 | ``` | 9 | ``` |
| 10 | 10 | ||
| 11 | Or you can build `yue.so` file with: | 11 | Ou você pode compilar o arquivo `yue.so` com: |
| 12 | 12 | ||
| 13 | ```shell | 13 | ```shell |
| 14 | make shared LUAI=/usr/local/include/lua LUAL=/usr/local/lib/lua | 14 | make shared LUAI=/usr/local/include/lua LUAL=/usr/local/lib/lua |
| 15 | ``` | 15 | ``` |
| 16 | 16 | ||
| 17 | Then get the binary file from path **bin/shared/yue.so**. | 17 | Depois, obtenha o arquivo binário no caminho **bin/shared/yue.so**. |
| 18 | 18 | ||
| 19 | ## Build Binary Tool | 19 | ## Compilar ferramenta binária |
| 20 | 20 | ||
| 21 | Clone this repo, then build and install executable with: | 21 | Clone este repositório e compile e instale o executável com: |
| 22 | 22 | ||
| 23 | ```shell | 23 | ```shell |
| 24 | make install | 24 | make install |
| 25 | ``` | 25 | ``` |
| 26 | 26 | ||
| 27 | Build YueScript tool without macro feature: | 27 | Compilar a ferramenta YueScript sem o recurso de macro: |
| 28 | 28 | ||
| 29 | ```shell | 29 | ```shell |
| 30 | make install NO_MACRO=true | 30 | make install NO_MACRO=true |
| 31 | ``` | 31 | ``` |
| 32 | 32 | ||
| 33 | Build YueScript tool without built-in Lua binary: | 33 | Compilar a ferramenta YueScript sem o binário Lua embutido: |
| 34 | 34 | ||
| 35 | ```shell | 35 | ```shell |
| 36 | make install NO_LUA=true | 36 | make install NO_LUA=true |
| 37 | ``` | 37 | ``` |
| 38 | 38 | ||
| 39 | ## Download Precompiled Binary | 39 | ## Baixar binário pré-compilado |
| 40 | 40 | ||
| 41 | You can download precompiled binary files, including binary executable files compatible with different Lua versions and library files. | 41 | Você pode baixar arquivos binários pré-compilados, incluindo executáveis compatíveis com diferentes versões do Lua e arquivos de biblioteca. |
| 42 | 42 | ||
| 43 | Download precompiled binary files from [here](https://github.com/IppClub/YueScript/releases). | 43 | Baixe os arquivos binários pré-compilados [aqui](https://github.com/IppClub/YueScript/releases). |
diff --git a/doc/docs/pt-br/doc/getting-started/introduction.md b/doc/docs/pt-br/doc/getting-started/introduction.md index a9a9389..8c3f30a 100644 --- a/doc/docs/pt-br/doc/getting-started/introduction.md +++ b/doc/docs/pt-br/doc/getting-started/introduction.md | |||
| @@ -1,16 +1,16 @@ | |||
| 1 | # Introduction | 1 | # Introdução |
| 2 | 2 | ||
| 3 | YueScript is a dynamic language that compiles to Lua. And it's a [MoonScript](https://github.com/leafo/moonscript) dialect. The codes written in YueScript are expressive and extremely concise. And it is suitable for writing some changing application logic with more maintainable codes and runs in a Lua embeded environment such as games or website servers. | 3 | YueScript é uma linguagem dinâmica que compila para Lua. É um dialeto do [MoonScript](https://github.com/leafo/moonscript). O código escrito em YueScript é expressivo e extremamente conciso. É adequado para escrever lógica de aplicação variável com código mais manutenível e roda em ambientes Lua embutidos, como jogos ou servidores web. |
| 4 | 4 | ||
| 5 | Yue (月) is the name of moon in Chinese and it's pronounced as [jyɛ]. | 5 | Yue (月) é o nome da lua em chinês e é pronunciado como [jyɛ]. |
| 6 | 6 | ||
| 7 | ## An Overview of YueScript | 7 | ## Uma visão geral do YueScript |
| 8 | 8 | ||
| 9 | ```yuescript | 9 | ```yuescript |
| 10 | -- import syntax | 10 | -- sintaxe de importação |
| 11 | import p, to_lua from "yue" | 11 | import p, to_lua from "yue" |
| 12 | 12 | ||
| 13 | -- object literals | 13 | -- literais de objeto |
| 14 | inventory = | 14 | inventory = |
| 15 | equipment: | 15 | equipment: |
| 16 | - "sword" | 16 | - "sword" |
| @@ -21,7 +21,7 @@ inventory = | |||
| 21 | - name: "bread" | 21 | - name: "bread" |
| 22 | count: 3 | 22 | count: 3 |
| 23 | 23 | ||
| 24 | -- list comprehension | 24 | -- compreensão de lista |
| 25 | map = (arr, action) -> | 25 | map = (arr, action) -> |
| 26 | [action item for item in *arr] | 26 | [action item for item in *arr] |
| 27 | 27 | ||
| @@ -31,14 +31,14 @@ filter = (arr, cond) -> | |||
| 31 | reduce = (arr, init, action): init -> | 31 | reduce = (arr, init, action): init -> |
| 32 | init = action init, item for item in *arr | 32 | init = action init, item for item in *arr |
| 33 | 33 | ||
| 34 | -- pipe operator | 34 | -- operador pipe |
| 35 | [1, 2, 3] | 35 | [1, 2, 3] |
| 36 | |> map (x) -> x * 2 | 36 | |> map (x) -> x * 2 |
| 37 | |> filter (x) -> x > 4 | 37 | |> filter (x) -> x > 4 |
| 38 | |> reduce 0, (a, b) -> a + b | 38 | |> reduce 0, (a, b) -> a + b |
| 39 | 39 | ||
| 40 | 40 | ||
| 41 | -- metatable manipulation | 41 | -- manipulação de metatable |
| 42 | apple = | 42 | apple = |
| 43 | size: 15 | 43 | size: 15 |
| 44 | <index>: | 44 | <index>: |
| @@ -47,17 +47,17 @@ apple = | |||
| 47 | with apple | 47 | with apple |
| 48 | p .size, .color, .<index> if .<>? | 48 | p .size, .color, .<index> if .<>? |
| 49 | 49 | ||
| 50 | -- js-like export syntax | 50 | -- sintaxe de exportação estilo js |
| 51 | export 🌛 = "月之脚本" | 51 | export 🌛 = "Script da Lua" |
| 52 | ``` | 52 | ``` |
| 53 | 53 | ||
| 54 | <YueDisplay> | 54 | <YueDisplay> |
| 55 | 55 | ||
| 56 | ```yue | 56 | ```yue |
| 57 | -- import syntax | 57 | -- sintaxe de importação |
| 58 | import p, to_lua from "yue" | 58 | import p, to_lua from "yue" |
| 59 | 59 | ||
| 60 | -- object literals | 60 | -- literais de objeto |
| 61 | inventory = | 61 | inventory = |
| 62 | equipment: | 62 | equipment: |
| 63 | - "sword" | 63 | - "sword" |
| @@ -68,7 +68,7 @@ inventory = | |||
| 68 | - name: "bread" | 68 | - name: "bread" |
| 69 | count: 3 | 69 | count: 3 |
| 70 | 70 | ||
| 71 | -- list comprehension | 71 | -- compreensão de lista |
| 72 | map = (arr, action) -> | 72 | map = (arr, action) -> |
| 73 | [action item for item in *arr] | 73 | [action item for item in *arr] |
| 74 | 74 | ||
| @@ -78,14 +78,14 @@ filter = (arr, cond) -> | |||
| 78 | reduce = (arr, init, action): init -> | 78 | reduce = (arr, init, action): init -> |
| 79 | init = action init, item for item in *arr | 79 | init = action init, item for item in *arr |
| 80 | 80 | ||
| 81 | -- pipe operator | 81 | -- operador pipe |
| 82 | [1, 2, 3] | 82 | [1, 2, 3] |
| 83 | |> map (x) -> x * 2 | 83 | |> map (x) -> x * 2 |
| 84 | |> filter (x) -> x > 4 | 84 | |> filter (x) -> x > 4 |
| 85 | |> reduce 0, (a, b) -> a + b | 85 | |> reduce 0, (a, b) -> a + b |
| 86 | 86 | ||
| 87 | 87 | ||
| 88 | -- metatable manipulation | 88 | -- manipulação de metatable |
| 89 | apple = | 89 | apple = |
| 90 | size: 15 | 90 | size: 15 |
| 91 | <index>: | 91 | <index>: |
| @@ -94,12 +94,12 @@ apple = | |||
| 94 | with apple | 94 | with apple |
| 95 | p .size, .color, .<index> if .<>? | 95 | p .size, .color, .<index> if .<>? |
| 96 | 96 | ||
| 97 | -- js-like export syntax | 97 | -- sintaxe de exportação estilo js |
| 98 | export 🌛 = "月之脚本" | 98 | export 🌛 = "Script da Lua" |
| 99 | ``` | 99 | ``` |
| 100 | 100 | ||
| 101 | </YueDisplay> | 101 | </YueDisplay> |
| 102 | 102 | ||
| 103 | ## About Dora SSR | 103 | ## Sobre o Dora SSR |
| 104 | 104 | ||
| 105 | YueScript is being developed and maintained alongside the open-source game engine [Dora SSR](https://github.com/Dora-SSR/Dora-SSR). It has been used to create engine tools, game demos and prototypes, validating its capabilities in real-world scenarios while enhancing the Dora SSR development experience. \ No newline at end of file | 105 | O YueScript está sendo desenvolvido e mantido em conjunto com o motor de jogo open-source [Dora SSR](https://github.com/Dora-SSR/Dora-SSR). Tem sido usado para criar ferramentas do motor, demonstrações de jogos e protótipos, validando suas capacidades em cenários do mundo real e aprimorando a experiência de desenvolvimento do Dora SSR. |
diff --git a/doc/docs/pt-br/doc/getting-started/usage.md b/doc/docs/pt-br/doc/getting-started/usage.md index 45161c6..7653838 100644 --- a/doc/docs/pt-br/doc/getting-started/usage.md +++ b/doc/docs/pt-br/doc/getting-started/usage.md | |||
| @@ -1,20 +1,20 @@ | |||
| 1 | # Usage | 1 | # Uso |
| 2 | 2 | ||
| 3 | ## Lua Module | 3 | ## Módulo Lua |
| 4 | 4 | ||
| 5 | Use YueScript module in Lua: | 5 | Use o módulo YueScript em Lua: |
| 6 | 6 | ||
| 7 | * **Case 1** | 7 | * **Caso 1** |
| 8 | 8 | ||
| 9 | Require "your_yuescript_entry.yue" in Lua. | 9 | Use require em "your_yuescript_entry.yue" no Lua. |
| 10 | ```Lua | 10 | ```Lua |
| 11 | require("yue")("your_yuescript_entry") | 11 | require("yue")("your_yuescript_entry") |
| 12 | ``` | 12 | ``` |
| 13 | And this code still works when you compile "your_yuescript_entry.yue" to "your_yuescript_entry.lua" in the same path. In the rest YueScript files just use the normal **require** or **import**. The code line numbers in error messages will also be handled correctly. | 13 | E esse código continua funcionando quando você compila "your_yuescript_entry.yue" para "your_yuescript_entry.lua" no mesmo caminho. Nos demais arquivos YueScript, use normalmente o **require** ou **import**. Os números de linha nas mensagens de erro também serão tratados corretamente. |
| 14 | 14 | ||
| 15 | * **Case 2** | 15 | * **Caso 2** |
| 16 | 16 | ||
| 17 | Require YueScript module and rewite message by hand. | 17 | Requerer o módulo YueScript e reescrever a mensagem manualmente. |
| 18 | 18 | ||
| 19 | ```lua | 19 | ```lua |
| 20 | local yue = require("yue") | 20 | local yue = require("yue") |
| @@ -26,9 +26,9 @@ Use YueScript module in Lua: | |||
| 26 | end) | 26 | end) |
| 27 | ``` | 27 | ``` |
| 28 | 28 | ||
| 29 | * **Case 3** | 29 | * **Caso 3** |
| 30 | 30 | ||
| 31 | Use the YueScript compiler function in Lua. | 31 | Usar a função compiladora do YueScript em Lua. |
| 32 | 32 | ||
| 33 | ```lua | 33 | ```lua |
| 34 | local yue = require("yue") | 34 | local yue = require("yue") |
| @@ -48,9 +48,9 @@ Use YueScript module in Lua: | |||
| 48 | }) | 48 | }) |
| 49 | ``` | 49 | ``` |
| 50 | 50 | ||
| 51 | ## YueScript Tool | 51 | ## Ferramenta YueScript |
| 52 | 52 | ||
| 53 | Use YueScript tool with: | 53 | Use a ferramenta YueScript com: |
| 54 | 54 | ||
| 55 | ```shell | 55 | ```shell |
| 56 | > yue -h | 56 | > yue -h |
| @@ -60,52 +60,53 @@ Usage: yue | |||
| 60 | yue -w [<directory>] [options] | 60 | yue -w [<directory>] [options] |
| 61 | yue - | 61 | yue - |
| 62 | 62 | ||
| 63 | Notes: | 63 | Notas: |
| 64 | - '-' / '--' must be the first and only argument. | 64 | - '-' / '--' deve ser o primeiro e único argumento. |
| 65 | - '-o/--output' can not be used with multiple input files. | 65 | - '-o/--output' não pode ser usado com múltiplos arquivos de entrada. |
| 66 | - '-w/--watch' can not be used with file input (directory only). | 66 | - '-w/--watch' não pode ser usado com entrada de arquivo (apenas diretório). |
| 67 | - with '-e/--execute', remaining tokens are treated as script args. | 67 | - com '-e/--execute', os tokens restantes são tratados como argumentos do script. |
| 68 | 68 | ||
| 69 | Options: | 69 | Opções: |
| 70 | -h, --help Show this help message and exit. | 70 | -h, --help Mostrar esta mensagem de ajuda e sair. |
| 71 | -e <str>, --execute <str> Execute a file or raw codes | 71 | -e <str>, --execute <str> Executar um arquivo ou código bruto |
| 72 | -m, --minify Generate minified codes | 72 | -m, --minify Gerar código minificado |
| 73 | -r, --rewrite Rewrite output to match original line numbers | 73 | -r, --rewrite Reescrever saída para corresponder aos números de linha originais |
| 74 | -t <output_to>, --output-to <output_to> | 74 | -t <output_to>, --output-to <output_to> |
| 75 | Specify where to place compiled files | 75 | Especificar onde colocar os arquivos compilados |
| 76 | -o <file>, --output <file> Write output to file | 76 | -o <file>, --output <file> Escrever saída em arquivo |
| 77 | -p, --print Write output to standard out | 77 | -p, --print Escrever saída na saída padrão |
| 78 | -b, --benchmark Dump compile time (doesn't write output) | 78 | -b, --benchmark Mostrar tempo de compilação (não grava saída) |
| 79 | -g, --globals Dump global variables used in NAME LINE COLUMN | 79 | -g, --globals Listar variáveis globais usadas em NOME LINHA COLUNA |
| 80 | -s, --spaces Use spaces in generated codes instead of tabs | 80 | -s, --spaces Usar espaços no código gerado em vez de tabulações |
| 81 | -l, --line-numbers Write line numbers from source codes | 81 | -l, --line-numbers Escrever números de linha do código fonte |
| 82 | -j, --no-implicit-return Disable implicit return at end of file | 82 | -j, --no-implicit-return Desabilitar retorno implícito no final do arquivo |
| 83 | -c, --reserve-comments Reserve comments before statement from source codes | 83 | -c, --reserve-comments Preservar comentários antes de instruções do código fonte |
| 84 | -w [<dir>], --watch [<dir>] | 84 | -w [<dir>], --watch [<dir>] |
| 85 | Watch changes and compile every file under directory | 85 | Observar alterações e compilar cada arquivo no diretório |
| 86 | -v, --version Print version | 86 | -v, --version Imprimir versão |
| 87 | - Read from standard in, print to standard out | 87 | - Ler da entrada padrão, imprimir na saída padrão |
| 88 | (Must be first and only argument) | 88 | (Deve ser o primeiro e único argumento) |
| 89 | -- Same as '-' (kept for backward compatibility) | 89 | -- Igual a '-' (mantido para compatibilidade retroativa) |
| 90 | 90 | ||
| 91 | --target <version> Specify the Lua version that codes will be generated to | 91 | --target <version> Especificar a versão do Lua para a qual o código será gerado |
| 92 | (version can only be 5.1 to 5.5) | 92 | (a versão pode ser apenas 5.1 a 5.5) |
| 93 | --path <path_str> Append an extra Lua search path string to package.path | 93 | --path <path_str> Adicionar um caminho de busca Lua extra ao package.path |
| 94 | --<key>=<value> Pass compiler option in key=value form (existing behavior) | 94 | --<key>=<value> Passar opção do compilador no formato key=value (comportamento existente) |
| 95 | 95 | ||
| 96 | Execute without options to enter REPL, type symbol '$' | 96 | Execute sem opções para entrar no REPL, digite o símbolo '$' |
| 97 | in a single line to start/stop multi-line mode | 97 | em uma única linha para iniciar/parar o modo multilinha |
| 98 | ``` | 98 | ``` |
| 99 | Use cases: | ||
| 100 | 99 | ||
| 101 | Recursively compile every YueScript file with extension **.yue** under current path: **yue .** | 100 | Casos de uso: |
| 102 | 101 | ||
| 103 | Compile and save results to a target path: **yue -t /target/path/ .** | 102 | Compilar recursivamente todos os arquivos YueScript com extensão **.yue** no caminho atual: **yue .** |
| 104 | 103 | ||
| 105 | Compile and reserve debug info: **yue -l .** | 104 | Compilar e salvar resultados em um caminho de destino: **yue -t /target/path/ .** |
| 106 | 105 | ||
| 107 | Compile and generate minified codes: **yue -m .** | 106 | Compilar e preservar informações de debug: **yue -l .** |
| 108 | 107 | ||
| 109 | Execute raw codes: **yue -e 'print 123'** | 108 | Compilar e gerar código minificado: **yue -m .** |
| 110 | 109 | ||
| 111 | Execute a YueScript file: **yue -e main.yue** | 110 | Executar código bruto: **yue -e 'print 123'** |
| 111 | |||
| 112 | Executar um arquivo YueScript: **yue -e main.yue** | ||
diff --git a/doc/docs/pt-br/doc/language-basics/attributes.md b/doc/docs/pt-br/doc/language-basics/attributes.md index e6fd5a7..8e27f21 100644 --- a/doc/docs/pt-br/doc/language-basics/attributes.md +++ b/doc/docs/pt-br/doc/language-basics/attributes.md | |||
| @@ -1,21 +1,21 @@ | |||
| 1 | # Attributes | 1 | # Atributos |
| 2 | 2 | ||
| 3 | Syntax support for Lua 5.4 attributes. And you can still use both the `const` and `close` declaration and get constant check and scoped callback working when targeting Lua versions below 5.4. | 3 | Suporte de sintaxe para atributos do Lua 5.4. E você ainda pode usar tanto a declaração `const` quanto `close` e obter verificação de constante e callback com escopo funcionando ao direcionar para versões do Lua abaixo da 5.4. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | const a = 123 | 6 | const a = 123 |
| 7 | close _ = <close>: -> print "Out of scope." | 7 | close _ = <close>: -> print "Fora do escopo." |
| 8 | ``` | 8 | ``` |
| 9 | <YueDisplay> | 9 | <YueDisplay> |
| 10 | 10 | ||
| 11 | ```yue | 11 | ```yue |
| 12 | const a = 123 | 12 | const a = 123 |
| 13 | close _ = <close>: -> print "Out of scope." | 13 | close _ = <close>: -> print "Fora do escopo." |
| 14 | ``` | 14 | ``` |
| 15 | 15 | ||
| 16 | </YueDisplay> | 16 | </YueDisplay> |
| 17 | 17 | ||
| 18 | You can do desctructuring with variables attributed as constant. | 18 | Você pode fazer desestruturação com variáveis atribuídas como constante. |
| 19 | 19 | ||
| 20 | ```yuescript | 20 | ```yuescript |
| 21 | const {:a, :b, c, d} = tb | 21 | const {:a, :b, c, d} = tb |
| @@ -30,7 +30,7 @@ const {:a, :b, c, d} = tb | |||
| 30 | 30 | ||
| 31 | </YueDisplay> | 31 | </YueDisplay> |
| 32 | 32 | ||
| 33 | You can also declare a global variable to be `const`. | 33 | Você também pode declarar uma variável global como `const`. |
| 34 | 34 | ||
| 35 | ```yuescript | 35 | ```yuescript |
| 36 | global const Constant = 123 | 36 | global const Constant = 123 |
diff --git a/doc/docs/pt-br/doc/language-basics/comment.md b/doc/docs/pt-br/doc/language-basics/comment.md index b67c97d..ed3102d 100644 --- a/doc/docs/pt-br/doc/language-basics/comment.md +++ b/doc/docs/pt-br/doc/language-basics/comment.md | |||
| @@ -1,13 +1,13 @@ | |||
| 1 | # Comment | 1 | # Comentário |
| 2 | 2 | ||
| 3 | ```yuescript | 3 | ```yuescript |
| 4 | -- I am a comment | 4 | -- Eu sou um comentário |
| 5 | 5 | ||
| 6 | str = --[[ | 6 | str = --[[ |
| 7 | This is a multi-line comment. | 7 | Este é um comentário multilinha. |
| 8 | It's OK. | 8 | Está OK. |
| 9 | ]] strA \ -- comment 1 | 9 | ]] strA \ -- comentário 1 |
| 10 | .. strB \ -- comment 2 | 10 | .. strB \ -- comentário 2 |
| 11 | .. strC | 11 | .. strC |
| 12 | 12 | ||
| 13 | func --[[port]] 3000, --[[ip]] "192.168.1.1" | 13 | func --[[port]] 3000, --[[ip]] "192.168.1.1" |
| @@ -15,13 +15,13 @@ func --[[port]] 3000, --[[ip]] "192.168.1.1" | |||
| 15 | <YueDisplay> | 15 | <YueDisplay> |
| 16 | 16 | ||
| 17 | ```yue | 17 | ```yue |
| 18 | -- I am a comment | 18 | -- Eu sou um comentário |
| 19 | 19 | ||
| 20 | str = --[[ | 20 | str = --[[ |
| 21 | This is a multi-line comment. | 21 | Este é um comentário multilinha. |
| 22 | It's OK. | 22 | Está OK. |
| 23 | ]] strA \ -- comment 1 | 23 | ]] strA \ -- comentário 1 |
| 24 | .. strB \ -- comment 2 | 24 | .. strB \ -- comentário 2 |
| 25 | .. strC | 25 | .. strC |
| 26 | 26 | ||
| 27 | func --[[port]] 3000, --[[ip]] "192.168.1.1" | 27 | func --[[port]] 3000, --[[ip]] "192.168.1.1" |
diff --git a/doc/docs/pt-br/doc/language-basics/literals.md b/doc/docs/pt-br/doc/language-basics/literals.md index e097c62..b32b73a 100644 --- a/doc/docs/pt-br/doc/language-basics/literals.md +++ b/doc/docs/pt-br/doc/language-basics/literals.md | |||
| @@ -1,33 +1,33 @@ | |||
| 1 | # Literals | 1 | # Literais |
| 2 | 2 | ||
| 3 | All of the primitive literals in Lua can be used. This applies to numbers, strings, booleans, and **nil**. | 3 | Todos os literais primitivos do Lua podem ser usados. Isso se aplica a números, strings, booleanos e **nil**. |
| 4 | 4 | ||
| 5 | Unlike Lua, Line breaks are allowed inside of single and double quote strings without an escape sequence: | 5 | Diferente do Lua, quebras de linha são permitidas dentro de strings com aspas simples e duplas sem sequência de escape: |
| 6 | 6 | ||
| 7 | ```yuescript | 7 | ```yuescript |
| 8 | some_string = "Here is a string | 8 | some_string = "Aqui está uma string |
| 9 | that has a line break in it." | 9 | que tem uma quebra de linha." |
| 10 | 10 | ||
| 11 | -- You can mix expressions into string literals using #{} syntax. | 11 | -- Você pode misturar expressões em literais de string usando a sintaxe #{}. |
| 12 | -- String interpolation is only available in double quoted strings. | 12 | -- Interpolação de string está disponível apenas em strings com aspas duplas. |
| 13 | print "I am #{math.random! * 100}% sure." | 13 | print "Tenho #{math.random! * 100}% de certeza." |
| 14 | ``` | 14 | ``` |
| 15 | <YueDisplay> | 15 | <YueDisplay> |
| 16 | 16 | ||
| 17 | ```yue | 17 | ```yue |
| 18 | some_string = "Here is a string | 18 | some_string = "Aqui está uma string |
| 19 | that has a line break in it." | 19 | que tem uma quebra de linha." |
| 20 | 20 | ||
| 21 | -- You can mix expressions into string literals using #{} syntax. | 21 | -- Você pode misturar expressões em literais de string usando a sintaxe #{}. |
| 22 | -- String interpolation is only available in double quoted strings. | 22 | -- Interpolação de string está disponível apenas em strings com aspas duplas. |
| 23 | print "I am #{math.random! * 100}% sure." | 23 | print "Tenho #{math.random! * 100}% de certeza." |
| 24 | ``` | 24 | ``` |
| 25 | 25 | ||
| 26 | </YueDisplay> | 26 | </YueDisplay> |
| 27 | 27 | ||
| 28 | ## Number Literals | 28 | ## Literais numéricos |
| 29 | 29 | ||
| 30 | You can use underscores in a number literal to increase readability. | 30 | Você pode usar underscores em um literal numérico para aumentar a legibilidade. |
| 31 | 31 | ||
| 32 | ```yuescript | 32 | ```yuescript |
| 33 | integer = 1_000_000 | 33 | integer = 1_000_000 |
| @@ -44,9 +44,9 @@ binary = 0B10011 | |||
| 44 | 44 | ||
| 45 | </YueDisplay> | 45 | </YueDisplay> |
| 46 | 46 | ||
| 47 | ## YAML Multiline String | 47 | ## String multilinha estilo YAML |
| 48 | 48 | ||
| 49 | The `|` prefix introduces a YAML-style multiline string literal: | 49 | O prefixo `|` introduz um literal de string multilinha no estilo YAML: |
| 50 | 50 | ||
| 51 | ```yuescript | 51 | ```yuescript |
| 52 | str = | | 52 | str = | |
| @@ -67,9 +67,9 @@ str = | | |||
| 67 | 67 | ||
| 68 | </YueDisplay> | 68 | </YueDisplay> |
| 69 | 69 | ||
| 70 | This allows writing structured multiline text conveniently. All line breaks and indentation are preserved relative to the first non-empty line, and expressions inside `#{...}` are interpolated automatically as `tostring(expr)`. | 70 | Isso permite escrever texto estruturado multilinha convenientemente. Todas as quebras de linha e indentação são preservadas em relação à primeira linha não vazia, e expressões dentro de `#{...}` são interpoladas automaticamente como `tostring(expr)`. |
| 71 | 71 | ||
| 72 | YAML Multiline String automatically detects the common leading whitespace prefix (minimum indentation across all non-empty lines) and removes it from all lines. This makes it easy to indent your code visually without affecting the resulting string content. | 72 | A string multilinha YAML detecta automaticamente o prefixo comum de espaço em branco à esquerda (indentação mínima em todas as linhas não vazias) e remove-o de todas as linhas. Isso facilita a indentação visual do seu código sem afetar o conteúdo da string resultante. |
| 73 | 73 | ||
| 74 | ```yuescript | 74 | ```yuescript |
| 75 | fn = -> | 75 | fn = -> |
| @@ -90,21 +90,21 @@ fn = -> | |||
| 90 | 90 | ||
| 91 | </YueDisplay> | 91 | </YueDisplay> |
| 92 | 92 | ||
| 93 | Internal indentation is preserved relative to the removed common prefix, allowing clean nested structures. | 93 | A indentação interna é preservada em relação ao prefixo comum removido, permitindo estruturas aninhadas limpas. |
| 94 | 94 | ||
| 95 | All special characters like quotes (`"`) and backslashes (`\`) in the YAMLMultiline block are automatically escaped so that the generated Lua string is syntactically valid and behaves as expected. | 95 | Todos os caracteres especiais como aspas (`"`) e barras invertidas (`\`) no bloco YAML Multiline são escapados automaticamente para que a string Lua gerada seja sintaticamente válida e se comporte como esperado. |
| 96 | 96 | ||
| 97 | ```yuescript | 97 | ```yuescript |
| 98 | str = | | 98 | str = | |
| 99 | path: "C:\Program Files\App" | 99 | path: "C:\Program Files\App" |
| 100 | note: 'He said: "#{Hello}!"' | 100 | note: 'Ele disse: "#{Hello}!"' |
| 101 | ``` | 101 | ``` |
| 102 | <YueDisplay> | 102 | <YueDisplay> |
| 103 | 103 | ||
| 104 | ```yue | 104 | ```yue |
| 105 | str = | | 105 | str = | |
| 106 | path: "C:\Program Files\App" | 106 | path: "C:\Program Files\App" |
| 107 | note: 'He said: "#{Hello}!"' | 107 | note: 'Ele disse: "#{Hello}!"' |
| 108 | ``` | 108 | ``` |
| 109 | 109 | ||
| 110 | </YueDisplay> | 110 | </YueDisplay> |
diff --git a/doc/docs/pt-br/doc/language-basics/operator.md b/doc/docs/pt-br/doc/language-basics/operator.md index 9a2e89b..aba9c50 100644 --- a/doc/docs/pt-br/doc/language-basics/operator.md +++ b/doc/docs/pt-br/doc/language-basics/operator.md | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | # Operator | 1 | # Operador |
| 2 | 2 | ||
| 3 | All of Lua's binary and unary operators are available. Additionally **!=** is as an alias for **~=**, and either **\\** or **::** can be used to write a chaining function call like `tb\func!` or `tb::func!`. And Yuescipt offers some other special operators to write more expressive codes. | 3 | Todos os operadores binários e unários do Lua estão disponíveis. Além disso, **!=** é um alias para **~=**, e **\\** ou **::** podem ser usados para escrever uma chamada de função encadeada como `tb\func!` ou `tb::func!`. E o YueScript oferece alguns outros operadores especiais para escrever códigos mais expressivos. |
| 4 | 4 | ||
| 5 | ```yuescript | 5 | ```yuescript |
| 6 | tb\func! if tb ~= nil | 6 | tb\func! if tb ~= nil |
| @@ -15,32 +15,32 @@ tb::func! if tb != nil | |||
| 15 | 15 | ||
| 16 | </YueDisplay> | 16 | </YueDisplay> |
| 17 | 17 | ||
| 18 | ## Chaining Comparisons | 18 | ## Comparações encadeadas |
| 19 | 19 | ||
| 20 | Comparisons can be arbitrarily chained: | 20 | Comparações podem ser encadeadas arbitrariamente: |
| 21 | 21 | ||
| 22 | ```yuescript | 22 | ```yuescript |
| 23 | print 1 < 2 <= 2 < 3 == 3 > 2 >= 1 == 1 < 3 != 5 | 23 | print 1 < 2 <= 2 < 3 == 3 > 2 >= 1 == 1 < 3 != 5 |
| 24 | -- output: true | 24 | -- saída: true |
| 25 | 25 | ||
| 26 | a = 5 | 26 | a = 5 |
| 27 | print 1 <= a <= 10 | 27 | print 1 <= a <= 10 |
| 28 | -- output: true | 28 | -- saída: true |
| 29 | ``` | 29 | ``` |
| 30 | <YueDisplay> | 30 | <YueDisplay> |
| 31 | 31 | ||
| 32 | ```yue | 32 | ```yue |
| 33 | print 1 < 2 <= 2 < 3 == 3 > 2 >= 1 == 1 < 3 != 5 | 33 | print 1 < 2 <= 2 < 3 == 3 > 2 >= 1 == 1 < 3 != 5 |
| 34 | -- output: true | 34 | -- saída: true |
| 35 | 35 | ||
| 36 | a = 5 | 36 | a = 5 |
| 37 | print 1 <= a <= 10 | 37 | print 1 <= a <= 10 |
| 38 | -- output: true | 38 | -- saída: true |
| 39 | ``` | 39 | ``` |
| 40 | 40 | ||
| 41 | </YueDisplay> | 41 | </YueDisplay> |
| 42 | 42 | ||
| 43 | Note the evaluation behavior of chained comparisons: | 43 | Observe o comportamento de avaliação das comparações encadeadas: |
| 44 | 44 | ||
| 45 | ```yuescript | 45 | ```yuescript |
| 46 | v = (x) -> | 46 | v = (x) -> |
| @@ -49,7 +49,7 @@ v = (x) -> | |||
| 49 | 49 | ||
| 50 | print v(1) < v(2) <= v(3) | 50 | print v(1) < v(2) <= v(3) |
| 51 | --[[ | 51 | --[[ |
| 52 | output: | 52 | saída: |
| 53 | 2 | 53 | 2 |
| 54 | 1 | 54 | 1 |
| 55 | 3 | 55 | 3 |
| @@ -58,7 +58,7 @@ print v(1) < v(2) <= v(3) | |||
| 58 | 58 | ||
| 59 | print v(1) > v(2) <= v(3) | 59 | print v(1) > v(2) <= v(3) |
| 60 | --[[ | 60 | --[[ |
| 61 | output: | 61 | saída: |
| 62 | 2 | 62 | 2 |
| 63 | 1 | 63 | 1 |
| 64 | false | 64 | false |
| @@ -73,7 +73,7 @@ v = (x) -> | |||
| 73 | 73 | ||
| 74 | print v(1) < v(2) <= v(3) | 74 | print v(1) < v(2) <= v(3) |
| 75 | --[[ | 75 | --[[ |
| 76 | output: | 76 | saída: |
| 77 | 2 | 77 | 2 |
| 78 | 1 | 78 | 1 |
| 79 | 3 | 79 | 3 |
| @@ -82,7 +82,7 @@ print v(1) < v(2) <= v(3) | |||
| 82 | 82 | ||
| 83 | print v(1) > v(2) <= v(3) | 83 | print v(1) > v(2) <= v(3) |
| 84 | --[[ | 84 | --[[ |
| 85 | output: | 85 | saída: |
| 86 | 2 | 86 | 2 |
| 87 | 1 | 87 | 1 |
| 88 | false | 88 | false |
| @@ -91,11 +91,11 @@ print v(1) > v(2) <= v(3) | |||
| 91 | 91 | ||
| 92 | </YueDisplay> | 92 | </YueDisplay> |
| 93 | 93 | ||
| 94 | The middle expression is only evaluated once, rather than twice as it would be if the expression were written as `v(1) < v(2) and v(2) <= v(3)`. However, the order of evaluations in a chained comparison is undefined. It is strongly recommended not to use expressions with side effects (such as printing) in chained comparisons. If side effects are required, the short-circuit `and` operator should be used explicitly. | 94 | A expressão do meio é avaliada apenas uma vez, em vez de duas vezes como seria se a expressão fosse escrita como `v(1) < v(2) and v(2) <= v(3)`. No entanto, a ordem das avaliações em uma comparação encadeada é indefinida. É fortemente recomendado não usar expressões com efeitos colaterais (como impressão) em comparações encadeadas. Se efeitos colaterais forem necessários, o operador de curto-circuito `and` deve ser usado explicitamente. |
| 95 | 95 | ||
| 96 | ## Table Appending | 96 | ## Anexar à tabela |
| 97 | 97 | ||
| 98 | The **[] =** operator is used to append values to tables. | 98 | O operador **[] =** é usado para anexar valores a tabelas. |
| 99 | 99 | ||
| 100 | ```yuescript | 100 | ```yuescript |
| 101 | tab = [] | 101 | tab = [] |
| @@ -110,13 +110,13 @@ tab[] = "Value" | |||
| 110 | 110 | ||
| 111 | </YueDisplay> | 111 | </YueDisplay> |
| 112 | 112 | ||
| 113 | You can also use the spread operator `...` to append all elements from one list to another: | 113 | Você também pode usar o operador spread `...` para anexar todos os elementos de uma lista a outra: |
| 114 | 114 | ||
| 115 | ```yuescript | 115 | ```yuescript |
| 116 | tbA = [1, 2, 3] | 116 | tbA = [1, 2, 3] |
| 117 | tbB = [4, 5, 6] | 117 | tbB = [4, 5, 6] |
| 118 | tbA[] = ...tbB | 118 | tbA[] = ...tbB |
| 119 | -- tbA is now [1, 2, 3, 4, 5, 6] | 119 | -- tbA agora é [1, 2, 3, 4, 5, 6] |
| 120 | ``` | 120 | ``` |
| 121 | <YueDisplay> | 121 | <YueDisplay> |
| 122 | 122 | ||
| @@ -124,14 +124,14 @@ tbA[] = ...tbB | |||
| 124 | tbA = [1, 2, 3] | 124 | tbA = [1, 2, 3] |
| 125 | tbB = [4, 5, 6] | 125 | tbB = [4, 5, 6] |
| 126 | tbA[] = ...tbB | 126 | tbA[] = ...tbB |
| 127 | -- tbA is now [1, 2, 3, 4, 5, 6] | 127 | -- tbA agora é [1, 2, 3, 4, 5, 6] |
| 128 | ``` | 128 | ``` |
| 129 | 129 | ||
| 130 | </YueDisplay> | 130 | </YueDisplay> |
| 131 | 131 | ||
| 132 | ## Table Spreading | 132 | ## Spread de tabela |
| 133 | 133 | ||
| 134 | You can concatenate array tables or hash tables using spread operator `...` before expressions in table literals. | 134 | Você pode concatenar tabelas de array ou tabelas hash usando o operador spread `...` antes de expressões em literais de tabela. |
| 135 | 135 | ||
| 136 | ```yuescript | 136 | ```yuescript |
| 137 | parts = | 137 | parts = |
| @@ -170,9 +170,9 @@ merge = {...a, ...b} | |||
| 170 | 170 | ||
| 171 | </YueDisplay> | 171 | </YueDisplay> |
| 172 | 172 | ||
| 173 | ## Table Reversed Indexing | 173 | ## Indexação reversa de tabela |
| 174 | 174 | ||
| 175 | You can use the **#** operator to get the last elements of a table. | 175 | Você pode usar o operador **#** para obter os últimos elementos de uma tabela. |
| 176 | 176 | ||
| 177 | ```yuescript | 177 | ```yuescript |
| 178 | last = data.items[#] | 178 | last = data.items[#] |
| @@ -191,11 +191,11 @@ data.items[#] = 1 | |||
| 191 | 191 | ||
| 192 | ## Metatable | 192 | ## Metatable |
| 193 | 193 | ||
| 194 | The **<>** operator can be used as a shortcut for metatable manipulation. | 194 | O operador **<>** pode ser usado como atalho para manipulação de metatable. |
| 195 | 195 | ||
| 196 | ### Metatable Creation | 196 | ### Criação de metatable |
| 197 | 197 | ||
| 198 | Create normal table with empty bracekets **<>** or metamethod key which is surrounded by **<>**. | 198 | Crie tabela normal com chaves vazias **<>** ou chave de metamétodo cercada por **<>**. |
| 199 | 199 | ||
| 200 | ```yuescript | 200 | ```yuescript |
| 201 | mt = {} | 201 | mt = {} |
| @@ -203,14 +203,14 @@ add = (right) => <>: mt, value: @value + right.value | |||
| 203 | mt.__add = add | 203 | mt.__add = add |
| 204 | 204 | ||
| 205 | a = <>: mt, value: 1 | 205 | a = <>: mt, value: 1 |
| 206 | -- set field with variable of the same name | 206 | -- definir campo com variável de mesmo nome |
| 207 | b = :<add>, value: 2 | 207 | b = :<add>, value: 2 |
| 208 | c = <add>: mt.__add, value: 3 | 208 | c = <add>: mt.__add, value: 3 |
| 209 | 209 | ||
| 210 | d = a + b + c | 210 | d = a + b + c |
| 211 | print d.value | 211 | print d.value |
| 212 | 212 | ||
| 213 | close _ = <close>: -> print "out of scope" | 213 | close _ = <close>: -> print "fora do escopo" |
| 214 | ``` | 214 | ``` |
| 215 | <YueDisplay> | 215 | <YueDisplay> |
| 216 | 216 | ||
| @@ -220,24 +220,24 @@ add = (right) => <>: mt, value: @value + right.value | |||
| 220 | mt.__add = add | 220 | mt.__add = add |
| 221 | 221 | ||
| 222 | a = <>: mt, value: 1 | 222 | a = <>: mt, value: 1 |
| 223 | -- set field with variable of the same name | 223 | -- definir campo com variável de mesmo nome |
| 224 | b = :<add>, value: 2 | 224 | b = :<add>, value: 2 |
| 225 | c = <add>: mt.__add, value: 3 | 225 | c = <add>: mt.__add, value: 3 |
| 226 | 226 | ||
| 227 | d = a + b + c | 227 | d = a + b + c |
| 228 | print d.value | 228 | print d.value |
| 229 | 229 | ||
| 230 | close _ = <close>: -> print "out of scope" | 230 | close _ = <close>: -> print "fora do escopo" |
| 231 | ``` | 231 | ``` |
| 232 | 232 | ||
| 233 | </YueDisplay> | 233 | </YueDisplay> |
| 234 | 234 | ||
| 235 | ### Metatable Accessing | 235 | ### Acesso à metatable |
| 236 | 236 | ||
| 237 | Accessing metatable with **<>** or metamethod name surrounded by **<>** or writing some expression in **<>**. | 237 | Acesse a metatable com **<>** ou nome do metamétodo cercado por **<>** ou escrevendo alguma expressão em **<>**. |
| 238 | 238 | ||
| 239 | ```yuescript | 239 | ```yuescript |
| 240 | -- create with metatable containing field "value" | 240 | -- criar com metatable contendo campo "value" |
| 241 | tb = <"value">: 123 | 241 | tb = <"value">: 123 |
| 242 | tb.<index> = tb.<> | 242 | tb.<index> = tb.<> |
| 243 | print tb.value | 243 | print tb.value |
| @@ -248,7 +248,7 @@ print tb.item | |||
| 248 | <YueDisplay> | 248 | <YueDisplay> |
| 249 | 249 | ||
| 250 | ```yue | 250 | ```yue |
| 251 | -- create with metatable containing field "value" | 251 | -- criar com metatable contendo campo "value" |
| 252 | tb = <"value">: 123 | 252 | tb = <"value">: 123 |
| 253 | tb.<index> = tb.<> | 253 | tb.<index> = tb.<> |
| 254 | print tb.value | 254 | print tb.value |
| @@ -258,9 +258,9 @@ print tb.item | |||
| 258 | 258 | ||
| 259 | </YueDisplay> | 259 | </YueDisplay> |
| 260 | 260 | ||
| 261 | ### Metatable Destructure | 261 | ### Desestruturação de metatable |
| 262 | 262 | ||
| 263 | Destruct metatable with metamethod key surrounded by **<>**. | 263 | Desestruture a metatable com chave de metamétodo cercada por **<>**. |
| 264 | 264 | ||
| 265 | ```yuescript | 265 | ```yuescript |
| 266 | {item, :new, :<close>, <index>: getter} = tb | 266 | {item, :new, :<close>, <index>: getter} = tb |
| @@ -275,9 +275,9 @@ print item, new, close, getter | |||
| 275 | 275 | ||
| 276 | </YueDisplay> | 276 | </YueDisplay> |
| 277 | 277 | ||
| 278 | ## Existence | 278 | ## Existência |
| 279 | 279 | ||
| 280 | The **?** operator can be used in a variety of contexts to check for existence. | 280 | O operador **?** pode ser usado em diversos contextos para verificar existência. |
| 281 | 281 | ||
| 282 | ```yuescript | 282 | ```yuescript |
| 283 | func?! | 283 | func?! |
| @@ -312,16 +312,16 @@ with? io.open "test.txt", "w" | |||
| 312 | 312 | ||
| 313 | </YueDisplay> | 313 | </YueDisplay> |
| 314 | 314 | ||
| 315 | ## Piping | 315 | ## Pipe |
| 316 | 316 | ||
| 317 | Instead of a series of nested function calls, you can pipe values with operator **|>**. | 317 | Em vez de uma série de chamadas de função aninhadas, você pode encaminhar valores com o operador **|>**. |
| 318 | 318 | ||
| 319 | ```yuescript | 319 | ```yuescript |
| 320 | "hello" |> print | 320 | "hello" |> print |
| 321 | 1 |> print 2 -- insert pipe item as the first argument | 321 | 1 |> print 2 -- insere o item do pipe como primeiro argumento |
| 322 | 2 |> print 1, _, 3 -- pipe with a placeholder | 322 | 2 |> print 1, _, 3 -- pipe com um placeholder |
| 323 | 323 | ||
| 324 | -- pipe expression in multiline | 324 | -- expressão pipe em multilinha |
| 325 | readFile "example.txt" | 325 | readFile "example.txt" |
| 326 | |> extract language, {} | 326 | |> extract language, {} |
| 327 | |> parse language | 327 | |> parse language |
| @@ -333,9 +333,9 @@ readFile "example.txt" | |||
| 333 | 333 | ||
| 334 | ```yue | 334 | ```yue |
| 335 | "hello" |> print | 335 | "hello" |> print |
| 336 | 1 |> print 2 -- insert pipe item as the first argument | 336 | 1 |> print 2 -- insere o item do pipe como primeiro argumento |
| 337 | 2 |> print 1, _, 3 -- pipe with a placeholder | 337 | 2 |> print 1, _, 3 -- pipe com um placeholder |
| 338 | -- pipe expression in multiline | 338 | -- expressão pipe em multilinha |
| 339 | readFile "example.txt" | 339 | readFile "example.txt" |
| 340 | |> extract language, {} | 340 | |> extract language, {} |
| 341 | |> parse language | 341 | |> parse language |
| @@ -346,9 +346,9 @@ readFile "example.txt" | |||
| 346 | 346 | ||
| 347 | </YueDisplay> | 347 | </YueDisplay> |
| 348 | 348 | ||
| 349 | ## Nil Coalescing | 349 | ## Coalescência de nil |
| 350 | 350 | ||
| 351 | The nil-coalescing operator **??** returns the value of its left-hand operand if it isn't **nil**; otherwise, it evaluates the right-hand operand and returns its result. The **??** operator doesn't evaluate its right-hand operand if the left-hand operand evaluates to non-nil. | 351 | O operador de coalescência de nil **??** retorna o valor do operando esquerdo se não for **nil**; caso contrário, avalia o operando direito e retorna seu resultado. O operador **??** não avalia seu operando direito se o operando esquerdo avaliar para não-nil. |
| 352 | ```yuescript | 352 | ```yuescript |
| 353 | local a, b, c, d | 353 | local a, b, c, d |
| 354 | a = b ?? c ?? d | 354 | a = b ?? c ?? d |
| @@ -367,31 +367,31 @@ a ??= false | |||
| 367 | 367 | ||
| 368 | </YueDisplay> | 368 | </YueDisplay> |
| 369 | 369 | ||
| 370 | ## Implicit Object | 370 | ## Objeto implícito |
| 371 | 371 | ||
| 372 | You can write a list of implicit structures that starts with the symbol **\*** or **-** inside a table block. If you are creating implicit object, the fields of the object must be with the same indent. | 372 | Você pode escrever uma lista de estruturas implícitas que começa com o símbolo **\*** ou **-** dentro de um bloco de tabela. Se você está criando objeto implícito, os campos do objeto devem estar com a mesma indentação. |
| 373 | 373 | ||
| 374 | ```yuescript | 374 | ```yuescript |
| 375 | -- assignment with implicit object | 375 | -- atribuição com objeto implícito |
| 376 | list = | 376 | list = |
| 377 | * 1 | 377 | * 1 |
| 378 | * 2 | 378 | * 2 |
| 379 | * 3 | 379 | * 3 |
| 380 | 380 | ||
| 381 | -- function call with implicit object | 381 | -- chamada de função com objeto implícito |
| 382 | func | 382 | func |
| 383 | * 1 | 383 | * 1 |
| 384 | * 2 | 384 | * 2 |
| 385 | * 3 | 385 | * 3 |
| 386 | 386 | ||
| 387 | -- return with implicit object | 387 | -- retorno com objeto implícito |
| 388 | f = -> | 388 | f = -> |
| 389 | return | 389 | return |
| 390 | * 1 | 390 | * 1 |
| 391 | * 2 | 391 | * 2 |
| 392 | * 3 | 392 | * 3 |
| 393 | 393 | ||
| 394 | -- table with implicit object | 394 | -- tabela com objeto implícito |
| 395 | tb = | 395 | tb = |
| 396 | name: "abc" | 396 | name: "abc" |
| 397 | 397 | ||
| @@ -416,26 +416,26 @@ tb = | |||
| 416 | <YueDisplay> | 416 | <YueDisplay> |
| 417 | 417 | ||
| 418 | ```yue | 418 | ```yue |
| 419 | -- assignment with implicit object | 419 | -- atribuição com objeto implícito |
| 420 | list = | 420 | list = |
| 421 | * 1 | 421 | * 1 |
| 422 | * 2 | 422 | * 2 |
| 423 | * 3 | 423 | * 3 |
| 424 | 424 | ||
| 425 | -- function call with implicit object | 425 | -- chamada de função com objeto implícito |
| 426 | func | 426 | func |
| 427 | * 1 | 427 | * 1 |
| 428 | * 2 | 428 | * 2 |
| 429 | * 3 | 429 | * 3 |
| 430 | 430 | ||
| 431 | -- return with implicit object | 431 | -- retorno com objeto implícito |
| 432 | f = -> | 432 | f = -> |
| 433 | return | 433 | return |
| 434 | * 1 | 434 | * 1 |
| 435 | * 2 | 435 | * 2 |
| 436 | * 3 | 436 | * 3 |
| 437 | 437 | ||
| 438 | -- table with implicit object | 438 | -- tabela com objeto implícito |
| 439 | tb = | 439 | tb = |
| 440 | name: "abc" | 440 | name: "abc" |
| 441 | 441 | ||
diff --git a/doc/docs/pt-br/doc/language-basics/whitespace.md b/doc/docs/pt-br/doc/language-basics/whitespace.md index d742a2b..df844f9 100644 --- a/doc/docs/pt-br/doc/language-basics/whitespace.md +++ b/doc/docs/pt-br/doc/language-basics/whitespace.md | |||
| @@ -1,10 +1,10 @@ | |||
| 1 | # Whitespace | 1 | # Espaço em branco |
| 2 | 2 | ||
| 3 | YueScript is a whitespace significant language. You have to write some code block in the same indent with space **' '** or tab **'\t'** like function body, value list and some control blocks. And expressions containing different whitespaces might mean different things. Tab is treated like 4 space, but it's better not mix the use of spaces and tabs. | 3 | YueScript é uma linguagem sensível a espaço em branco. Você precisa escrever blocos de código na mesma indentação com espaço **' '** ou tabulação **'\t'**, como corpo de função, lista de valores e alguns blocos de controle. E expressões contendo diferentes espaços em branco podem significar coisas diferentes. Tabulação é tratada como 4 espaços, mas é melhor não misturar o uso de espaços e tabulações. |
| 4 | 4 | ||
| 5 | ## Statement Separator | 5 | ## Separador de instrução |
| 6 | 6 | ||
| 7 | A statement normally ends at a line break. You can also use a semicolon `;` to explicitly terminate a statement, which allows writing multiple statements on the same line: | 7 | Uma instrução normalmente termina em uma quebra de linha. Você também pode usar ponto e vírgula `;` para terminar explicitamente uma instrução, o que permite escrever múltiplas instruções na mesma linha: |
| 8 | 8 | ||
| 9 | ```yuescript | 9 | ```yuescript |
| 10 | a = 1; b = 2; print a + b | 10 | a = 1; b = 2; print a + b |
| @@ -17,9 +17,9 @@ a = 1; b = 2; print a + b | |||
| 17 | 17 | ||
| 18 | </YueDisplay> | 18 | </YueDisplay> |
| 19 | 19 | ||
| 20 | ## Multiline Chaining | 20 | ## Encadeamento multilinha |
| 21 | 21 | ||
| 22 | You can write multi-line chaining function calls with a same indent. | 22 | Você pode escrever chamadas de função encadeadas em múltiplas linhas com a mesma indentação. |
| 23 | 23 | ||
| 24 | ```yuescript | 24 | ```yuescript |
| 25 | Rx.Observable | 25 | Rx.Observable |
diff --git a/doc/docs/pt-br/doc/objects/object-oriented-programming.md b/doc/docs/pt-br/doc/objects/object-oriented-programming.md index 6a8559e..3d5f061 100644 --- a/doc/docs/pt-br/doc/objects/object-oriented-programming.md +++ b/doc/docs/pt-br/doc/objects/object-oriented-programming.md | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | # Object Oriented Programming | 1 | # Programação orientada a objetos |
| 2 | 2 | ||
| 3 | In these examples, the generated Lua code may appear overwhelming. It is best to focus on the meaning of the YueScript code at first, then look into the Lua code if you wish to know the implementation details. | 3 | Nestes exemplos, o código Lua gerado pode parecer avassalador. É melhor focar primeiro no significado do código YueScript e depois olhar o código Lua se desejar conhecer os detalhes da implementação. |
| 4 | 4 | ||
| 5 | A simple class: | 5 | Uma classe simples: |
| 6 | 6 | ||
| 7 | ```yuescript | 7 | ```yuescript |
| 8 | class Inventory | 8 | class Inventory |
| @@ -31,15 +31,15 @@ class Inventory | |||
| 31 | 31 | ||
| 32 | </YueDisplay> | 32 | </YueDisplay> |
| 33 | 33 | ||
| 34 | A class is declared with a class statement followed by a table-like declaration where all of the methods and properties are listed. | 34 | Uma classe é declarada com uma instrução class seguida de uma declaração semelhante a tabela onde todos os métodos e propriedades são listados. |
| 35 | 35 | ||
| 36 | The new property is special in that it will become the constructor. | 36 | A propriedade new é especial pois se tornará o construtor. |
| 37 | 37 | ||
| 38 | Notice how all the methods in the class use the fat arrow function syntax. When calling methods on a instance, the instance itself is sent in as the first argument. The fat arrow handles the creation of a self argument. | 38 | Observe como todos os métodos da classe usam a sintaxe de função seta fat. Ao chamar métodos em uma instância, a própria instância é enviada como primeiro argumento. A seta fat cuida da criação do argumento self. |
| 39 | 39 | ||
| 40 | The @ prefix on a variable name is shorthand for self.. @items becomes self.items. | 40 | O prefixo @ em um nome de variável é abreviação para self.. @items torna-se self.items. |
| 41 | 41 | ||
| 42 | Creating an instance of the class is done by calling the name of the class as a function. | 42 | Criar uma instância da classe é feito chamando o nome da classe como uma função. |
| 43 | 43 | ||
| 44 | ```yuescript | 44 | ```yuescript |
| 45 | inv = Inventory! | 45 | inv = Inventory! |
| @@ -56,11 +56,11 @@ inv\add_item "pants" | |||
| 56 | 56 | ||
| 57 | </YueDisplay> | 57 | </YueDisplay> |
| 58 | 58 | ||
| 59 | Because the instance of the class needs to be sent to the methods when they are called, the \ operator is used. | 59 | Como a instância da classe precisa ser enviada aos métodos quando são chamados, o operador \ é usado. |
| 60 | 60 | ||
| 61 | All properties of a class are shared among the instances. This is fine for functions, but for other types of objects, undesired results may occur. | 61 | Todas as propriedades de uma classe são compartilhadas entre as instâncias. Isso é bom para funções, mas para outros tipos de objetos, resultados indesejados podem ocorrer. |
| 62 | 62 | ||
| 63 | Consider the example below, the clothes property is shared amongst all instances, so modifications to it in one instance will show up in another: | 63 | Considere o exemplo abaixo, a propriedade clothes é compartilhada entre todas as instâncias, então modificações nela em uma instância aparecerão em outra: |
| 64 | 64 | ||
| 65 | ```yuescript | 65 | ```yuescript |
| 66 | class Person | 66 | class Person |
| @@ -74,7 +74,7 @@ b = Person! | |||
| 74 | a\give_item "pants" | 74 | a\give_item "pants" |
| 75 | b\give_item "shirt" | 75 | b\give_item "shirt" |
| 76 | 76 | ||
| 77 | -- will print both pants and shirt | 77 | -- vai imprimir tanto pants quanto shirt |
| 78 | print item for item in *a.clothes | 78 | print item for item in *a.clothes |
| 79 | ``` | 79 | ``` |
| 80 | <YueDisplay> | 80 | <YueDisplay> |
| @@ -91,13 +91,13 @@ b = Person! | |||
| 91 | a\give_item "pants" | 91 | a\give_item "pants" |
| 92 | b\give_item "shirt" | 92 | b\give_item "shirt" |
| 93 | 93 | ||
| 94 | -- will print both pants and shirt | 94 | -- vai imprimir tanto pants quanto shirt |
| 95 | print item for item in *a.clothes | 95 | print item for item in *a.clothes |
| 96 | ``` | 96 | ``` |
| 97 | 97 | ||
| 98 | </YueDisplay> | 98 | </YueDisplay> |
| 99 | 99 | ||
| 100 | The proper way to avoid this problem is to create the mutable state of the object in the constructor: | 100 | A forma correta de evitar esse problema é criar o estado mutável do objeto no construtor: |
| 101 | 101 | ||
| 102 | ```yuescript | 102 | ```yuescript |
| 103 | class Person | 103 | class Person |
| @@ -114,9 +114,9 @@ class Person | |||
| 114 | 114 | ||
| 115 | </YueDisplay> | 115 | </YueDisplay> |
| 116 | 116 | ||
| 117 | ## Inheritance | 117 | ## Herança |
| 118 | 118 | ||
| 119 | The extends keyword can be used in a class declaration to inherit the properties and methods from another class. | 119 | A palavra-chave extends pode ser usada em uma declaração de classe para herdar as propriedades e métodos de outra classe. |
| 120 | 120 | ||
| 121 | ```yuescript | 121 | ```yuescript |
| 122 | class BackPack extends Inventory | 122 | class BackPack extends Inventory |
| @@ -137,18 +137,18 @@ class BackPack extends Inventory | |||
| 137 | 137 | ||
| 138 | </YueDisplay> | 138 | </YueDisplay> |
| 139 | 139 | ||
| 140 | Here we extend our Inventory class, and limit the amount of items it can carry. | 140 | Aqui estendemos nossa classe Inventory e limitamos a quantidade de itens que ela pode carregar. |
| 141 | 141 | ||
| 142 | In this example, we don't define a constructor on the subclass, so the parent class' constructor is called when we make a new instance. If we did define a constructor then we can use the super method to call the parent constructor. | 142 | Neste exemplo, não definimos um construtor na subclasse, então o construtor da classe pai é chamado quando criamos uma nova instância. Se definirmos um construtor, podemos usar o método super para chamar o construtor pai. |
| 143 | 143 | ||
| 144 | Whenever a class inherits from another, it sends a message to the parent class by calling the method __inherited on the parent class if it exists. The function receives two arguments, the class that is being inherited and the child class. | 144 | Sempre que uma classe herda de outra, ela envia uma mensagem à classe pai chamando o método __inherited na classe pai se ele existir. A função recebe dois argumentos: a classe que está sendo herdada e a classe filha. |
| 145 | 145 | ||
| 146 | ```yuescript | 146 | ```yuescript |
| 147 | class Shelf | 147 | class Shelf |
| 148 | @__inherited: (child) => | 148 | @__inherited: (child) => |
| 149 | print @__name, "was inherited by", child.__name | 149 | print @__name, "was inherited by", child.__name |
| 150 | 150 | ||
| 151 | -- will print: Shelf was inherited by Cupboard | 151 | -- vai imprimir: Shelf was inherited by Cupboard |
| 152 | class Cupboard extends Shelf | 152 | class Cupboard extends Shelf |
| 153 | ``` | 153 | ``` |
| 154 | <YueDisplay> | 154 | <YueDisplay> |
| @@ -158,7 +158,7 @@ class Shelf | |||
| 158 | @__inherited: (child) => | 158 | @__inherited: (child) => |
| 159 | print @__name, "was inherited by", child.__name | 159 | print @__name, "was inherited by", child.__name |
| 160 | 160 | ||
| 161 | -- will print: Shelf was inherited by Cupboard | 161 | -- vai imprimir: Shelf was inherited by Cupboard |
| 162 | class Cupboard extends Shelf | 162 | class Cupboard extends Shelf |
| 163 | ``` | 163 | ``` |
| 164 | 164 | ||
| @@ -166,27 +166,27 @@ class Cupboard extends Shelf | |||
| 166 | 166 | ||
| 167 | ## Super | 167 | ## Super |
| 168 | 168 | ||
| 169 | **super** is a special keyword that can be used in two different ways: It can be treated as an object, or it can be called like a function. It only has special functionality when inside a class. | 169 | **super** é uma palavra-chave especial que pode ser usada de duas formas diferentes: pode ser tratado como um objeto, ou pode ser chamado como uma função. Só tem funcionalidade especial quando está dentro de uma classe. |
| 170 | 170 | ||
| 171 | When called as a function, it will call the function of the same name in the parent class. The current self will automatically be passed as the first argument. (As seen in the inheritance example above) | 171 | Quando chamado como função, chamará a função de mesmo nome na classe pai. O self atual será automaticamente passado como primeiro argumento. (Como visto no exemplo de herança acima) |
| 172 | 172 | ||
| 173 | When super is used as a normal value, it is a reference to the parent class object. | 173 | Quando super é usado como valor normal, é uma referência ao objeto da classe pai. |
| 174 | 174 | ||
| 175 | It can be accessed like any of object in order to retrieve values in the parent class that might have been shadowed by the child class. | 175 | Pode ser acessado como qualquer objeto para recuperar valores na classe pai que possam ter sido sombreados pela classe filha. |
| 176 | 176 | ||
| 177 | When the \ calling operator is used with super, self is inserted as the first argument instead of the value of super itself. When using . to retrieve a function, the raw function is returned. | 177 | Quando o operador de chamada \ é usado com super, self é inserido como primeiro argumento em vez do valor do próprio super. Ao usar . para recuperar uma função, a função bruta é retornada. |
| 178 | 178 | ||
| 179 | A few examples of using super in different ways: | 179 | Alguns exemplos de uso de super de diferentes formas: |
| 180 | 180 | ||
| 181 | ```yuescript | 181 | ```yuescript |
| 182 | class MyClass extends ParentClass | 182 | class MyClass extends ParentClass |
| 183 | a_method: => | 183 | a_method: => |
| 184 | -- the following have the same effect: | 184 | -- os seguintes têm o mesmo efeito: |
| 185 | super "hello", "world" | 185 | super "hello", "world" |
| 186 | super\a_method "hello", "world" | 186 | super\a_method "hello", "world" |
| 187 | super.a_method self, "hello", "world" | 187 | super.a_method self, "hello", "world" |
| 188 | 188 | ||
| 189 | -- super as a value is equal to the parent class: | 189 | -- super como valor é igual à classe pai: |
| 190 | assert super == ParentClass | 190 | assert super == ParentClass |
| 191 | ``` | 191 | ``` |
| 192 | <YueDisplay> | 192 | <YueDisplay> |
| @@ -194,28 +194,28 @@ class MyClass extends ParentClass | |||
| 194 | ```yue | 194 | ```yue |
| 195 | class MyClass extends ParentClass | 195 | class MyClass extends ParentClass |
| 196 | a_method: => | 196 | a_method: => |
| 197 | -- the following have the same effect: | 197 | -- os seguintes têm o mesmo efeito: |
| 198 | super "hello", "world" | 198 | super "hello", "world" |
| 199 | super\a_method "hello", "world" | 199 | super\a_method "hello", "world" |
| 200 | super.a_method self, "hello", "world" | 200 | super.a_method self, "hello", "world" |
| 201 | 201 | ||
| 202 | -- super as a value is equal to the parent class: | 202 | -- super como valor é igual à classe pai: |
| 203 | assert super == ParentClass | 203 | assert super == ParentClass |
| 204 | ``` | 204 | ``` |
| 205 | 205 | ||
| 206 | </YueDisplay> | 206 | </YueDisplay> |
| 207 | 207 | ||
| 208 | **super** can also be used on left side of a Function Stub. The only major difference is that instead of the resulting function being bound to the value of super, it is bound to self. | 208 | **super** também pode ser usado no lado esquerdo de um Function Stub. A única diferença principal é que, em vez da função resultante estar vinculada ao valor de super, ela está vinculada a self. |
| 209 | 209 | ||
| 210 | ## Types | 210 | ## Tipos |
| 211 | 211 | ||
| 212 | Every instance of a class carries its type with it. This is stored in the special __class property. This property holds the class object. The class object is what we call to build a new instance. We can also index the class object to retrieve class methods and properties. | 212 | Cada instância de uma classe carrega seu tipo consigo. Isso é armazenado na propriedade especial __class. Esta propriedade contém o objeto da classe. O objeto da classe é o que chamamos para construir uma nova instância. Também podemos indexar o objeto da classe para recuperar métodos e propriedades da classe. |
| 213 | 213 | ||
| 214 | ```yuescript | 214 | ```yuescript |
| 215 | b = BackPack! | 215 | b = BackPack! |
| 216 | assert b.__class == BackPack | 216 | assert b.__class == BackPack |
| 217 | 217 | ||
| 218 | print BackPack.size -- prints 10 | 218 | print BackPack.size -- imprime 10 |
| 219 | ``` | 219 | ``` |
| 220 | <YueDisplay> | 220 | <YueDisplay> |
| 221 | 221 | ||
| @@ -223,45 +223,45 @@ print BackPack.size -- prints 10 | |||
| 223 | b = BackPack! | 223 | b = BackPack! |
| 224 | assert b.__class == BackPack | 224 | assert b.__class == BackPack |
| 225 | 225 | ||
| 226 | print BackPack.size -- prints 10 | 226 | print BackPack.size -- imprime 10 |
| 227 | ``` | 227 | ``` |
| 228 | 228 | ||
| 229 | </YueDisplay> | 229 | </YueDisplay> |
| 230 | 230 | ||
| 231 | ## Class Objects | 231 | ## Objetos de classe |
| 232 | 232 | ||
| 233 | The class object is what we create when we use a class statement. The class object is stored in a variable of the same name of the class. | 233 | O objeto da classe é o que criamos quando usamos uma instrução class. O objeto da classe é armazenado em uma variável com o mesmo nome da classe. |
| 234 | 234 | ||
| 235 | The class object can be called like a function in order to create new instances. That's how we created instances of classes in the examples above. | 235 | O objeto da classe pode ser chamado como uma função para criar novas instâncias. É assim que criamos instâncias de classes nos exemplos acima. |
| 236 | 236 | ||
| 237 | A class is made up of two tables. The class table itself, and the base table. The base is used as the metatable for all the instances. All properties listed in the class declaration are placed in the base. | 237 | Uma classe é composta por duas tabelas. A própria tabela da classe e a tabela base. A base é usada como metatable para todas as instâncias. Todas as propriedades listadas na declaração da classe são colocadas na base. |
| 238 | 238 | ||
| 239 | The class object's metatable reads properties from the base if they don't exist in the class object. This means we can access functions and properties directly from the class. | 239 | A metatable do objeto da classe lê propriedades da base se não existirem no objeto da classe. Isso significa que podemos acessar funções e propriedades diretamente da classe. |
| 240 | 240 | ||
| 241 | It is important to note that assigning to the class object does not assign into the base, so it's not a valid way to add new methods to instances. Instead the base must explicitly be changed. See the __base field below. | 241 | É importante notar que atribuir ao objeto da classe não atribui à base, então não é uma forma válida de adicionar novos métodos às instâncias. Em vez disso, a base deve ser alterada explicitamente. Veja o campo __base abaixo. |
| 242 | 242 | ||
| 243 | The class object has a couple special properties: | 243 | O objeto da classe tem algumas propriedades especiais: |
| 244 | 244 | ||
| 245 | The name of the class as when it was declared is stored as a string in the __name field of the class object. | 245 | O nome da classe quando foi declarada é armazenado como string no campo __name do objeto da classe. |
| 246 | 246 | ||
| 247 | ```yuescript | 247 | ```yuescript |
| 248 | print BackPack.__name -- prints Backpack | 248 | print BackPack.__name -- imprime Backpack |
| 249 | ``` | 249 | ``` |
| 250 | <YueDisplay> | 250 | <YueDisplay> |
| 251 | 251 | ||
| 252 | ```yue | 252 | ```yue |
| 253 | print BackPack.__name -- prints Backpack | 253 | print BackPack.__name -- imprime Backpack |
| 254 | ``` | 254 | ``` |
| 255 | 255 | ||
| 256 | </YueDisplay> | 256 | </YueDisplay> |
| 257 | 257 | ||
| 258 | The base object is stored in __base. We can modify this table to add functionality to instances that have already been created and ones that are yet to be created. | 258 | O objeto base é armazenado em __base. Podemos modificar esta tabela para adicionar funcionalidade a instâncias que já foram criadas e às que ainda serão criadas. |
| 259 | 259 | ||
| 260 | If the class extends from anything, the parent class object is stored in __parent. | 260 | Se a classe estende de algo, o objeto da classe pai é armazenado em __parent. |
| 261 | 261 | ||
| 262 | ## Class Variables | 262 | ## Variáveis de classe |
| 263 | 263 | ||
| 264 | We can create variables directly in the class object instead of in the base by using @ in the front of the property name in a class declaration. | 264 | Podemos criar variáveis diretamente no objeto da classe em vez da base usando @ na frente do nome da propriedade em uma declaração de classe. |
| 265 | 265 | ||
| 266 | ```yuescript | 266 | ```yuescript |
| 267 | class Things | 267 | class Things |
| @@ -269,7 +269,7 @@ class Things | |||
| 269 | 269 | ||
| 270 | Things\some_func! | 270 | Things\some_func! |
| 271 | 271 | ||
| 272 | -- class variables not visible in instances | 272 | -- variáveis de classe não visíveis em instâncias |
| 273 | assert Things().some_func == nil | 273 | assert Things().some_func == nil |
| 274 | ``` | 274 | ``` |
| 275 | <YueDisplay> | 275 | <YueDisplay> |
| @@ -280,13 +280,13 @@ class Things | |||
| 280 | 280 | ||
| 281 | Things\some_func! | 281 | Things\some_func! |
| 282 | 282 | ||
| 283 | -- class variables not visible in instances | 283 | -- variáveis de classe não visíveis em instâncias |
| 284 | assert Things().some_func == nil | 284 | assert Things().some_func == nil |
| 285 | ``` | 285 | ``` |
| 286 | 286 | ||
| 287 | </YueDisplay> | 287 | </YueDisplay> |
| 288 | 288 | ||
| 289 | In expressions, we can use @@ to access a value that is stored in the __class of self. Thus, @@hello is shorthand for self.__class.hello. | 289 | Em expressões, podemos usar @@ para acessar um valor armazenado no __class de self. Assim, @@hello é abreviação para self.__class.hello. |
| 290 | 290 | ||
| 291 | ```yuescript | 291 | ```yuescript |
| 292 | class Counter | 292 | class Counter |
| @@ -298,7 +298,7 @@ class Counter | |||
| 298 | Counter! | 298 | Counter! |
| 299 | Counter! | 299 | Counter! |
| 300 | 300 | ||
| 301 | print Counter.count -- prints 2 | 301 | print Counter.count -- imprime 2 |
| 302 | ``` | 302 | ``` |
| 303 | <YueDisplay> | 303 | <YueDisplay> |
| 304 | 304 | ||
| @@ -312,12 +312,12 @@ class Counter | |||
| 312 | Counter! | 312 | Counter! |
| 313 | Counter! | 313 | Counter! |
| 314 | 314 | ||
| 315 | print Counter.count -- prints 2 | 315 | print Counter.count -- imprime 2 |
| 316 | ``` | 316 | ``` |
| 317 | 317 | ||
| 318 | </YueDisplay> | 318 | </YueDisplay> |
| 319 | 319 | ||
| 320 | The calling semantics of @@ are similar to @. Calling a @@ name will pass the class in as the first argument using Lua's colon syntax. | 320 | A semântica de chamada de @@ é semelhante a @. Chamar um nome @@ passará a classe como primeiro argumento usando a sintaxe de dois pontos do Lua. |
| 321 | 321 | ||
| 322 | ```yuescript | 322 | ```yuescript |
| 323 | @@hello 1,2,3,4 | 323 | @@hello 1,2,3,4 |
| @@ -330,11 +330,11 @@ The calling semantics of @@ are similar to @. Calling a @@ name will pass the cl | |||
| 330 | 330 | ||
| 331 | </YueDisplay> | 331 | </YueDisplay> |
| 332 | 332 | ||
| 333 | ## Class Declaration Statements | 333 | ## Instruções de declaração de classe |
| 334 | 334 | ||
| 335 | In the body of a class declaration, we can have normal expressions in addition to key/value pairs. In this context, self is equal to the class object. | 335 | No corpo de uma declaração de classe, podemos ter expressões normais além de pares chave/valor. Neste contexto, self é igual ao objeto da classe. |
| 336 | 336 | ||
| 337 | Here is an alternative way to create a class variable compared to what's described above: | 337 | Aqui está uma forma alternativa de criar variável de classe comparada ao descrito acima: |
| 338 | 338 | ||
| 339 | ```yuescript | 339 | ```yuescript |
| 340 | class Things | 340 | class Things |
| @@ -349,9 +349,9 @@ class Things | |||
| 349 | 349 | ||
| 350 | </YueDisplay> | 350 | </YueDisplay> |
| 351 | 351 | ||
| 352 | These expressions are executed after all the properties have been added to the base. | 352 | Estas expressões são executadas após todas as propriedades terem sido adicionadas à base. |
| 353 | 353 | ||
| 354 | All variables declared in the body of the class are local to the classes properties. This is convenient for placing private values or helper functions that only the class methods can access: | 354 | Todas as variáveis declaradas no corpo da classe são locais às propriedades da classe. Isso é conveniente para colocar valores privados ou funções auxiliares que apenas os métodos da classe podem acessar: |
| 355 | 355 | ||
| 356 | ```yuescript | 356 | ```yuescript |
| 357 | class MoreThings | 357 | class MoreThings |
| @@ -374,11 +374,11 @@ class MoreThings | |||
| 374 | 374 | ||
| 375 | </YueDisplay> | 375 | </YueDisplay> |
| 376 | 376 | ||
| 377 | ## @ and @@ Values | 377 | ## Valores @ e @@ |
| 378 | 378 | ||
| 379 | When @ and @@ are prefixed in front of a name they represent, respectively, that name accessed in self and self.__class. | 379 | Quando @ e @@ são prefixados na frente de um nome, eles representam, respectivamente, esse nome acessado em self e self.__class. |
| 380 | 380 | ||
| 381 | If they are used all by themselves, they are aliases for self and self.__class. | 381 | Se forem usados sozinhos, são aliases para self e self.__class. |
| 382 | 382 | ||
| 383 | ```yuescript | 383 | ```yuescript |
| 384 | assert @ == self | 384 | assert @ == self |
| @@ -393,7 +393,7 @@ assert @@ == self.__class | |||
| 393 | 393 | ||
| 394 | </YueDisplay> | 394 | </YueDisplay> |
| 395 | 395 | ||
| 396 | For example, a quick way to create a new instance of the same class from an instance method using @@: | 396 | Por exemplo, uma forma rápida de criar uma nova instância da mesma classe a partir de um método de instância usando @@: |
| 397 | 397 | ||
| 398 | ```yuescript | 398 | ```yuescript |
| 399 | some_instance_method = (...) => @@ ... | 399 | some_instance_method = (...) => @@ ... |
| @@ -406,15 +406,15 @@ some_instance_method = (...) => @@ ... | |||
| 406 | 406 | ||
| 407 | </YueDisplay> | 407 | </YueDisplay> |
| 408 | 408 | ||
| 409 | ## Constructor Property Promotion | 409 | ## Promoção de propriedade no construtor |
| 410 | 410 | ||
| 411 | To reduce the boilerplate code for definition of simple value objects. You can write a simple class like: | 411 | Para reduzir o código repetitivo na definição de objetos de valor simples. Você pode escrever uma classe simples como: |
| 412 | 412 | ||
| 413 | ```yuescript | 413 | ```yuescript |
| 414 | class Something | 414 | class Something |
| 415 | new: (@foo, @bar, @@biz, @@baz) => | 415 | new: (@foo, @bar, @@biz, @@baz) => |
| 416 | 416 | ||
| 417 | -- Which is short for | 417 | -- O que é abreviação para |
| 418 | 418 | ||
| 419 | class Something | 419 | class Something |
| 420 | new: (foo, bar, biz, baz) => | 420 | new: (foo, bar, biz, baz) => |
| @@ -429,7 +429,7 @@ class Something | |||
| 429 | class Something | 429 | class Something |
| 430 | new: (@foo, @bar, @@biz, @@baz) => | 430 | new: (@foo, @bar, @@biz, @@baz) => |
| 431 | 431 | ||
| 432 | -- Which is short for | 432 | -- O que é abreviação para |
| 433 | 433 | ||
| 434 | class Something | 434 | class Something |
| 435 | new: (foo, bar, biz, baz) => | 435 | new: (foo, bar, biz, baz) => |
| @@ -441,7 +441,7 @@ class Something | |||
| 441 | 441 | ||
| 442 | </YueDisplay> | 442 | </YueDisplay> |
| 443 | 443 | ||
| 444 | You can also use this syntax for a common function to initialize a object's fields. | 444 | Você também pode usar esta sintaxe para uma função comum para inicializar os campos de um objeto. |
| 445 | 445 | ||
| 446 | ```yuescript | 446 | ```yuescript |
| 447 | new = (@fieldA, @fieldB) => @ | 447 | new = (@fieldA, @fieldB) => @ |
| @@ -458,9 +458,9 @@ print obj | |||
| 458 | 458 | ||
| 459 | </YueDisplay> | 459 | </YueDisplay> |
| 460 | 460 | ||
| 461 | ## Class Expressions | 461 | ## Expressões de classe |
| 462 | 462 | ||
| 463 | The class syntax can also be used as an expression which can be assigned to a variable or explicitly returned. | 463 | A sintaxe de classe também pode ser usada como expressão que pode ser atribuída a uma variável ou retornada explicitamente. |
| 464 | 464 | ||
| 465 | ```yuescript | 465 | ```yuescript |
| 466 | x = class Bucket | 466 | x = class Bucket |
| @@ -477,9 +477,9 @@ x = class Bucket | |||
| 477 | 477 | ||
| 478 | </YueDisplay> | 478 | </YueDisplay> |
| 479 | 479 | ||
| 480 | ## Anonymous classes | 480 | ## Classes anônimas |
| 481 | 481 | ||
| 482 | The name can be left out when declaring a class. The __name attribute will be nil, unless the class expression is in an assignment. The name on the left hand side of the assignment is used instead of nil. | 482 | O nome pode ser omitido ao declarar uma classe. O atributo __name será nil, a menos que a expressão da classe esteja em uma atribuição. O nome no lado esquerdo da atribuição é usado em vez de nil. |
| 483 | 483 | ||
| 484 | ```yuescript | 484 | ```yuescript |
| 485 | BigBucket = class extends Bucket | 485 | BigBucket = class extends Bucket |
| @@ -498,7 +498,7 @@ assert Bucket.__name == "BigBucket" | |||
| 498 | 498 | ||
| 499 | </YueDisplay> | 499 | </YueDisplay> |
| 500 | 500 | ||
| 501 | You can even leave off the body, meaning you can write a blank anonymous class like this: | 501 | Você pode até omitir o corpo, significando que pode escrever uma classe anônima em branco assim: |
| 502 | 502 | ||
| 503 | ```yuescript | 503 | ```yuescript |
| 504 | x = class | 504 | x = class |
| @@ -511,9 +511,9 @@ x = class | |||
| 511 | 511 | ||
| 512 | </YueDisplay> | 512 | </YueDisplay> |
| 513 | 513 | ||
| 514 | ## Class Mixing | 514 | ## Mistura de classes |
| 515 | 515 | ||
| 516 | You can do mixing with keyword `using` to copy functions from either a plain table or a predefined class object into your new class. When doing mixing with a plain table, you can override the class indexing function (metamethod `__index`) to your customized implementation. When doing mixing with an existing class object, the class object's metamethods won't be copied. | 516 | Você pode fazer mistura com a palavra-chave `using` para copiar funções de uma tabela simples ou de um objeto de classe predefinido para sua nova classe. Ao fazer mistura com uma tabela simples, você pode sobrescrever a função de indexação da classe (metamétodo `__index`) para sua implementação personalizada. Ao fazer mistura com um objeto de classe existente, os metamétodos do objeto da classe não serão copiados. |
| 517 | 517 | ||
| 518 | ```yuescript | 518 | ```yuescript |
| 519 | MyIndex = __index: var: 1 | 519 | MyIndex = __index: var: 1 |
| @@ -530,7 +530,7 @@ class Y using X | |||
| 530 | y = Y! | 530 | y = Y! |
| 531 | y\func! | 531 | y\func! |
| 532 | 532 | ||
| 533 | assert y.__class.__parent ~= X -- X is not parent of Y | 533 | assert y.__class.__parent ~= X -- X não é pai de Y |
| 534 | ``` | 534 | ``` |
| 535 | <YueDisplay> | 535 | <YueDisplay> |
| 536 | 536 | ||
| @@ -549,7 +549,7 @@ class Y using X | |||
| 549 | y = Y! | 549 | y = Y! |
| 550 | y\func! | 550 | y\func! |
| 551 | 551 | ||
| 552 | assert y.__class.__parent ~= X -- X is not parent of Y | 552 | assert y.__class.__parent ~= X -- X não é pai de Y |
| 553 | ``` | 553 | ``` |
| 554 | 554 | ||
| 555 | </YueDisplay> | 555 | </YueDisplay> |
diff --git a/doc/docs/pt-br/doc/objects/with-statement.md b/doc/docs/pt-br/doc/objects/with-statement.md index 7786803..6495d09 100644 --- a/doc/docs/pt-br/doc/objects/with-statement.md +++ b/doc/docs/pt-br/doc/objects/with-statement.md | |||
| @@ -1,13 +1,12 @@ | |||
| 1 | # With Statement | 1 | # Instrução With |
| 2 | 2 | ||
| 3 | Um padrão comum envolvendo a criação de um objeto é chamar uma série de funções e definir uma série de propriedades imediatamente após criá-lo. | ||
| 3 | 4 | ||
| 4 | A common pattern involving the creation of an object is calling a series of functions and setting a series of properties immediately after creating it. | 5 | Isso resulta em repetir o nome do objeto várias vezes no código, adicionando ruído desnecessário. Uma solução comum para isso é passar uma tabela como argumento que contém uma coleção de chaves e valores para sobrescrever. O inconveniente é que o construtor desse objeto deve suportar essa forma. |
| 5 | 6 | ||
| 6 | This results in repeating the name of the object multiple times in code, adding unnecessary noise. A common solution to this is to pass a table in as an argument which contains a collection of keys and values to overwrite. The downside to this is that the constructor of this object must support this form. | 7 | O bloco with ajuda a aliviar isso. Dentro de um bloco with podemos usar instruções especiais que começam com . ou \ que representam essas operações aplicadas ao objeto com o qual estamos usando with. |
| 7 | 8 | ||
| 8 | The with block helps to alleviate this. Within a with block we can use a special statements that begin with either . or \ which represent those operations applied to the object we are using with on. | 9 | Por exemplo, trabalhamos com um objeto recém-criado: |
| 9 | |||
| 10 | For example, we work with a newly created object: | ||
| 11 | 10 | ||
| 12 | ```yuescript | 11 | ```yuescript |
| 13 | with Person! | 12 | with Person! |
| @@ -28,7 +27,7 @@ with Person! | |||
| 28 | 27 | ||
| 29 | </YueDisplay> | 28 | </YueDisplay> |
| 30 | 29 | ||
| 31 | The with statement can also be used as an expression which returns the value it has been giving access to. | 30 | A instrução with também pode ser usada como expressão que retorna o valor ao qual foi dado acesso. |
| 32 | 31 | ||
| 33 | ```yuescript | 32 | ```yuescript |
| 34 | file = with File "favorite_foods.txt" | 33 | file = with File "favorite_foods.txt" |
| @@ -43,7 +42,7 @@ file = with File "favorite_foods.txt" | |||
| 43 | 42 | ||
| 44 | </YueDisplay> | 43 | </YueDisplay> |
| 45 | 44 | ||
| 46 | Or… | 45 | Ou… |
| 47 | 46 | ||
| 48 | ```yuescript | 47 | ```yuescript |
| 49 | create_person = (name, relatives) -> | 48 | create_person = (name, relatives) -> |
| @@ -66,9 +65,9 @@ me = create_person "Leaf", [dad, mother, sister] | |||
| 66 | 65 | ||
| 67 | </YueDisplay> | 66 | </YueDisplay> |
| 68 | 67 | ||
| 69 | In this usage, with can be seen as a special form of the K combinator. | 68 | Neste uso, with pode ser visto como uma forma especial do combinador K. |
| 70 | 69 | ||
| 71 | The expression in the with statement can also be an assignment, if you want to give a name to the expression. | 70 | A expressão na instrução with também pode ser uma atribuição, se você quiser dar um nome à expressão. |
| 72 | 71 | ||
| 73 | ```yuescript | 72 | ```yuescript |
| 74 | with str := "Hello" | 73 | with str := "Hello" |
| @@ -85,7 +84,7 @@ with str := "Hello" | |||
| 85 | 84 | ||
| 86 | </YueDisplay> | 85 | </YueDisplay> |
| 87 | 86 | ||
| 88 | You can access special keys with `[]` in a `with` statement. | 87 | Você pode acessar chaves especiais com `[]` em uma instrução `with`. |
| 89 | 88 | ||
| 90 | ```yuescript | 89 | ```yuescript |
| 91 | with tb | 90 | with tb |
| @@ -94,7 +93,7 @@ with tb | |||
| 94 | with [abc] | 93 | with [abc] |
| 95 | [3] = [2]\func! | 94 | [3] = [2]\func! |
| 96 | ["key-name"] = value | 95 | ["key-name"] = value |
| 97 | [] = "abc" -- appending to "tb" | 96 | [] = "abc" -- anexando a "tb" |
| 98 | ``` | 97 | ``` |
| 99 | <YueDisplay> | 98 | <YueDisplay> |
| 100 | 99 | ||
| @@ -105,12 +104,12 @@ with tb | |||
| 105 | with [abc] | 104 | with [abc] |
| 106 | [3] = [2]\func! | 105 | [3] = [2]\func! |
| 107 | ["key-name"] = value | 106 | ["key-name"] = value |
| 108 | [] = "abc" -- appending to "tb" | 107 | [] = "abc" -- anexando a "tb" |
| 109 | ``` | 108 | ``` |
| 110 | 109 | ||
| 111 | </YueDisplay> | 110 | </YueDisplay> |
| 112 | 111 | ||
| 113 | `with?` is an enhanced version of `with` syntax, which introduces an existential check to safely access objects that may be nil without explicit null checks. | 112 | `with?` é uma versão aprimorada da sintaxe `with`, que introduz uma verificação existencial para acessar com segurança objetos que podem ser nil sem verificações explícitas de null. |
| 114 | 113 | ||
| 115 | ```yuescript | 114 | ```yuescript |
| 116 | with? obj | 115 | with? obj |
diff --git a/doc/docs/pt-br/doc/reference/license-mit.md b/doc/docs/pt-br/doc/reference/license-mit.md index f1d5d60..0e00e90 100644 --- a/doc/docs/pt-br/doc/reference/license-mit.md +++ b/doc/docs/pt-br/doc/reference/license-mit.md | |||
| @@ -1,23 +1,21 @@ | |||
| 1 | # License: MIT | 1 | # Licença: MIT |
| 2 | 2 | ||
| 3 | Copyright (c) 2017-2026 Li Jin \<dragon-fly@qq.com\> | 3 | Copyright (c) 2017-2026 Li Jin \<dragon-fly@qq.com\> |
| 4 | 4 | ||
| 5 | Permission is hereby granted, free of charge, to any person obtaining a copy | 5 | A permissão é concedida, gratuitamente, a qualquer pessoa que obtenha uma cópia |
| 6 | of this software and associated documentation files (the "Software"), to deal | 6 | deste software e dos arquivos de documentação associados (o "Software"), para negociar |
| 7 | in the Software without restriction, including without limitation the rights | 7 | o Software sem restrições, incluindo, sem limitação, os direitos de usar, copiar, |
| 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 8 | modificar, mesclar, publicar, distribuir, sublicenciar e/ou vender |
| 9 | copies of the Software, and to permit persons to whom the Software is | 9 | cópias do Software, e permitir que pessoas a quem o Software seja fornecido o façam, |
| 10 | furnished to do so, subject to the following conditions: | 10 | sujeito às seguintes condições: |
| 11 | 11 | ||
| 12 | The above copyright notice and this permission notice shall be included in all | 12 | O aviso de direitos autorais acima e este aviso de permissão devem ser incluídos em todas as |
| 13 | copies or substantial portions of the Software. | 13 | cópias ou partes substanciais do Software. |
| 14 | 14 | ||
| 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 15 | O SOFTWARE É FORNECIDO "NO ESTADO EM QUE SE ENCONTRA", SEM GARANTIA DE QUALQUER TIPO, |
| 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 16 | EXPRESSA OU IMPLÍCITA, INCLUINDO, MAS NÃO SE LIMITANDO ÀS GARANTIAS DE COMERCIALIZAÇÃO, |
| 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 17 | ADEQUAÇÃO A UM DETERMINADO FIM E NÃO VIOLAÇÃO. EM NENHUMA HIPÓTESE OS AUTORES OU |
| 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 18 | DETENTORES DOS DIREITOS AUTORAIS SERÃO RESPONSÁVEIS POR QUAISQUER REIVINDICAÇÕES, |
| 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 19 | DANOS OU OUTRAS RESPONSABILIDADES, SEJA EM UMA AÇÃO DE CONTRATO, ATO ILÍCITO OU OUTRA, |
| 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | 20 | DECORRENTES DE, FORA DE OU RELACIONADAS COM O SOFTWARE OU O USO OU OUTRAS NEGOCIAÇÕES |
| 21 | SOFTWARE. | 21 | NO SOFTWARE. |
| 22 | |||
| 23 | <CompilerModal /> | ||
diff --git a/doc/docs/pt-br/doc/reference/the-yuescript-library.md b/doc/docs/pt-br/doc/reference/the-yuescript-library.md index 3761755..2a65ffb 100644 --- a/doc/docs/pt-br/doc/reference/the-yuescript-library.md +++ b/doc/docs/pt-br/doc/reference/the-yuescript-library.md | |||
| @@ -1,61 +1,61 @@ | |||
| 1 | # The YueScript Library | 1 | # A biblioteca YueScript |
| 2 | 2 | ||
| 3 | Access it by `local yue = require("yue")` in Lua. | 3 | Acesse com `local yue = require("yue")` no Lua. |
| 4 | 4 | ||
| 5 | ## yue | 5 | ## yue |
| 6 | 6 | ||
| 7 | **Description:** | 7 | **Descrição:** |
| 8 | 8 | ||
| 9 | The YueScript language library. | 9 | A biblioteca da linguagem YueScript. |
| 10 | 10 | ||
| 11 | ### version | 11 | ### version |
| 12 | 12 | ||
| 13 | **Type:** Field. | 13 | **Tipo:** Campo. |
| 14 | 14 | ||
| 15 | **Description:** | 15 | **Descrição:** |
| 16 | 16 | ||
| 17 | The YueScript version. | 17 | A versão do YueScript. |
| 18 | 18 | ||
| 19 | **Signature:** | 19 | **Assinatura:** |
| 20 | ```lua | 20 | ```lua |
| 21 | version: string | 21 | version: string |
| 22 | ``` | 22 | ``` |
| 23 | 23 | ||
| 24 | ### dirsep | 24 | ### dirsep |
| 25 | 25 | ||
| 26 | **Type:** Field. | 26 | **Tipo:** Campo. |
| 27 | 27 | ||
| 28 | **Description:** | 28 | **Descrição:** |
| 29 | 29 | ||
| 30 | The file separator for the current platform. | 30 | O separador de arquivos da plataforma atual. |
| 31 | 31 | ||
| 32 | **Signature:** | 32 | **Assinatura:** |
| 33 | ```lua | 33 | ```lua |
| 34 | dirsep: string | 34 | dirsep: string |
| 35 | ``` | 35 | ``` |
| 36 | 36 | ||
| 37 | ### yue_compiled | 37 | ### yue_compiled |
| 38 | 38 | ||
| 39 | **Type:** Field. | 39 | **Tipo:** Campo. |
| 40 | 40 | ||
| 41 | **Description:** | 41 | **Descrição:** |
| 42 | 42 | ||
| 43 | The compiled module code cache. | 43 | O cache de código de módulo compilado. |
| 44 | 44 | ||
| 45 | **Signature:** | 45 | **Assinatura:** |
| 46 | ```lua | 46 | ```lua |
| 47 | yue_compiled: {string: string} | 47 | yue_compiled: {string: string} |
| 48 | ``` | 48 | ``` |
| 49 | 49 | ||
| 50 | ### to_lua | 50 | ### to_lua |
| 51 | 51 | ||
| 52 | **Type:** Function. | 52 | **Tipo:** Função. |
| 53 | 53 | ||
| 54 | **Description:** | 54 | **Descrição:** |
| 55 | 55 | ||
| 56 | The YueScript compiling function. It compiles the YueScript code to Lua code. | 56 | A função de compilação do YueScript. Compila o código YueScript para código Lua. |
| 57 | 57 | ||
| 58 | **Signature:** | 58 | **Assinatura:** |
| 59 | ```lua | 59 | ```lua |
| 60 | to_lua: function(code: string, config?: Config): | 60 | to_lua: function(code: string, config?: Config): |
| 61 | --[[codes]] string | nil, | 61 | --[[codes]] string | nil, |
| @@ -63,682 +63,682 @@ to_lua: function(code: string, config?: Config): | |||
| 63 | --[[globals]] {{string, integer, integer}} | nil | 63 | --[[globals]] {{string, integer, integer}} | nil |
| 64 | ``` | 64 | ``` |
| 65 | 65 | ||
| 66 | **Parameters:** | 66 | **Parâmetros:** |
| 67 | 67 | ||
| 68 | | Parameter | Type | Description | | 68 | | Parâmetro | Tipo | Descrição | |
| 69 | | --- | --- | --- | | 69 | | --- | --- | --- | |
| 70 | | code | string | The YueScript code. | | 70 | | code | string | O código YueScript. | |
| 71 | | config | Config | [Optional] The compiler options. | | 71 | | config | Config | [Opcional] As opções do compilador. | |
| 72 | 72 | ||
| 73 | **Returns:** | 73 | **Retorna:** |
| 74 | 74 | ||
| 75 | | Return Type | Description | | 75 | | Tipo de Retorno | Descrição | |
| 76 | | --- | --- | | 76 | | --- | --- | |
| 77 | | string \| nil | The compiled Lua code, or nil if the compilation failed. | | 77 | | string \| nil | O código Lua compilado, ou nil se a compilação falhou. | |
| 78 | | string \| nil | The error message, or nil if the compilation succeeded. | | 78 | | string \| nil | A mensagem de erro, ou nil se a compilação foi bem-sucedida. | |
| 79 | | {{string, integer, integer}} \| nil | The global variables appearing in the code (with name, row and column), or nil if the compiler option `lint_global` is false. | | 79 | | {{string, integer, integer}} \| nil | As variáveis globais que aparecem no código (com nome, linha e coluna), ou nil se a opção do compilador `lint_global` for false. | |
| 80 | 80 | ||
| 81 | ### file_exist | 81 | ### file_exist |
| 82 | 82 | ||
| 83 | **Type:** Function. | 83 | **Tipo:** Função. |
| 84 | 84 | ||
| 85 | **Description:** | 85 | **Descrição:** |
| 86 | 86 | ||
| 87 | The source file existence checking function. Can be overridden to customize the behavior. | 87 | Função de verificação de existência do arquivo fonte. Pode ser sobrescrita para personalizar o comportamento. |
| 88 | 88 | ||
| 89 | **Signature:** | 89 | **Assinatura:** |
| 90 | ```lua | 90 | ```lua |
| 91 | file_exist: function(filename: string): boolean | 91 | file_exist: function(filename: string): boolean |
| 92 | ``` | 92 | ``` |
| 93 | 93 | ||
| 94 | **Parameters:** | 94 | **Parâmetros:** |
| 95 | 95 | ||
| 96 | | Parameter | Type | Description | | 96 | | Parâmetro | Tipo | Descrição | |
| 97 | | --- | --- | --- | | 97 | | --- | --- | --- | |
| 98 | | filename | string | The file name. | | 98 | | filename | string | O nome do arquivo. | |
| 99 | 99 | ||
| 100 | **Returns:** | 100 | **Retorna:** |
| 101 | 101 | ||
| 102 | | Return Type | Description | | 102 | | Tipo de Retorno | Descrição | |
| 103 | | --- | --- | | 103 | | --- | --- | |
| 104 | | boolean | Whether the file exists. | | 104 | | boolean | Se o arquivo existe. | |
| 105 | 105 | ||
| 106 | ### read_file | 106 | ### read_file |
| 107 | 107 | ||
| 108 | **Type:** Function. | 108 | **Tipo:** Função. |
| 109 | 109 | ||
| 110 | **Description:** | 110 | **Descrição:** |
| 111 | 111 | ||
| 112 | The source file reading function. Can be overridden to customize the behavior. | 112 | Função de leitura do arquivo fonte. Pode ser sobrescrita para personalizar o comportamento. |
| 113 | 113 | ||
| 114 | **Signature:** | 114 | **Assinatura:** |
| 115 | ```lua | 115 | ```lua |
| 116 | read_file: function(filename: string): string | 116 | read_file: function(filename: string): string |
| 117 | ``` | 117 | ``` |
| 118 | 118 | ||
| 119 | **Parameters:** | 119 | **Parâmetros:** |
| 120 | 120 | ||
| 121 | | Parameter | Type | Description | | 121 | | Parâmetro | Tipo | Descrição | |
| 122 | | --- | --- | --- | | 122 | | --- | --- | --- | |
| 123 | | filename | string | The file name. | | 123 | | filename | string | O nome do arquivo. | |
| 124 | 124 | ||
| 125 | **Returns:** | 125 | **Retorna:** |
| 126 | 126 | ||
| 127 | | Return Type | Description | | 127 | | Tipo de Retorno | Descrição | |
| 128 | | --- | --- | | 128 | | --- | --- | |
| 129 | | string | The file content. | | 129 | | string | O conteúdo do arquivo. | |
| 130 | 130 | ||
| 131 | ### insert_loader | 131 | ### insert_loader |
| 132 | 132 | ||
| 133 | **Type:** Function. | 133 | **Tipo:** Função. |
| 134 | 134 | ||
| 135 | **Description:** | 135 | **Descrição:** |
| 136 | 136 | ||
| 137 | Insert the YueScript loader to the package loaders (searchers). | 137 | Insere o carregador YueScript nos carregadores de pacote (searchers). |
| 138 | 138 | ||
| 139 | **Signature:** | 139 | **Assinatura:** |
| 140 | ```lua | 140 | ```lua |
| 141 | insert_loader: function(pos?: integer): boolean | 141 | insert_loader: function(pos?: integer): boolean |
| 142 | ``` | 142 | ``` |
| 143 | 143 | ||
| 144 | **Parameters:** | 144 | **Parâmetros:** |
| 145 | 145 | ||
| 146 | | Parameter | Type | Description | | 146 | | Parâmetro | Tipo | Descrição | |
| 147 | | --- | --- | --- | | 147 | | --- | --- | --- | |
| 148 | | pos | integer | [Optional] The position to insert the loader. Default is 3. | | 148 | | pos | integer | [Opcional] A posição para inserir o carregador. Padrão é 3. | |
| 149 | 149 | ||
| 150 | **Returns:** | 150 | **Retorna:** |
| 151 | 151 | ||
| 152 | | Return Type | Description | | 152 | | Tipo de Retorno | Descrição | |
| 153 | | --- | --- | | 153 | | --- | --- | |
| 154 | | boolean | Whether the loader is inserted successfully. It will fail if the loader is already inserted. | | 154 | | boolean | Se o carregador foi inserido com sucesso. Falhará se o carregador já estiver inserido. | |
| 155 | 155 | ||
| 156 | ### remove_loader | 156 | ### remove_loader |
| 157 | 157 | ||
| 158 | **Type:** Function. | 158 | **Tipo:** Função. |
| 159 | 159 | ||
| 160 | **Description:** | 160 | **Descrição:** |
| 161 | 161 | ||
| 162 | Remove the YueScript loader from the package loaders (searchers). | 162 | Remove o carregador YueScript dos carregadores de pacote (searchers). |
| 163 | 163 | ||
| 164 | **Signature:** | 164 | **Assinatura:** |
| 165 | ```lua | 165 | ```lua |
| 166 | remove_loader: function(): boolean | 166 | remove_loader: function(): boolean |
| 167 | ``` | 167 | ``` |
| 168 | 168 | ||
| 169 | **Returns:** | 169 | **Retorna:** |
| 170 | 170 | ||
| 171 | | Return Type | Description | | 171 | | Tipo de Retorno | Descrição | |
| 172 | | --- | --- | | 172 | | --- | --- | |
| 173 | | boolean | Whether the loader is removed successfully. It will fail if the loader is not inserted. | | 173 | | boolean | Se o carregador foi removido com sucesso. Falhará se o carregador não estiver inserido. | |
| 174 | 174 | ||
| 175 | ### loadstring | 175 | ### loadstring |
| 176 | 176 | ||
| 177 | **Type:** Function. | 177 | **Tipo:** Função. |
| 178 | 178 | ||
| 179 | **Description:** | 179 | **Descrição:** |
| 180 | 180 | ||
| 181 | Loads YueScript code from a string into a function. | 181 | Carrega código YueScript de uma string em uma função. |
| 182 | 182 | ||
| 183 | **Signature:** | 183 | **Assinatura:** |
| 184 | ```lua | 184 | ```lua |
| 185 | loadstring: function(input: string, chunkname: string, env: table, config?: Config): | 185 | loadstring: function(input: string, chunkname: string, env: table, config?: Config): |
| 186 | --[[loaded function]] nil | function(...: any): (any...), | 186 | --[[loaded function]] nil | function(...: any): (any...), |
| 187 | --[[error]] string | nil | 187 | --[[error]] string | nil |
| 188 | ``` | 188 | ``` |
| 189 | 189 | ||
| 190 | **Parameters:** | 190 | **Parâmetros:** |
| 191 | 191 | ||
| 192 | | Parameter | Type | Description | | 192 | | Parâmetro | Tipo | Descrição | |
| 193 | | --- | --- | --- | | 193 | | --- | --- | --- | |
| 194 | | input | string | The YueScript code. | | 194 | | input | string | O código YueScript. | |
| 195 | | chunkname | string | The name of the code chunk. | | 195 | | chunkname | string | O nome do chunk de código. | |
| 196 | | env | table | The environment table. | | 196 | | env | table | A tabela de ambiente. | |
| 197 | | config | Config | [Optional] The compiler options. | | 197 | | config | Config | [Opcional] As opções do compilador. | |
| 198 | 198 | ||
| 199 | **Returns:** | 199 | **Retorna:** |
| 200 | 200 | ||
| 201 | | Return Type | Description | | 201 | | Tipo de Retorno | Descrição | |
| 202 | | --- | --- | | 202 | | --- | --- | |
| 203 | | function \| nil | The loaded function, or nil if the loading failed. | | 203 | | function \| nil | A função carregada, ou nil se o carregamento falhou. | |
| 204 | | string \| nil | The error message, or nil if the loading succeeded. | | 204 | | string \| nil | A mensagem de erro, ou nil se o carregamento foi bem-sucedido. | |
| 205 | 205 | ||
| 206 | ### loadstring | 206 | ### loadstring |
| 207 | 207 | ||
| 208 | **Type:** Function. | 208 | **Tipo:** Função. |
| 209 | 209 | ||
| 210 | **Description:** | 210 | **Descrição:** |
| 211 | 211 | ||
| 212 | Loads YueScript code from a string into a function. | 212 | Carrega código YueScript de uma string em uma função. |
| 213 | 213 | ||
| 214 | **Signature:** | 214 | **Assinatura:** |
| 215 | ```lua | 215 | ```lua |
| 216 | loadstring: function(input: string, chunkname: string, config?: Config): | 216 | loadstring: function(input: string, chunkname: string, config?: Config): |
| 217 | --[[loaded function]] nil | function(...: any): (any...), | 217 | --[[loaded function]] nil | function(...: any): (any...), |
| 218 | --[[error]] string | nil | 218 | --[[error]] string | nil |
| 219 | ``` | 219 | ``` |
| 220 | 220 | ||
| 221 | **Parameters:** | 221 | **Parâmetros:** |
| 222 | 222 | ||
| 223 | | Parameter | Type | Description | | 223 | | Parâmetro | Tipo | Descrição | |
| 224 | | --- | --- | --- | | 224 | | --- | --- | --- | |
| 225 | | input | string | The YueScript code. | | 225 | | input | string | O código YueScript. | |
| 226 | | chunkname | string | The name of the code chunk. | | 226 | | chunkname | string | O nome do chunk de código. | |
| 227 | | config | Config | [Optional] The compiler options. | | 227 | | config | Config | [Opcional] As opções do compilador. | |
| 228 | 228 | ||
| 229 | **Returns:** | 229 | **Retorna:** |
| 230 | 230 | ||
| 231 | | Return Type | Description | | 231 | | Tipo de Retorno | Descrição | |
| 232 | | --- | --- | | 232 | | --- | --- | |
| 233 | | function \| nil | The loaded function, or nil if the loading failed. | | 233 | | function \| nil | A função carregada, ou nil se o carregamento falhou. | |
| 234 | | string \| nil | The error message, or nil if the loading succeeded. | | 234 | | string \| nil | A mensagem de erro, ou nil se o carregamento foi bem-sucedido. | |
| 235 | 235 | ||
| 236 | ### loadstring | 236 | ### loadstring |
| 237 | 237 | ||
| 238 | **Type:** Function. | 238 | **Tipo:** Função. |
| 239 | 239 | ||
| 240 | **Description:** | 240 | **Descrição:** |
| 241 | 241 | ||
| 242 | Loads YueScript code from a string into a function. | 242 | Carrega código YueScript de uma string em uma função. |
| 243 | 243 | ||
| 244 | **Signature:** | 244 | **Assinatura:** |
| 245 | ```lua | 245 | ```lua |
| 246 | loadstring: function(input: string, config?: Config): | 246 | loadstring: function(input: string, config?: Config): |
| 247 | --[[loaded function]] nil | function(...: any): (any...), | 247 | --[[loaded function]] nil | function(...: any): (any...), |
| 248 | --[[error]] string | nil | 248 | --[[error]] string | nil |
| 249 | ``` | 249 | ``` |
| 250 | 250 | ||
| 251 | **Parameters:** | 251 | **Parâmetros:** |
| 252 | 252 | ||
| 253 | | Parameter | Type | Description | | 253 | | Parâmetro | Tipo | Descrição | |
| 254 | | --- | --- | --- | | 254 | | --- | --- | --- | |
| 255 | | input | string | The YueScript code. | | 255 | | input | string | O código YueScript. | |
| 256 | | config | Config | [Optional] The compiler options. | | 256 | | config | Config | [Opcional] As opções do compilador. | |
| 257 | 257 | ||
| 258 | **Returns:** | 258 | **Retorna:** |
| 259 | 259 | ||
| 260 | | Return Type | Description | | 260 | | Tipo de Retorno | Descrição | |
| 261 | | --- | --- | | 261 | | --- | --- | |
| 262 | | function \| nil | The loaded function, or nil if the loading failed. | | 262 | | function \| nil | A função carregada, ou nil se o carregamento falhou. | |
| 263 | | string \| nil | The error message, or nil if the loading succeeded. | | 263 | | string \| nil | A mensagem de erro, ou nil se o carregamento foi bem-sucedido. | |
| 264 | 264 | ||
| 265 | ### loadfile | 265 | ### loadfile |
| 266 | 266 | ||
| 267 | **Type:** Function. | 267 | **Tipo:** Função. |
| 268 | 268 | ||
| 269 | **Description:** | 269 | **Descrição:** |
| 270 | 270 | ||
| 271 | Loads YueScript code from a file into a function. | 271 | Carrega código YueScript de um arquivo em uma função. |
| 272 | 272 | ||
| 273 | **Signature:** | 273 | **Assinatura:** |
| 274 | ```lua | 274 | ```lua |
| 275 | loadfile: function(filename: string, env: table, config?: Config): | 275 | loadfile: function(filename: string, env: table, config?: Config): |
| 276 | nil | function(...: any): (any...), | 276 | nil | function(...: any): (any...), |
| 277 | string | nil | 277 | string | nil |
| 278 | ``` | 278 | ``` |
| 279 | 279 | ||
| 280 | **Parameters:** | 280 | **Parâmetros:** |
| 281 | 281 | ||
| 282 | | Parameter | Type | Description | | 282 | | Parâmetro | Tipo | Descrição | |
| 283 | | --- | --- | --- | | 283 | | --- | --- | --- | |
| 284 | | filename | string | The file name. | | 284 | | filename | string | O nome do arquivo. | |
| 285 | | env | table | The environment table. | | 285 | | env | table | A tabela de ambiente. | |
| 286 | | config | Config | [Optional] The compiler options. | | 286 | | config | Config | [Opcional] As opções do compilador. | |
| 287 | 287 | ||
| 288 | **Returns:** | 288 | **Retorna:** |
| 289 | 289 | ||
| 290 | | Return Type | Description | | 290 | | Tipo de Retorno | Descrição | |
| 291 | | --- | --- | | 291 | | --- | --- | |
| 292 | | function \| nil | The loaded function, or nil if the loading failed. | | 292 | | function \| nil | A função carregada, ou nil se o carregamento falhou. | |
| 293 | | string \| nil | The error message, or nil if the loading succeeded. | | 293 | | string \| nil | A mensagem de erro, ou nil se o carregamento foi bem-sucedido. | |
| 294 | 294 | ||
| 295 | ### loadfile | 295 | ### loadfile |
| 296 | 296 | ||
| 297 | **Type:** Function. | 297 | **Tipo:** Função. |
| 298 | 298 | ||
| 299 | **Description:** | 299 | **Descrição:** |
| 300 | 300 | ||
| 301 | Loads YueScript code from a file into a function. | 301 | Carrega código YueScript de um arquivo em uma função. |
| 302 | 302 | ||
| 303 | **Signature:** | 303 | **Assinatura:** |
| 304 | ```lua | 304 | ```lua |
| 305 | loadfile: function(filename: string, config?: Config): | 305 | loadfile: function(filename: string, config?: Config): |
| 306 | nil | function(...: any): (any...), | 306 | nil | function(...: any): (any...), |
| 307 | string | nil | 307 | string | nil |
| 308 | ``` | 308 | ``` |
| 309 | 309 | ||
| 310 | **Parameters:** | 310 | **Parâmetros:** |
| 311 | 311 | ||
| 312 | | Parameter | Type | Description | | 312 | | Parâmetro | Tipo | Descrição | |
| 313 | | --- | --- | --- | | 313 | | --- | --- | --- | |
| 314 | | filename | string | The file name. | | 314 | | filename | string | O nome do arquivo. | |
| 315 | | config | Config | [Optional] The compiler options. | | 315 | | config | Config | [Opcional] As opções do compilador. | |
| 316 | 316 | ||
| 317 | **Returns:** | 317 | **Retorna:** |
| 318 | 318 | ||
| 319 | | Return Type | Description | | 319 | | Tipo de Retorno | Descrição | |
| 320 | | --- | --- | | 320 | | --- | --- | |
| 321 | | function \| nil | The loaded function, or nil if the loading failed. | | 321 | | function \| nil | A função carregada, ou nil se o carregamento falhou. | |
| 322 | | string \| nil | The error message, or nil if the loading succeeded. | | 322 | | string \| nil | A mensagem de erro, ou nil se o carregamento foi bem-sucedido. | |
| 323 | 323 | ||
| 324 | ### dofile | 324 | ### dofile |
| 325 | 325 | ||
| 326 | **Type:** Function. | 326 | **Tipo:** Função. |
| 327 | 327 | ||
| 328 | **Description:** | 328 | **Descrição:** |
| 329 | 329 | ||
| 330 | Loads YueScript code from a file into a function and executes it. | 330 | Carrega código YueScript de um arquivo em uma função e o executa. |
| 331 | 331 | ||
| 332 | **Signature:** | 332 | **Assinatura:** |
| 333 | ```lua | 333 | ```lua |
| 334 | dofile: function(filename: string, env: table, config?: Config): any... | 334 | dofile: function(filename: string, env: table, config?: Config): any... |
| 335 | ``` | 335 | ``` |
| 336 | 336 | ||
| 337 | **Parameters:** | 337 | **Parâmetros:** |
| 338 | 338 | ||
| 339 | | Parameter | Type | Description | | 339 | | Parâmetro | Tipo | Descrição | |
| 340 | | --- | --- | --- | | 340 | | --- | --- | --- | |
| 341 | | filename | string | The file name. | | 341 | | filename | string | O nome do arquivo. | |
| 342 | | env | table | The environment table. | | 342 | | env | table | A tabela de ambiente. | |
| 343 | | config | Config | [Optional] The compiler options. | | 343 | | config | Config | [Opcional] As opções do compilador. | |
| 344 | 344 | ||
| 345 | **Returns:** | 345 | **Retorna:** |
| 346 | 346 | ||
| 347 | | Return Type | Description | | 347 | | Tipo de Retorno | Descrição | |
| 348 | | --- | --- | | 348 | | --- | --- | |
| 349 | | any... | The return values of the loaded function. | | 349 | | any... | Os valores de retorno da função carregada. | |
| 350 | 350 | ||
| 351 | ### dofile | 351 | ### dofile |
| 352 | 352 | ||
| 353 | **Type:** Function. | 353 | **Tipo:** Função. |
| 354 | 354 | ||
| 355 | **Description:** | 355 | **Descrição:** |
| 356 | 356 | ||
| 357 | Loads YueScript code from a file into a function and executes it. | 357 | Carrega código YueScript de um arquivo em uma função e o executa. |
| 358 | 358 | ||
| 359 | **Signature:** | 359 | **Assinatura:** |
| 360 | ```lua | 360 | ```lua |
| 361 | dofile: function(filename: string, config?: Config): any... | 361 | dofile: function(filename: string, config?: Config): any... |
| 362 | ``` | 362 | ``` |
| 363 | 363 | ||
| 364 | **Parameters:** | 364 | **Parâmetros:** |
| 365 | 365 | ||
| 366 | | Parameter | Type | Description | | 366 | | Parâmetro | Tipo | Descrição | |
| 367 | | --- | --- | --- | | 367 | | --- | --- | --- | |
| 368 | | filename | string | The file name. | | 368 | | filename | string | O nome do arquivo. | |
| 369 | | config | Config | [Optional] The compiler options. | | 369 | | config | Config | [Opcional] As opções do compilador. | |
| 370 | 370 | ||
| 371 | **Returns:** | 371 | **Retorna:** |
| 372 | 372 | ||
| 373 | | Return Type | Description | | 373 | | Tipo de Retorno | Descrição | |
| 374 | | --- | --- | | 374 | | --- | --- | |
| 375 | | any... | The return values of the loaded function. | | 375 | | any... | Os valores de retorno da função carregada. | |
| 376 | 376 | ||
| 377 | ### find_modulepath | 377 | ### find_modulepath |
| 378 | 378 | ||
| 379 | **Type:** Function. | 379 | **Tipo:** Função. |
| 380 | 380 | ||
| 381 | **Description:** | 381 | **Descrição:** |
| 382 | 382 | ||
| 383 | Resolves the YueScript module name to the file path. | 383 | Resolve o nome do módulo YueScript para o caminho do arquivo. |
| 384 | 384 | ||
| 385 | **Signature:** | 385 | **Assinatura:** |
| 386 | ```lua | 386 | ```lua |
| 387 | find_modulepath: function(name: string): string | 387 | find_modulepath: function(name: string): string |
| 388 | ``` | 388 | ``` |
| 389 | 389 | ||
| 390 | **Parameters:** | 390 | **Parâmetros:** |
| 391 | 391 | ||
| 392 | | Parameter | Type | Description | | 392 | | Parâmetro | Tipo | Descrição | |
| 393 | | --- | --- | --- | | 393 | | --- | --- | --- | |
| 394 | | name | string | The module name. | | 394 | | name | string | O nome do módulo. | |
| 395 | 395 | ||
| 396 | **Returns:** | 396 | **Retorna:** |
| 397 | 397 | ||
| 398 | | Return Type | Description | | 398 | | Tipo de Retorno | Descrição | |
| 399 | | --- | --- | | 399 | | --- | --- | |
| 400 | | string | The file path. | | 400 | | string | O caminho do arquivo. | |
| 401 | 401 | ||
| 402 | ### pcall | 402 | ### pcall |
| 403 | 403 | ||
| 404 | **Type:** Function. | 404 | **Tipo:** Função. |
| 405 | 405 | ||
| 406 | **Description:** | 406 | **Descrição:** |
| 407 | 407 | ||
| 408 | Calls a function in protected mode. | 408 | Chama uma função em modo protegido. |
| 409 | Catches any errors and returns a status code and results or error object. | 409 | Captura quaisquer erros e retorna um código de status e resultados ou objeto de erro. |
| 410 | Rewrites the error line number to the original line number in the YueScript code when errors occur. | 410 | Reescreve o número da linha do erro para o número da linha original no código YueScript quando ocorrem erros. |
| 411 | 411 | ||
| 412 | **Signature:** | 412 | **Assinatura:** |
| 413 | ```lua | 413 | ```lua |
| 414 | pcall: function(f: function, ...: any): boolean, any... | 414 | pcall: function(f: function, ...: any): boolean, any... |
| 415 | ``` | 415 | ``` |
| 416 | 416 | ||
| 417 | **Parameters:** | 417 | **Parâmetros:** |
| 418 | 418 | ||
| 419 | | Parameter | Type | Description | | 419 | | Parâmetro | Tipo | Descrição | |
| 420 | | --- | --- | --- | | 420 | | --- | --- | --- | |
| 421 | | f | function | The function to call. | | 421 | | f | function | A função a chamar. | |
| 422 | | ... | any | Arguments to pass to the function. | | 422 | | ... | any | Argumentos a passar para a função. | |
| 423 | 423 | ||
| 424 | **Returns:** | 424 | **Retorna:** |
| 425 | 425 | ||
| 426 | | Return Type | Description | | 426 | | Tipo de Retorno | Descrição | |
| 427 | | --- | --- | | 427 | | --- | --- | |
| 428 | | boolean, ... | Status code and function results or error object. | | 428 | | boolean, ... | Código de status e resultados da função ou objeto de erro. | |
| 429 | 429 | ||
| 430 | ### require | 430 | ### require |
| 431 | 431 | ||
| 432 | **Type:** Function. | 432 | **Tipo:** Função. |
| 433 | 433 | ||
| 434 | **Description:** | 434 | **Descrição:** |
| 435 | 435 | ||
| 436 | Loads a given module. Can be either a Lua module or a YueScript module. | 436 | Carrega um módulo dado. Pode ser um módulo Lua ou um módulo YueScript. |
| 437 | Rewrites the error line number to the original line number in the YueScript code if the module is a YueScript module and loading fails. | 437 | Reescreve o número da linha do erro para o número da linha original no código YueScript se o módulo for um módulo YueScript e o carregamento falhar. |
| 438 | 438 | ||
| 439 | **Signature:** | 439 | **Assinatura:** |
| 440 | ```lua | 440 | ```lua |
| 441 | require: function(name: string): any... | 441 | require: function(name: string): any... |
| 442 | ``` | 442 | ``` |
| 443 | 443 | ||
| 444 | **Parameters:** | 444 | **Parâmetros:** |
| 445 | 445 | ||
| 446 | | Parameter | Type | Description | | 446 | | Parâmetro | Tipo | Descrição | |
| 447 | | --- | --- | --- | | 447 | | --- | --- | --- | |
| 448 | | modname | string | The name of the module to load. | | 448 | | modname | string | O nome do módulo a carregar. | |
| 449 | 449 | ||
| 450 | **Returns:** | 450 | **Retorna:** |
| 451 | 451 | ||
| 452 | | Return Type | Description | | 452 | | Tipo de Retorno | Descrição | |
| 453 | | --- | --- | | 453 | | --- | --- | |
| 454 | | any | The value stored at package.loaded[modname] if the module is already loaded.Otherwise, tries to find a loader and returns the final value of package.loaded[modname] and a loader data as a second result. | | 454 | | any | O valor armazenado em package.loaded[modname] se o módulo já estiver carregado. Caso contrário, tenta encontrar um carregador e retorna o valor final de package.loaded[modname] e os dados do carregador como segundo resultado. | |
| 455 | 455 | ||
| 456 | ### p | 456 | ### p |
| 457 | 457 | ||
| 458 | **Type:** Function. | 458 | **Tipo:** Função. |
| 459 | 459 | ||
| 460 | **Description:** | 460 | **Descrição:** |
| 461 | 461 | ||
| 462 | Inspects the structures of the passed values and prints string representations. | 462 | Inspeciona as estruturas dos valores passados e imprime representações em string. |
| 463 | 463 | ||
| 464 | **Signature:** | 464 | **Assinatura:** |
| 465 | ```lua | 465 | ```lua |
| 466 | p: function(...: any) | 466 | p: function(...: any) |
| 467 | ``` | 467 | ``` |
| 468 | 468 | ||
| 469 | **Parameters:** | 469 | **Parâmetros:** |
| 470 | 470 | ||
| 471 | | Parameter | Type | Description | | 471 | | Parâmetro | Tipo | Descrição | |
| 472 | | --- | --- | --- | | 472 | | --- | --- | --- | |
| 473 | | ... | any | The values to inspect. | | 473 | | ... | any | Os valores a inspecionar. | |
| 474 | 474 | ||
| 475 | ### options | 475 | ### options |
| 476 | 476 | ||
| 477 | **Type:** Field. | 477 | **Tipo:** Campo. |
| 478 | 478 | ||
| 479 | **Description:** | 479 | **Descrição:** |
| 480 | 480 | ||
| 481 | The current compiler options. | 481 | As opções atuais do compilador. |
| 482 | 482 | ||
| 483 | **Signature:** | 483 | **Assinatura:** |
| 484 | ```lua | 484 | ```lua |
| 485 | options: Config.Options | 485 | options: Config.Options |
| 486 | ``` | 486 | ``` |
| 487 | 487 | ||
| 488 | ### traceback | 488 | ### traceback |
| 489 | 489 | ||
| 490 | **Type:** Function. | 490 | **Tipo:** Função. |
| 491 | 491 | ||
| 492 | **Description:** | 492 | **Descrição:** |
| 493 | 493 | ||
| 494 | The traceback function that rewrites the stack trace line numbers to the original line numbers in the YueScript code. | 494 | A função traceback que reescreve os números das linhas do stack trace para os números das linhas originais no código YueScript. |
| 495 | 495 | ||
| 496 | **Signature:** | 496 | **Assinatura:** |
| 497 | ```lua | 497 | ```lua |
| 498 | traceback: function(message: string): string | 498 | traceback: function(message: string): string |
| 499 | ``` | 499 | ``` |
| 500 | 500 | ||
| 501 | **Parameters:** | 501 | **Parâmetros:** |
| 502 | 502 | ||
| 503 | | Parameter | Type | Description | | 503 | | Parâmetro | Tipo | Descrição | |
| 504 | | --- | --- | --- | | 504 | | --- | --- | --- | |
| 505 | | message | string | The traceback message. | | 505 | | message | string | A mensagem de traceback. | |
| 506 | 506 | ||
| 507 | **Returns:** | 507 | **Retorna:** |
| 508 | 508 | ||
| 509 | | Return Type | Description | | 509 | | Tipo de Retorno | Descrição | |
| 510 | | --- | --- | | 510 | | --- | --- | |
| 511 | | string | The rewritten traceback message. | | 511 | | string | A mensagem de traceback reescrita. | |
| 512 | 512 | ||
| 513 | ### is_ast | 513 | ### is_ast |
| 514 | 514 | ||
| 515 | **Type:** Function. | 515 | **Tipo:** Função. |
| 516 | 516 | ||
| 517 | **Description:** | 517 | **Descrição:** |
| 518 | 518 | ||
| 519 | Checks whether the code matches the specified AST. | 519 | Verifica se o código corresponde ao AST especificado. |
| 520 | 520 | ||
| 521 | **Signature:** | 521 | **Assinatura:** |
| 522 | ```lua | 522 | ```lua |
| 523 | is_ast: function(astName: string, code: string): boolean | 523 | is_ast: function(astName: string, code: string): boolean |
| 524 | ``` | 524 | ``` |
| 525 | 525 | ||
| 526 | **Parameters:** | 526 | **Parâmetros:** |
| 527 | 527 | ||
| 528 | | Parameter | Type | Description | | 528 | | Parâmetro | Tipo | Descrição | |
| 529 | | --- | --- | --- | | 529 | | --- | --- | --- | |
| 530 | | astName | string | The AST name. | | 530 | | astName | string | O nome do AST. | |
| 531 | | code | string | The code. | | 531 | | code | string | O código. | |
| 532 | 532 | ||
| 533 | **Returns:** | 533 | **Retorna:** |
| 534 | 534 | ||
| 535 | | Return Type | Description | | 535 | | Tipo de Retorno | Descrição | |
| 536 | | --- | --- | | 536 | | --- | --- | |
| 537 | | boolean | Whether the code matches the AST. | | 537 | | boolean | Se o código corresponde ao AST. | |
| 538 | 538 | ||
| 539 | ### AST | 539 | ### AST |
| 540 | 540 | ||
| 541 | **Type:** Field. | 541 | **Tipo:** Campo. |
| 542 | 542 | ||
| 543 | **Description:** | 543 | **Descrição:** |
| 544 | 544 | ||
| 545 | The AST type definition with name, row, column and sub nodes. | 545 | A definição do tipo AST com nome, linha, coluna e subnós. |
| 546 | 546 | ||
| 547 | **Signature:** | 547 | **Assinatura:** |
| 548 | ```lua | 548 | ```lua |
| 549 | type AST = {string, integer, integer, any} | 549 | type AST = {string, integer, integer, any} |
| 550 | ``` | 550 | ``` |
| 551 | 551 | ||
| 552 | ### to_ast | 552 | ### to_ast |
| 553 | 553 | ||
| 554 | **Type:** Function. | 554 | **Tipo:** Função. |
| 555 | 555 | ||
| 556 | **Description:** | 556 | **Descrição:** |
| 557 | 557 | ||
| 558 | Converts the code to the AST. | 558 | Converte o código para o AST. |
| 559 | 559 | ||
| 560 | **Signature:** | 560 | **Assinatura:** |
| 561 | ```lua | 561 | ```lua |
| 562 | to_ast: function(code: string, flattenLevel?: number, astName?: string, reserveComment?: boolean): | 562 | to_ast: function(code: string, flattenLevel?: number, astName?: string, reserveComment?: boolean): |
| 563 | --[[AST]] AST | nil, | 563 | --[[AST]] AST | nil, |
| 564 | --[[error]] nil | string | 564 | --[[error]] nil | string |
| 565 | ``` | 565 | ``` |
| 566 | 566 | ||
| 567 | **Parameters:** | 567 | **Parâmetros:** |
| 568 | 568 | ||
| 569 | | Parameter | Type | Description | | 569 | | Parâmetro | Tipo | Descrição | |
| 570 | | --- | --- | --- | | 570 | | --- | --- | --- | |
| 571 | | code | string | The code. | | 571 | | code | string | O código. | |
| 572 | | flattenLevel | integer | [Optional] The flatten level. Higher level means more flattening. Default is 0. Maximum is 2. | | 572 | | flattenLevel | integer | [Opcional] O nível de achatamento. Nível mais alto significa mais achatamento. Padrão é 0. Máximo é 2. | |
| 573 | | astName | string | [Optional] The AST name. Default is "File". | | 573 | | astName | string | [Opcional] O nome do AST. Padrão é "File". | |
| 574 | | reserveComment | boolean | [Optional] Whether to reserve the original comments. Default is false. | | 574 | | reserveComment | boolean | [Opcional] Se deve preservar os comentários originais. Padrão é false. | |
| 575 | 575 | ||
| 576 | **Returns:** | 576 | **Retorna:** |
| 577 | 577 | ||
| 578 | | Return Type | Description | | 578 | | Tipo de Retorno | Descrição | |
| 579 | | --- | --- | | 579 | | --- | --- | |
| 580 | | AST \| nil | The AST, or nil if the conversion failed. | | 580 | | AST \| nil | O AST, ou nil se a conversão falhou. | |
| 581 | | string \| nil | The error message, or nil if the conversion succeeded. | | 581 | | string \| nil | A mensagem de erro, ou nil se a conversão foi bem-sucedida. | |
| 582 | 582 | ||
| 583 | ### format | 583 | ### format |
| 584 | 584 | ||
| 585 | **Type:** Function. | 585 | **Tipo:** Função. |
| 586 | 586 | ||
| 587 | **Description:** | 587 | **Descrição:** |
| 588 | 588 | ||
| 589 | Formats the YueScript code. | 589 | Formata o código YueScript. |
| 590 | 590 | ||
| 591 | **Signature:** | 591 | **Assinatura:** |
| 592 | ```lua | 592 | ```lua |
| 593 | format: function(code: string, tabSize?: number, reserveComment?: boolean): string | 593 | format: function(code: string, tabSize?: number, reserveComment?: boolean): string |
| 594 | ``` | 594 | ``` |
| 595 | 595 | ||
| 596 | **Parameters:** | 596 | **Parâmetros:** |
| 597 | 597 | ||
| 598 | | Parameter | Type | Description | | 598 | | Parâmetro | Tipo | Descrição | |
| 599 | | --- | --- | --- | | 599 | | --- | --- | --- | |
| 600 | | code | string | The code. | | 600 | | code | string | O código. | |
| 601 | | tabSize | integer | [Optional] The tab size. Default is 4. | | 601 | | tabSize | integer | [Opcional] O tamanho da tabulação. Padrão é 4. | |
| 602 | | reserveComment | boolean | [Optional] Whether to reserve the original comments. Default is true. | | 602 | | reserveComment | boolean | [Opcional] Se deve preservar os comentários originais. Padrão é true. | |
| 603 | 603 | ||
| 604 | **Returns:** | 604 | **Retorna:** |
| 605 | 605 | ||
| 606 | | Return Type | Description | | 606 | | Tipo de Retorno | Descrição | |
| 607 | | --- | --- | | 607 | | --- | --- | |
| 608 | | string | The formatted code. | | 608 | | string | O código formatado. | |
| 609 | 609 | ||
| 610 | ### __call | 610 | ### __call |
| 611 | 611 | ||
| 612 | **Type:** Metamethod. | 612 | **Tipo:** Metamétodo. |
| 613 | 613 | ||
| 614 | **Description:** | 614 | **Descrição:** |
| 615 | 615 | ||
| 616 | Requires the YueScript module. | 616 | Requer o módulo YueScript. |
| 617 | Rewrites the error line number to the original line number in the YueScript code when loading fails. | 617 | Reescreve o número da linha do erro para o número da linha original no código YueScript quando o carregamento falha. |
| 618 | 618 | ||
| 619 | **Signature:** | 619 | **Assinatura:** |
| 620 | ```lua | 620 | ```lua |
| 621 | metamethod __call: function(self: yue, module: string): any... | 621 | metamethod __call: function(self: yue, module: string): any... |
| 622 | ``` | 622 | ``` |
| 623 | 623 | ||
| 624 | **Parameters:** | 624 | **Parâmetros:** |
| 625 | 625 | ||
| 626 | | Parameter | Type | Description | | 626 | | Parâmetro | Tipo | Descrição | |
| 627 | | --- | --- | --- | | 627 | | --- | --- | --- | |
| 628 | | module | string | The module name. | | 628 | | module | string | O nome do módulo. | |
| 629 | 629 | ||
| 630 | **Returns:** | 630 | **Retorna:** |
| 631 | 631 | ||
| 632 | | Return Type | Description | | 632 | | Tipo de Retorno | Descrição | |
| 633 | | --- | --- | | 633 | | --- | --- | |
| 634 | | any | The module value. | | 634 | | any | O valor do módulo. | |
| 635 | 635 | ||
| 636 | ## Config | 636 | ## Config |
| 637 | 637 | ||
| 638 | **Description:** | 638 | **Descrição:** |
| 639 | 639 | ||
| 640 | The compiler compile options. | 640 | As opções de compilação do compilador. |
| 641 | 641 | ||
| 642 | ### lint_global | 642 | ### lint_global |
| 643 | 643 | ||
| 644 | **Type:** Field. | 644 | **Tipo:** Campo. |
| 645 | 645 | ||
| 646 | **Description:** | 646 | **Descrição:** |
| 647 | 647 | ||
| 648 | Whether the compiler should collect the global variables appearing in the code. | 648 | Se o compilador deve coletar as variáveis globais que aparecem no código. |
| 649 | 649 | ||
| 650 | **Signature:** | 650 | **Assinatura:** |
| 651 | ```lua | 651 | ```lua |
| 652 | lint_global: boolean | 652 | lint_global: boolean |
| 653 | ``` | 653 | ``` |
| 654 | 654 | ||
| 655 | ### implicit_return_root | 655 | ### implicit_return_root |
| 656 | 656 | ||
| 657 | **Type:** Field. | 657 | **Tipo:** Campo. |
| 658 | 658 | ||
| 659 | **Description:** | 659 | **Descrição:** |
| 660 | 660 | ||
| 661 | Whether the compiler should do an implicit return for the root code block. | 661 | Se o compilador deve fazer retorno implícito para o bloco de código raiz. |
| 662 | 662 | ||
| 663 | **Signature:** | 663 | **Assinatura:** |
| 664 | ```lua | 664 | ```lua |
| 665 | implicit_return_root: boolean | 665 | implicit_return_root: boolean |
| 666 | ``` | 666 | ``` |
| 667 | 667 | ||
| 668 | ### reserve_line_number | 668 | ### reserve_line_number |
| 669 | 669 | ||
| 670 | **Type:** Field. | 670 | **Tipo:** Campo. |
| 671 | 671 | ||
| 672 | **Description:** | 672 | **Descrição:** |
| 673 | 673 | ||
| 674 | Whether the compiler should reserve the original line number in the compiled code. | 674 | Se o compilador deve preservar o número da linha original no código compilado. |
| 675 | 675 | ||
| 676 | **Signature:** | 676 | **Assinatura:** |
| 677 | ```lua | 677 | ```lua |
| 678 | reserve_line_number: boolean | 678 | reserve_line_number: boolean |
| 679 | ``` | 679 | ``` |
| 680 | 680 | ||
| 681 | ### reserve_comment | 681 | ### reserve_comment |
| 682 | 682 | ||
| 683 | **Type:** Field. | 683 | **Tipo:** Campo. |
| 684 | 684 | ||
| 685 | **Description:** | 685 | **Descrição:** |
| 686 | 686 | ||
| 687 | Whether the compiler should reserve the original comments in the compiled code. | 687 | Se o compilador deve preservar os comentários originais no código compilado. |
| 688 | 688 | ||
| 689 | **Signature:** | 689 | **Assinatura:** |
| 690 | ```lua | 690 | ```lua |
| 691 | reserve_comment: boolean | 691 | reserve_comment: boolean |
| 692 | ``` | 692 | ``` |
| 693 | 693 | ||
| 694 | ### space_over_tab | 694 | ### space_over_tab |
| 695 | 695 | ||
| 696 | **Type:** Field. | 696 | **Tipo:** Campo. |
| 697 | 697 | ||
| 698 | **Description:** | 698 | **Descrição:** |
| 699 | 699 | ||
| 700 | Whether the compiler should use the space character instead of the tab character in the compiled code. | 700 | Se o compilador deve usar o caractere de espaço em vez do caractere de tabulação no código compilado. |
| 701 | 701 | ||
| 702 | **Signature:** | 702 | **Assinatura:** |
| 703 | ```lua | 703 | ```lua |
| 704 | space_over_tab: boolean | 704 | space_over_tab: boolean |
| 705 | ``` | 705 | ``` |
| 706 | 706 | ||
| 707 | ### same_module | 707 | ### same_module |
| 708 | 708 | ||
| 709 | **Type:** Field. | 709 | **Tipo:** Campo. |
| 710 | 710 | ||
| 711 | **Description:** | 711 | **Descrição:** |
| 712 | 712 | ||
| 713 | Whether the compiler should treat the code to be compiled as the same currently being compiled module. For internal use only. | 713 | Se o compilador deve tratar o código a ser compilado como o mesmo módulo que está sendo compilado atualmente. Apenas para uso interno. |
| 714 | 714 | ||
| 715 | **Signature:** | 715 | **Assinatura:** |
| 716 | ```lua | 716 | ```lua |
| 717 | same_module: boolean | 717 | same_module: boolean |
| 718 | ``` | 718 | ``` |
| 719 | 719 | ||
| 720 | ### line_offset | 720 | ### line_offset |
| 721 | 721 | ||
| 722 | **Type:** Field. | 722 | **Tipo:** Campo. |
| 723 | 723 | ||
| 724 | **Description:** | 724 | **Descrição:** |
| 725 | 725 | ||
| 726 | Whether the compiler error message should include the line number offset. For internal use only. | 726 | Se a mensagem de erro do compilador deve incluir o deslocamento do número da linha. Apenas para uso interno. |
| 727 | 727 | ||
| 728 | **Signature:** | 728 | **Assinatura:** |
| 729 | ```lua | 729 | ```lua |
| 730 | line_offset: integer | 730 | line_offset: integer |
| 731 | ``` | 731 | ``` |
| 732 | 732 | ||
| 733 | ### yue.Config.LuaTarget | 733 | ### yue.Config.LuaTarget |
| 734 | 734 | ||
| 735 | **Type:** Enumeration. | 735 | **Tipo:** Enumeração. |
| 736 | 736 | ||
| 737 | **Description:** | 737 | **Descrição:** |
| 738 | 738 | ||
| 739 | The target Lua version enumeration. | 739 | A enumeração da versão alvo do Lua. |
| 740 | 740 | ||
| 741 | **Signature:** | 741 | **Assinatura:** |
| 742 | ```lua | 742 | ```lua |
| 743 | enum LuaTarget | 743 | enum LuaTarget |
| 744 | "5.1" | 744 | "5.1" |
| @@ -751,71 +751,71 @@ end | |||
| 751 | 751 | ||
| 752 | ### options | 752 | ### options |
| 753 | 753 | ||
| 754 | **Type:** Field. | 754 | **Tipo:** Campo. |
| 755 | 755 | ||
| 756 | **Description:** | 756 | **Descrição:** |
| 757 | 757 | ||
| 758 | The extra options to be passed to the compilation function. | 758 | As opções extras a serem passadas para a função de compilação. |
| 759 | 759 | ||
| 760 | **Signature:** | 760 | **Assinatura:** |
| 761 | ```lua | 761 | ```lua |
| 762 | options: Options | 762 | options: Options |
| 763 | ``` | 763 | ``` |
| 764 | 764 | ||
| 765 | ## Options | 765 | ## Options |
| 766 | 766 | ||
| 767 | **Description:** | 767 | **Descrição:** |
| 768 | 768 | ||
| 769 | The extra compiler options definition. | 769 | A definição das opções extras do compilador. |
| 770 | 770 | ||
| 771 | ### target | 771 | ### target |
| 772 | 772 | ||
| 773 | **Type:** Field. | 773 | **Tipo:** Campo. |
| 774 | 774 | ||
| 775 | **Description:** | 775 | **Descrição:** |
| 776 | 776 | ||
| 777 | The target Lua version for the compilation. | 777 | A versão alvo do Lua para a compilação. |
| 778 | 778 | ||
| 779 | **Signature:** | 779 | **Assinatura:** |
| 780 | ```lua | 780 | ```lua |
| 781 | target: LuaTarget | 781 | target: LuaTarget |
| 782 | ``` | 782 | ``` |
| 783 | 783 | ||
| 784 | ### path | 784 | ### path |
| 785 | 785 | ||
| 786 | **Type:** Field. | 786 | **Tipo:** Campo. |
| 787 | 787 | ||
| 788 | **Description:** | 788 | **Descrição:** |
| 789 | 789 | ||
| 790 | The extra module search path. | 790 | O caminho de busca de módulo extra. |
| 791 | 791 | ||
| 792 | **Signature:** | 792 | **Assinatura:** |
| 793 | ```lua | 793 | ```lua |
| 794 | path: string | 794 | path: string |
| 795 | ``` | 795 | ``` |
| 796 | 796 | ||
| 797 | ### dump_locals | 797 | ### dump_locals |
| 798 | 798 | ||
| 799 | **Type:** Field. | 799 | **Tipo:** Campo. |
| 800 | 800 | ||
| 801 | **Description:** | 801 | **Descrição:** |
| 802 | 802 | ||
| 803 | Whether to dump the local variables in the traceback error message. Default is false. | 803 | Se deve incluir as variáveis locais na mensagem de erro do traceback. Padrão é false. |
| 804 | 804 | ||
| 805 | **Signature:** | 805 | **Assinatura:** |
| 806 | ```lua | 806 | ```lua |
| 807 | dump_locals: boolean | 807 | dump_locals: boolean |
| 808 | ``` | 808 | ``` |
| 809 | 809 | ||
| 810 | ### simplified | 810 | ### simplified |
| 811 | 811 | ||
| 812 | **Type:** Field. | 812 | **Tipo:** Campo. |
| 813 | 813 | ||
| 814 | **Description:** | 814 | **Descrição:** |
| 815 | 815 | ||
| 816 | Whether to simplify the error message. Default is true. | 816 | Se deve simplificar a mensagem de erro. Padrão é true. |
| 817 | 817 | ||
| 818 | **Signature:** | 818 | **Assinatura:** |
| 819 | ```lua | 819 | ```lua |
| 820 | simplified: boolean | 820 | simplified: boolean |
| 821 | ``` | 821 | ``` |
diff --git a/doc/docs/zh/doc/control-flow/conditionals.md b/doc/docs/zh/doc/control-flow/conditionals.md index e4b217a..ba77f40 100644 --- a/doc/docs/zh/doc/control-flow/conditionals.md +++ b/doc/docs/zh/doc/control-flow/conditionals.md | |||
| @@ -137,14 +137,3 @@ if a in list | |||
| 137 | ``` | 137 | ``` |
| 138 | 138 | ||
| 139 | </YueDisplay> | 139 | </YueDisplay> |
| 140 | |||
| 141 | ```yuescript | ||
| 142 | print "你很幸运!" unless math.random! > 0.1 | ||
| 143 | ``` | ||
| 144 | <YueDisplay> | ||
| 145 | |||
| 146 | ```yue | ||
| 147 | print "你很幸运!" unless math.random! > 0.1 | ||
| 148 | ``` | ||
| 149 | |||
| 150 | </YueDisplay> | ||
diff --git a/doc/docs/zh/doc/reference/license-mit.md b/doc/docs/zh/doc/reference/license-mit.md index 1a07518..24b5b15 100644 --- a/doc/docs/zh/doc/reference/license-mit.md +++ b/doc/docs/zh/doc/reference/license-mit.md | |||
| @@ -5,5 +5,3 @@ | |||
| 5 | 特此免费授予任何获得本软件副本和相关文档文件(下称“软件”)的人不受限制地处置该软件的权利,包括不受限制地使用、复制、修改、合并、发布、分发、转授许可和/或出售该软件副本,以及再授权被配发了本软件的人如上的权利,须在下列条件下: | 5 | 特此免费授予任何获得本软件副本和相关文档文件(下称“软件”)的人不受限制地处置该软件的权利,包括不受限制地使用、复制、修改、合并、发布、分发、转授许可和/或出售该软件副本,以及再授权被配发了本软件的人如上的权利,须在下列条件下: |
| 6 | 上述版权声明和本许可声明应包含在该软件的所有副本或实质成分中。 | 6 | 上述版权声明和本许可声明应包含在该软件的所有副本或实质成分中。 |
| 7 | 本软件是“如此”提供的,没有任何形式的明示或暗示的保证,包括但不限于对适销性、特定用途的适用性和不侵权的保证。在任何情况下,作者或版权持有人都不对任何索赔、损害或其他责任负责,无论这些追责来自合同、侵权或其它行为中,还是产生于、源于或有关于本软件以及本软件的使用或其它处置。 | 7 | 本软件是“如此”提供的,没有任何形式的明示或暗示的保证,包括但不限于对适销性、特定用途的适用性和不侵权的保证。在任何情况下,作者或版权持有人都不对任何索赔、损害或其他责任负责,无论这些追责来自合同、侵权或其它行为中,还是产生于、源于或有关于本软件以及本软件的使用或其它处置。 |
| 8 | |||
| 9 | <CompilerModal /> | ||
