aboutsummaryrefslogtreecommitdiff
path: root/doc/docs/de
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2026-02-06 08:42:20 +0800
committerLi Jin <dragon-fly@qq.com>2026-02-06 08:42:20 +0800
commitb350a76827329e05e97c25e07bb8ea2a7efe30b4 (patch)
tree81d865d8e5856c4c991385c0d0856522d803f075 /doc/docs/de
parent5d7a9205df3c20f5b6a0464f3e1123394a7ca23a (diff)
downloadyuescript-codex/add-portuguese-and-german-language-support.tar.gz
yuescript-codex/add-portuguese-and-german-language-support.tar.bz2
yuescript-codex/add-portuguese-and-german-language-support.zip
docs: add German and Portuguese (Brazil) localescodex/add-portuguese-and-german-language-support
Diffstat (limited to 'doc/docs/de')
-rw-r--r--doc/docs/de/doc/assignment.md138
-rw-r--r--doc/docs/de/doc/attributes.md46
-rw-r--r--doc/docs/de/doc/backcalls.md69
-rw-r--r--doc/docs/de/doc/comment.md30
-rw-r--r--doc/docs/de/doc/comprehensions.md271
-rw-r--r--doc/docs/de/doc/conditionals.md149
-rw-r--r--doc/docs/de/doc/continue.md41
-rw-r--r--doc/docs/de/doc/destructuring-assignment.md240
-rw-r--r--doc/docs/de/doc/do.md66
-rw-r--r--doc/docs/de/doc/for-loop.md127
-rw-r--r--doc/docs/de/doc/function-literals.md494
-rw-r--r--doc/docs/de/doc/function-stubs.md48
-rw-r--r--doc/docs/de/doc/if-assignment.md72
-rwxr-xr-xdoc/docs/de/doc/index.md11
-rw-r--r--doc/docs/de/doc/installation.md43
-rw-r--r--doc/docs/de/doc/introduction.md105
-rw-r--r--doc/docs/de/doc/licence-mit.md23
-rw-r--r--doc/docs/de/doc/line-decorators.md44
-rw-r--r--doc/docs/de/doc/literals.md110
-rw-r--r--doc/docs/de/doc/macro.md275
-rw-r--r--doc/docs/de/doc/module.md245
-rw-r--r--doc/docs/de/doc/object-oriented-programming.md555
-rw-r--r--doc/docs/de/doc/operator.md460
-rw-r--r--doc/docs/de/doc/switch.md296
-rw-r--r--doc/docs/de/doc/table-literals.md168
-rw-r--r--doc/docs/de/doc/the-using-clause-controlling-destructive-assignment.md98
-rw-r--r--doc/docs/de/doc/the-yuescript-library.md821
-rw-r--r--doc/docs/de/doc/try.md105
-rw-r--r--doc/docs/de/doc/usage.md111
-rw-r--r--doc/docs/de/doc/varargs-assignment.md24
-rw-r--r--doc/docs/de/doc/while-loop.md69
-rw-r--r--doc/docs/de/doc/whitespace.md43
-rw-r--r--doc/docs/de/doc/with-statement.md126
-rw-r--r--doc/docs/de/index.md24
-rwxr-xr-xdoc/docs/de/try/index.md6
35 files changed, 5553 insertions, 0 deletions
diff --git a/doc/docs/de/doc/assignment.md b/doc/docs/de/doc/assignment.md
new file mode 100644
index 0000000..4dac6f4
--- /dev/null
+++ b/doc/docs/de/doc/assignment.md
@@ -0,0 +1,138 @@
1# Assignment
2
3The variable is dynamic typed and is defined as local by default. But you can change the scope of declaration by **local** and **global** statement.
4
5```yuescript
6hello = "world"
7a, b, c = 1, 2, 3
8hello = 123 -- uses the existing variable
9```
10<YueDisplay>
11
12```yue
13hello = "world"
14a, b, c = 1, 2, 3
15hello = 123 -- uses the existing variable
16```
17
18</YueDisplay>
19
20## Perform Update
21
22You can perform update assignment with many binary operators.
23```yuescript
24x = 1
25x += 1
26x -= 1
27x *= 10
28x /= 10
29x %= 10
30s ..= "world" -- will add a new local if local variable is not exist
31arg or= "default value"
32```
33<YueDisplay>
34
35```yue
36x = 1
37x += 1
38x -= 1
39x *= 10
40x /= 10
41x %= 10
42s ..= "world" -- will add a new local if local variable is not exist
43arg or= "default value"
44```
45
46</YueDisplay>
47
48## Chaining Assignment
49
50You can do chaining assignment to assign multiple items to hold the same value.
51```yuescript
52a = b = c = d = e = 0
53x = y = z = f!
54```
55<YueDisplay>
56
57```yue
58a = b = c = d = e = 0
59x = y = z = f!
60```
61
62</YueDisplay>
63
64## Explicit Locals
65```yuescript
66do
67 local a = 1
68 local *
69 print "forward declare all variables as locals"
70 x = -> 1 + y + z
71 y, z = 2, 3
72 global instance = Item\new!
73
74do
75 local X = 1
76 local ^
77 print "only forward declare upper case variables"
78 a = 1
79 B = 2
80```
81<YueDisplay>
82
83```yue
84do
85 local a = 1
86 local *
87 print "forward declare all variables as locals"
88 x = -> 1 + y + z
89 y, z = 2, 3
90 global instance = Item\new!
91
92do
93 local X = 1
94 local ^
95 print "only forward declare upper case variables"
96 a = 1
97 B = 2
98```
99
100</YueDisplay>
101
102## Explicit Globals
103```yuescript
104do
105 global a = 1
106 global *
107 print "declare all variables as globals"
108 x = -> 1 + y + z
109 y, z = 2, 3
110
111do
112 global X = 1
113 global ^
114 print "only declare upper case variables as globals"
115 a = 1
116 B = 2
117 local Temp = "a local value"
118```
119<YueDisplay>
120
121```yue
122do
123 global a = 1
124 global *
125 print "declare all variables as globals"
126 x = -> 1 + y + z
127 y, z = 2, 3
128
129do
130 global X = 1
131 global ^
132 print "only declare upper case variables as globals"
133 a = 1
134 B = 2
135 local Temp = "a local value"
136```
137
138</YueDisplay>
diff --git a/doc/docs/de/doc/attributes.md b/doc/docs/de/doc/attributes.md
new file mode 100644
index 0000000..e6fd5a7
--- /dev/null
+++ b/doc/docs/de/doc/attributes.md
@@ -0,0 +1,46 @@
1# Attributes
2
3Syntax 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.
4
5```yuescript
6const a = 123
7close _ = <close>: -> print "Out of scope."
8```
9<YueDisplay>
10
11```yue
12const a = 123
13close _ = <close>: -> print "Out of scope."
14```
15
16</YueDisplay>
17
18You can do desctructuring with variables attributed as constant.
19
20```yuescript
21const {:a, :b, c, d} = tb
22-- a = 1
23```
24<YueDisplay>
25
26```yue
27const {:a, :b, c, d} = tb
28-- a = 1
29```
30
31</YueDisplay>
32
33You can also declare a global variable to be `const`.
34
35```yuescript
36global const Constant = 123
37-- Constant = 1
38```
39<YueDisplay>
40
41```yue
42global const Constant = 123
43-- Constant = 1
44```
45
46</YueDisplay>
diff --git a/doc/docs/de/doc/backcalls.md b/doc/docs/de/doc/backcalls.md
new file mode 100644
index 0000000..e34331e
--- /dev/null
+++ b/doc/docs/de/doc/backcalls.md
@@ -0,0 +1,69 @@
1# Backcalls
2
3Backcalls 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.
4
5```yuescript
6x <- f
7print "hello" .. x
8```
9<YueDisplay>
10
11```yue
12x <- f
13print "hello" .. x
14```
15
16</YueDisplay>
17
18Fat arrow functions are also available.
19
20```yuescript
21<= f
22print @value
23```
24<YueDisplay>
25
26```yue
27<= f
28print @value
29```
30
31</YueDisplay>
32
33You can specify a placeholder for where you want the backcall function to go as a parameter.
34
35```yuescript
36(x) <- map _, [1, 2, 3]
37x * 2
38```
39<YueDisplay>
40
41```yue
42(x) <- map _, [1, 2, 3]
43x * 2
44```
45
46</YueDisplay>
47
48If 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.
49
50```yuescript
51result, msg = do
52 data <- readAsync "filename.txt"
53 print data
54 info <- processAsync data
55 check info
56print result, msg
57```
58<YueDisplay>
59
60```yue
61result, msg = do
62 data <- readAsync "filename.txt"
63 print data
64 info <- processAsync data
65 check info
66print result, msg
67```
68
69</YueDisplay>
diff --git a/doc/docs/de/doc/comment.md b/doc/docs/de/doc/comment.md
new file mode 100644
index 0000000..b67c97d
--- /dev/null
+++ b/doc/docs/de/doc/comment.md
@@ -0,0 +1,30 @@
1# Comment
2
3```yuescript
4-- I am a comment
5
6str = --[[
7This is a multi-line comment.
8It's OK.
9]] strA \ -- comment 1
10 .. strB \ -- comment 2
11 .. strC
12
13func --[[port]] 3000, --[[ip]] "192.168.1.1"
14```
15<YueDisplay>
16
17```yue
18-- I am a comment
19
20str = --[[
21This is a multi-line comment.
22It's OK.
23]] strA \ -- comment 1
24 .. strB \ -- comment 2
25 .. strC
26
27func --[[port]] 3000, --[[ip]] "192.168.1.1"
28```
29
30</YueDisplay>
diff --git a/doc/docs/de/doc/comprehensions.md b/doc/docs/de/doc/comprehensions.md
new file mode 100644
index 0000000..3a92167
--- /dev/null
+++ b/doc/docs/de/doc/comprehensions.md
@@ -0,0 +1,271 @@
1# Comprehensions
2
3Comprehensions 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.
4
5## List Comprehensions
6
7The following creates a copy of the items table but with all the values doubled.
8
9```yuescript
10items = [ 1, 2, 3, 4 ]
11doubled = [item * 2 for i, item in ipairs items]
12```
13<YueDisplay>
14
15```yue
16items = [ 1, 2, 3, 4 ]
17doubled = [item * 2 for i, item in ipairs items]
18```
19
20</YueDisplay>
21
22The items included in the new table can be restricted with a when clause:
23
24```yuescript
25slice = [item for i, item in ipairs items when i > 1 and i < 3]
26```
27<YueDisplay>
28
29```yue
30slice = [item for i, item in ipairs items when i > 1 and i < 3]
31```
32
33</YueDisplay>
34
35Because it is common to iterate over the values of a numerically indexed table, an **\*** operator is introduced. The doubled example can be rewritten as:
36
37```yuescript
38doubled = [item * 2 for item in *items]
39```
40<YueDisplay>
41
42```yue
43doubled = [item * 2 for item in *items]
44```
45
46</YueDisplay>
47
48In list comprehensions, you can also use the spread operator `...` to flatten nested lists, achieving a flat map effect:
49
50```yuescript
51data =
52 a: [1, 2, 3]
53 b: [4, 5, 6]
54
55flat = [...v for k,v in pairs data]
56-- flat is now [1, 2, 3, 4, 5, 6]
57```
58<YueDisplay>
59
60```yue
61data =
62 a: [1, 2, 3]
63 b: [4, 5, 6]
64
65flat = [...v for k,v in pairs data]
66-- flat is now [1, 2, 3, 4, 5, 6]
67```
68
69</YueDisplay>
70
71The for and when clauses can be chained as much as desired. The only requirement is that a comprehension has at least one for clause.
72
73Using multiple for clauses is the same as using nested loops:
74
75```yuescript
76x_coords = [4, 5, 6, 7]
77y_coords = [9, 2, 3]
78
79points = [ [x, y] for x in *x_coords \
80for y in *y_coords]
81```
82<YueDisplay>
83
84```yue
85x_coords = [4, 5, 6, 7]
86y_coords = [9, 2, 3]
87
88points = [ [x, y] for x in *x_coords \
89for y in *y_coords]
90```
91
92</YueDisplay>
93
94Numeric for loops can also be used in comprehensions:
95
96```yuescript
97evens = [i for i = 1, 100 when i % 2 == 0]
98```
99<YueDisplay>
100
101```yue
102evens = [i for i = 1, 100 when i % 2 == 0]
103```
104
105</YueDisplay>
106
107## Table Comprehensions
108
109The syntax for table comprehensions is very similar, only differing by using **{** and **}** and taking two values from each iteration.
110
111This example makes a copy of the tablething:
112
113```yuescript
114thing = {
115 color: "red"
116 name: "fast"
117 width: 123
118}
119
120thing_copy = {k, v for k, v in pairs thing}
121```
122<YueDisplay>
123
124```yue
125thing = {
126 color: "red"
127 name: "fast"
128 width: 123
129}
130
131thing_copy = {k, v for k, v in pairs thing}
132```
133
134</YueDisplay>
135
136```yuescript
137no_color = {k, v for k, v in pairs thing when k != "color"}
138```
139<YueDisplay>
140
141```yue
142no_color = {k, v for k, v in pairs thing when k != "color"}
143```
144
145</YueDisplay>
146
147The **\*** operator is also supported. Here we create a square root look up table for a few numbers.
148
149```yuescript
150numbers = [1, 2, 3, 4]
151sqrts = {i, math.sqrt i for i in *numbers}
152```
153<YueDisplay>
154
155```yue
156numbers = [1, 2, 3, 4]
157sqrts = {i, math.sqrt i for i in *numbers}
158```
159
160</YueDisplay>
161
162The 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:
163
164In 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.
165
166```yuescript
167tuples = [ ["hello", "world"], ["foo", "bar"]]
168tbl = {unpack tuple for tuple in *tuples}
169```
170<YueDisplay>
171
172```yue
173tuples = [ ["hello", "world"], ["foo", "bar"]]
174tbl = {unpack tuple for tuple in *tuples}
175```
176
177</YueDisplay>
178
179## Slicing
180
181A 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.
182
183Here we can set the minimum and maximum bounds, taking all items with indexes between 1 and 5 inclusive:
184
185```yuescript
186slice = [item for item in *items[1, 5]]
187```
188<YueDisplay>
189
190```yue
191slice = [item for item in *items[1, 5]]
192```
193
194</YueDisplay>
195
196Any 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:
197
198```yuescript
199slice = [item for item in *items[2,]]
200```
201<YueDisplay>
202
203```yue
204slice = [item for item in *items[2,]]
205```
206
207</YueDisplay>
208
209If 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, …)
210
211```yuescript
212slice = [item for item in *items[,,2]]
213```
214<YueDisplay>
215
216```yue
217slice = [item for item in *items[,,2]]
218```
219
220</YueDisplay>
221
222Both the minimum and maximum bounds can be negative, which means that the bounds are counted from the end of the table.
223
224```yuescript
225-- take the last 4 items
226slice = [item for item in *items[-4,-1]]
227```
228<YueDisplay>
229
230```yue
231-- take the last 4 items
232slice = [item for item in *items[-4,-1]]
233```
234
235</YueDisplay>
236
237The step size can also be negative, which means that the items are taken in reverse order.
238
239```yuescript
240reverse_slice = [item for item in *items[-1,1,-1]]
241```
242<YueDisplay>
243
244```yue
245reverse_slice = [item for item in *items[-1,1,-1]]
246```
247
248</YueDisplay>
249
250### Slicing Expression
251
252Slicing can also be used as an expression. This is useful for getting a sub-list of a table.
253
254```yuescript
255-- take the 2nd and 4th items as a new list
256sub_list = items[2, 4]
257
258-- take the last 4 items
259last_four_items = items[-4, -1]
260```
261<YueDisplay>
262
263```yue
264-- take the 2nd and 4th items as a new list
265sub_list = items[2, 4]
266
267-- take the last 4 items
268last_four_items = items[-4, -1]
269```
270
271</YueDisplay>
diff --git a/doc/docs/de/doc/conditionals.md b/doc/docs/de/doc/conditionals.md
new file mode 100644
index 0000000..5ba81cf
--- /dev/null
+++ b/doc/docs/de/doc/conditionals.md
@@ -0,0 +1,149 @@
1# Conditionals
2
3```yuescript
4have_coins = false
5if have_coins
6 print "Got coins"
7else
8 print "No coins"
9```
10<YueDisplay>
11
12```yue
13have_coins = false
14if have_coins
15 print "Got coins"
16else
17 print "No coins"
18```
19
20</YueDisplay>
21
22A short syntax for single statements can also be used:
23
24```yuescript
25have_coins = false
26if have_coins then print "Got coins" else print "No coins"
27```
28<YueDisplay>
29
30```yue
31have_coins = false
32if have_coins then print "Got coins" else print "No coins"
33```
34
35</YueDisplay>
36
37Because if statements can be used as expressions, this can also be written as:
38
39```yuescript
40have_coins = false
41print if have_coins then "Got coins" else "No coins"
42```
43<YueDisplay>
44
45```yue
46have_coins = false
47print if have_coins then "Got coins" else "No coins"
48```
49
50</YueDisplay>
51
52Conditionals can also be used in return statements and assignments:
53
54```yuescript
55is_tall = (name) ->
56 if name == "Rob"
57 true
58 else
59 false
60
61message = if is_tall "Rob"
62 "I am very tall"
63else
64 "I am not so tall"
65
66print message -- prints: I am very tall
67```
68<YueDisplay>
69
70```yue
71is_tall = (name) ->
72 if name == "Rob"
73 true
74 else
75 false
76
77message = if is_tall "Rob"
78 "I am very tall"
79else
80 "I am not so tall"
81
82print message -- prints: I am very tall
83```
84
85</YueDisplay>
86
87The opposite of if is unless:
88
89```yuescript
90unless os.date("%A") == "Monday"
91 print "it is not Monday!"
92```
93<YueDisplay>
94
95```yue
96unless os.date("%A") == "Monday"
97 print "it is not Monday!"
98```
99
100</YueDisplay>
101
102```yuescript
103print "You're lucky!" unless math.random! > 0.1
104```
105<YueDisplay>
106
107```yue
108print "You're lucky!" unless math.random! > 0.1
109```
110
111</YueDisplay>
112
113## In Expression
114
115You can write range checking code with an `in-expression`.
116
117```yuescript
118a = 5
119
120if a in [1, 3, 5, 7]
121 print "checking equality with discrete values"
122
123if a in list
124 print "checking if `a` is in a list"
125```
126<YueDisplay>
127
128```yue
129a = 5
130
131if a in [1, 3, 5, 7]
132 print "checking equality with discrete values"
133
134if a in list
135 print "checking if `a` is in a list"
136```
137
138</YueDisplay>
139
140```yuescript
141print "You're lucky!" unless math.random! > 0.1
142```
143<YueDisplay>
144
145```yue
146print "You're lucky!" unless math.random! > 0.1
147```
148
149</YueDisplay>
diff --git a/doc/docs/de/doc/continue.md b/doc/docs/de/doc/continue.md
new file mode 100644
index 0000000..b000765
--- /dev/null
+++ b/doc/docs/de/doc/continue.md
@@ -0,0 +1,41 @@
1# Continue
2
3A continue statement can be used to skip the current iteration in a loop.
4
5```yuescript
6i = 0
7while i < 10
8 i += 1
9 continue if i % 2 == 0
10 print i
11```
12<YueDisplay>
13
14```yue
15i = 0
16while i < 10
17 i += 1
18 continue if i % 2 == 0
19 print i
20```
21
22</YueDisplay>
23
24continue 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:
25
26```yuescript
27my_numbers = [1, 2, 3, 4, 5, 6]
28odds = for x in *my_numbers
29 continue if x % 2 == 1
30 x
31```
32<YueDisplay>
33
34```yue
35my_numbers = [1, 2, 3, 4, 5, 6]
36odds = for x in *my_numbers
37 continue if x % 2 == 1
38 x
39```
40
41</YueDisplay>
diff --git a/doc/docs/de/doc/destructuring-assignment.md b/doc/docs/de/doc/destructuring-assignment.md
new file mode 100644
index 0000000..e7b8046
--- /dev/null
+++ b/doc/docs/de/doc/destructuring-assignment.md
@@ -0,0 +1,240 @@
1# Destructuring Assignment
2
3Destructuring assignment is a way to quickly extract values from a table by their name or position in array based tables.
4
5Typically 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.
6
7This is best explained with examples. Here is how you would unpack the first two values from a table:
8
9```yuescript
10thing = [1, 2]
11
12[a, b] = thing
13print a, b
14```
15<YueDisplay>
16
17```yue
18thing = [1, 2]
19
20[a, b] = thing
21print a, b
22```
23
24</YueDisplay>
25
26In 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.
27
28```yuescript
29obj = {
30 hello: "world"
31 day: "tuesday"
32 length: 20
33}
34
35{hello: hello, day: the_day} = obj
36print hello, the_day
37
38:day = obj -- OK to do simple destructuring without braces
39```
40<YueDisplay>
41
42```yue
43obj = {
44 hello: "world"
45 day: "tuesday"
46 length: 20
47}
48
49{hello: hello, day: the_day} = obj
50print hello, the_day
51
52:day = obj -- OK to do simple destructuring without braces
53```
54
55</YueDisplay>
56
57This also works with nested data structures as well:
58
59```yuescript
60obj2 = {
61 numbers: [1, 2, 3, 4]
62 properties: {
63 color: "green"
64 height: 13.5
65 }
66}
67
68{numbers: [first, second], properties: {color: color}} = obj2
69print first, second, color
70```
71<YueDisplay>
72
73```yue
74obj2 = {
75 numbers: [1, 2, 3, 4]
76 properties: {
77 color: "green"
78 height: 13.5
79 }
80}
81
82{numbers: [first, second], properties: {color: color}} = obj2
83print first, second, color
84```
85
86</YueDisplay>
87
88If the destructuring statement is complicated, feel free to spread it out over a few lines. A slightly more complicated example:
89
90```yuescript
91{
92 numbers: [first, second]
93 properties: {
94 color: color
95 }
96} = obj2
97```
98<YueDisplay>
99
100```yue
101{
102 numbers: [first, second]
103 properties: {
104 color: color
105 }
106} = obj2
107```
108
109</YueDisplay>
110
111It'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:
112
113```yuescript
114{:concat, :insert} = table
115```
116<YueDisplay>
117
118```yue
119{:concat, :insert} = table
120```
121
122</YueDisplay>
123
124This is effectively the same as import, but we can rename fields we want to extract by mixing the syntax:
125
126```yuescript
127{:mix, :max, random: rand} = math
128```
129<YueDisplay>
130
131```yue
132{:mix, :max, random: rand} = math
133```
134
135</YueDisplay>
136
137You can write default values while doing destructuring like:
138
139```yuescript
140{:name = "nameless", :job = "jobless"} = person
141```
142<YueDisplay>
143
144```yue
145{:name = "nameless", :job = "jobless"} = person
146```
147
148</YueDisplay>
149
150You can use `_` as placeholder when doing a list destructuring:
151
152```yuescript
153[_, two, _, four] = items
154```
155<YueDisplay>
156
157```yue
158[_, two, _, four] = items
159```
160
161</YueDisplay>
162
163## Range Destructuring
164
165You 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.
166
167```yuescript
168orders = ["first", "second", "third", "fourth", "last"]
169[first, ...bulk, last] = orders
170print first -- prints: first
171print bulk -- prints: {"second", "third", "fourth"}
172print last -- prints: last
173```
174<YueDisplay>
175
176```yue
177orders = ["first", "second", "third", "fourth", "last"]
178[first, ...bulk, last] = orders
179print first -- prints: first
180print bulk -- prints: {"second", "third", "fourth"}
181print last -- prints: last
182```
183
184</YueDisplay>
185
186The 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:
187
188```yuescript
189-- Capture everything after first element
190[first, ...rest] = orders
191
192-- Capture everything before last element
193[...start, last] = orders
194
195-- Capture things except the middle elements
196[first, ..._, last] = orders
197```
198<YueDisplay>
199
200```yue
201-- Capture everything after first element
202[first, ...rest] = orders
203
204-- Capture everything before last element
205[...start, last] = orders
206
207-- Capture things except the middle elements
208[first, ..._, last] = orders
209```
210
211</YueDisplay>
212
213## Destructuring In Other Places
214
215Destructuring can also show up in places where an assignment implicitly takes place. An example of this is a for loop:
216
217```yuescript
218tuples = [
219 ["hello", "world"]
220 ["egg", "head"]
221]
222
223for [left, right] in *tuples
224 print left, right
225```
226<YueDisplay>
227
228```yue
229tuples = [
230 ["hello", "world"]
231 ["egg", "head"]
232]
233
234for [left, right] in *tuples
235 print left, right
236```
237
238</YueDisplay>
239
240We 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.
diff --git a/doc/docs/de/doc/do.md b/doc/docs/de/doc/do.md
new file mode 100644
index 0000000..4990d6f
--- /dev/null
+++ b/doc/docs/de/doc/do.md
@@ -0,0 +1,66 @@
1# Do
2
3When used as a statement, do works just like it does in Lua.
4
5```yuescript
6do
7 var = "hello"
8 print var
9print var -- nil here
10```
11<YueDisplay>
12
13```yue
14do
15 var = "hello"
16 print var
17print var -- nil here
18```
19
20</YueDisplay>
21
22YueScript'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.
23
24```yuescript
25counter = do
26 i = 0
27 ->
28 i += 1
29 i
30
31print counter!
32print counter!
33```
34<YueDisplay>
35
36```yue
37counter = do
38 i = 0
39 ->
40 i += 1
41 i
42
43print counter!
44print counter!
45```
46
47</YueDisplay>
48
49```yuescript
50tbl = {
51 key: do
52 print "assigning key!"
53 1234
54}
55```
56<YueDisplay>
57
58```yue
59tbl = {
60 key: do
61 print "assigning key!"
62 1234
63}
64```
65
66</YueDisplay>
diff --git a/doc/docs/de/doc/for-loop.md b/doc/docs/de/doc/for-loop.md
new file mode 100644
index 0000000..cabcde5
--- /dev/null
+++ b/doc/docs/de/doc/for-loop.md
@@ -0,0 +1,127 @@
1# For Loop
2
3There are two for loop forms, just like in Lua. A numeric one and a generic one:
4
5```yuescript
6for i = 10, 20
7 print i
8
9for k = 1, 15, 2 -- an optional step provided
10 print k
11
12for key, value in pairs object
13 print key, value
14```
15<YueDisplay>
16
17```yue
18for i = 10, 20
19 print i
20
21for k = 1, 15, 2 -- an optional step provided
22 print k
23
24for key, value in pairs object
25 print key, value
26```
27
28</YueDisplay>
29
30The slicing and **\*** operators can be used, just like with comprehensions:
31
32```yuescript
33for item in *items[2, 4]
34 print item
35```
36<YueDisplay>
37
38```yue
39for item in *items[2, 4]
40 print item
41```
42
43</YueDisplay>
44
45A shorter syntax is also available for all variations when the body is only a single line:
46
47```yuescript
48for item in *items do print item
49
50for j = 1, 10, 3 do print j
51```
52<YueDisplay>
53
54```yue
55for item in *items do print item
56
57for j = 1, 10, 3 do print j
58```
59
60</YueDisplay>
61
62A 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.
63
64Doubling every even number:
65
66```yuescript
67doubled_evens = for i = 1, 20
68 if i % 2 == 0
69 i * 2
70 else
71 i
72```
73<YueDisplay>
74
75```yue
76doubled_evens = for i = 1, 20
77 if i % 2 == 0
78 i * 2
79 else
80 i
81```
82
83</YueDisplay>
84
85In 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.
86
87For example, to find the first number greater than 10:
88
89```yuescript
90first_large = for n in *numbers
91 break n if n > 10
92```
93<YueDisplay>
94
95```yue
96first_large = for n in *numbers
97 break n if n > 10
98```
99
100</YueDisplay>
101
102This break-with-value syntax enables concise and expressive search or early-exit patterns directly within loop expressions.
103
104You can also filter values by combining the for loop expression with the continue statement.
105
106For 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.
107
108```yuescript
109func_a = -> for i = 1, 10 do print i
110func_b = -> return for i = 1, 10 do i
111
112print func_a! -- prints nil
113print func_b! -- prints table object
114```
115<YueDisplay>
116
117```yue
118func_a = -> for i = 1, 10 do print i
119func_b = -> return for i = 1, 10 do i
120
121print func_a! -- prints nil
122print func_b! -- prints table object
123```
124
125</YueDisplay>
126
127This 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/de/doc/function-literals.md b/doc/docs/de/doc/function-literals.md
new file mode 100644
index 0000000..316e07c
--- /dev/null
+++ b/doc/docs/de/doc/function-literals.md
@@ -0,0 +1,494 @@
1# Function Literals
2
3All functions are created using a function expression. A simple function is denoted using the arrow: **->**.
4
5```yuescript
6my_function = ->
7my_function() -- call the empty function
8```
9<YueDisplay>
10
11```yue
12my_function = ->
13my_function() -- call the empty function
14```
15
16</YueDisplay>
17
18The 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:
19
20```yuescript
21func_a = -> print "hello world"
22
23func_b = ->
24 value = 100
25 print "The value:", value
26```
27<YueDisplay>
28
29```yue
30func_a = -> print "hello world"
31
32func_b = ->
33 value = 100
34 print "The value:", value
35```
36
37</YueDisplay>
38
39If 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.
40
41```yuescript
42func_a!
43func_b()
44```
45<YueDisplay>
46
47```yue
48func_a!
49func_b()
50```
51
52</YueDisplay>
53
54Functions with arguments can be created by preceding the arrow with a list of argument names in parentheses:
55
56```yuescript
57sum = (x, y) -> print "sum", x + y
58```
59<YueDisplay>
60
61```yue
62sum = (x, y) -> print "sum", x + y
63```
64
65</YueDisplay>
66
67Functions 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.
68
69```yuescript
70sum 10, 20
71print sum 10, 20
72
73a b c "a", "b", "c"
74```
75<YueDisplay>
76
77```yue
78sum 10, 20
79print sum 10, 20
80
81a b c "a", "b", "c"
82```
83
84</YueDisplay>
85
86In 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.
87
88```yuescript
89print "x:", sum(10, 20), "y:", sum(30, 40)
90```
91<YueDisplay>
92
93```yue
94print "x:", sum(10, 20), "y:", sum(30, 40)
95```
96
97</YueDisplay>
98
99There must not be any space between the opening parenthesis and the function.
100
101Functions will coerce the last statement in their body into a return statement, this is called implicit return:
102
103```yuescript
104sum = (x, y) -> x + y
105print "The sum is ", sum 10, 20
106```
107<YueDisplay>
108
109```yue
110sum = (x, y) -> x + y
111print "The sum is ", sum 10, 20
112```
113
114</YueDisplay>
115
116And if you need to explicitly return, you can use the return keyword:
117
118```yuescript
119sum = (x, y) -> return x + y
120```
121<YueDisplay>
122
123```yue
124sum = (x, y) -> return x + y
125```
126
127</YueDisplay>
128
129Just like in Lua, functions can return multiple values. The last statement must be a list of values separated by commas:
130
131```yuescript
132mystery = (x, y) -> x + y, x - y
133a, b = mystery 10, 20
134```
135<YueDisplay>
136
137```yue
138mystery = (x, y) -> x + y, x - y
139a, b = mystery 10, 20
140```
141
142</YueDisplay>
143
144## Fat Arrows
145
146Because 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.
147
148```yuescript
149func = (num) => @value + num
150```
151<YueDisplay>
152
153```yue
154func = (num) => @value + num
155```
156
157</YueDisplay>
158
159## Argument Defaults
160
161It 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.
162
163```yuescript
164my_function = (name = "something", height = 100) ->
165 print "Hello I am", name
166 print "My height is", height
167```
168<YueDisplay>
169
170```yue
171my_function = (name = "something", height = 100) ->
172 print "Hello I am", name
173 print "My height is", height
174```
175
176</YueDisplay>
177
178An 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.
179
180```yuescript
181some_args = (x = 100, y = x + 1000) ->
182 print x + y
183```
184<YueDisplay>
185
186```yue
187some_args = (x = 100, y = x + 1000) ->
188 print x + y
189```
190
191</YueDisplay>
192
193## Considerations
194
195Because of the expressive parentheses-less way of calling functions, some restrictions must be put in place to avoid parsing ambiguity involving whitespace.
196
197The minus sign plays two roles, a unary negation operator and a binary subtraction operator. Consider how the following examples compile:
198
199```yuescript
200a = x - 10
201b = x-10
202c = x -y
203d = x- z
204```
205<YueDisplay>
206
207```yue
208a = x - 10
209b = x-10
210c = x -y
211d = x- z
212```
213
214</YueDisplay>
215
216The 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.
217
218When 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.
219
220Where 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.
221
222```yuescript
223x = func"hello" + 100
224y = func "hello" + 100
225```
226<YueDisplay>
227
228```yue
229x = func"hello" + 100
230y = func "hello" + 100
231```
232
233</YueDisplay>
234
235## Multi-line arguments
236
237When 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.
238
239If 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
240
241```yuescript
242my_func 5, 4, 3,
243 8, 9, 10
244
245cool_func 1, 2,
246 3, 4,
247 5, 6,
248 7, 8
249```
250<YueDisplay>
251
252```yue
253my_func 5, 4, 3,
254 8, 9, 10
255
256cool_func 1, 2,
257 3, 4,
258 5, 6,
259 7, 8
260```
261
262</YueDisplay>
263
264This type of invocation can be nested. The level of indentation is used to determine to which function the arguments belong to.
265
266```yuescript
267my_func 5, 6, 7,
268 6, another_func 6, 7, 8,
269 9, 1, 2,
270 5, 4
271```
272<YueDisplay>
273
274```yue
275my_func 5, 6, 7,
276 6, another_func 6, 7, 8,
277 9, 1, 2,
278 5, 4
279```
280
281</YueDisplay>
282
283Because 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.
284
285```yuescript
286x = [
287 1, 2, 3, 4, a_func 4, 5,
288 5, 6,
289 8, 9, 10
290]
291```
292<YueDisplay>
293
294```yue
295x = [
296 1, 2, 3, 4, a_func 4, 5,
297 5, 6,
298 8, 9, 10
299]
300```
301
302</YueDisplay>
303
304Although uncommon, notice how we can give a deeper indentation for function arguments if we know we will be using a lower indentation further on.
305
306```yuescript
307y = [ my_func 1, 2, 3,
308 4, 5,
309 5, 6, 7
310]
311```
312<YueDisplay>
313
314```yue
315y = [ my_func 1, 2, 3,
316 4, 5,
317 5, 6, 7
318]
319```
320
321</YueDisplay>
322
323The 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:
324
325```yuescript
326if func 1, 2, 3,
327 "hello",
328 "world"
329 print "hello"
330 print "I am inside if"
331
332if func 1, 2, 3,
333 "hello",
334 "world"
335 print "hello"
336 print "I am inside if"
337```
338<YueDisplay>
339
340```yue
341if func 1, 2, 3,
342 "hello",
343 "world"
344 print "hello"
345 print "I am inside if"
346
347if func 1, 2, 3,
348 "hello",
349 "world"
350 print "hello"
351 print "I am inside if"
352```
353
354</YueDisplay>
355
356## Parameter Destructuring
357
358YueScript now supports destructuring function parameters when the argument is an object. Two forms of destructuring table literals are available:
359
360* **Curly-brace wrapped literals/object parameters**, allowing optional default values when fields are missing (e.g., `{:a, :b}`, `{a: a1 = 123}`).
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.
363
364```yuescript
365f1 = (:a, :b, :c) ->
366 print a, b, c
367
368f1 a: 1, b: "2", c: {}
369
370f2 = ({a: a1 = 123, :b = 'abc'}, c = {}) ->
371 print a1, b, c
372
373arg1 = {a: 0}
374f2 arg1, arg2
375```
376<YueDisplay>
377
378```yue
379f1 = (:a, :b, :c) ->
380 print a, b, c
381
382f1 a: 1, b: "2", c: {}
383
384f2 = ({a: a1 = 123, :b = 'abc'}, c = {}) ->
385print a1, b, c
386
387arg1 = {a: 0}
388f2 arg1, arg2
389```
390
391</YueDisplay>
392
393## Prefixed Return Expression
394
395When 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:
396
397```yuescript
398findFirstEven = (list): nil ->
399 for item in *list
400 if type(item) == "table"
401 for sub in *item
402 if sub % 2 == 0
403 return sub
404```
405<YueDisplay>
406
407```yue
408findFirstEven = (list): nil ->
409 for item in *list
410 if type(item) == "table"
411 for sub in *item
412 if sub % 2 == 0
413 return sub
414```
415
416</YueDisplay>
417
418This is equivalent to:
419
420```yuescript
421findFirstEven = (list) ->
422 for item in *list
423 if type(item) == "table"
424 for sub in *item
425 if sub % 2 == 0
426 return sub
427 nil
428```
429<YueDisplay>
430
431```yue
432findFirstEven = (list) ->
433 for item in *list
434 if type(item) == "table"
435 for sub in *item
436 if sub % 2 == 0
437 return sub
438 nil
439```
440
441</YueDisplay>
442
443The 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.
444
445## Named Varargs
446
447You 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).
448
449```yuescript
450f = (...t) ->
451 print "argument count:", t.n
452 print "table length:", #t
453 for i = 1, t.n
454 print t[i]
455
456f 1, 2, 3
457f "a", "b", "c", "d"
458f!
459
460-- Handling cases with nil values
461process = (...args) ->
462 sum = 0
463 for i = 1, args.n
464 if args[i] != nil and type(args[i]) == "number"
465 sum += args[i]
466 sum
467
468process 1, nil, 3, nil, 5
469```
470<YueDisplay>
471
472```yue
473f = (...t) ->
474 print "argument count:", t.n
475 print "table length:", #t
476 for i = 1, t.n
477 print t[i]
478
479f 1, 2, 3
480f "a", "b", "c", "d"
481f!
482
483-- Handling cases with nil values
484process = (...args) ->
485 sum = 0
486 for i = 1, args.n
487 if args[i] != nil and type(args[i]) == "number"
488 sum += args[i]
489 sum
490
491process 1, nil, 3, nil, 5
492```
493
494</YueDisplay>
diff --git a/doc/docs/de/doc/function-stubs.md b/doc/docs/de/doc/function-stubs.md
new file mode 100644
index 0000000..57a8b0c
--- /dev/null
+++ b/doc/docs/de/doc/function-stubs.md
@@ -0,0 +1,48 @@
1# Function Stubs
2
3It 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.
4
5The 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.
6
7Its syntax is the same as calling an instance method with the \ operator but with no argument list provided.
8
9```yuescript
10my_object = {
11 value: 1000
12 write: => print "the value:", @value
13}
14
15run_callback = (func) ->
16 print "running callback..."
17 func!
18
19-- this will not work:
20-- the function has to no reference to my_object
21run_callback my_object.write
22
23-- function stub syntax
24-- lets us bundle the object into a new function
25run_callback my_object\write
26```
27<YueDisplay>
28
29```yue
30my_object = {
31 value: 1000
32 write: => print "the value:", @value
33}
34
35run_callback = (func) ->
36 print "running callback..."
37 func!
38
39-- this will not work:
40-- the function has to no reference to my_object
41run_callback my_object.write
42
43-- function stub syntax
44-- lets us bundle the object into a new function
45run_callback my_object\write
46```
47
48</YueDisplay>
diff --git a/doc/docs/de/doc/if-assignment.md b/doc/docs/de/doc/if-assignment.md
new file mode 100644
index 0000000..02984e8
--- /dev/null
+++ b/doc/docs/de/doc/if-assignment.md
@@ -0,0 +1,72 @@
1# If Assignment
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.
4
5```yuescript
6if user := database.find_user "moon"
7 print user.name
8```
9<YueDisplay>
10
11```yue
12if user := database.find_user "moon"
13 print user.name
14```
15
16</YueDisplay>
17
18```yuescript
19if hello := os.getenv "hello"
20 print "You have hello", hello
21elseif world := os.getenv "world"
22 print "you have world", world
23else
24 print "nothing :("
25```
26<YueDisplay>
27
28```yue
29if hello := os.getenv "hello"
30 print "You have hello", hello
31elseif world := os.getenv "world"
32 print "you have world", world
33else
34 print "nothing :("
35```
36
37</YueDisplay>
38
39If assignment with multiple return values. Only the first value is getting checked, other values are scoped.
40```yuescript
41if success, result := pcall -> "get result without problems"
42 print result -- variable result is scoped
43print "OK"
44```
45<YueDisplay>
46
47```yue
48if success, result := pcall -> "get result without problems"
49 print result -- variable result is scoped
50print "OK"
51```
52
53</YueDisplay>
54
55## While Assignment
56
57You can also use if assignment in a while loop to get the value as the loop condition.
58
59```yuescript
60while byte := stream\read_one!
61 -- do something with the byte
62 print byte
63```
64<YueDisplay>
65
66```yue
67while byte := stream\read_one!
68 -- do something with the byte
69 print byte
70```
71
72</YueDisplay>
diff --git a/doc/docs/de/doc/index.md b/doc/docs/de/doc/index.md
new file mode 100755
index 0000000..3c4857f
--- /dev/null
+++ b/doc/docs/de/doc/index.md
@@ -0,0 +1,11 @@
1---
2title: Referenz
3---
4
5# YueScript-Dokumentation
6
7<img src="/image/yuescript.svg" width="250px" height="250px" alt="logo" style="padding-top: 3em; padding-bottom: 2em;"/>
8
9Willkommen in der offiziellen <b>YueScript</b>-Dokumentation!<br/>
10Hier findest du Sprachfeatures, Nutzung, Referenzbeispiele und Ressourcen.<br/>
11Bitte wähle ein Kapitel in der Seitenleiste, um mit YueScript zu beginnen.
diff --git a/doc/docs/de/doc/installation.md b/doc/docs/de/doc/installation.md
new file mode 100644
index 0000000..a93ddfd
--- /dev/null
+++ b/doc/docs/de/doc/installation.md
@@ -0,0 +1,43 @@
1# Installation
2
3## Lua Module
4
5Install [luarocks](https://luarocks.org), a package manager for Lua modules. Then install it as a Lua module and executable with:
6
7```shell
8luarocks install yuescript
9```
10
11Or you can build `yue.so` file with:
12
13```shell
14make shared LUAI=/usr/local/include/lua LUAL=/usr/local/lib/lua
15```
16
17Then get the binary file from path **bin/shared/yue.so**.
18
19## Build Binary Tool
20
21Clone this repo, then build and install executable with:
22
23```shell
24make install
25```
26
27Build YueScript tool without macro feature:
28
29```shell
30make install NO_MACRO=true
31```
32
33Build YueScript tool without built-in Lua binary:
34
35```shell
36make install NO_LUA=true
37```
38
39## Download Precompiled Binary
40
41You can download precompiled binary files, including binary executable files compatible with different Lua versions and library files.
42
43Download precompiled binary files from [here](https://github.com/IppClub/YueScript/releases).
diff --git a/doc/docs/de/doc/introduction.md b/doc/docs/de/doc/introduction.md
new file mode 100644
index 0000000..a9a9389
--- /dev/null
+++ b/doc/docs/de/doc/introduction.md
@@ -0,0 +1,105 @@
1# Introduction
2
3YueScript 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.
4
5Yue (月) is the name of moon in Chinese and it's pronounced as [jyɛ].
6
7## An Overview of YueScript
8
9```yuescript
10-- import syntax
11import p, to_lua from "yue"
12
13-- object literals
14inventory =
15 equipment:
16 - "sword"
17 - "shield"
18 items:
19 - name: "potion"
20 count: 10
21 - name: "bread"
22 count: 3
23
24-- list comprehension
25map = (arr, action) ->
26 [action item for item in *arr]
27
28filter = (arr, cond) ->
29 [item for item in *arr when cond item]
30
31reduce = (arr, init, action): init ->
32 init = action init, item for item in *arr
33
34-- pipe operator
35[1, 2, 3]
36 |> map (x) -> x * 2
37 |> filter (x) -> x > 4
38 |> reduce 0, (a, b) -> a + b
39 |> print
40
41-- metatable manipulation
42apple =
43 size: 15
44 <index>:
45 color: 0x00ffff
46
47with apple
48 p .size, .color, .<index> if .<>?
49
50-- js-like export syntax
51export 🌛 = "月之脚本"
52```
53
54<YueDisplay>
55
56```yue
57-- import syntax
58import p, to_lua from "yue"
59
60-- object literals
61inventory =
62 equipment:
63 - "sword"
64 - "shield"
65 items:
66 - name: "potion"
67 count: 10
68 - name: "bread"
69 count: 3
70
71-- list comprehension
72map = (arr, action) ->
73 [action item for item in *arr]
74
75filter = (arr, cond) ->
76 [item for item in *arr when cond item]
77
78reduce = (arr, init, action): init ->
79 init = action init, item for item in *arr
80
81-- pipe operator
82[1, 2, 3]
83 |> map (x) -> x * 2
84 |> filter (x) -> x > 4
85 |> reduce 0, (a, b) -> a + b
86 |> print
87
88-- metatable manipulation
89apple =
90 size: 15
91 <index>:
92 color: 0x00ffff
93
94with apple
95 p .size, .color, .<index> if .<>?
96
97-- js-like export syntax
98export 🌛 = "月之脚本"
99```
100
101</YueDisplay>
102
103## About Dora SSR
104
105YueScript 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
diff --git a/doc/docs/de/doc/licence-mit.md b/doc/docs/de/doc/licence-mit.md
new file mode 100644
index 0000000..f1d5d60
--- /dev/null
+++ b/doc/docs/de/doc/licence-mit.md
@@ -0,0 +1,23 @@
1# License: MIT
2
3Copyright (c) 2017-2026 Li Jin \<dragon-fly@qq.com\>
4
5Permission is hereby granted, free of charge, to any person obtaining a copy
6of this software and associated documentation files (the "Software"), to deal
7in the Software without restriction, including without limitation the rights
8to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9copies of the Software, and to permit persons to whom the Software is
10furnished to do so, subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in all
13copies or substantial portions of the Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21SOFTWARE.
22
23<CompilerModal />
diff --git a/doc/docs/de/doc/line-decorators.md b/doc/docs/de/doc/line-decorators.md
new file mode 100644
index 0000000..292bc77
--- /dev/null
+++ b/doc/docs/de/doc/line-decorators.md
@@ -0,0 +1,44 @@
1# Line Decorators
2
3For convenience, the for loop and if statement can be applied to single statements at the end of the line:
4
5```yuescript
6print "hello world" if name == "Rob"
7```
8<YueDisplay>
9
10```yue
11print "hello world" if name == "Rob"
12```
13
14</YueDisplay>
15
16And with basic loops:
17
18```yuescript
19print "item: ", item for item in *items
20```
21<YueDisplay>
22
23```yue
24print "item: ", item for item in *items
25```
26
27</YueDisplay>
28
29And with while loops:
30
31```yuescript
32game\update! while game\isRunning!
33
34reader\parse_line! until reader\eof!
35```
36<YueDisplay>
37
38```yue
39game\update! while game\isRunning!
40
41reader\parse_line! until reader\eof!
42```
43
44</YueDisplay>
diff --git a/doc/docs/de/doc/literals.md b/doc/docs/de/doc/literals.md
new file mode 100644
index 0000000..e097c62
--- /dev/null
+++ b/doc/docs/de/doc/literals.md
@@ -0,0 +1,110 @@
1# Literals
2
3All of the primitive literals in Lua can be used. This applies to numbers, strings, booleans, and **nil**.
4
5Unlike Lua, Line breaks are allowed inside of single and double quote strings without an escape sequence:
6
7```yuescript
8some_string = "Here is a string
9 that has a line break in it."
10
11-- You can mix expressions into string literals using #{} syntax.
12-- String interpolation is only available in double quoted strings.
13print "I am #{math.random! * 100}% sure."
14```
15<YueDisplay>
16
17```yue
18some_string = "Here is a string
19 that has a line break in it."
20
21-- You can mix expressions into string literals using #{} syntax.
22-- String interpolation is only available in double quoted strings.
23print "I am #{math.random! * 100}% sure."
24```
25
26</YueDisplay>
27
28## Number Literals
29
30You can use underscores in a number literal to increase readability.
31
32```yuescript
33integer = 1_000_000
34hex = 0xEF_BB_BF
35binary = 0B10011
36```
37<YueDisplay>
38
39```yue
40integer = 1_000_000
41hex = 0xEF_BB_BF
42binary = 0B10011
43```
44
45</YueDisplay>
46
47## YAML Multiline String
48
49The `|` prefix introduces a YAML-style multiline string literal:
50
51```yuescript
52str = |
53 key: value
54 list:
55 - item1
56 - #{expr}
57```
58<YueDisplay>
59
60```yue
61str = |
62 key: value
63 list:
64 - item1
65 - #{expr}
66```
67
68</YueDisplay>
69
70This 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)`.
71
72YAML 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.
73
74```yuescript
75fn = ->
76 str = |
77 foo:
78 bar: baz
79 return str
80```
81<YueDisplay>
82
83```yue
84fn = ->
85 str = |
86 foo:
87 bar: baz
88 return str
89```
90
91</YueDisplay>
92
93Internal indentation is preserved relative to the removed common prefix, allowing clean nested structures.
94
95All 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.
96
97```yuescript
98str = |
99 path: "C:\Program Files\App"
100 note: 'He said: "#{Hello}!"'
101```
102<YueDisplay>
103
104```yue
105str = |
106 path: "C:\Program Files\App"
107 note: 'He said: "#{Hello}!"'
108```
109
110</YueDisplay>
diff --git a/doc/docs/de/doc/macro.md b/doc/docs/de/doc/macro.md
new file mode 100644
index 0000000..6d194c3
--- /dev/null
+++ b/doc/docs/de/doc/macro.md
@@ -0,0 +1,275 @@
1# Macro
2
3## Common Usage
4
5Macro function is used for evaluating a string in the compile time and insert the generated codes into final compilation.
6
7```yuescript
8macro PI2 = -> math.pi * 2
9area = $PI2 * 5
10
11macro HELLO = -> "'hello world'"
12print $HELLO
13
14macro config = (debugging) ->
15 global debugMode = debugging == "true"
16 ""
17
18macro asserts = (cond) ->
19 debugMode and "assert #{cond}" or ""
20
21macro assert = (cond) ->
22 debugMode and "assert #{cond}" or "#{cond}"
23
24$config true
25$asserts item ~= nil
26
27$config false
28value = $assert item
29
30-- the passed expressions are treated as strings
31macro and = (...) -> "#{ table.concat {...}, ' and ' }"
32if $and f1!, f2!, f3!
33 print "OK"
34```
35<YueDisplay>
36
37```yue
38macro PI2 = -> math.pi * 2
39area = $PI2 * 5
40
41macro HELLO = -> "'hello world'"
42print $HELLO
43
44macro config = (debugging) ->
45 global debugMode = debugging == "true"
46 ""
47
48macro asserts = (cond) ->
49 debugMode and "assert #{cond}" or ""
50
51macro assert = (cond) ->
52 debugMode and "assert #{cond}" or "#{cond}"
53
54$config true
55$asserts item ~= nil
56
57$config false
58value = $assert item
59
60-- the passed expressions are treated as strings
61macro and = (...) -> "#{ table.concat {...}, ' and ' }"
62if $and f1!, f2!, f3!
63 print "OK"
64```
65
66</YueDisplay>
67
68## Insert Raw Codes
69
70A macro function can either return a YueScript string or a config table containing Lua codes.
71```yuescript
72macro yueFunc = (var) -> "local #{var} = ->"
73$yueFunc funcA
74funcA = -> "fail to assign to the Yue macro defined variable"
75
76macro luaFunc = (var) -> {
77 code: "local function #{var}() end"
78 type: "lua"
79}
80$luaFunc funcB
81funcB = -> "fail to assign to the Lua macro defined variable"
82
83macro lua = (code) -> {
84 :code
85 type: "lua"
86}
87
88-- the raw string leading and ending symbols are auto trimed
89$lua[==[
90-- raw Lua codes insertion
91if cond then
92 print("output")
93end
94]==]
95```
96<YueDisplay>
97
98```yue
99macro yueFunc = (var) -> "local #{var} = ->"
100$yueFunc funcA
101funcA = -> "fail to assign to the Yue macro defined variable"
102
103macro luaFunc = (var) -> {
104 code: "local function #{var}() end"
105 type: "lua"
106}
107$luaFunc funcB
108funcB = -> "fail to assign to the Lua macro defined variable"
109
110macro lua = (code) -> {
111 :code
112 type: "lua"
113}
114
115-- the raw string leading and ending symbols are auto trimed
116$lua[==[
117-- raw Lua codes insertion
118if cond then
119 print("output")
120end
121]==]
122```
123
124</YueDisplay>
125
126## Export Macro
127
128Macro 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
130-- file: utils.yue
131export macro map = (items, action) -> "[#{action} for _ in *#{items}]"
132export macro filter = (items, action) -> "[_ for _ in *#{items} when #{action}]"
133export macro foreach = (items, action) -> "for _ in *#{items}
134 #{action}"
135
136-- file main.yue
137import "utils" as {
138 $, -- symbol to import all macros
139 $foreach: $each -- rename macro $foreach to $each
140}
141[1, 2, 3] |> $map(_ * 2) |> $filter(_ > 4) |> $each print _
142```
143<YueDisplay>
144
145```yue
146-- file: utils.yue
147export macro map = (items, action) -> "[#{action} for _ in *#{items}]"
148export macro filter = (items, action) -> "[_ for _ in *#{items} when #{action}]"
149export macro foreach = (items, action) -> "for _ in *#{items}
150 #{action}"
151
152-- file main.yue
153-- import function is not available in browser, try it in a real environment
154--[[
155import "utils" as {
156 $, -- symbol to import all macros
157 $foreach: $each -- rename macro $foreach to $each
158}
159[1, 2, 3] |> $map(_ * 2) |> $filter(_ > 4) |> $each print _
160]]
161```
162
163</YueDisplay>
164
165## Builtin Macro
166
167There are some builtin macros but you can override them by declaring macros with the same names.
168```yuescript
169print $FILE -- get string of current module name
170print $LINE -- get number 2
171```
172<YueDisplay>
173
174```yue
175print $FILE -- get string of current module name
176print $LINE -- get number 2
177```
178
179</YueDisplay>
180
181## Generating Macros with Macros
182
183In 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.
184
185```yuescript
186macro Enum = (...) ->
187 items = {...}
188 itemSet = {item, true for item in *items}
189 (item) ->
190 error "got \"#{item}\", expecting one of #{table.concat items, ', '}" unless itemSet[item]
191 "\"#{item}\""
192
193macro BodyType = $Enum(
194 Static
195 Dynamic
196 Kinematic
197)
198
199print "Valid enum type:", $BodyType Static
200-- print "Compilation error with enum type:", $BodyType Unknown
201```
202
203<YueDisplay>
204
205```yue
206macro Enum = (...) ->
207 items = {...}
208 itemSet = {item, true for item in *items}
209 (item) ->
210 error "got \"#{item}\", expecting one of #{table.concat items, ', '}" unless itemSet[item]
211 "\"#{item}\""
212
213macro BodyType = $Enum(
214 Static
215 Dynamic
216 Kinematic
217)
218
219print "Valid enum type:", $BodyType Static
220-- print "Compilation error with enum type:", $BodyType Unknown
221```
222
223</YueDisplay>
224
225## Argument Validation
226
227You can declare the expected AST node types in the argument list, and check whether the incoming macro arguments meet the expectations at compile time.
228
229```yuescript
230macro printNumAndStr = (num `Num, str `String) -> |
231 print(
232 #{num}
233 #{str}
234 )
235
236$printNumAndStr 123, "hello"
237```
238<YueDisplay>
239
240```yue
241macro printNumAndStr = (num `Num, str `String) -> |
242 print(
243 #{num}
244 #{str}
245 )
246
247$printNumAndStr 123, "hello"
248```
249
250</YueDisplay>
251
252If you need more flexible argument checking, you can use the built-in `$is_ast` macro function to manually check at the appropriate place.
253
254```yuescript
255macro printNumAndStr = (num, str) ->
256 error "expected Num as first argument" unless $is_ast Num, num
257 error "expected String as second argument" unless $is_ast String, str
258 "print(#{num}, #{str})"
259
260$printNumAndStr 123, "hello"
261```
262<YueDisplay>
263
264```yue
265macro printNumAndStr = (num, str) ->
266 error "expected Num as first argument" unless $is_ast Num, num
267 error "expected String as second argument" unless $is_ast String, str
268 "print(#{num}, #{str})"
269
270$printNumAndStr 123, "hello"
271```
272
273</YueDisplay>
274
275For 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).
diff --git a/doc/docs/de/doc/module.md b/doc/docs/de/doc/module.md
new file mode 100644
index 0000000..c955092
--- /dev/null
+++ b/doc/docs/de/doc/module.md
@@ -0,0 +1,245 @@
1# Module
2
3## Import
4
5The 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.
6
7```yuescript
8-- used as table destructuring
9do
10 import insert, concat from table
11 -- report error when assigning to insert, concat
12 import C, Ct, Cmt from require "lpeg"
13 -- shortcut for implicit requiring
14 import x, y, z from 'mymodule'
15 -- import with Python style
16 from 'module' import a, b, c
17
18-- shortcut for requring a module
19do
20 import 'module'
21 import 'module_x'
22 import "d-a-s-h-e-s"
23 import "module.part"
24
25-- requring module with aliasing or table destructuring
26do
27 import "player" as PlayerModule
28 import "lpeg" as :C, :Ct, :Cmt
29 import "export" as {one, two, Something:{umm:{ch}}}
30```
31<YueDisplay>
32
33```yue
34-- used as table destructuring
35do
36 import insert, concat from table
37 -- report error when assigning to insert, concat
38 import C, Ct, Cmt from require "lpeg"
39 -- shortcut for implicit requiring
40 import x, y, z from 'mymodule'
41 -- import with Python style
42 from 'module' import a, b, c
43
44-- shortcut for requring a module
45do
46 import 'module'
47 import 'module_x'
48 import "d-a-s-h-e-s"
49 import "module.part"
50
51-- requring module with aliasing or table destructuring
52do
53 import "player" as PlayerModule
54 import "lpeg" as :C, :Ct, :Cmt
55 import "export" as {one, two, Something:{umm:{ch}}}
56```
57
58</YueDisplay>
59
60## Import Global
61
62You 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.
63
64```yuescript
65do
66 import tostring
67 import table.concat
68 print concat ["a", tostring 1]
69```
70<YueDisplay>
71
72```yue
73do
74 import tostring
75 import table.concat
76 print concat ["a", tostring 1]
77```
78
79</YueDisplay>
80
81### Automatic Global Variable Import
82
83You 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.
84
85Names that are explicitly declared as globals in the same scope will not be imported, so you can still assign to them.
86
87```yuescript
88do
89 import global
90 print "hello"
91 math.random 3
92 -- print = nil -- error: imported globals are const
93
94do
95 -- explicit global variable will not be imported
96 import global
97 global FLAG
98 print FLAG
99 FLAG = 123
100```
101<YueDisplay>
102
103```yue
104do
105 import global
106 print "hello"
107 math.random 3
108 -- print = nil -- error: imported globals are const
109
110do
111 -- explicit global variable will not be imported
112 import global
113 global FLAG
114 print FLAG
115 FLAG = 123
116```
117
118</YueDisplay>
119
120## Export
121
122The export statement offers a concise way to define modules.
123
124### Named Export
125
126Named export will define a local variable as well as adding a field in the exported table.
127
128```yuescript
129export a, b, c = 1, 2, 3
130export cool = "cat"
131
132export What = if this
133 "abc"
134else
135 "def"
136
137export y = ->
138 hallo = 3434
139
140export class Something
141 umm: "cool"
142```
143<YueDisplay>
144
145```yue
146export a, b, c = 1, 2, 3
147export cool = "cat"
148
149export What = if this
150 "abc"
151else
152 "def"
153
154export y = ->
155 hallo = 3434
156
157export class Something
158 umm: "cool"
159```
160
161</YueDisplay>
162
163Doing named export with destructuring.
164
165```yuescript
166export :loadstring, to_lua: tolua = yue
167export {itemA: {:fieldA = 'default'}} = tb
168```
169<YueDisplay>
170
171```yue
172export :loadstring, to_lua: tolua = yue
173export {itemA: {:fieldA = 'default'}} = tb
174```
175
176</YueDisplay>
177
178Export named items from module without creating local variables.
179
180```yuescript
181export.itemA = tb
182export.<index> = items
183export["a-b-c"] = 123
184```
185<YueDisplay>
186
187```yue
188export.itemA = tb
189export.<index> = items
190export["a-b-c"] = 123
191```
192
193</YueDisplay>
194
195### Unnamed Export
196
197Unnamed export will add the target item into the array part of the exported table.
198
199```yuescript
200d, e, f = 3, 2, 1
201export d, e, f
202
203export if this
204 123
205else
206 456
207
208export with tmp
209 j = 2000
210```
211<YueDisplay>
212
213```yue
214d, e, f = 3, 2, 1
215export d, e, f
216
217export if this
218 123
219else
220 456
221
222export with tmp
223 j = 2000
224```
225
226</YueDisplay>
227
228### Default Export
229
230Using the **default** keyword in export statement to replace the exported table with any thing.
231
232```yuescript
233export default ->
234 print "hello"
235 123
236```
237<YueDisplay>
238
239```yue
240export default ->
241 print "hello"
242 123
243```
244
245</YueDisplay>
diff --git a/doc/docs/de/doc/object-oriented-programming.md b/doc/docs/de/doc/object-oriented-programming.md
new file mode 100644
index 0000000..6a8559e
--- /dev/null
+++ b/doc/docs/de/doc/object-oriented-programming.md
@@ -0,0 +1,555 @@
1# Object Oriented Programming
2
3In 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.
4
5A simple class:
6
7```yuescript
8class Inventory
9 new: =>
10 @items = {}
11
12 add_item: (name) =>
13 if @items[name]
14 @items[name] += 1
15 else
16 @items[name] = 1
17```
18<YueDisplay>
19
20```yue
21class Inventory
22 new: =>
23 @items = {}
24
25 add_item: (name) =>
26 if @items[name]
27 @items[name] += 1
28 else
29 @items[name] = 1
30```
31
32</YueDisplay>
33
34A class is declared with a class statement followed by a table-like declaration where all of the methods and properties are listed.
35
36The new property is special in that it will become the constructor.
37
38Notice 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.
39
40The @ prefix on a variable name is shorthand for self.. @items becomes self.items.
41
42Creating an instance of the class is done by calling the name of the class as a function.
43
44```yuescript
45inv = Inventory!
46inv\add_item "t-shirt"
47inv\add_item "pants"
48```
49<YueDisplay>
50
51```yue
52inv = Inventory!
53inv\add_item "t-shirt"
54inv\add_item "pants"
55```
56
57</YueDisplay>
58
59Because the instance of the class needs to be sent to the methods when they are called, the \ operator is used.
60
61All properties of a class are shared among the instances. This is fine for functions, but for other types of objects, undesired results may occur.
62
63Consider the example below, the clothes property is shared amongst all instances, so modifications to it in one instance will show up in another:
64
65```yuescript
66class Person
67 clothes: []
68 give_item: (name) =>
69 table.insert @clothes, name
70
71a = Person!
72b = Person!
73
74a\give_item "pants"
75b\give_item "shirt"
76
77-- will print both pants and shirt
78print item for item in *a.clothes
79```
80<YueDisplay>
81
82```yue
83class Person
84 clothes: []
85 give_item: (name) =>
86 table.insert @clothes, name
87
88a = Person!
89b = Person!
90
91a\give_item "pants"
92b\give_item "shirt"
93
94-- will print both pants and shirt
95print item for item in *a.clothes
96```
97
98</YueDisplay>
99
100The proper way to avoid this problem is to create the mutable state of the object in the constructor:
101
102```yuescript
103class Person
104 new: =>
105 @clothes = []
106```
107<YueDisplay>
108
109```yue
110class Person
111 new: =>
112 @clothes = []
113```
114
115</YueDisplay>
116
117## Inheritance
118
119The extends keyword can be used in a class declaration to inherit the properties and methods from another class.
120
121```yuescript
122class BackPack extends Inventory
123 size: 10
124 add_item: (name) =>
125 if #@items > size then error "backpack is full"
126 super name
127```
128<YueDisplay>
129
130```yue
131class BackPack extends Inventory
132 size: 10
133 add_item: (name) =>
134 if #@items > size then error "backpack is full"
135 super name
136```
137
138</YueDisplay>
139
140Here we extend our Inventory class, and limit the amount of items it can carry.
141
142In 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.
143
144Whenever 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.
145
146```yuescript
147class Shelf
148 @__inherited: (child) =>
149 print @__name, "was inherited by", child.__name
150
151-- will print: Shelf was inherited by Cupboard
152class Cupboard extends Shelf
153```
154<YueDisplay>
155
156```yue
157class Shelf
158 @__inherited: (child) =>
159 print @__name, "was inherited by", child.__name
160
161-- will print: Shelf was inherited by Cupboard
162class Cupboard extends Shelf
163```
164
165</YueDisplay>
166
167## Super
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.
170
171When 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)
172
173When super is used as a normal value, it is a reference to the parent class object.
174
175It 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.
176
177When 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.
178
179A few examples of using super in different ways:
180
181```yuescript
182class MyClass extends ParentClass
183 a_method: =>
184 -- the following have the same effect:
185 super "hello", "world"
186 super\a_method "hello", "world"
187 super.a_method self, "hello", "world"
188
189 -- super as a value is equal to the parent class:
190 assert super == ParentClass
191```
192<YueDisplay>
193
194```yue
195class MyClass extends ParentClass
196 a_method: =>
197 -- the following have the same effect:
198 super "hello", "world"
199 super\a_method "hello", "world"
200 super.a_method self, "hello", "world"
201
202 -- super as a value is equal to the parent class:
203 assert super == ParentClass
204```
205
206</YueDisplay>
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.
209
210## Types
211
212Every 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.
213
214```yuescript
215b = BackPack!
216assert b.__class == BackPack
217
218print BackPack.size -- prints 10
219```
220<YueDisplay>
221
222```yue
223b = BackPack!
224assert b.__class == BackPack
225
226print BackPack.size -- prints 10
227```
228
229</YueDisplay>
230
231## Class Objects
232
233The 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.
234
235The 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.
236
237A 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.
238
239The 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.
240
241It 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.
242
243The class object has a couple special properties:
244
245The name of the class as when it was declared is stored as a string in the __name field of the class object.
246
247```yuescript
248print BackPack.__name -- prints Backpack
249```
250<YueDisplay>
251
252```yue
253print BackPack.__name -- prints Backpack
254```
255
256</YueDisplay>
257
258The 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.
259
260If the class extends from anything, the parent class object is stored in __parent.
261
262## Class Variables
263
264We 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.
265
266```yuescript
267class Things
268 @some_func: => print "Hello from", @__name
269
270Things\some_func!
271
272-- class variables not visible in instances
273assert Things().some_func == nil
274```
275<YueDisplay>
276
277```yue
278class Things
279 @some_func: => print "Hello from", @__name
280
281Things\some_func!
282
283-- class variables not visible in instances
284assert Things().some_func == nil
285```
286
287</YueDisplay>
288
289In expressions, we can use @@ to access a value that is stored in the __class of self. Thus, @@hello is shorthand for self.__class.hello.
290
291```yuescript
292class Counter
293 @count: 0
294
295 new: =>
296 @@count += 1
297
298Counter!
299Counter!
300
301print Counter.count -- prints 2
302```
303<YueDisplay>
304
305```yue
306class Counter
307 @count: 0
308
309 new: =>
310 @@count += 1
311
312Counter!
313Counter!
314
315print Counter.count -- prints 2
316```
317
318</YueDisplay>
319
320The calling semantics of @@ are similar to @. Calling a @@ name will pass the class in as the first argument using Lua's colon syntax.
321
322```yuescript
323@@hello 1,2,3,4
324```
325<YueDisplay>
326
327```yue
328@@hello 1,2,3,4
329```
330
331</YueDisplay>
332
333## Class Declaration Statements
334
335In 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.
336
337Here is an alternative way to create a class variable compared to what's described above:
338
339```yuescript
340class Things
341 @class_var = "hello world"
342```
343<YueDisplay>
344
345```yue
346class Things
347 @class_var = "hello world"
348```
349
350</YueDisplay>
351
352These expressions are executed after all the properties have been added to the base.
353
354All 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:
355
356```yuescript
357class MoreThings
358 secret = 123
359 log = (msg) -> print "LOG:", msg
360
361 some_method: =>
362 log "hello world: " .. secret
363```
364<YueDisplay>
365
366```yue
367class MoreThings
368 secret = 123
369 log = (msg) -> print "LOG:", msg
370
371 some_method: =>
372 log "hello world: " .. secret
373```
374
375</YueDisplay>
376
377## @ and @@ Values
378
379When @ and @@ are prefixed in front of a name they represent, respectively, that name accessed in self and self.__class.
380
381If they are used all by themselves, they are aliases for self and self.__class.
382
383```yuescript
384assert @ == self
385assert @@ == self.__class
386```
387<YueDisplay>
388
389```yue
390assert @ == self
391assert @@ == self.__class
392```
393
394</YueDisplay>
395
396For example, a quick way to create a new instance of the same class from an instance method using @@:
397
398```yuescript
399some_instance_method = (...) => @@ ...
400```
401<YueDisplay>
402
403```yue
404some_instance_method = (...) => @@ ...
405```
406
407</YueDisplay>
408
409## Constructor Property Promotion
410
411To reduce the boilerplate code for definition of simple value objects. You can write a simple class like:
412
413```yuescript
414class Something
415 new: (@foo, @bar, @@biz, @@baz) =>
416
417-- Which is short for
418
419class Something
420 new: (foo, bar, biz, baz) =>
421 @foo = foo
422 @bar = bar
423 @@biz = biz
424 @@baz = baz
425```
426<YueDisplay>
427
428```yue
429class Something
430 new: (@foo, @bar, @@biz, @@baz) =>
431
432-- Which is short for
433
434class Something
435 new: (foo, bar, biz, baz) =>
436 @foo = foo
437 @bar = bar
438 @@biz = biz
439 @@baz = baz
440```
441
442</YueDisplay>
443
444You can also use this syntax for a common function to initialize a object's fields.
445
446```yuescript
447new = (@fieldA, @fieldB) => @
448obj = new {}, 123, "abc"
449print obj
450```
451<YueDisplay>
452
453```yue
454new = (@fieldA, @fieldB) => @
455obj = new {}, 123, "abc"
456print obj
457```
458
459</YueDisplay>
460
461## Class Expressions
462
463The class syntax can also be used as an expression which can be assigned to a variable or explicitly returned.
464
465```yuescript
466x = class Bucket
467 drops: 0
468 add_drop: => @drops += 1
469```
470<YueDisplay>
471
472```yue
473x = class Bucket
474 drops: 0
475 add_drop: => @drops += 1
476```
477
478</YueDisplay>
479
480## Anonymous classes
481
482The 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.
483
484```yuescript
485BigBucket = class extends Bucket
486 add_drop: => @drops += 10
487
488assert Bucket.__name == "BigBucket"
489```
490<YueDisplay>
491
492```yue
493BigBucket = class extends Bucket
494 add_drop: => @drops += 10
495
496assert Bucket.__name == "BigBucket"
497```
498
499</YueDisplay>
500
501You can even leave off the body, meaning you can write a blank anonymous class like this:
502
503```yuescript
504x = class
505```
506<YueDisplay>
507
508```yue
509x = class
510```
511
512</YueDisplay>
513
514## Class Mixing
515
516You 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.
517
518```yuescript
519MyIndex = __index: var: 1
520
521class X using MyIndex
522 func: =>
523 print 123
524
525x = X!
526print x.var
527
528class Y using X
529
530y = Y!
531y\func!
532
533assert y.__class.__parent ~= X -- X is not parent of Y
534```
535<YueDisplay>
536
537```yue
538MyIndex = __index: var: 1
539
540class X using MyIndex
541 func: =>
542 print 123
543
544x = X!
545print x.var
546
547class Y using X
548
549y = Y!
550y\func!
551
552assert y.__class.__parent ~= X -- X is not parent of Y
553```
554
555</YueDisplay>
diff --git a/doc/docs/de/doc/operator.md b/doc/docs/de/doc/operator.md
new file mode 100644
index 0000000..9a2e89b
--- /dev/null
+++ b/doc/docs/de/doc/operator.md
@@ -0,0 +1,460 @@
1# Operator
2
3All 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.
4
5```yuescript
6tb\func! if tb ~= nil
7tb::func! if tb != nil
8```
9<YueDisplay>
10
11```yue
12tb\func! if tb ~= nil
13tb::func! if tb != nil
14```
15
16</YueDisplay>
17
18## Chaining Comparisons
19
20Comparisons can be arbitrarily chained:
21
22```yuescript
23print 1 < 2 <= 2 < 3 == 3 > 2 >= 1 == 1 < 3 != 5
24-- output: true
25
26a = 5
27print 1 <= a <= 10
28-- output: true
29```
30<YueDisplay>
31
32```yue
33print 1 < 2 <= 2 < 3 == 3 > 2 >= 1 == 1 < 3 != 5
34-- output: true
35
36a = 5
37print 1 <= a <= 10
38-- output: true
39```
40
41</YueDisplay>
42
43Note the evaluation behavior of chained comparisons:
44
45```yuescript
46v = (x) ->
47 print x
48 x
49
50print v(1) < v(2) <= v(3)
51--[[
52 output:
53 2
54 1
55 3
56 true
57]]
58
59print v(1) > v(2) <= v(3)
60--[[
61 output:
62 2
63 1
64 false
65]]
66```
67<YueDisplay>
68
69```yue
70v = (x) ->
71 print x
72 x
73
74print v(1) < v(2) <= v(3)
75--[[
76 output:
77 2
78 1
79 3
80 true
81]]
82
83print v(1) > v(2) <= v(3)
84--[[
85 output:
86 2
87 1
88 false
89]]
90```
91
92</YueDisplay>
93
94The 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.
95
96## Table Appending
97
98The **[] =** operator is used to append values to tables.
99
100```yuescript
101tab = []
102tab[] = "Value"
103```
104<YueDisplay>
105
106```yue
107tab = []
108tab[] = "Value"
109```
110
111</YueDisplay>
112
113You can also use the spread operator `...` to append all elements from one list to another:
114
115```yuescript
116tbA = [1, 2, 3]
117tbB = [4, 5, 6]
118tbA[] = ...tbB
119-- tbA is now [1, 2, 3, 4, 5, 6]
120```
121<YueDisplay>
122
123```yue
124tbA = [1, 2, 3]
125tbB = [4, 5, 6]
126tbA[] = ...tbB
127-- tbA is now [1, 2, 3, 4, 5, 6]
128```
129
130</YueDisplay>
131
132## Table Spreading
133
134You can concatenate array tables or hash tables using spread operator `...` before expressions in table literals.
135
136```yuescript
137parts =
138 * "shoulders"
139 * "knees"
140lyrics =
141 * "head"
142 * ...parts
143 * "and"
144 * "toes"
145
146copy = {...other}
147
148a = {1, 2, 3, x: 1}
149b = {4, 5, y: 1}
150merge = {...a, ...b}
151```
152<YueDisplay>
153
154```yue
155parts =
156 * "shoulders"
157 * "knees"
158lyrics =
159 * "head"
160 * ...parts
161 * "and"
162 * "toes"
163
164copy = {...other}
165
166a = {1, 2, 3, x: 1}
167b = {4, 5, y: 1}
168merge = {...a, ...b}
169```
170
171</YueDisplay>
172
173## Table Reversed Indexing
174
175You can use the **#** operator to get the last elements of a table.
176
177```yuescript
178last = data.items[#]
179second_last = data.items[#-1]
180data.items[#] = 1
181```
182<YueDisplay>
183
184```yue
185last = data.items[#]
186second_last = data.items[#-1]
187data.items[#] = 1
188```
189
190</YueDisplay>
191
192## Metatable
193
194The **<>** operator can be used as a shortcut for metatable manipulation.
195
196### Metatable Creation
197
198Create normal table with empty bracekets **<>** or metamethod key which is surrounded by **<>**.
199
200```yuescript
201mt = {}
202add = (right) => <>: mt, value: @value + right.value
203mt.__add = add
204
205a = <>: mt, value: 1
206 -- set field with variable of the same name
207b = :<add>, value: 2
208c = <add>: mt.__add, value: 3
209
210d = a + b + c
211print d.value
212
213close _ = <close>: -> print "out of scope"
214```
215<YueDisplay>
216
217```yue
218mt = {}
219add = (right) => <>: mt, value: @value + right.value
220mt.__add = add
221
222a = <>: mt, value: 1
223 -- set field with variable of the same name
224b = :<add>, value: 2
225c = <add>: mt.__add, value: 3
226
227d = a + b + c
228print d.value
229
230close _ = <close>: -> print "out of scope"
231```
232
233</YueDisplay>
234
235### Metatable Accessing
236
237Accessing metatable with **<>** or metamethod name surrounded by **<>** or writing some expression in **<>**.
238
239```yuescript
240-- create with metatable containing field "value"
241tb = <"value">: 123
242tb.<index> = tb.<>
243print tb.value
244
245tb.<> = __index: {item: "hello"}
246print tb.item
247```
248<YueDisplay>
249
250```yue
251-- create with metatable containing field "value"
252tb = <"value">: 123
253tb.<index> = tb.<>
254print tb.value
255tb.<> = __index: {item: "hello"}
256print tb.item
257```
258
259</YueDisplay>
260
261### Metatable Destructure
262
263Destruct metatable with metamethod key surrounded by **<>**.
264
265```yuescript
266{item, :new, :<close>, <index>: getter} = tb
267print item, new, close, getter
268```
269<YueDisplay>
270
271```yue
272{item, :new, :<close>, <index>: getter} = tb
273print item, new, close, getter
274```
275
276</YueDisplay>
277
278## Existence
279
280The **?** operator can be used in a variety of contexts to check for existence.
281
282```yuescript
283func?!
284print abc?["hello world"]?.xyz
285
286x = tab?.value
287len = utf8?.len or string?.len or (o) -> #o
288
289if print and x?
290 print x
291
292with? io.open "test.txt", "w"
293 \write "hello"
294 \close!
295```
296<YueDisplay>
297
298```yue
299func?!
300print abc?["hello world"]?.xyz
301
302x = tab?.value
303len = utf8?.len or string?.len or (o) -> #o
304
305if print and x?
306 print x
307
308with? io.open "test.txt", "w"
309 \write "hello"
310 \close!
311```
312
313</YueDisplay>
314
315## Piping
316
317Instead of a series of nested function calls, you can pipe values with operator **|>**.
318
319```yuescript
320"hello" |> print
3211 |> print 2 -- insert pipe item as the first argument
3222 |> print 1, _, 3 -- pipe with a placeholder
323
324-- pipe expression in multiline
325readFile "example.txt"
326 |> extract language, {}
327 |> parse language
328 |> emit
329 |> render
330 |> print
331```
332<YueDisplay>
333
334```yue
335"hello" |> print
3361 |> print 2 -- insert pipe item as the first argument
3372 |> print 1, _, 3 -- pipe with a placeholder
338-- pipe expression in multiline
339readFile "example.txt"
340 |> extract language, {}
341 |> parse language
342 |> emit
343 |> render
344 |> print
345```
346
347</YueDisplay>
348
349## Nil Coalescing
350
351The 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
353local a, b, c, d
354a = b ?? c ?? d
355func a ?? {}
356
357a ??= false
358```
359<YueDisplay>
360
361```yue
362local a, b, c, d
363a = b ?? c ?? d
364func a ?? {}
365a ??= false
366```
367
368</YueDisplay>
369
370## Implicit Object
371
372You 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
374```yuescript
375-- assignment with implicit object
376list =
377 * 1
378 * 2
379 * 3
380
381-- function call with implicit object
382func
383 * 1
384 * 2
385 * 3
386
387-- return with implicit object
388f = ->
389 return
390 * 1
391 * 2
392 * 3
393
394-- table with implicit object
395tb =
396 name: "abc"
397
398 values:
399 - "a"
400 - "b"
401 - "c"
402
403 objects:
404 - name: "a"
405 value: 1
406 func: => @value + 1
407 tb:
408 fieldA: 1
409
410 - name: "b"
411 value: 2
412 func: => @value + 2
413 tb: { }
414
415```
416<YueDisplay>
417
418```yue
419-- assignment with implicit object
420list =
421 * 1
422 * 2
423 * 3
424
425-- function call with implicit object
426func
427 * 1
428 * 2
429 * 3
430
431-- return with implicit object
432f = ->
433 return
434 * 1
435 * 2
436 * 3
437
438-- table with implicit object
439tb =
440 name: "abc"
441
442 values:
443 - "a"
444 - "b"
445 - "c"
446
447 objects:
448 - name: "a"
449 value: 1
450 func: => @value + 1
451 tb:
452 fieldA: 1
453
454 - name: "b"
455 value: 2
456 func: => @value + 2
457 tb: { }
458```
459
460</YueDisplay>
diff --git a/doc/docs/de/doc/switch.md b/doc/docs/de/doc/switch.md
new file mode 100644
index 0000000..f503a80
--- /dev/null
+++ b/doc/docs/de/doc/switch.md
@@ -0,0 +1,296 @@
1# Switch
2
3The 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.
4
5```yuescript
6switch name := "Dan"
7 when "Robert"
8 print "You are Robert"
9 when "Dan", "Daniel"
10 print "Your name, it's Dan"
11 else
12 print "I don't know about you with name #{name}"
13```
14<YueDisplay>
15
16```yue
17switch name := "Dan"
18 when "Robert"
19 print "You are Robert"
20 when "Dan", "Daniel"
21 print "Your name, it's Dan"
22 else
23 print "I don't know about you with name #{name}"
24```
25
26</YueDisplay>
27
28A switch when clause can match against multiple values by listing them out comma separated.
29
30Switches can be used as expressions as well, here we can assign the result of the switch to a variable:
31
32```yuescript
33b = 1
34next_number = switch b
35 when 1
36 2
37 when 2
38 3
39 else
40 error "can't count that high!"
41```
42<YueDisplay>
43
44```yue
45b = 1
46next_number = switch b
47 when 1
48 2
49 when 2
50 3
51 else
52 error "can't count that high!"
53```
54
55</YueDisplay>
56
57We 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.
58
59```yuescript
60msg = switch math.random(1, 5)
61 when 1 then "you are lucky"
62 when 2 then "you are almost lucky"
63 else "not so lucky"
64```
65<YueDisplay>
66
67```yue
68msg = switch math.random(1, 5)
69 when 1 then "you are lucky"
70 when 2 then "you are almost lucky"
71 else "not so lucky"
72```
73
74</YueDisplay>
75
76If 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.
77
78```yuescript
79switch math.random(1, 5)
80 when 1
81 print "you are lucky" -- two indents
82 else
83 print "not so lucky"
84
85switch math.random(1, 5) when 1
86 print "you are lucky" -- one indent
87else
88 print "not so lucky"
89```
90<YueDisplay>
91
92```yue
93switch math.random(1, 5)
94 when 1
95 print "you are lucky" -- two indents
96 else
97 print "not so lucky"
98
99switch math.random(1, 5) when 1
100 print "you are lucky" -- one indent
101else
102 print "not so lucky"
103```
104
105</YueDisplay>
106
107It 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.
108
109## Table Matching
110
111You can do table matching in a switch when clause, if the table can be destructured by a specific structure and get non-nil values.
112
113```yuescript
114items =
115 * x: 100
116 y: 200
117 * width: 300
118 height: 400
119
120for item in *items
121 switch item
122 when :x, :y
123 print "Vec2 #{x}, #{y}"
124 when :width, :height
125 print "size #{width}, #{height}"
126```
127<YueDisplay>
128
129```yue
130items =
131 * x: 100
132 y: 200
133 * width: 300
134 height: 400
135
136for item in *items
137 switch item
138 when :x, :y
139 print "Vec2 #{x}, #{y}"
140 when :width, :height
141 print "size #{width}, #{height}"
142```
143
144</YueDisplay>
145
146You can use default values to optionally destructure the table for some fields.
147
148```yuescript
149item = {}
150
151{pos: {:x = 50, :y = 200}} = item -- get error: attempt to index a nil value (field 'pos')
152
153switch item
154 when {pos: {:x = 50, :y = 200}}
155 print "Vec2 #{x}, #{y}" -- table destructuring will still pass
156```
157<YueDisplay>
158
159```yue
160item = {}
161
162{pos: {:x = 50, :y = 200}} = item -- get error: attempt to index a nil value (field 'pos')
163
164switch item
165 when {pos: {:x = 50, :y = 200}}
166 print "Vec2 #{x}, #{y}" -- table destructuring will still pass
167```
168
169</YueDisplay>
170
171You can also match against array elements, table fields, and even nested structures with array or table literals.
172
173Match against array elements.
174
175```yuescript
176switch tb
177 when [1, 2, 3]
178 print "1, 2, 3"
179 when [1, b, 3]
180 print "1, #{b}, 3"
181 when [1, 2, b = 3] -- b has a default value
182 print "1, 2, #{b}"
183```
184<YueDisplay>
185
186```yue
187switch tb
188 when [1, 2, 3]
189 print "1, 2, 3"
190 when [1, b, 3]
191 print "1, #{b}, 3"
192 when [1, 2, b = 3] -- b has a default value
193 print "1, 2, #{b}"
194```
195
196</YueDisplay>
197
198Match against table fields with destructuring.
199
200```yuescript
201switch tb
202 when success: true, :result
203 print "success", result
204 when success: false
205 print "failed", result
206 else
207 print "invalid"
208```
209<YueDisplay>
210
211```yue
212switch tb
213 when success: true, :result
214 print "success", result
215 when success: false
216 print "failed", result
217 else
218 print "invalid"
219```
220
221</YueDisplay>
222
223Match against nested table structures.
224
225```yuescript
226switch tb
227 when data: {type: "success", :content}
228 print "success", content
229 when data: {type: "error", :content}
230 print "failed", content
231 else
232 print "invalid"
233```
234<YueDisplay>
235
236```yue
237switch tb
238 when data: {type: "success", :content}
239 print "success", content
240 when data: {type: "error", :content}
241 print "failed", content
242 else
243 print "invalid"
244```
245
246</YueDisplay>
247
248Match against array of tables.
249
250```yuescript
251switch tb
252 when [
253 {a: 1, b: 2}
254 {a: 3, b: 4}
255 {a: 5, b: 6}
256 fourth
257 ]
258 print "matched", fourth
259```
260<YueDisplay>
261
262```yue
263switch tb
264 when [
265 {a: 1, b: 2}
266 {a: 3, b: 4}
267 {a: 5, b: 6}
268 fourth
269 ]
270 print "matched", fourth
271```
272
273</YueDisplay>
274
275Match against a list and capture a range of elements.
276
277```yuescript
278segments = ["admin", "users", "logs", "view"]
279switch segments
280 when [...groups, resource, action]
281 print "Group:", groups -- prints: {"admin", "users"}
282 print "Resource:", resource -- prints: "logs"
283 print "Action:", action -- prints: "view"
284```
285<YueDisplay>
286
287```yue
288segments = ["admin", "users", "logs", "view"]
289switch segments
290 when [...groups, resource, action]
291 print "Group:", groups -- prints: {"admin", "users"}
292 print "Resource:", resource -- prints: "logs"
293 print "Action:", action -- prints: "view"
294```
295
296</YueDisplay>
diff --git a/doc/docs/de/doc/table-literals.md b/doc/docs/de/doc/table-literals.md
new file mode 100644
index 0000000..c1adcab
--- /dev/null
+++ b/doc/docs/de/doc/table-literals.md
@@ -0,0 +1,168 @@
1# Table Literals
2
3Like in Lua, tables are delimited in curly braces.
4
5```yuescript
6some_values = [1, 2, 3, 4]
7```
8<YueDisplay>
9
10```yue
11some_values = [1, 2, 3, 4]
12```
13
14</YueDisplay>
15
16Unlike Lua, assigning a value to a key in a table is done with **:** (instead of **=**).
17
18```yuescript
19some_values = {
20 name: "Bill",
21 age: 200,
22 ["favorite food"]: "rice"
23}
24```
25<YueDisplay>
26
27```yue
28some_values = {
29 name: "Bill",
30 age: 200,
31 ["favorite food"]: "rice"
32}
33```
34
35</YueDisplay>
36
37The curly braces can be left off if a single table of key value pairs is being assigned.
38
39```yuescript
40profile =
41 height: "4 feet",
42 shoe_size: 13,
43 favorite_foods: ["ice cream", "donuts"]
44```
45<YueDisplay>
46
47```yue
48profile =
49 height: "4 feet",
50 shoe_size: 13,
51 favorite_foods: ["ice cream", "donuts"]
52```
53
54</YueDisplay>
55
56Newlines can be used to delimit values instead of a comma (or both):
57
58```yuescript
59values = {
60 1, 2, 3, 4
61 5, 6, 7, 8
62 name: "superman"
63 occupation: "crime fighting"
64}
65```
66<YueDisplay>
67
68```yue
69values = {
70 1, 2, 3, 4
71 5, 6, 7, 8
72 name: "superman"
73 occupation: "crime fighting"
74}
75```
76
77</YueDisplay>
78
79When creating a single line table literal, the curly braces can also be left off:
80
81```yuescript
82my_function dance: "Tango", partner: "none"
83
84y = type: "dog", legs: 4, tails: 1
85```
86<YueDisplay>
87
88```yue
89my_function dance: "Tango", partner: "none"
90
91y = type: "dog", legs: 4, tails: 1
92```
93
94</YueDisplay>
95
96The keys of a table literal can be language keywords without being escaped:
97
98```yuescript
99tbl = {
100 do: "something"
101 end: "hunger"
102}
103```
104<YueDisplay>
105
106```yue
107tbl = {
108 do: "something"
109 end: "hunger"
110}
111```
112
113</YueDisplay>
114
115If 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:
116
117```yuescript
118hair = "golden"
119height = 200
120person = { :hair, :height, shoe_size: 40 }
121
122print_table :hair, :height
123```
124<YueDisplay>
125
126```yue
127hair = "golden"
128height = 200
129person = { :hair, :height, shoe_size: 40 }
130
131print_table :hair, :height
132```
133
134</YueDisplay>
135
136If 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.
137
138```yuescript
139t = {
140 [1 + 2]: "hello"
141 "hello world": true
142}
143```
144<YueDisplay>
145
146```yue
147t = {
148 [1 + 2]: "hello"
149 "hello world": true
150}
151```
152
153</YueDisplay>
154
155Lua 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.
156
157```yuescript
158some_values = [1, 2, 3, 4]
159list_with_one_element = [1, ]
160```
161<YueDisplay>
162
163```yue
164some_values = [1, 2, 3, 4]
165list_with_one_element = [1, ]
166```
167
168</YueDisplay>
diff --git a/doc/docs/de/doc/the-using-clause-controlling-destructive-assignment.md b/doc/docs/de/doc/the-using-clause-controlling-destructive-assignment.md
new file mode 100644
index 0000000..fb9b740
--- /dev/null
+++ b/doc/docs/de/doc/the-using-clause-controlling-destructive-assignment.md
@@ -0,0 +1,98 @@
1# The Using Clause; Controlling Destructive Assignment
2
3While 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:
4
5```yuescript
6i = 100
7
8-- many lines of code...
9
10my_func = ->
11 i = 10
12 while i > 0
13 print i
14 i -= 1
15
16my_func!
17
18print i -- will print 0
19```
20<YueDisplay>
21
22```yue
23i = 100
24
25-- many lines of code...
26
27my_func = ->
28 i = 10
29 while i > 0
30 print i
31 i -= 1
32
33my_func!
34
35print i -- will print 0
36```
37
38</YueDisplay>
39
40In 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.
41
42It 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.
43
44The 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.
45
46```yuescript
47i = 100
48
49my_func = (using nil) ->
50 i = "hello" -- a new local variable is created here
51
52my_func!
53print i -- prints 100, i is unaffected
54```
55<YueDisplay>
56
57```yue
58i = 100
59
60my_func = (using nil) ->
61 i = "hello" -- a new local variable is created here
62
63my_func!
64print i -- prints 100, i is unaffected
65```
66
67</YueDisplay>
68
69Multiple names can be separated by commas. Closure values can still be accessed, they just cant be modified:
70
71```yuescript
72tmp = 1213
73i, k = 100, 50
74
75my_func = (add using k, i) ->
76 tmp = tmp + add -- a new local tmp is created
77 i += tmp
78 k += tmp
79
80my_func(22)
81print i, k -- these have been updated
82```
83<YueDisplay>
84
85```yue
86tmp = 1213
87i, k = 100, 50
88
89my_func = (add using k, i) ->
90 tmp = tmp + add -- a new local tmp is created
91 i += tmp
92 k += tmp
93
94my_func(22)
95print i, k -- these have been updated
96```
97
98</YueDisplay>
diff --git a/doc/docs/de/doc/the-yuescript-library.md b/doc/docs/de/doc/the-yuescript-library.md
new file mode 100644
index 0000000..3761755
--- /dev/null
+++ b/doc/docs/de/doc/the-yuescript-library.md
@@ -0,0 +1,821 @@
1# The YueScript Library
2
3Access it by `local yue = require("yue")` in Lua.
4
5## yue
6
7**Description:**
8
9The YueScript language library.
10
11### version
12
13**Type:** Field.
14
15**Description:**
16
17The YueScript version.
18
19**Signature:**
20```lua
21version: string
22```
23
24### dirsep
25
26**Type:** Field.
27
28**Description:**
29
30The file separator for the current platform.
31
32**Signature:**
33```lua
34dirsep: string
35```
36
37### yue_compiled
38
39**Type:** Field.
40
41**Description:**
42
43The compiled module code cache.
44
45**Signature:**
46```lua
47yue_compiled: {string: string}
48```
49
50### to_lua
51
52**Type:** Function.
53
54**Description:**
55
56The YueScript compiling function. It compiles the YueScript code to Lua code.
57
58**Signature:**
59```lua
60to_lua: function(code: string, config?: Config):
61 --[[codes]] string | nil,
62 --[[error]] string | nil,
63 --[[globals]] {{string, integer, integer}} | nil
64```
65
66**Parameters:**
67
68| Parameter | Type | Description |
69| --- | --- | --- |
70| code | string | The YueScript code. |
71| config | Config | [Optional] The compiler options. |
72
73**Returns:**
74
75| Return Type | Description |
76| --- | --- |
77| string \| nil | The compiled Lua code, or nil if the compilation failed. |
78| string \| nil | The error message, or nil if the compilation succeeded. |
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. |
80
81### file_exist
82
83**Type:** Function.
84
85**Description:**
86
87The source file existence checking function. Can be overridden to customize the behavior.
88
89**Signature:**
90```lua
91file_exist: function(filename: string): boolean
92```
93
94**Parameters:**
95
96| Parameter | Type | Description |
97| --- | --- | --- |
98| filename | string | The file name. |
99
100**Returns:**
101
102| Return Type | Description |
103| --- | --- |
104| boolean | Whether the file exists. |
105
106### read_file
107
108**Type:** Function.
109
110**Description:**
111
112The source file reading function. Can be overridden to customize the behavior.
113
114**Signature:**
115```lua
116read_file: function(filename: string): string
117```
118
119**Parameters:**
120
121| Parameter | Type | Description |
122| --- | --- | --- |
123| filename | string | The file name. |
124
125**Returns:**
126
127| Return Type | Description |
128| --- | --- |
129| string | The file content. |
130
131### insert_loader
132
133**Type:** Function.
134
135**Description:**
136
137Insert the YueScript loader to the package loaders (searchers).
138
139**Signature:**
140```lua
141insert_loader: function(pos?: integer): boolean
142```
143
144**Parameters:**
145
146| Parameter | Type | Description |
147| --- | --- | --- |
148| pos | integer | [Optional] The position to insert the loader. Default is 3. |
149
150**Returns:**
151
152| Return Type | Description |
153| --- | --- |
154| boolean | Whether the loader is inserted successfully. It will fail if the loader is already inserted. |
155
156### remove_loader
157
158**Type:** Function.
159
160**Description:**
161
162Remove the YueScript loader from the package loaders (searchers).
163
164**Signature:**
165```lua
166remove_loader: function(): boolean
167```
168
169**Returns:**
170
171| Return Type | Description |
172| --- | --- |
173| boolean | Whether the loader is removed successfully. It will fail if the loader is not inserted. |
174
175### loadstring
176
177**Type:** Function.
178
179**Description:**
180
181Loads YueScript code from a string into a function.
182
183**Signature:**
184```lua
185loadstring: function(input: string, chunkname: string, env: table, config?: Config):
186 --[[loaded function]] nil | function(...: any): (any...),
187 --[[error]] string | nil
188```
189
190**Parameters:**
191
192| Parameter | Type | Description |
193| --- | --- | --- |
194| input | string | The YueScript code. |
195| chunkname | string | The name of the code chunk. |
196| env | table | The environment table. |
197| config | Config | [Optional] The compiler options. |
198
199**Returns:**
200
201| Return Type | Description |
202| --- | --- |
203| function \| nil | The loaded function, or nil if the loading failed. |
204| string \| nil | The error message, or nil if the loading succeeded. |
205
206### loadstring
207
208**Type:** Function.
209
210**Description:**
211
212Loads YueScript code from a string into a function.
213
214**Signature:**
215```lua
216loadstring: function(input: string, chunkname: string, config?: Config):
217 --[[loaded function]] nil | function(...: any): (any...),
218 --[[error]] string | nil
219```
220
221**Parameters:**
222
223| Parameter | Type | Description |
224| --- | --- | --- |
225| input | string | The YueScript code. |
226| chunkname | string | The name of the code chunk. |
227| config | Config | [Optional] The compiler options. |
228
229**Returns:**
230
231| Return Type | Description |
232| --- | --- |
233| function \| nil | The loaded function, or nil if the loading failed. |
234| string \| nil | The error message, or nil if the loading succeeded. |
235
236### loadstring
237
238**Type:** Function.
239
240**Description:**
241
242Loads YueScript code from a string into a function.
243
244**Signature:**
245```lua
246loadstring: function(input: string, config?: Config):
247 --[[loaded function]] nil | function(...: any): (any...),
248 --[[error]] string | nil
249```
250
251**Parameters:**
252
253| Parameter | Type | Description |
254| --- | --- | --- |
255| input | string | The YueScript code. |
256| config | Config | [Optional] The compiler options. |
257
258**Returns:**
259
260| Return Type | Description |
261| --- | --- |
262| function \| nil | The loaded function, or nil if the loading failed. |
263| string \| nil | The error message, or nil if the loading succeeded. |
264
265### loadfile
266
267**Type:** Function.
268
269**Description:**
270
271Loads YueScript code from a file into a function.
272
273**Signature:**
274```lua
275loadfile: function(filename: string, env: table, config?: Config):
276 nil | function(...: any): (any...),
277 string | nil
278```
279
280**Parameters:**
281
282| Parameter | Type | Description |
283| --- | --- | --- |
284| filename | string | The file name. |
285| env | table | The environment table. |
286| config | Config | [Optional] The compiler options. |
287
288**Returns:**
289
290| Return Type | Description |
291| --- | --- |
292| function \| nil | The loaded function, or nil if the loading failed. |
293| string \| nil | The error message, or nil if the loading succeeded. |
294
295### loadfile
296
297**Type:** Function.
298
299**Description:**
300
301Loads YueScript code from a file into a function.
302
303**Signature:**
304```lua
305loadfile: function(filename: string, config?: Config):
306 nil | function(...: any): (any...),
307 string | nil
308```
309
310**Parameters:**
311
312| Parameter | Type | Description |
313| --- | --- | --- |
314| filename | string | The file name. |
315| config | Config | [Optional] The compiler options. |
316
317**Returns:**
318
319| Return Type | Description |
320| --- | --- |
321| function \| nil | The loaded function, or nil if the loading failed. |
322| string \| nil | The error message, or nil if the loading succeeded. |
323
324### dofile
325
326**Type:** Function.
327
328**Description:**
329
330Loads YueScript code from a file into a function and executes it.
331
332**Signature:**
333```lua
334dofile: function(filename: string, env: table, config?: Config): any...
335```
336
337**Parameters:**
338
339| Parameter | Type | Description |
340| --- | --- | --- |
341| filename | string | The file name. |
342| env | table | The environment table. |
343| config | Config | [Optional] The compiler options. |
344
345**Returns:**
346
347| Return Type | Description |
348| --- | --- |
349| any... | The return values of the loaded function. |
350
351### dofile
352
353**Type:** Function.
354
355**Description:**
356
357Loads YueScript code from a file into a function and executes it.
358
359**Signature:**
360```lua
361dofile: function(filename: string, config?: Config): any...
362```
363
364**Parameters:**
365
366| Parameter | Type | Description |
367| --- | --- | --- |
368| filename | string | The file name. |
369| config | Config | [Optional] The compiler options. |
370
371**Returns:**
372
373| Return Type | Description |
374| --- | --- |
375| any... | The return values of the loaded function. |
376
377### find_modulepath
378
379**Type:** Function.
380
381**Description:**
382
383Resolves the YueScript module name to the file path.
384
385**Signature:**
386```lua
387find_modulepath: function(name: string): string
388```
389
390**Parameters:**
391
392| Parameter | Type | Description |
393| --- | --- | --- |
394| name | string | The module name. |
395
396**Returns:**
397
398| Return Type | Description |
399| --- | --- |
400| string | The file path. |
401
402### pcall
403
404**Type:** Function.
405
406**Description:**
407
408Calls a function in protected mode.
409Catches any errors and returns a status code and results or error object.
410Rewrites the error line number to the original line number in the YueScript code when errors occur.
411
412**Signature:**
413```lua
414pcall: function(f: function, ...: any): boolean, any...
415```
416
417**Parameters:**
418
419| Parameter | Type | Description |
420| --- | --- | --- |
421| f | function | The function to call. |
422| ... | any | Arguments to pass to the function. |
423
424**Returns:**
425
426| Return Type | Description |
427| --- | --- |
428| boolean, ... | Status code and function results or error object. |
429
430### require
431
432**Type:** Function.
433
434**Description:**
435
436Loads a given module. Can be either a Lua module or a YueScript module.
437Rewrites the error line number to the original line number in the YueScript code if the module is a YueScript module and loading fails.
438
439**Signature:**
440```lua
441require: function(name: string): any...
442```
443
444**Parameters:**
445
446| Parameter | Type | Description |
447| --- | --- | --- |
448| modname | string | The name of the module to load. |
449
450**Returns:**
451
452| Return Type | Description |
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. |
455
456### p
457
458**Type:** Function.
459
460**Description:**
461
462Inspects the structures of the passed values and prints string representations.
463
464**Signature:**
465```lua
466p: function(...: any)
467```
468
469**Parameters:**
470
471| Parameter | Type | Description |
472| --- | --- | --- |
473| ... | any | The values to inspect. |
474
475### options
476
477**Type:** Field.
478
479**Description:**
480
481The current compiler options.
482
483**Signature:**
484```lua
485options: Config.Options
486```
487
488### traceback
489
490**Type:** Function.
491
492**Description:**
493
494The traceback function that rewrites the stack trace line numbers to the original line numbers in the YueScript code.
495
496**Signature:**
497```lua
498traceback: function(message: string): string
499```
500
501**Parameters:**
502
503| Parameter | Type | Description |
504| --- | --- | --- |
505| message | string | The traceback message. |
506
507**Returns:**
508
509| Return Type | Description |
510| --- | --- |
511| string | The rewritten traceback message. |
512
513### is_ast
514
515**Type:** Function.
516
517**Description:**
518
519Checks whether the code matches the specified AST.
520
521**Signature:**
522```lua
523is_ast: function(astName: string, code: string): boolean
524```
525
526**Parameters:**
527
528| Parameter | Type | Description |
529| --- | --- | --- |
530| astName | string | The AST name. |
531| code | string | The code. |
532
533**Returns:**
534
535| Return Type | Description |
536| --- | --- |
537| boolean | Whether the code matches the AST. |
538
539### AST
540
541**Type:** Field.
542
543**Description:**
544
545The AST type definition with name, row, column and sub nodes.
546
547**Signature:**
548```lua
549type AST = {string, integer, integer, any}
550```
551
552### to_ast
553
554**Type:** Function.
555
556**Description:**
557
558Converts the code to the AST.
559
560**Signature:**
561```lua
562to_ast: function(code: string, flattenLevel?: number, astName?: string, reserveComment?: boolean):
563 --[[AST]] AST | nil,
564 --[[error]] nil | string
565```
566
567**Parameters:**
568
569| Parameter | Type | Description |
570| --- | --- | --- |
571| code | string | The code. |
572| flattenLevel | integer | [Optional] The flatten level. Higher level means more flattening. Default is 0. Maximum is 2. |
573| astName | string | [Optional] The AST name. Default is "File". |
574| reserveComment | boolean | [Optional] Whether to reserve the original comments. Default is false. |
575
576**Returns:**
577
578| Return Type | Description |
579| --- | --- |
580| AST \| nil | The AST, or nil if the conversion failed. |
581| string \| nil | The error message, or nil if the conversion succeeded. |
582
583### format
584
585**Type:** Function.
586
587**Description:**
588
589Formats the YueScript code.
590
591**Signature:**
592```lua
593format: function(code: string, tabSize?: number, reserveComment?: boolean): string
594```
595
596**Parameters:**
597
598| Parameter | Type | Description |
599| --- | --- | --- |
600| code | string | The code. |
601| tabSize | integer | [Optional] The tab size. Default is 4. |
602| reserveComment | boolean | [Optional] Whether to reserve the original comments. Default is true. |
603
604**Returns:**
605
606| Return Type | Description |
607| --- | --- |
608| string | The formatted code. |
609
610### __call
611
612**Type:** Metamethod.
613
614**Description:**
615
616Requires the YueScript module.
617Rewrites the error line number to the original line number in the YueScript code when loading fails.
618
619**Signature:**
620```lua
621metamethod __call: function(self: yue, module: string): any...
622```
623
624**Parameters:**
625
626| Parameter | Type | Description |
627| --- | --- | --- |
628| module | string | The module name. |
629
630**Returns:**
631
632| Return Type | Description |
633| --- | --- |
634| any | The module value. |
635
636## Config
637
638**Description:**
639
640The compiler compile options.
641
642### lint_global
643
644**Type:** Field.
645
646**Description:**
647
648Whether the compiler should collect the global variables appearing in the code.
649
650**Signature:**
651```lua
652lint_global: boolean
653```
654
655### implicit_return_root
656
657**Type:** Field.
658
659**Description:**
660
661Whether the compiler should do an implicit return for the root code block.
662
663**Signature:**
664```lua
665implicit_return_root: boolean
666```
667
668### reserve_line_number
669
670**Type:** Field.
671
672**Description:**
673
674Whether the compiler should reserve the original line number in the compiled code.
675
676**Signature:**
677```lua
678reserve_line_number: boolean
679```
680
681### reserve_comment
682
683**Type:** Field.
684
685**Description:**
686
687Whether the compiler should reserve the original comments in the compiled code.
688
689**Signature:**
690```lua
691reserve_comment: boolean
692```
693
694### space_over_tab
695
696**Type:** Field.
697
698**Description:**
699
700Whether the compiler should use the space character instead of the tab character in the compiled code.
701
702**Signature:**
703```lua
704space_over_tab: boolean
705```
706
707### same_module
708
709**Type:** Field.
710
711**Description:**
712
713Whether the compiler should treat the code to be compiled as the same currently being compiled module. For internal use only.
714
715**Signature:**
716```lua
717same_module: boolean
718```
719
720### line_offset
721
722**Type:** Field.
723
724**Description:**
725
726Whether the compiler error message should include the line number offset. For internal use only.
727
728**Signature:**
729```lua
730line_offset: integer
731```
732
733### yue.Config.LuaTarget
734
735**Type:** Enumeration.
736
737**Description:**
738
739The target Lua version enumeration.
740
741**Signature:**
742```lua
743enum LuaTarget
744 "5.1"
745 "5.2"
746 "5.3"
747 "5.4"
748 "5.5"
749end
750```
751
752### options
753
754**Type:** Field.
755
756**Description:**
757
758The extra options to be passed to the compilation function.
759
760**Signature:**
761```lua
762options: Options
763```
764
765## Options
766
767**Description:**
768
769The extra compiler options definition.
770
771### target
772
773**Type:** Field.
774
775**Description:**
776
777The target Lua version for the compilation.
778
779**Signature:**
780```lua
781target: LuaTarget
782```
783
784### path
785
786**Type:** Field.
787
788**Description:**
789
790The extra module search path.
791
792**Signature:**
793```lua
794path: string
795```
796
797### dump_locals
798
799**Type:** Field.
800
801**Description:**
802
803Whether to dump the local variables in the traceback error message. Default is false.
804
805**Signature:**
806```lua
807dump_locals: boolean
808```
809
810### simplified
811
812**Type:** Field.
813
814**Description:**
815
816Whether to simplify the error message. Default is true.
817
818**Signature:**
819```lua
820simplified: boolean
821```
diff --git a/doc/docs/de/doc/try.md b/doc/docs/de/doc/try.md
new file mode 100644
index 0000000..23c7877
--- /dev/null
+++ b/doc/docs/de/doc/try.md
@@ -0,0 +1,105 @@
1# Try
2
3The syntax for Lua error handling in a common form.
4
5```yuescript
6try
7 func 1, 2, 3
8catch err
9 print yue.traceback err
10
11success, result = try
12 func 1, 2, 3
13catch err
14 yue.traceback err
15
16try func 1, 2, 3
17catch err
18 print yue.traceback err
19
20success, result = try func 1, 2, 3
21
22try
23 print "trying"
24 func 1, 2, 3
25
26-- working with if assignment pattern
27if success, result := try func 1, 2, 3
28catch err
29 print yue.traceback err
30 print result
31```
32<YueDisplay>
33
34```yue
35try
36 func 1, 2, 3
37catch err
38 print yue.traceback err
39
40success, result = try
41 func 1, 2, 3
42catch err
43 yue.traceback err
44
45try func 1, 2, 3
46catch err
47 print yue.traceback err
48
49success, result = try func 1, 2, 3
50
51try
52 print "trying"
53 func 1, 2, 3
54
55-- working with if assignment pattern
56if success, result := try func 1, 2, 3
57catch err
58 print yue.traceback err
59 print result
60```
61
62</YueDisplay>
63
64## Try?
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.
67
68```yuescript
69a, b, c = try? func!
70
71-- with nil coalescing operator
72a = (try? func!) ?? "default"
73
74-- as function argument
75f try? func!
76
77-- with catch block
78f try?
79 print 123
80 func!
81catch e
82 print e
83 e
84```
85<YueDisplay>
86
87```yue
88a, b, c = try? func!
89
90-- with nil coalescing operator
91a = (try? func!) ?? "default"
92
93-- as function argument
94f try? func!
95
96-- with catch block
97f try?
98 print 123
99 func!
100catch e
101 print e
102 e
103```
104
105</YueDisplay>
diff --git a/doc/docs/de/doc/usage.md b/doc/docs/de/doc/usage.md
new file mode 100644
index 0000000..45161c6
--- /dev/null
+++ b/doc/docs/de/doc/usage.md
@@ -0,0 +1,111 @@
1# Usage
2
3## Lua Module
4
5Use YueScript module in Lua:
6
7* **Case 1**
8
9 Require "your_yuescript_entry.yue" in Lua.
10 ```Lua
11 require("yue")("your_yuescript_entry")
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.
14
15* **Case 2**
16
17 Require YueScript module and rewite message by hand.
18
19 ```lua
20 local yue = require("yue")
21 yue.insert_loader()
22 local success, result = xpcall(function()
23 return require("yuescript_module_name")
24 end, function(err)
25 return yue.traceback(err)
26 end)
27 ```
28
29* **Case 3**
30
31 Use the YueScript compiler function in Lua.
32
33 ```lua
34 local yue = require("yue")
35 local codes, err, globals = yue.to_lua([[
36 f = ->
37 print "hello world"
38 f!
39 ]],{
40 implicit_return_root = true,
41 reserve_line_number = true,
42 lint_global = true,
43 space_over_tab = false,
44 options = {
45 target = "5.4",
46 path = "/script"
47 }
48 })
49 ```
50
51## YueScript Tool
52
53Use YueScript tool with:
54
55```shell
56> yue -h
57Usage: yue
58 [options] [<file/directory>] ...
59 yue -e <code_or_file> [args...]
60 yue -w [<directory>] [options]
61 yue -
62
63Notes:
64 - '-' / '--' must be the first and only argument.
65 - '-o/--output' can not be used with multiple input files.
66 - '-w/--watch' can not be used with file input (directory only).
67 - with '-e/--execute', remaining tokens are treated as script args.
68
69Options:
70 -h, --help Show this help message and exit.
71 -e <str>, --execute <str> Execute a file or raw codes
72 -m, --minify Generate minified codes
73 -r, --rewrite Rewrite output to match original line numbers
74 -t <output_to>, --output-to <output_to>
75 Specify where to place compiled files
76 -o <file>, --output <file> Write output to file
77 -p, --print Write output to standard out
78 -b, --benchmark Dump compile time (doesn't write output)
79 -g, --globals Dump global variables used in NAME LINE COLUMN
80 -s, --spaces Use spaces in generated codes instead of tabs
81 -l, --line-numbers Write line numbers from source codes
82 -j, --no-implicit-return Disable implicit return at end of file
83 -c, --reserve-comments Reserve comments before statement from source codes
84 -w [<dir>], --watch [<dir>]
85 Watch changes and compile every file under directory
86 -v, --version Print version
87 - Read from standard in, print to standard out
88 (Must be first and only argument)
89 -- Same as '-' (kept for backward compatibility)
90
91 --target <version> Specify the Lua version that codes will be generated to
92 (version can only be 5.1 to 5.5)
93 --path <path_str> Append an extra Lua search path string to package.path
94 --<key>=<value> Pass compiler option in key=value form (existing behavior)
95
96 Execute without options to enter REPL, type symbol '$'
97 in a single line to start/stop multi-line mode
98```
99Use cases:
100
101Recursively compile every YueScript file with extension **.yue** under current path: **yue .**
102
103Compile and save results to a target path: **yue -t /target/path/ .**
104
105Compile and reserve debug info: **yue -l .**
106
107Compile and generate minified codes: **yue -m .**
108
109Execute raw codes: **yue -e 'print 123'**
110
111Execute a YueScript file: **yue -e main.yue**
diff --git a/doc/docs/de/doc/varargs-assignment.md b/doc/docs/de/doc/varargs-assignment.md
new file mode 100644
index 0000000..1d66680
--- /dev/null
+++ b/doc/docs/de/doc/varargs-assignment.md
@@ -0,0 +1,24 @@
1# Varargs Assignment
2
3You can assign the results returned from a function to a varargs symbol `...`. And then access its content using the Lua way.
4
5```yuescript
6list = [1, 2, 3, 4, 5]
7fn = (ok) -> ok, table.unpack list
8ok, ... = fn true
9count = select '#', ...
10first = select 1, ...
11print ok, count, first
12```
13<YueDisplay>
14
15```yue
16list = [1, 2, 3, 4, 5]
17fn = (ok) -> ok, table.unpack list
18ok, ... = fn true
19count = select '#', ...
20first = select 1, ...
21print ok, count, first
22```
23
24</YueDisplay>
diff --git a/doc/docs/de/doc/while-loop.md b/doc/docs/de/doc/while-loop.md
new file mode 100644
index 0000000..502935e
--- /dev/null
+++ b/doc/docs/de/doc/while-loop.md
@@ -0,0 +1,69 @@
1# While Loop
2
3The while loop also comes in four variations:
4
5```yuescript
6i = 10
7while i > 0
8 print i
9 i -= 1
10
11while running == true do my_function!
12```
13<YueDisplay>
14
15```yue
16i = 10
17while i > 0
18 print i
19 i -= 1
20
21while running == true do my_function!
22```
23
24</YueDisplay>
25
26```yuescript
27i = 10
28until i == 0
29 print i
30 i -= 1
31
32until running == false do my_function!
33```
34<YueDisplay>
35
36```yue
37i = 10
38until i == 0
39 print i
40 i -= 1
41until running == false do my_function!
42```
43
44</YueDisplay>
45
46Like 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.
47
48## Repeat Loop
49
50The repeat loop comes from Lua:
51
52```yuescript
53i = 10
54repeat
55 print i
56 i -= 1
57until i == 0
58```
59<YueDisplay>
60
61```yue
62i = 10
63repeat
64 print i
65 i -= 1
66until i == 0
67```
68
69</YueDisplay>
diff --git a/doc/docs/de/doc/whitespace.md b/doc/docs/de/doc/whitespace.md
new file mode 100644
index 0000000..d742a2b
--- /dev/null
+++ b/doc/docs/de/doc/whitespace.md
@@ -0,0 +1,43 @@
1# Whitespace
2
3YueScript 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.
4
5## Statement Separator
6
7A 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:
8
9```yuescript
10a = 1; b = 2; print a + b
11```
12<YueDisplay>
13
14```yue
15a = 1; b = 2; print a + b
16```
17
18</YueDisplay>
19
20## Multiline Chaining
21
22You can write multi-line chaining function calls with a same indent.
23
24```yuescript
25Rx.Observable
26 .fromRange 1, 8
27 \filter (x) -> x % 2 == 0
28 \concat Rx.Observable.of 'who do we appreciate'
29 \map (value) -> value .. '!'
30 \subscribe print
31```
32<YueDisplay>
33
34```yue
35Rx.Observable
36 .fromRange 1, 8
37 \filter (x) -> x % 2 == 0
38 \concat Rx.Observable.of 'who do we appreciate'
39 \map (value) -> value .. '!'
40 \subscribe print
41```
42
43</YueDisplay>
diff --git a/doc/docs/de/doc/with-statement.md b/doc/docs/de/doc/with-statement.md
new file mode 100644
index 0000000..7786803
--- /dev/null
+++ b/doc/docs/de/doc/with-statement.md
@@ -0,0 +1,126 @@
1# With Statement
2
3
4A 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
6This 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
8The 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
10For example, we work with a newly created object:
11
12```yuescript
13with Person!
14 .name = "Oswald"
15 \add_relative my_dad
16 \save!
17 print .name
18```
19<YueDisplay>
20
21```yue
22with Person!
23 .name = "Oswald"
24 \add_relative my_dad
25 \save!
26 print .name
27```
28
29</YueDisplay>
30
31The with statement can also be used as an expression which returns the value it has been giving access to.
32
33```yuescript
34file = with File "favorite_foods.txt"
35 \set_encoding "utf8"
36```
37<YueDisplay>
38
39```yue
40file = with File "favorite_foods.txt"
41 \set_encoding "utf8"
42```
43
44</YueDisplay>
45
46Or…
47
48```yuescript
49create_person = (name, relatives) ->
50 with Person!
51 .name = name
52 \add_relative relative for relative in *relatives
53
54me = create_person "Leaf", [dad, mother, sister]
55```
56<YueDisplay>
57
58```yue
59create_person = (name, relatives) ->
60 with Person!
61 .name = name
62 \add_relative relative for relative in *relatives
63
64me = create_person "Leaf", [dad, mother, sister]
65```
66
67</YueDisplay>
68
69In this usage, with can be seen as a special form of the K combinator.
70
71The expression in the with statement can also be an assignment, if you want to give a name to the expression.
72
73```yuescript
74with str := "Hello"
75 print "original:", str
76 print "upper:", \upper!
77```
78<YueDisplay>
79
80```yue
81with str := "Hello"
82 print "original:", str
83 print "upper:", \upper!
84```
85
86</YueDisplay>
87
88You can access special keys with `[]` in a `with` statement.
89
90```yuescript
91with tb
92 [1] = 1
93 print [2]
94 with [abc]
95 [3] = [2]\func!
96 ["key-name"] = value
97 [] = "abc" -- appending to "tb"
98```
99<YueDisplay>
100
101```yue
102with tb
103 [1] = 1
104 print [2]
105 with [abc]
106 [3] = [2]\func!
107 ["key-name"] = value
108 [] = "abc" -- appending to "tb"
109```
110
111</YueDisplay>
112
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.
114
115```yuescript
116with? obj
117 print obj.name
118```
119<YueDisplay>
120
121```yue
122with? obj
123 print obj.name
124```
125
126</YueDisplay>
diff --git a/doc/docs/de/index.md b/doc/docs/de/index.md
new file mode 100644
index 0000000..1a923b2
--- /dev/null
+++ b/doc/docs/de/index.md
@@ -0,0 +1,24 @@
1---
2layout: home
3hero:
4 name: YueScript
5 tagline: Eine Sprache, die zu Lua kompiliert
6 image:
7 src: /image/yuescript.svg
8 alt: YueScript
9 actions:
10 - theme: brand
11 text: Schnellstart →
12 link: /de/doc/
13features:
14 - title: Vertrauter Lua-Workflow
15 details: Schreibe kompakte Syntax, die in gut lesbares Lua mit vorhersehbarer Ausgabe kompiliert wird.
16 - title: Moderne Sprachfeatures
17 details: Pipe, Pattern Matching, Slicing und Destructuring – ohne auf Lua-Interop zu verzichten.
18 - title: Schnelle Iteration
19 details: Jedes Feedback ist willkommen, um die Entwicklung und Weiterentwicklung der Sprache zu beschleunigen!
20footer:
21 message: MIT-Lizenz.
22 copyright: Copyright © 2017-2026 Li Jin. Alle Rechte vorbehalten.
23---
24---
diff --git a/doc/docs/de/try/index.md b/doc/docs/de/try/index.md
new file mode 100755
index 0000000..f8c3193
--- /dev/null
+++ b/doc/docs/de/try/index.md
@@ -0,0 +1,6 @@
1# YueScript Online-Compiler
2---
3
4Probiere YueScript im Browser mit WASM aus.
5
6<YueCompiler />