aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2025-08-29 10:50:05 +0800
committerLi Jin <dragon-fly@qq.com>2025-08-29 10:50:05 +0800
commit5b3dba9c9c62562ce8982113b2fc96a775e73354 (patch)
tree1c0068d50f09e9b39bf390c218a5df9a89c20392
parent6137b16568d4223d6001a0956209669fbb06e8a4 (diff)
downloadyuescript-5b3dba9c9c62562ce8982113b2fc96a775e73354.tar.gz
yuescript-5b3dba9c9c62562ce8982113b2fc96a775e73354.tar.bz2
yuescript-5b3dba9c9c62562ce8982113b2fc96a775e73354.zip
Updated docs. [skip CI]
-rwxr-xr-xdoc/docs/.vuepress/components/YueCompiler.vue83
-rwxr-xr-xdoc/docs/doc/README.md47
-rwxr-xr-xdoc/docs/zh/doc/README.md48
3 files changed, 156 insertions, 22 deletions
diff --git a/doc/docs/.vuepress/components/YueCompiler.vue b/doc/docs/.vuepress/components/YueCompiler.vue
index 6b6042c..3a22d1c 100755
--- a/doc/docs/.vuepress/components/YueCompiler.vue
+++ b/doc/docs/.vuepress/components/YueCompiler.vue
@@ -1,21 +1,21 @@
1<template> 1<template>
2 <div style="width: 100%; height: auto;"> 2 <div style="width: 100%; height: auto;">
3 <div class="parent" style="background-color: #f5f7ff;"> 3 <div class="parent" style="background-color: #f5f7ff;">
4 <div class="childL" style="height: 2.5em;"> 4 <div class="editor-section">
5 <div class="childTitle">YueScript {{ info }}</div> 5 <div class="childTitle">YueScript {{ info }}</div>
6 <div class="editor-container" ref='yueEditor'>
7 <ClientOnly>
8 <prism-editor class="my-editor" v-model="code" :highlight="highlighterYue" @input="codeChanged($event)" line-numbers :readonly="readonly"></prism-editor>
9 </ClientOnly>
10 </div>
6 </div> 11 </div>
7 <div class="childR" style="height: 2.5em;"> 12 <div class="editor-section">
8 <div class="childTitle">Lua</div> 13 <div class="childTitle">Lua</div>
9 </div> 14 <div class="editor-container">
10 <div class="childL" ref='yueEditor' style="height: 30em;"> 15 <ClientOnly>
11 <ClientOnly> 16 <prism-editor class="my-editor" v-model="compiled" :highlight="highlighterLua" @input="codeChanged($event)" :line-numbers="isMobileLayout" readonly></prism-editor>
12 <prism-editor class="my-editor" v-model="code" :highlight="highlighterYue" @input="codeChanged($event)" line-numbers :readonly="readonly"></prism-editor> 17 </ClientOnly>
13 </ClientOnly> 18 </div>
14 </div>
15 <div class="childR" style="height: 30em;">
16 <ClientOnly>
17 <prism-editor class="my-editor" v-model="compiled" :highlight="highlighterLua" @input="codeChanged($event)" readonly></prism-editor>
18 </ClientOnly>
19 </div> 19 </div>
20 </div> 20 </div>
21 <div v-if="!compileronly"> 21 <div v-if="!compileronly">
@@ -57,9 +57,18 @@
57 code: '', 57 code: '',
58 compiled: '', 58 compiled: '',
59 result: '', 59 result: '',
60 windowWidth: 0,
60 }; 61 };
61 }, 62 },
63 computed: {
64 isMobileLayout() {
65 return this.windowWidth <= 768;
66 },
67 },
62 mounted () { 68 mounted () {
69 this.windowWidth = window.innerWidth;
70 window.addEventListener('resize', this.handleResize);
71
63 if (this.text !== '') { 72 if (this.text !== '') {
64 this.$data.code = this.text; 73 this.$data.code = this.text;
65 this.codeChanged(this.text); 74 this.codeChanged(this.text);
@@ -86,7 +95,13 @@
86 })(this); 95 })(this);
87 check(); 96 check();
88 }, 97 },
98 beforeDestroy() {
99 window.removeEventListener('resize', this.handleResize);
100 },
89 methods: { 101 methods: {
102 handleResize() {
103 this.windowWidth = window.innerWidth;
104 },
90 runCode() { 105 runCode() {
91 if (window.yue && this.$data.compiled !== '') { 106 if (window.yue && this.$data.compiled !== '') {
92 let res = ''; 107 let res = '';
@@ -136,27 +151,35 @@
136 resize: none; 151 resize: none;
137 margin-top: 5px; 152 margin-top: 5px;
138 } 153 }
139 .childL { 154
140 float: left; 155 .parent {
141 width: 50%; 156 display: flex;
142 box-sizing: border-box; 157 flex-wrap: wrap;
143 background-clip: content-box; 158 width: 100%;
144 background: #f5f7ff;
145 } 159 }
146 .childR { 160
147 float: left; 161 .editor-section {
148 width: 50%; 162 width: 50%;
149 box-sizing: border-box; 163 box-sizing: border-box;
150 background-clip: content-box;
151 background: #f5f7ff; 164 background: #f5f7ff;
152 } 165 }
166
167 .editor-container {
168 height: 55vh;
169 }
170
153 .childTitle { 171 .childTitle {
154 width: 100%; 172 width: 100%;
155 font-size: 1.2em; 173 font-size: 1.2em;
156 color: #b7ae8f; 174 color: #b7ae8f;
157 text-align: center; 175 text-align: center;
158 padding: 0.2em; 176 padding: 0.2em;
177 height: 2.5em;
178 display: flex;
179 align-items: center;
180 justify-content: center;
159 } 181 }
182
160 .button { 183 .button {
161 float: right; 184 float: right;
162 border: none; 185 border: none;
@@ -173,9 +196,11 @@
173 margin-top: 10px; 196 margin-top: 10px;
174 margin-right: 5px; 197 margin-right: 5px;
175 } 198 }
199
176 .button:hover { 200 .button:hover {
177 background-color: #beb69a; 201 background-color: #beb69a;
178 } 202 }
203
179 .button:focus, 204 .button:focus,
180 .button:active:focus, 205 .button:active:focus,
181 .button.active:focus, 206 .button.active:focus,
@@ -207,5 +232,19 @@
207 .my-editor >>> .prism-editor__textarea:focus { 232 .my-editor >>> .prism-editor__textarea:focus {
208 outline: none; 233 outline: none;
209 } 234 }
210</style>
211 235
236 /* 移动端响应式布局 */
237 @media screen and (max-width: 768px) {
238 .parent {
239 flex-direction: column;
240 }
241
242 .editor-section {
243 width: 100%;
244 }
245
246 .editor-container {
247 height: 30vh;
248 }
249 }
250</style>
diff --git a/doc/docs/doc/README.md b/doc/docs/doc/README.md
index 5b8fc59..57f27c8 100755
--- a/doc/docs/doc/README.md
+++ b/doc/docs/doc/README.md
@@ -2161,6 +2161,53 @@ f2 arg1, arg2
2161</pre> 2161</pre>
2162</YueDisplay> 2162</YueDisplay>
2163 2163
2164### Prefixed Return Expression
2165
2166When 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:
2167
2168```moon
2169findFirstEven = (list): nil ->
2170 for item in *list
2171 if type(item) == "table"
2172 for sub in *item
2173 if sub % 2 == 0
2174 return sub
2175```
2176<YueDisplay>
2177<pre>
2178findFirstEven = (list): nil ->
2179 for item in *list
2180 if type(item) == "table"
2181 for sub in *item
2182 if sub % 2 == 0
2183 return sub
2184</pre>
2185</YueDisplay>
2186
2187This is equivalent to:
2188
2189```moon
2190findFirstEven = (list) ->
2191 for item in *list
2192 if type(item) == "table"
2193 for sub in *item
2194 if sub % 2 == 0
2195 return sub
2196 nil
2197```
2198<YueDisplay>
2199<pre>
2200findFirstEven = (list) ->
2201 for item in *list
2202 if type(item) == "table"
2203 for sub in *item
2204 if sub % 2 == 0
2205 return sub
2206 nil
2207</pre>
2208</YueDisplay>
2209
2210The 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.
2164 2211
2165## Backcalls 2212## Backcalls
2166 2213
diff --git a/doc/docs/zh/doc/README.md b/doc/docs/zh/doc/README.md
index 0aea3d5..5cfe4e6 100755
--- a/doc/docs/zh/doc/README.md
+++ b/doc/docs/zh/doc/README.md
@@ -2121,6 +2121,54 @@ f2 arg1, arg2
2121</pre> 2121</pre>
2122</YueDisplay> 2122</YueDisplay>
2123 2123
2124### 前置返回表达式
2125
2126在深度嵌套的函数体中,为了提升返回值的可读性及编写便利性,我们新增了 “前置返回表达式” 语法。其形式如下:
2127
2128```moon
2129findFirstEven = (list): nil ->
2130 for item in *list
2131 if type(item) == "table"
2132 for sub in *item
2133 if sub % 2 == 0
2134 return sub
2135```
2136<YueDisplay>
2137<pre>
2138findFirstEven = (list): nil ->
2139 for item in *list
2140 if type(item) == "table"
2141 for sub in *item
2142 if sub % 2 == 0
2143 return sub
2144</pre>
2145</YueDisplay>
2146
2147这个写法等价于:
2148
2149```moon
2150findFirstEven = (list) ->
2151 for item in *list
2152 if type(item) == "table"
2153 for sub in *item
2154 if sub % 2 == 0
2155 return sub
2156 nil
2157```
2158<YueDisplay>
2159<pre>
2160findFirstEven = (list) ->
2161 for item in *list
2162 if type(item) == "table"
2163 for sub in *item
2164 if sub % 2 == 0
2165 return sub
2166 nil
2167</pre>
2168</YueDisplay>
2169
2170唯一的区别在于:你可以将函数的返回值表达式提前写在 `->` 或 `=>` 前,用以指示该函数应隐式返回该表达式的值。这样即使在多层循环或条件判断的场景下,也无需编写尾行悬挂的返回表达式,逻辑结构会更加直观清晰。
2171
2124## 反向回调 2172## 反向回调
2125 2173
2126反向回调用于减少函数回调的嵌套。它们使用指向左侧的箭头,并且默认会被定义为传入后续函数调用的最后一个参数。它的语法大部分与常规箭头函数相同,只是它指向另一方向,并且后续的函数体不需要进行缩进。 2174反向回调用于减少函数回调的嵌套。它们使用指向左侧的箭头,并且默认会被定义为传入后续函数调用的最后一个参数。它的语法大部分与常规箭头函数相同,只是它指向另一方向,并且后续的函数体不需要进行缩进。