aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2026-02-06 10:30:49 +0800
committerLi Jin <dragon-fly@qq.com>2026-02-06 10:30:49 +0800
commitaa3ecc7badfb39cb9167fb95c9a678257c1d9954 (patch)
treea309d9af64ae060e2086c8bcdcf943693c8dcbba
parent03902475c542c3ec4f1884c4217f8a4ef61f3ca8 (diff)
downloadyuescript-aa3ecc7badfb39cb9167fb95c9a678257c1d9954.tar.gz
yuescript-aa3ecc7badfb39cb9167fb95c9a678257c1d9954.tar.bz2
yuescript-aa3ecc7badfb39cb9167fb95c9a678257c1d9954.zip
Fixed docs.
-rw-r--r--doc/docs/.vitepress/config.mts242
-rw-r--r--doc/docs/id-id/doc/advanced/do.md66
-rw-r--r--doc/docs/id-id/doc/advanced/line-decorators.md44
-rw-r--r--doc/docs/id-id/doc/advanced/macro.md275
-rw-r--r--doc/docs/id-id/doc/advanced/module.md245
-rw-r--r--doc/docs/id-id/doc/advanced/try.md105
-rw-r--r--doc/docs/id-id/doc/assignment/assignment.md138
-rw-r--r--doc/docs/id-id/doc/assignment/destructuring-assignment.md240
-rw-r--r--doc/docs/id-id/doc/assignment/if-assignment.md72
-rw-r--r--doc/docs/id-id/doc/assignment/the-using-clause-controlling-destructive-assignment.md98
-rw-r--r--doc/docs/id-id/doc/assignment/varargs-assignment.md24
-rw-r--r--doc/docs/id-id/doc/control-flow/conditionals.md149
-rw-r--r--doc/docs/id-id/doc/control-flow/continue.md41
-rw-r--r--doc/docs/id-id/doc/control-flow/for-loop.md127
-rw-r--r--doc/docs/id-id/doc/control-flow/switch.md296
-rw-r--r--doc/docs/id-id/doc/control-flow/while-loop.md69
-rw-r--r--doc/docs/id-id/doc/data-structures/comprehensions.md271
-rw-r--r--doc/docs/id-id/doc/data-structures/table-literals.md168
-rw-r--r--doc/docs/id-id/doc/functions/backcalls.md69
-rw-r--r--doc/docs/id-id/doc/functions/function-literals.md494
-rw-r--r--doc/docs/id-id/doc/functions/function-stubs.md48
-rw-r--r--doc/docs/id-id/doc/getting-started/installation.md43
-rw-r--r--doc/docs/id-id/doc/getting-started/introduction.md105
-rw-r--r--doc/docs/id-id/doc/getting-started/usage.md111
-rwxr-xr-xdoc/docs/id-id/doc/index.md11
-rw-r--r--doc/docs/id-id/doc/language-basics/attributes.md46
-rw-r--r--doc/docs/id-id/doc/language-basics/comment.md30
-rw-r--r--doc/docs/id-id/doc/language-basics/literals.md110
-rw-r--r--doc/docs/id-id/doc/language-basics/operator.md460
-rw-r--r--doc/docs/id-id/doc/language-basics/whitespace.md43
-rw-r--r--doc/docs/id-id/doc/objects/object-oriented-programming.md555
-rw-r--r--doc/docs/id-id/doc/objects/with-statement.md126
-rw-r--r--doc/docs/id-id/doc/reference/license-mit.md23
-rw-r--r--doc/docs/id-id/doc/reference/the-yuescript-library.md821
-rw-r--r--doc/docs/id-id/index.md23
-rwxr-xr-xdoc/docs/id-id/try/index.md12
-rw-r--r--spec/inputs/compile_doc.yue100
-rw-r--r--spec/inputs/test/format_spec.yue2
-rw-r--r--spec/outputs/codes_from_doc_de.lua (renamed from spec/outputs/codes_from_doc.lua)5326
-rw-r--r--spec/outputs/codes_from_doc_en.lua5148
-rw-r--r--spec/outputs/codes_from_doc_id-id.lua5148
-rw-r--r--spec/outputs/codes_from_doc_pt-br.lua5148
-rw-r--r--spec/outputs/codes_from_doc_zh.lua5326
-rw-r--r--spec/outputs/compile_doc.lua134
-rw-r--r--spec/outputs/test/format_spec.lua2
-rw-r--r--src/yuescript/yue_compiler.cpp2
-rw-r--r--src/yuescript/yue_parser.cpp4
47 files changed, 26587 insertions, 5553 deletions
diff --git a/doc/docs/.vitepress/config.mts b/doc/docs/.vitepress/config.mts
index ed89e32..9491a8d 100644
--- a/doc/docs/.vitepress/config.mts
+++ b/doc/docs/.vitepress/config.mts
@@ -20,6 +20,40 @@ const yuescriptLanguage = {
20} 20}
21 21
22const sidebarText = { 22const sidebarText = {
23 de: {
24 introduction: 'Einführung',
25 installation: 'Installation',
26 usage: 'Verwendung',
27 macro: 'Makro',
28 operator: 'Operatoren',
29 module: 'Modul',
30 assignment: 'Zuweisung',
31 destructuringAssignment: 'Destrukturierende Zuweisung',
32 ifAssignment: 'If-Zuweisung',
33 varargsAssignment: 'Varargs-Zuweisung',
34 whitespace: 'Leerraum',
35 comment: 'Kommentare',
36 try: 'Try/Catch',
37 attributes: 'Attribute',
38 literals: 'Literale',
39 functionLiterals: 'Funktionsliterale',
40 backcalls: 'Backcalls',
41 tableLiterals: 'Tabellenliterale',
42 comprehensions: 'Comprehensions',
43 forLoop: 'For-Schleife',
44 whileLoop: 'While-Schleife',
45 continueStatement: 'Continue-Anweisung',
46 conditionals: 'Bedingungen',
47 lineDecorators: 'Zeilen-Dekoratoren',
48 switch: 'Switch',
49 objectOrientedProgramming: 'Objektorientierte Programmierung',
50 withStatement: 'With-Anweisung',
51 do: 'Do',
52 functionStubs: 'Funktions-Stubs',
53 usingClause: 'Die Using-Klausel; Kontrolle destruktiver Zuweisung',
54 yuescriptLibrary: 'Die YueScript-Bibliothek',
55 licenseMit: 'Lizenz: MIT',
56 },
23 en: { 57 en: {
24 introduction: 'Introduction', 58 introduction: 'Introduction',
25 installation: 'Installation', 59 installation: 'Installation',
@@ -54,73 +88,39 @@ const sidebarText = {
54 yuescriptLibrary: 'The YueScript Library', 88 yuescriptLibrary: 'The YueScript Library',
55 licenseMit: 'License: MIT', 89 licenseMit: 'License: MIT',
56 }, 90 },
57 zh: { 91 idId: {
58 introduction: '介绍', 92 introduction: 'Pendahuluan',
59 installation: '安装', 93 installation: 'Instalasi',
60 usage: '使用方法', 94 usage: 'Penggunaan',
61 macro: '宏',
62 operator: '操作符',
63 module: '模块',
64 assignment: '赋值',
65 destructuringAssignment: '解构赋值',
66 ifAssignment: 'if 赋值',
67 varargsAssignment: '可变参数赋值',
68 whitespace: '空白',
69 comment: '注释',
70 try: '错误处理',
71 attributes: '属性',
72 literals: '字面量',
73 functionLiterals: '函数字面量',
74 backcalls: '反向回调',
75 tableLiterals: '表格字面量',
76 comprehensions: '推导式',
77 forLoop: 'for 循环',
78 whileLoop: 'while 循环',
79 continueStatement: 'continue 语句',
80 conditionals: '条件语句',
81 lineDecorators: '代码行修饰符',
82 switch: 'switch 语句',
83 objectOrientedProgramming: '面向对象编程',
84 withStatement: 'with 语句',
85 do: 'do 语句',
86 functionStubs: '函数存根',
87 usingClause: '使用 using 语句:防止破坏性赋值',
88 yuescriptLibrary: '月之脚本语言库',
89 licenseMit: 'MIT 许可证',
90 },
91 de: {
92 introduction: 'Einführung',
93 installation: 'Installation',
94 usage: 'Verwendung',
95 macro: 'Makro', 95 macro: 'Makro',
96 operator: 'Operatoren', 96 operator: 'Operator',
97 module: 'Modul', 97 module: 'Modul',
98 assignment: 'Zuweisung', 98 assignment: 'Penugasan',
99 destructuringAssignment: 'Destrukturierende Zuweisung', 99 destructuringAssignment: 'Penugasan Destrukturisasi',
100 ifAssignment: 'If-Zuweisung', 100 ifAssignment: 'Penugasan If',
101 varargsAssignment: 'Varargs-Zuweisung', 101 varargsAssignment: 'Penugasan Varargs',
102 whitespace: 'Leerraum', 102 whitespace: 'Spasi Kosong',
103 comment: 'Kommentare', 103 comment: 'Komentar',
104 try: 'Try/Catch', 104 try: 'Coba',
105 attributes: 'Attribute', 105 attributes: 'Atribut',
106 literals: 'Literale', 106 literals: 'Literal',
107 functionLiterals: 'Funktionsliterale', 107 functionLiterals: 'Literal Fungsi',
108 backcalls: 'Backcalls', 108 backcalls: 'Pemanggilan Mundur',
109 tableLiterals: 'Tabellenliterale', 109 tableLiterals: 'Literal Tabel',
110 comprehensions: 'Comprehensions', 110 comprehensions: 'Kompresi',
111 forLoop: 'For-Schleife', 111 forLoop: 'Perulangan For',
112 whileLoop: 'While-Schleife', 112 whileLoop: 'Perulangan While',
113 continueStatement: 'Continue-Anweisung', 113 continueStatement: 'Pernyataan Lanjutkan',
114 conditionals: 'Bedingungen', 114 conditionals: 'Percabangan',
115 lineDecorators: 'Zeilen-Dekoratoren', 115 lineDecorators: 'Dekorator Baris',
116 switch: 'Switch', 116 switch: 'Switch',
117 objectOrientedProgramming: 'Objektorientierte Programmierung', 117 objectOrientedProgramming: 'Pemrograman Berorientasi Objek',
118 withStatement: 'With-Anweisung', 118 withStatement: 'Pernyataan With',
119 do: 'Do', 119 do: 'Do',
120 functionStubs: 'Funktions-Stubs', 120 functionStubs: 'Fungsi Sementara',
121 usingClause: 'Die Using-Klausel; Kontrolle destruktiver Zuweisung', 121 usingClause: 'Klausa Using; Mengontrol Penugasan Destruktif',
122 yuescriptLibrary: 'Die YueScript-Bibliothek', 122 yuescriptLibrary: 'Pustaka YueScript',
123 licenseMit: 'Lizenz: MIT', 123 licenseMit: 'Lisensi: MIT',
124 }, 124 },
125 ptBr: { 125 ptBr: {
126 introduction: 'Introdução', 126 introduction: 'Introdução',
@@ -156,6 +156,40 @@ const sidebarText = {
156 yuescriptLibrary: 'A biblioteca do YueScript', 156 yuescriptLibrary: 'A biblioteca do YueScript',
157 licenseMit: 'Licença: MIT', 157 licenseMit: 'Licença: MIT',
158 }, 158 },
159 zh: {
160 introduction: '介绍',
161 installation: '安装',
162 usage: '使用方法',
163 macro: '宏',
164 operator: '操作符',
165 module: '模块',
166 assignment: '赋值',
167 destructuringAssignment: '解构赋值',
168 ifAssignment: 'if 赋值',
169 varargsAssignment: '可变参数赋值',
170 whitespace: '空白',
171 comment: '注释',
172 try: '错误处理',
173 attributes: '属性',
174 literals: '字面量',
175 functionLiterals: '函数字面量',
176 backcalls: '反向回调',
177 tableLiterals: '表格字面量',
178 comprehensions: '推导式',
179 forLoop: 'for 循环',
180 whileLoop: 'while 循环',
181 continueStatement: 'continue 语句',
182 conditionals: '条件语句',
183 lineDecorators: '代码行修饰符',
184 switch: 'switch 语句',
185 objectOrientedProgramming: '面向对象编程',
186 withStatement: 'with 语句',
187 do: 'do 语句',
188 functionStubs: '函数存根',
189 usingClause: '使用 using 语句:防止破坏性赋值',
190 yuescriptLibrary: '月之脚本语言库',
191 licenseMit: 'MIT 许可证',
192 },
159} as const 193} as const
160 194
161type SidebarLocale = keyof typeof sidebarText 195type SidebarLocale = keyof typeof sidebarText
@@ -173,6 +207,17 @@ type SidebarGroupText = {
173} 207}
174 208
175const sidebarGroups: Record<SidebarLocale, SidebarGroupText> = { 209const sidebarGroups: Record<SidebarLocale, SidebarGroupText> = {
210 de: {
211 gettingStarted: 'Erste Schritte',
212 languageBasics: 'Sprachgrundlagen',
213 assignment: 'Zuweisung',
214 functions: 'Funktionen',
215 controlFlow: 'Kontrollfluss',
216 dataStructures: 'Datenstrukturen',
217 objects: 'Objekte',
218 advancedFeatures: 'Erweiterte Funktionen',
219 reference: 'Referenz',
220 },
176 en: { 221 en: {
177 gettingStarted: 'Getting Started', 222 gettingStarted: 'Getting Started',
178 languageBasics: 'Language Basics', 223 languageBasics: 'Language Basics',
@@ -184,27 +229,16 @@ const sidebarGroups: Record<SidebarLocale, SidebarGroupText> = {
184 advancedFeatures: 'Advanced Features', 229 advancedFeatures: 'Advanced Features',
185 reference: 'Reference', 230 reference: 'Reference',
186 }, 231 },
187 zh: { 232 idId: {
188 gettingStarted: '起步', 233 gettingStarted: 'Memulai',
189 languageBasics: '语言基础', 234 languageBasics: 'Dasar-dasar Bahasa',
190 assignment: '赋值', 235 assignment: 'Penugasan',
191 functions: '函数', 236 functions: 'Fungsi',
192 controlFlow: '控制流', 237 controlFlow: 'Alur Kontrol',
193 dataStructures: '数据结构', 238 dataStructures: 'Struktur Data',
194 objects: '面向对象', 239 objects: 'Objek',
195 advancedFeatures: '高级特性', 240 advancedFeatures: 'Fitur Lanjutan',
196 reference: '参考', 241 reference: 'Referensi',
197 },
198 de: {
199 gettingStarted: 'Erste Schritte',
200 languageBasics: 'Sprachgrundlagen',
201 assignment: 'Zuweisung',
202 functions: 'Funktionen',
203 controlFlow: 'Kontrollfluss',
204 dataStructures: 'Datenstrukturen',
205 objects: 'Objekte',
206 advancedFeatures: 'Erweiterte Funktionen',
207 reference: 'Referenz',
208 }, 242 },
209 ptBr: { 243 ptBr: {
210 gettingStarted: 'Primeiros passos', 244 gettingStarted: 'Primeiros passos',
@@ -217,6 +251,17 @@ const sidebarGroups: Record<SidebarLocale, SidebarGroupText> = {
217 advancedFeatures: 'Recursos avançados', 251 advancedFeatures: 'Recursos avançados',
218 reference: 'Referência', 252 reference: 'Referência',
219 }, 253 },
254 zh: {
255 gettingStarted: '起步',
256 languageBasics: '语言基础',
257 assignment: '赋值',
258 functions: '函数',
259 controlFlow: '控制流',
260 dataStructures: '数据结构',
261 objects: '面向对象',
262 advancedFeatures: '高级特性',
263 reference: '参考',
264 },
220} 265}
221 266
222function createSidebar(basePath: string, locale: SidebarLocale) { 267function createSidebar(basePath: string, locale: SidebarLocale) {
@@ -384,17 +429,17 @@ export default defineConfig({
384 sidebar: createSidebar('/doc', 'en'), 429 sidebar: createSidebar('/doc', 'en'),
385 } 430 }
386 }, 431 },
387 zh: { 432 'id-id': {
388 label: '简体中文', 433 label: 'Bahasa Indonesia',
389 lang: 'zh-CN', 434 lang: 'id-ID',
390 description: '一门编译到 Lua 的语言', 435 description: 'Bahasa yang dikompilasi ke Lua',
391 themeConfig: { 436 themeConfig: {
392 nav: [ 437 nav: [
393 { text: '文档', link: '/zh/doc/' }, 438 { text: 'Dokumentasi', link: '/id-id/doc/' },
394 { text: '试一试!', link: '/zh/try/' }, 439 { text: 'Coba Yue!', link: '/id-id/try/' },
395 { text: 'GitHub', link: 'https://github.com/IppClub/Yuescript' } 440 { text: 'GitHub', link: 'https://github.com/IppClub/Yuescript' }
396 ], 441 ],
397 sidebar: createSidebar('/zh/doc', 'zh'), 442 sidebar: createSidebar('/id-id/doc', 'idId'),
398 } 443 }
399 }, 444 },
400 de: { 445 de: {
@@ -422,7 +467,20 @@ export default defineConfig({
422 ], 467 ],
423 sidebar: createSidebar('/pt-br/doc', 'ptBr'), 468 sidebar: createSidebar('/pt-br/doc', 'ptBr'),
424 } 469 }
425 } 470 },
471 zh: {
472 label: '简体中文',
473 lang: 'zh-CN',
474 description: '一门编译到 Lua 的语言',
475 themeConfig: {
476 nav: [
477 { text: '文档', link: '/zh/doc/' },
478 { text: '试一试!', link: '/zh/try/' },
479 { text: 'GitHub', link: 'https://github.com/IppClub/Yuescript' }
480 ],
481 sidebar: createSidebar('/zh/doc', 'zh'),
482 }
483 },
426 }, 484 },
427 themeConfig: { 485 themeConfig: {
428 search: { 486 search: {
diff --git a/doc/docs/id-id/doc/advanced/do.md b/doc/docs/id-id/doc/advanced/do.md
new file mode 100644
index 0000000..4990d6f
--- /dev/null
+++ b/doc/docs/id-id/doc/advanced/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/id-id/doc/advanced/line-decorators.md b/doc/docs/id-id/doc/advanced/line-decorators.md
new file mode 100644
index 0000000..292bc77
--- /dev/null
+++ b/doc/docs/id-id/doc/advanced/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/id-id/doc/advanced/macro.md b/doc/docs/id-id/doc/advanced/macro.md
new file mode 100644
index 0000000..6d194c3
--- /dev/null
+++ b/doc/docs/id-id/doc/advanced/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/id-id/doc/advanced/module.md b/doc/docs/id-id/doc/advanced/module.md
new file mode 100644
index 0000000..c955092
--- /dev/null
+++ b/doc/docs/id-id/doc/advanced/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/id-id/doc/advanced/try.md b/doc/docs/id-id/doc/advanced/try.md
new file mode 100644
index 0000000..23c7877
--- /dev/null
+++ b/doc/docs/id-id/doc/advanced/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/id-id/doc/assignment/assignment.md b/doc/docs/id-id/doc/assignment/assignment.md
new file mode 100644
index 0000000..4dac6f4
--- /dev/null
+++ b/doc/docs/id-id/doc/assignment/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/id-id/doc/assignment/destructuring-assignment.md b/doc/docs/id-id/doc/assignment/destructuring-assignment.md
new file mode 100644
index 0000000..e7b8046
--- /dev/null
+++ b/doc/docs/id-id/doc/assignment/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/id-id/doc/assignment/if-assignment.md b/doc/docs/id-id/doc/assignment/if-assignment.md
new file mode 100644
index 0000000..02984e8
--- /dev/null
+++ b/doc/docs/id-id/doc/assignment/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/id-id/doc/assignment/the-using-clause-controlling-destructive-assignment.md b/doc/docs/id-id/doc/assignment/the-using-clause-controlling-destructive-assignment.md
new file mode 100644
index 0000000..fb9b740
--- /dev/null
+++ b/doc/docs/id-id/doc/assignment/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/id-id/doc/assignment/varargs-assignment.md b/doc/docs/id-id/doc/assignment/varargs-assignment.md
new file mode 100644
index 0000000..1d66680
--- /dev/null
+++ b/doc/docs/id-id/doc/assignment/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/id-id/doc/control-flow/conditionals.md b/doc/docs/id-id/doc/control-flow/conditionals.md
new file mode 100644
index 0000000..5ba81cf
--- /dev/null
+++ b/doc/docs/id-id/doc/control-flow/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/id-id/doc/control-flow/continue.md b/doc/docs/id-id/doc/control-flow/continue.md
new file mode 100644
index 0000000..b000765
--- /dev/null
+++ b/doc/docs/id-id/doc/control-flow/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/id-id/doc/control-flow/for-loop.md b/doc/docs/id-id/doc/control-flow/for-loop.md
new file mode 100644
index 0000000..cabcde5
--- /dev/null
+++ b/doc/docs/id-id/doc/control-flow/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/id-id/doc/control-flow/switch.md b/doc/docs/id-id/doc/control-flow/switch.md
new file mode 100644
index 0000000..f503a80
--- /dev/null
+++ b/doc/docs/id-id/doc/control-flow/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/id-id/doc/control-flow/while-loop.md b/doc/docs/id-id/doc/control-flow/while-loop.md
new file mode 100644
index 0000000..502935e
--- /dev/null
+++ b/doc/docs/id-id/doc/control-flow/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/id-id/doc/data-structures/comprehensions.md b/doc/docs/id-id/doc/data-structures/comprehensions.md
new file mode 100644
index 0000000..3a92167
--- /dev/null
+++ b/doc/docs/id-id/doc/data-structures/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/id-id/doc/data-structures/table-literals.md b/doc/docs/id-id/doc/data-structures/table-literals.md
new file mode 100644
index 0000000..c1adcab
--- /dev/null
+++ b/doc/docs/id-id/doc/data-structures/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/id-id/doc/functions/backcalls.md b/doc/docs/id-id/doc/functions/backcalls.md
new file mode 100644
index 0000000..e34331e
--- /dev/null
+++ b/doc/docs/id-id/doc/functions/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/id-id/doc/functions/function-literals.md b/doc/docs/id-id/doc/functions/function-literals.md
new file mode 100644
index 0000000..316e07c
--- /dev/null
+++ b/doc/docs/id-id/doc/functions/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/id-id/doc/functions/function-stubs.md b/doc/docs/id-id/doc/functions/function-stubs.md
new file mode 100644
index 0000000..57a8b0c
--- /dev/null
+++ b/doc/docs/id-id/doc/functions/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/id-id/doc/getting-started/installation.md b/doc/docs/id-id/doc/getting-started/installation.md
new file mode 100644
index 0000000..a93ddfd
--- /dev/null
+++ b/doc/docs/id-id/doc/getting-started/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/id-id/doc/getting-started/introduction.md b/doc/docs/id-id/doc/getting-started/introduction.md
new file mode 100644
index 0000000..a9a9389
--- /dev/null
+++ b/doc/docs/id-id/doc/getting-started/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/id-id/doc/getting-started/usage.md b/doc/docs/id-id/doc/getting-started/usage.md
new file mode 100644
index 0000000..45161c6
--- /dev/null
+++ b/doc/docs/id-id/doc/getting-started/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/id-id/doc/index.md b/doc/docs/id-id/doc/index.md
new file mode 100755
index 0000000..b7f609b
--- /dev/null
+++ b/doc/docs/id-id/doc/index.md
@@ -0,0 +1,11 @@
1---
2title: Reference
3---
4
5# YueScript Documentation
6
7<img src="/image/yuescript.svg" width="250px" height="250px" alt="logo" style="padding-top: 3em; padding-bottom: 2em;"/>
8
9Welcome to the <b>YueScript</b> official documentation!<br/>
10Here you can find the language features, usage, reference examples and resources.<br/>
11Please select a chapter from the sidebar to start learning about YueScript.
diff --git a/doc/docs/id-id/doc/language-basics/attributes.md b/doc/docs/id-id/doc/language-basics/attributes.md
new file mode 100644
index 0000000..e6fd5a7
--- /dev/null
+++ b/doc/docs/id-id/doc/language-basics/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/id-id/doc/language-basics/comment.md b/doc/docs/id-id/doc/language-basics/comment.md
new file mode 100644
index 0000000..b67c97d
--- /dev/null
+++ b/doc/docs/id-id/doc/language-basics/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/id-id/doc/language-basics/literals.md b/doc/docs/id-id/doc/language-basics/literals.md
new file mode 100644
index 0000000..e097c62
--- /dev/null
+++ b/doc/docs/id-id/doc/language-basics/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/id-id/doc/language-basics/operator.md b/doc/docs/id-id/doc/language-basics/operator.md
new file mode 100644
index 0000000..9a2e89b
--- /dev/null
+++ b/doc/docs/id-id/doc/language-basics/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/id-id/doc/language-basics/whitespace.md b/doc/docs/id-id/doc/language-basics/whitespace.md
new file mode 100644
index 0000000..d742a2b
--- /dev/null
+++ b/doc/docs/id-id/doc/language-basics/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/id-id/doc/objects/object-oriented-programming.md b/doc/docs/id-id/doc/objects/object-oriented-programming.md
new file mode 100644
index 0000000..6a8559e
--- /dev/null
+++ b/doc/docs/id-id/doc/objects/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/id-id/doc/objects/with-statement.md b/doc/docs/id-id/doc/objects/with-statement.md
new file mode 100644
index 0000000..7786803
--- /dev/null
+++ b/doc/docs/id-id/doc/objects/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/id-id/doc/reference/license-mit.md b/doc/docs/id-id/doc/reference/license-mit.md
new file mode 100644
index 0000000..f1d5d60
--- /dev/null
+++ b/doc/docs/id-id/doc/reference/license-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/id-id/doc/reference/the-yuescript-library.md b/doc/docs/id-id/doc/reference/the-yuescript-library.md
new file mode 100644
index 0000000..3761755
--- /dev/null
+++ b/doc/docs/id-id/doc/reference/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/id-id/index.md b/doc/docs/id-id/index.md
new file mode 100644
index 0000000..016b688
--- /dev/null
+++ b/doc/docs/id-id/index.md
@@ -0,0 +1,23 @@
1---
2layout: home
3hero:
4 name: YueScript
5 tagline: A language that compiles to Lua
6 image:
7 src: /image/yuescript.svg
8 alt: YueScript
9 actions:
10 - theme: brand
11 text: Quick Start →
12 link: /doc/
13features:
14 - title: Familiar Lua workflows
15 details: Write concise syntax that compiles to readable Lua, with predictable output.
16 - title: Modern language features
17 details: Pipe, pattern matching, slicing, and destructuring without giving up Lua interop.
18 - title: Rapid Iteration
19 details: Any feedback is welcome to help accelerate the language development and evolution!
20footer:
21 message: MIT License.
22 copyright: Copyright © 2017-2026 Li Jin. All rights reserved.
23---
diff --git a/doc/docs/id-id/try/index.md b/doc/docs/id-id/try/index.md
new file mode 100755
index 0000000..85a903b
--- /dev/null
+++ b/doc/docs/id-id/try/index.md
@@ -0,0 +1,12 @@
1---
2aside: false
3prev: false
4next: false
5---
6
7# YueScript Online Compiler
8---
9
10Try YueScript in the browser with WASM.
11
12<YueCompiler />
diff --git a/spec/inputs/compile_doc.yue b/spec/inputs/compile_doc.yue
index 45a0b16..20f68df 100644
--- a/spec/inputs/compile_doc.yue
+++ b/spec/inputs/compile_doc.yue
@@ -1,66 +1,44 @@
1outputFolder = ... 1outputFolder = ...
2for [compiledFile, docFiles] in *[ 2
3 ["codes_from_doc.lua", [ 3getFiles = (locale) ->
4 "doc/docs/doc/introduction.md" 4 locale = if locale == "en" then "" else "#{locale}/"
5 "doc/docs/doc/macro.md" 5 [
6 "doc/docs/doc/operator.md" 6 "doc/docs/#{locale}doc/index.md"
7 "doc/docs/doc/module.md" 7 "doc/docs/#{locale}doc/advanced/do.md"
8 "doc/docs/doc/assignment.md" 8 "doc/docs/#{locale}doc/advanced/line-decorators.md"
9 "doc/docs/doc/destructuring-assignment.md" 9 "doc/docs/#{locale}doc/advanced/macro.md"
10 "doc/docs/doc/if-assignment.md" 10 "doc/docs/#{locale}doc/advanced/module.md"
11 "doc/docs/doc/varargs-assignment.md" 11 "doc/docs/#{locale}doc/advanced/try.md"
12 "doc/docs/doc/whitespace.md" 12 "doc/docs/#{locale}doc/data-structures/table-literals.md"
13 "doc/docs/doc/comment.md" 13 "doc/docs/#{locale}doc/data-structures/comprehensions.md"
14 "doc/docs/doc/try.md" 14 "doc/docs/#{locale}doc/objects/object-oriented-programming.md"
15 "doc/docs/doc/attributes.md" 15 "doc/docs/#{locale}doc/objects/with-statement.md"
16 "doc/docs/doc/literals.md" 16 "doc/docs/#{locale}doc/assignment/assignment.md"
17 "doc/docs/doc/function-literals.md" 17 "doc/docs/#{locale}doc/assignment/varargs-assignment.md"
18 "doc/docs/doc/backcalls.md" 18 "doc/docs/#{locale}doc/assignment/if-assignment.md"
19 "doc/docs/doc/table-literals.md" 19 "doc/docs/#{locale}doc/assignment/destructuring-assignment.md"
20 "doc/docs/doc/comprehensions.md" 20 "doc/docs/#{locale}doc/assignment/the-using-clause-controlling-destructive-assignment.md"
21 "doc/docs/doc/for-loop.md" 21 "doc/docs/#{locale}doc/getting-started/usage.md"
22 "doc/docs/doc/while-loop.md" 22 "doc/docs/#{locale}doc/getting-started/introduction.md"
23 "doc/docs/doc/continue.md" 23 "doc/docs/#{locale}doc/getting-started/installation.md"
24 "doc/docs/doc/conditionals.md" 24 "doc/docs/#{locale}doc/control-flow/conditionals.md"
25 "doc/docs/doc/line-decorators.md" 25 "doc/docs/#{locale}doc/control-flow/for-loop.md"
26 "doc/docs/doc/switch.md" 26 "doc/docs/#{locale}doc/control-flow/continue.md"
27 "doc/docs/doc/object-oriented-programming.md" 27 "doc/docs/#{locale}doc/control-flow/switch.md"
28 "doc/docs/doc/with-statement.md" 28 "doc/docs/#{locale}doc/control-flow/while-loop.md"
29 "doc/docs/doc/do.md" 29 "doc/docs/#{locale}doc/functions/function-stubs.md"
30 "doc/docs/doc/function-stubs.md" 30 "doc/docs/#{locale}doc/functions/backcalls.md"
31 "doc/docs/doc/the-using-clause-controlling-destructive-assignment.md" 31 "doc/docs/#{locale}doc/functions/function-literals.md"
32 ]] 32 "doc/docs/#{locale}doc/language-basics/whitespace.md"
33 ["codes_from_doc_zh.lua", [ 33 "doc/docs/#{locale}doc/language-basics/comment.md"
34 "doc/docs/zh/doc/introduction.md" 34 "doc/docs/#{locale}doc/language-basics/attributes.md"
35 "doc/docs/zh/doc/macro.md" 35 "doc/docs/#{locale}doc/language-basics/operator.md"
36 "doc/docs/zh/doc/operator.md" 36 "doc/docs/#{locale}doc/language-basics/literals.md"
37 "doc/docs/zh/doc/module.md" 37 "doc/docs/#{locale}doc/reference/license-mit.md"
38 "doc/docs/zh/doc/assignment.md" 38 "doc/docs/#{locale}doc/reference/the-yuescript-library.md"
39 "doc/docs/zh/doc/destructuring-assignment.md"
40 "doc/docs/zh/doc/if-assignment.md"
41 "doc/docs/zh/doc/varargs-assignment.md"
42 "doc/docs/zh/doc/whitespace.md"
43 "doc/docs/zh/doc/comment.md"
44 "doc/docs/zh/doc/try.md"
45 "doc/docs/zh/doc/attributes.md"
46 "doc/docs/zh/doc/literals.md"
47 "doc/docs/zh/doc/function-literals.md"
48 "doc/docs/zh/doc/backcalls.md"
49 "doc/docs/zh/doc/table-literals.md"
50 "doc/docs/zh/doc/comprehensions.md"
51 "doc/docs/zh/doc/for-loop.md"
52 "doc/docs/zh/doc/while-loop.md"
53 "doc/docs/zh/doc/continue.md"
54 "doc/docs/zh/doc/conditionals.md"
55 "doc/docs/zh/doc/line-decorators.md"
56 "doc/docs/zh/doc/switch.md"
57 "doc/docs/zh/doc/object-oriented-programming.md"
58 "doc/docs/zh/doc/with-statement.md"
59 "doc/docs/zh/doc/do.md"
60 "doc/docs/zh/doc/function-stubs.md"
61 "doc/docs/zh/doc/the-using-clause-controlling-destructive-assignment.md"
62 ]]
63 ] 39 ]
40docs = [ ["codes_from_doc_#{locale}.lua", getFiles locale] for locale in *["en", "zh", "pt-br", "de", "id-id"]]
41for [compiledFile, docFiles] in *docs
64 codes = [] 42 codes = []
65 for docFile in *docFiles 43 for docFile in *docFiles
66 close input = with? io.open docFile 44 close input = with? io.open docFile
diff --git a/spec/inputs/test/format_spec.yue b/spec/inputs/test/format_spec.yue
index 2069795..afe9331 100644
--- a/spec/inputs/test/format_spec.yue
+++ b/spec/inputs/test/format_spec.yue
@@ -182,7 +182,7 @@ for file in *files
182 original_ast = yue.to_ast code 182 original_ast = yue.to_ast code
183 assert.is_not_nil original_ast 183 assert.is_not_nil original_ast
184 rewriteLineCol original_ast 184 rewriteLineCol original_ast
185 formated = yue.format code, 0, false 185 formated = yue.format code, 0, true
186 ast = yue.to_ast formated 186 ast = yue.to_ast formated
187 assert.is_not_nil ast 187 assert.is_not_nil ast
188 rewriteLineCol ast 188 rewriteLineCol ast
diff --git a/spec/outputs/codes_from_doc.lua b/spec/outputs/codes_from_doc_de.lua
index d74ac16..0b3670c 100644
--- a/spec/outputs/codes_from_doc.lua
+++ b/spec/outputs/codes_from_doc_de.lua
@@ -1,159 +1,73 @@
1local _module_0 = { }
2local p, to_lua
3do 1do
4 local _obj_0 = require("yue") 2 local var = "hello"
5 p, to_lua = _obj_0.p, _obj_0.to_lua 3 print(var)
6end 4end
7local inventory = { 5print(var)
8 equipment = { 6local counter
9 "sword", 7do
10 "shield" 8 local i = 0
11 }, 9 counter = function()
12 items = { 10 i = i + 1
13 { 11 return i
14 name = "potion",
15 count = 10
16 },
17 {
18 name = "bread",
19 count = 3
20 }
21 }
22}
23local map
24map = function(arr, action)
25 local _accum_0 = { }
26 local _len_0 = 1
27 for _index_0 = 1, #arr do
28 local item = arr[_index_0]
29 _accum_0[_len_0] = action(item)
30 _len_0 = _len_0 + 1
31 end 12 end
32 return _accum_0
33end 13end
34local filter 14print(counter())
35filter = function(arr, cond) 15print(counter())
36 local _accum_0 = { } 16local tbl = {
37 local _len_0 = 1 17 key = (function()
38 for _index_0 = 1, #arr do 18 print("assigning key!")
39 local item = arr[_index_0] 19 return 1234
40 if cond(item) then 20 end)()
41 _accum_0[_len_0] = item 21}
42 _len_0 = _len_0 + 1 22do
43 end 23 local var = "hello"
44 end 24 print(var)
45 return _accum_0
46end 25end
47local reduce 26print(var)
48reduce = function(arr, init, action) 27local counter
49 for _index_0 = 1, #arr do 28do
50 local item = arr[_index_0] 29 local i = 0
51 init = action(init, item) 30 counter = function()
31 i = i + 1
32 return i
52 end 33 end
53 return init
54end 34end
55print(reduce(filter(map({ 35print(counter())
56 1, 36print(counter())
57 2, 37local tbl = {
58 3 38 key = (function()
59}, function(x) 39 print("assigning key!")
60 return x * 2 40 return 1234
61end), function(x) 41 end)()
62 return x > 4 42}
63end), 0, function(a, b) 43if name == "Rob" then
64 return a + b 44 print("hello world")
65end))
66local apple = setmetatable({
67 size = 15,
68}, {
69 __index = {
70 color = 0x00ffff
71 }
72})
73if (getmetatable(apple) ~= nil) then
74 p(apple.size, apple.color, getmetatable(apple).__index)
75end 45end
76local _u1f31b = "月之脚本" 46local _list_0 = items
77_module_0["🌛"] = _u1f31b 47for _index_0 = 1, #_list_0 do
78return _module_0 48 local item = _list_0[_index_0]
79local _module_0 = { } 49 print("item: ", item)
80local p, to_lua
81do
82 local _obj_0 = require("yue")
83 p, to_lua = _obj_0.p, _obj_0.to_lua
84end 50end
85local inventory = { 51while game:isRunning() do
86 equipment = { 52 game:update()
87 "sword",
88 "shield"
89 },
90 items = {
91 {
92 name = "potion",
93 count = 10
94 },
95 {
96 name = "bread",
97 count = 3
98 }
99 }
100}
101local map
102map = function(arr, action)
103 local _accum_0 = { }
104 local _len_0 = 1
105 for _index_0 = 1, #arr do
106 local item = arr[_index_0]
107 _accum_0[_len_0] = action(item)
108 _len_0 = _len_0 + 1
109 end
110 return _accum_0
111end 53end
112local filter 54while not reader:eof() do
113filter = function(arr, cond) 55 reader:parse_line()
114 local _accum_0 = { }
115 local _len_0 = 1
116 for _index_0 = 1, #arr do
117 local item = arr[_index_0]
118 if cond(item) then
119 _accum_0[_len_0] = item
120 _len_0 = _len_0 + 1
121 end
122 end
123 return _accum_0
124end 56end
125local reduce 57if name == "Rob" then
126reduce = function(arr, init, action) 58 print("hello world")
127 for _index_0 = 1, #arr do
128 local item = arr[_index_0]
129 init = action(init, item)
130 end
131 return init
132end 59end
133print(reduce(filter(map({ 60local _list_0 = items
134 1, 61for _index_0 = 1, #_list_0 do
135 2, 62 local item = _list_0[_index_0]
136 3 63 print("item: ", item)
137}, function(x) 64end
138 return x * 2 65while game:isRunning() do
139end), function(x) 66 game:update()
140 return x > 4 67end
141end), 0, function(a, b) 68while not reader:eof() do
142 return a + b 69 reader:parse_line()
143end))
144local apple = setmetatable({
145 size = 15,
146}, {
147 __index = {
148 color = 0x00ffff
149 }
150})
151if (getmetatable(apple) ~= nil) then
152 p(apple.size, apple.color, getmetatable(apple).__index)
153end 70end
154local _u1f31b = "月之脚本"
155_module_0["🌛"] = _u1f31b
156return _module_0
157local area = 6.2831853071796 * 5 71local area = 6.2831853071796 * 5
158print('hello world') 72print('hello world')
159do 73do
@@ -232,592 +146,6 @@ end
232do 146do
233 print(123, "hello") 147 print(123, "hello")
234end 148end
235if tb ~= nil then
236 tb:func()
237end
238if tb ~= nil then
239 tb:func()
240end
241print(1 < 2 and 2 <= 2 and 2 < 3 and 3 == 3 and 3 > 2 and 2 >= 1 and 1 == 1 and 1 < 3 and 3 ~= 5)
242local a = 5
243print(1 <= a and a <= 10)
244local v
245v = function(x)
246 print(x)
247 return x
248end
249print((function()
250 local _cond_0 = v(2)
251 if not (v(1) < _cond_0) then
252 return false
253 else
254 return _cond_0 <= v(3)
255 end
256end)())
257print((function()
258 local _cond_0 = v(2)
259 if not (v(1) > _cond_0) then
260 return false
261 else
262 return _cond_0 <= v(3)
263 end
264end)())
265local tab = { }
266tab[#tab + 1] = "Value"
267local tbA = {
268 1,
269 2,
270 3
271}
272local tbB = {
273 4,
274 5,
275 6
276}
277local _len_0 = #tbA + 1
278for _index_0 = 1, #tbB do
279 local _elm_0 = tbB[_index_0]
280 tbA[_len_0], _len_0 = _elm_0, _len_0 + 1
281end
282local parts = {
283 "shoulders",
284 "knees"
285}
286local lyrics
287do
288 local _tab_0 = {
289 "head"
290 }
291 local _idx_0 = 1
292 for _key_0, _value_0 in pairs(parts) do
293 if _idx_0 == _key_0 then
294 _tab_0[#_tab_0 + 1] = _value_0
295 _idx_0 = _idx_0 + 1
296 else
297 _tab_0[_key_0] = _value_0
298 end
299 end
300 _tab_0[#_tab_0 + 1] = "and"
301 _tab_0[#_tab_0 + 1] = "toes"
302 lyrics = _tab_0
303end
304local copy
305do
306 local _tab_0 = { }
307 local _idx_0 = 1
308 for _key_0, _value_0 in pairs(other) do
309 if _idx_0 == _key_0 then
310 _tab_0[#_tab_0 + 1] = _value_0
311 _idx_0 = _idx_0 + 1
312 else
313 _tab_0[_key_0] = _value_0
314 end
315 end
316 copy = _tab_0
317end
318local a = {
319 1,
320 2,
321 3,
322 x = 1
323}
324local b = {
325 4,
326 5,
327 y = 1
328}
329local merge
330local _tab_0 = { }
331local _idx_0 = 1
332for _key_0, _value_0 in pairs(a) do
333 if _idx_0 == _key_0 then
334 _tab_0[#_tab_0 + 1] = _value_0
335 _idx_0 = _idx_0 + 1
336 else
337 _tab_0[_key_0] = _value_0
338 end
339end
340local _idx_1 = 1
341for _key_0, _value_0 in pairs(b) do
342 if _idx_1 == _key_0 then
343 _tab_0[#_tab_0 + 1] = _value_0
344 _idx_1 = _idx_1 + 1
345 else
346 _tab_0[_key_0] = _value_0
347 end
348end
349merge = _tab_0
350local last
351do
352 local _item_0 = data.items
353 last = _item_0[#_item_0]
354end
355local second_last
356do
357 local _item_0 = data.items
358 second_last = _item_0[#_item_0 - 1]
359end
360local _obj_0 = data.items
361_obj_0[#_obj_0] = 1
362local mt = { }
363local add
364add = function(self, right)
365 return setmetatable({
366 value = self.value + right.value
367 }, mt)
368end
369mt.__add = add
370local a = setmetatable({
371 value = 1
372}, mt)
373local b = setmetatable({
374 value = 2
375}, {
376 __add = add
377})
378local c = setmetatable({
379 value = 3
380}, {
381 __add = mt.__add
382})
383local d = a + b + c
384print(d.value)
385local _ <close> = setmetatable({ }, {
386 __close = function()
387 return print("out of scope")
388 end
389})
390local tb = setmetatable({ }, {
391 ["value"] = 123
392})
393getmetatable(tb).__index = getmetatable(tb)
394print(tb.value)
395setmetatable(tb, {
396 __index = {
397 item = "hello"
398 }
399})
400print(tb.item)
401local item, new, close, getter
402do
403 local _obj_0 = tb
404 item, new = _obj_0[1], _obj_0.new
405 do
406 local _obj_1 = getmetatable(_obj_0)
407 close, getter = _obj_1.__close, _obj_1.__index
408 end
409end
410print(item, new, close, getter)
411do
412 local _obj_0 = func
413 if _obj_0 ~= nil then
414 _obj_0()
415 end
416end
417print((function()
418 local _obj_0 = abc
419 if _obj_0 ~= nil then
420 local _obj_1 = _obj_0["hello world"]
421 if _obj_1 ~= nil then
422 return _obj_1.xyz
423 end
424 return nil
425 end
426 return nil
427end)())
428local x
429do
430 local _obj_0 = tab
431 if _obj_0 ~= nil then
432 x = _obj_0.value
433 end
434end
435local len = (function()
436 local _obj_0 = utf8
437 if _obj_0 ~= nil then
438 return _obj_0.len
439 end
440 return nil
441end)() or (function()
442 local _obj_0 = string
443 if _obj_0 ~= nil then
444 return _obj_0.len
445 end
446 return nil
447end)() or function(o)
448 return #o
449end
450if print and (x ~= nil) then
451 print(x)
452end
453local _with_0 = io.open("test.txt", "w")
454if _with_0 ~= nil then
455 _with_0:write("hello")
456 _with_0:close()
457end
458print("hello")
459print(1, 2)
460print(1, 2, 3)
461print(render(emit(parse(extract(readFile("example.txt"), language, { }), language))))
462local a, b, c, d
463if b ~= nil then
464 a = b
465else
466 if c ~= nil then
467 a = c
468 else
469 a = d
470 end
471end
472func((function()
473 if a ~= nil then
474 return a
475 else
476 return { }
477 end
478end)())
479if a == nil then
480 a = false
481end
482local list = {
483 1,
484 2,
485 3
486}
487func({
488 1,
489 2,
490 3
491})
492local f
493f = function()
494 return {
495 1,
496 2,
497 3
498 }
499end
500local tb = {
501 name = "abc",
502 values = {
503 "a",
504 "b",
505 "c"
506 },
507 objects = {
508 {
509 name = "a",
510 value = 1,
511 func = function(self)
512 return self.value + 1
513 end,
514 tb = {
515 fieldA = 1
516 }
517 },
518 {
519 name = "b",
520 value = 2,
521 func = function(self)
522 return self.value + 2
523 end,
524 tb = { }
525 }
526 }
527}
528if tb ~= nil then
529 tb:func()
530end
531if tb ~= nil then
532 tb:func()
533end
534print(1 < 2 and 2 <= 2 and 2 < 3 and 3 == 3 and 3 > 2 and 2 >= 1 and 1 == 1 and 1 < 3 and 3 ~= 5)
535local a = 5
536print(1 <= a and a <= 10)
537local v
538v = function(x)
539 print(x)
540 return x
541end
542print((function()
543 local _cond_0 = v(2)
544 if not (v(1) < _cond_0) then
545 return false
546 else
547 return _cond_0 <= v(3)
548 end
549end)())
550print((function()
551 local _cond_0 = v(2)
552 if not (v(1) > _cond_0) then
553 return false
554 else
555 return _cond_0 <= v(3)
556 end
557end)())
558local tab = { }
559tab[#tab + 1] = "Value"
560local tbA = {
561 1,
562 2,
563 3
564}
565local tbB = {
566 4,
567 5,
568 6
569}
570local _len_0 = #tbA + 1
571for _index_0 = 1, #tbB do
572 local _elm_0 = tbB[_index_0]
573 tbA[_len_0], _len_0 = _elm_0, _len_0 + 1
574end
575local parts = {
576 "shoulders",
577 "knees"
578}
579local lyrics
580do
581 local _tab_0 = {
582 "head"
583 }
584 local _idx_0 = 1
585 for _key_0, _value_0 in pairs(parts) do
586 if _idx_0 == _key_0 then
587 _tab_0[#_tab_0 + 1] = _value_0
588 _idx_0 = _idx_0 + 1
589 else
590 _tab_0[_key_0] = _value_0
591 end
592 end
593 _tab_0[#_tab_0 + 1] = "and"
594 _tab_0[#_tab_0 + 1] = "toes"
595 lyrics = _tab_0
596end
597local copy
598do
599 local _tab_0 = { }
600 local _idx_0 = 1
601 for _key_0, _value_0 in pairs(other) do
602 if _idx_0 == _key_0 then
603 _tab_0[#_tab_0 + 1] = _value_0
604 _idx_0 = _idx_0 + 1
605 else
606 _tab_0[_key_0] = _value_0
607 end
608 end
609 copy = _tab_0
610end
611local a = {
612 1,
613 2,
614 3,
615 x = 1
616}
617local b = {
618 4,
619 5,
620 y = 1
621}
622local merge
623local _tab_0 = { }
624local _idx_0 = 1
625for _key_0, _value_0 in pairs(a) do
626 if _idx_0 == _key_0 then
627 _tab_0[#_tab_0 + 1] = _value_0
628 _idx_0 = _idx_0 + 1
629 else
630 _tab_0[_key_0] = _value_0
631 end
632end
633local _idx_1 = 1
634for _key_0, _value_0 in pairs(b) do
635 if _idx_1 == _key_0 then
636 _tab_0[#_tab_0 + 1] = _value_0
637 _idx_1 = _idx_1 + 1
638 else
639 _tab_0[_key_0] = _value_0
640 end
641end
642merge = _tab_0
643local last
644do
645 local _item_0 = data.items
646 last = _item_0[#_item_0]
647end
648local second_last
649do
650 local _item_0 = data.items
651 second_last = _item_0[#_item_0 - 1]
652end
653local _obj_0 = data.items
654_obj_0[#_obj_0] = 1
655local mt = { }
656local add
657add = function(self, right)
658 return setmetatable({
659 value = self.value + right.value
660 }, mt)
661end
662mt.__add = add
663local a = setmetatable({
664 value = 1
665}, mt)
666local b = setmetatable({
667 value = 2
668}, {
669 __add = add
670})
671local c = setmetatable({
672 value = 3
673}, {
674 __add = mt.__add
675})
676local d = a + b + c
677print(d.value)
678local _ <close> = setmetatable({ }, {
679 __close = function()
680 return print("out of scope")
681 end
682})
683local tb = setmetatable({ }, {
684 ["value"] = 123
685})
686getmetatable(tb).__index = getmetatable(tb)
687print(tb.value)
688setmetatable(tb, {
689 __index = {
690 item = "hello"
691 }
692})
693print(tb.item)
694local item, new, close, getter
695do
696 local _obj_0 = tb
697 item, new = _obj_0[1], _obj_0.new
698 do
699 local _obj_1 = getmetatable(_obj_0)
700 close, getter = _obj_1.__close, _obj_1.__index
701 end
702end
703print(item, new, close, getter)
704do
705 local _obj_0 = func
706 if _obj_0 ~= nil then
707 _obj_0()
708 end
709end
710print((function()
711 local _obj_0 = abc
712 if _obj_0 ~= nil then
713 local _obj_1 = _obj_0["hello world"]
714 if _obj_1 ~= nil then
715 return _obj_1.xyz
716 end
717 return nil
718 end
719 return nil
720end)())
721local x
722do
723 local _obj_0 = tab
724 if _obj_0 ~= nil then
725 x = _obj_0.value
726 end
727end
728local len = (function()
729 local _obj_0 = utf8
730 if _obj_0 ~= nil then
731 return _obj_0.len
732 end
733 return nil
734end)() or (function()
735 local _obj_0 = string
736 if _obj_0 ~= nil then
737 return _obj_0.len
738 end
739 return nil
740end)() or function(o)
741 return #o
742end
743if print and (x ~= nil) then
744 print(x)
745end
746local _with_0 = io.open("test.txt", "w")
747if _with_0 ~= nil then
748 _with_0:write("hello")
749 _with_0:close()
750end
751print("hello")
752print(1, 2)
753print(1, 2, 3)
754print(render(emit(parse(extract(readFile("example.txt"), language, { }), language))))
755local a, b, c, d
756if b ~= nil then
757 a = b
758else
759 if c ~= nil then
760 a = c
761 else
762 a = d
763 end
764end
765func((function()
766 if a ~= nil then
767 return a
768 else
769 return { }
770 end
771end)())
772if a == nil then
773 a = false
774end
775local list = {
776 1,
777 2,
778 3
779}
780func({
781 1,
782 2,
783 3
784})
785local f
786f = function()
787 return {
788 1,
789 2,
790 3
791 }
792end
793local tb = {
794 name = "abc",
795 values = {
796 "a",
797 "b",
798 "c"
799 },
800 objects = {
801 {
802 name = "a",
803 value = 1,
804 func = function(self)
805 return self.value + 1
806 end,
807 tb = {
808 fieldA = 1
809 }
810 },
811 {
812 name = "b",
813 value = 2,
814 func = function(self)
815 return self.value + 2
816 end,
817 tb = { }
818 }
819 }
820}
821do 149do
822 local insert, concat = table.insert, table.concat 150 local insert, concat = table.insert, table.concat
823 local C, Ct, Cmt 151 local C, Ct, Cmt
@@ -1080,460 +408,6 @@ _module_0 = function()
1080 return 123 408 return 123
1081end 409end
1082return _module_0 410return _module_0
1083local hello = "world"
1084local a, b, c = 1, 2, 3
1085hello = 123
1086local x = 1
1087x = x + 1
1088x = x - 1
1089x = x * 10
1090x = x / 10
1091x = x % 10
1092local s = s .. "world"
1093local arg = arg or "default value"
1094local a = 0
1095local b = 0
1096local c = 0
1097local d = 0
1098local e = 0
1099local x = f()
1100local y = x
1101local z = x
1102do
1103 local a = 1
1104 local x, y, z
1105 print("forward declare all variables as locals")
1106 x = function()
1107 return 1 + y + z
1108 end
1109 y, z = 2, 3
1110 instance = Item:new()
1111end
1112do
1113 local X = 1
1114 local B
1115 print("only forward declare upper case variables")
1116 local a = 1
1117 B = 2
1118end
1119do
1120 a = 1
1121 print("declare all variables as globals")
1122 x = function()
1123 return 1 + y + z
1124 end
1125 y, z = 2, 3
1126end
1127do
1128 X = 1
1129 print("only declare upper case variables as globals")
1130 local a = 1
1131 B = 2
1132 local Temp = "a local value"
1133end
1134local hello = "world"
1135local a, b, c = 1, 2, 3
1136hello = 123
1137local x = 1
1138x = x + 1
1139x = x - 1
1140x = x * 10
1141x = x / 10
1142x = x % 10
1143local s = s .. "world"
1144local arg = arg or "default value"
1145local a = 0
1146local b = 0
1147local c = 0
1148local d = 0
1149local e = 0
1150local x = f()
1151local y = x
1152local z = x
1153do
1154 local a = 1
1155 local x, y, z
1156 print("forward declare all variables as locals")
1157 x = function()
1158 return 1 + y + z
1159 end
1160 y, z = 2, 3
1161 instance = Item:new()
1162end
1163do
1164 local X = 1
1165 local B
1166 print("only forward declare upper case variables")
1167 local a = 1
1168 B = 2
1169end
1170do
1171 a = 1
1172 print("declare all variables as globals")
1173 x = function()
1174 return 1 + y + z
1175 end
1176 y, z = 2, 3
1177end
1178do
1179 X = 1
1180 print("only declare upper case variables as globals")
1181 local a = 1
1182 B = 2
1183 local Temp = "a local value"
1184end
1185local thing = {
1186 1,
1187 2
1188}
1189local a, b = thing[1], thing[2]
1190print(a, b)
1191local obj = {
1192 hello = "world",
1193 day = "tuesday",
1194 length = 20
1195}
1196local hello, the_day = obj.hello, obj.day
1197print(hello, the_day)
1198local day = obj.day
1199local obj2 = {
1200 numbers = {
1201 1,
1202 2,
1203 3,
1204 4
1205 },
1206 properties = {
1207 color = "green",
1208 height = 13.5
1209 }
1210}
1211local first, second, color = obj2.numbers[1], obj2.numbers[2], obj2.properties.color
1212print(first, second, color)
1213local first, second, color
1214local _obj_0 = obj2
1215first, second, color = _obj_0.numbers[1], _obj_0.numbers[2], _obj_0.properties.color
1216local concat, insert
1217local _obj_0 = table
1218concat, insert = _obj_0.concat, _obj_0.insert
1219local mix, max, rand
1220local _obj_0 = math
1221mix, max, rand = _obj_0.mix, _obj_0.max, _obj_0.random
1222local name, job
1223local _obj_0 = person
1224name, job = _obj_0.name, _obj_0.job
1225if name == nil then
1226 name = "nameless"
1227end
1228if job == nil then
1229 job = "jobless"
1230end
1231local two, four
1232local _obj_0 = items
1233two, four = _obj_0[2], _obj_0[4]
1234local orders = {
1235 "first",
1236 "second",
1237 "third",
1238 "fourth",
1239 "last"
1240}
1241local first, bulk, last = orders[1], (function()
1242 local _accum_0 = { }
1243 local _len_0 = 1
1244 local _max_0 = #orders + -2 + 1
1245 for _index_0 = 2, _max_0 do
1246 local _item_0 = orders[_index_0]
1247 _accum_0[_len_0] = _item_0
1248 _len_0 = _len_0 + 1
1249 end
1250 return _accum_0
1251end)(), orders[#orders]
1252print(first)
1253print(bulk)
1254print(last)
1255local first, rest
1256do
1257 local _obj_0 = orders
1258 first, rest = _obj_0[1], (function()
1259 local _accum_0 = { }
1260 local _len_0 = 1
1261 local _max_0 = #_obj_0
1262 for _index_0 = 2, _max_0 do
1263 local _item_0 = _obj_0[_index_0]
1264 _accum_0[_len_0] = _item_0
1265 _len_0 = _len_0 + 1
1266 end
1267 return _accum_0
1268 end)()
1269end
1270local start, last
1271do
1272 local _obj_0 = orders
1273 start, last = (function()
1274 local _accum_0 = { }
1275 local _len_0 = 1
1276 local _max_0 = #_obj_0 + -2 + 1
1277 for _index_0 = 1, _max_0 do
1278 local _item_0 = _obj_0[_index_0]
1279 _accum_0[_len_0] = _item_0
1280 _len_0 = _len_0 + 1
1281 end
1282 return _accum_0
1283 end)(), _obj_0[#_obj_0]
1284end
1285local _obj_0 = orders
1286first, last = _obj_0[1], _obj_0[#_obj_0]
1287local tuples = {
1288 {
1289 "hello",
1290 "world"
1291 },
1292 {
1293 "egg",
1294 "head"
1295 }
1296}
1297for _index_0 = 1, #tuples do
1298 local _des_0 = tuples[_index_0]
1299 local left, right = _des_0[1], _des_0[2]
1300 print(left, right)
1301end
1302local thing = {
1303 1,
1304 2
1305}
1306local a, b = thing[1], thing[2]
1307print(a, b)
1308local obj = {
1309 hello = "world",
1310 day = "tuesday",
1311 length = 20
1312}
1313local hello, the_day = obj.hello, obj.day
1314print(hello, the_day)
1315local day = obj.day
1316local obj2 = {
1317 numbers = {
1318 1,
1319 2,
1320 3,
1321 4
1322 },
1323 properties = {
1324 color = "green",
1325 height = 13.5
1326 }
1327}
1328local first, second, color = obj2.numbers[1], obj2.numbers[2], obj2.properties.color
1329print(first, second, color)
1330local first, second, color
1331local _obj_0 = obj2
1332first, second, color = _obj_0.numbers[1], _obj_0.numbers[2], _obj_0.properties.color
1333local concat, insert
1334local _obj_0 = table
1335concat, insert = _obj_0.concat, _obj_0.insert
1336local mix, max, rand
1337local _obj_0 = math
1338mix, max, rand = _obj_0.mix, _obj_0.max, _obj_0.random
1339local name, job
1340local _obj_0 = person
1341name, job = _obj_0.name, _obj_0.job
1342if name == nil then
1343 name = "nameless"
1344end
1345if job == nil then
1346 job = "jobless"
1347end
1348local two, four
1349local _obj_0 = items
1350two, four = _obj_0[2], _obj_0[4]
1351local orders = {
1352 "first",
1353 "second",
1354 "third",
1355 "fourth",
1356 "last"
1357}
1358local first, bulk, last = orders[1], (function()
1359 local _accum_0 = { }
1360 local _len_0 = 1
1361 local _max_0 = #orders + -2 + 1
1362 for _index_0 = 2, _max_0 do
1363 local _item_0 = orders[_index_0]
1364 _accum_0[_len_0] = _item_0
1365 _len_0 = _len_0 + 1
1366 end
1367 return _accum_0
1368end)(), orders[#orders]
1369print(first)
1370print(bulk)
1371print(last)
1372local first, rest
1373do
1374 local _obj_0 = orders
1375 first, rest = _obj_0[1], (function()
1376 local _accum_0 = { }
1377 local _len_0 = 1
1378 local _max_0 = #_obj_0
1379 for _index_0 = 2, _max_0 do
1380 local _item_0 = _obj_0[_index_0]
1381 _accum_0[_len_0] = _item_0
1382 _len_0 = _len_0 + 1
1383 end
1384 return _accum_0
1385 end)()
1386end
1387local start, last
1388do
1389 local _obj_0 = orders
1390 start, last = (function()
1391 local _accum_0 = { }
1392 local _len_0 = 1
1393 local _max_0 = #_obj_0 + -2 + 1
1394 for _index_0 = 1, _max_0 do
1395 local _item_0 = _obj_0[_index_0]
1396 _accum_0[_len_0] = _item_0
1397 _len_0 = _len_0 + 1
1398 end
1399 return _accum_0
1400 end)(), _obj_0[#_obj_0]
1401end
1402local _obj_0 = orders
1403first, last = _obj_0[1], _obj_0[#_obj_0]
1404local tuples = {
1405 {
1406 "hello",
1407 "world"
1408 },
1409 {
1410 "egg",
1411 "head"
1412 }
1413}
1414for _index_0 = 1, #tuples do
1415 local _des_0 = tuples[_index_0]
1416 local left, right = _des_0[1], _des_0[2]
1417 print(left, right)
1418end
1419local user = database.find_user("moon")
1420if user then
1421 print(user.name)
1422end
1423local hello = os.getenv("hello")
1424if hello then
1425 print("You have hello", hello)
1426else
1427 local world = os.getenv("world")
1428 if world then
1429 print("you have world", world)
1430 else
1431 print("nothing :(")
1432 end
1433end
1434do
1435 local success, result = pcall(function()
1436 return "get result without problems"
1437 end)
1438 if success then
1439 print(result)
1440 end
1441end
1442print("OK")
1443repeat
1444 local byte = stream:read_one()
1445 if byte then
1446 print(byte)
1447 else
1448 break
1449 end
1450until false
1451local user = database.find_user("moon")
1452if user then
1453 print(user.name)
1454end
1455local hello = os.getenv("hello")
1456if hello then
1457 print("You have hello", hello)
1458else
1459 local world = os.getenv("world")
1460 if world then
1461 print("you have world", world)
1462 else
1463 print("nothing :(")
1464 end
1465end
1466do
1467 local success, result = pcall(function()
1468 return "get result without problems"
1469 end)
1470 if success then
1471 print(result)
1472 end
1473end
1474print("OK")
1475repeat
1476 local byte = stream:read_one()
1477 if byte then
1478 print(byte)
1479 else
1480 break
1481 end
1482until false
1483local list = {
1484 1,
1485 2,
1486 3,
1487 4,
1488 5
1489}
1490local fn
1491fn = function(ok)
1492 return ok, table.unpack(list)
1493end
1494(function(_arg_0, ...)
1495 local ok = _arg_0
1496 local count = select('#', ...)
1497 local first = select(1, ...)
1498 return print(ok, count, first)
1499end)(fn(true))
1500local list = {
1501 1,
1502 2,
1503 3,
1504 4,
1505 5
1506}
1507local fn
1508fn = function(ok)
1509 return ok, table.unpack(list)
1510end
1511(function(_arg_0, ...)
1512 local ok = _arg_0
1513 local count = select('#', ...)
1514 local first = select(1, ...)
1515 return print(ok, count, first)
1516end)(fn(true))
1517local a = 1
1518local b = 2
1519print(a + b)
1520Rx.Observable.fromRange(1, 8):filter(function(x)
1521 return x % 2 == 0
1522end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
1523 return value .. '!'
1524end):subscribe(print)
1525local a = 1
1526local b = 2
1527print(a + b)
1528Rx.Observable.fromRange(1, 8):filter(function(x)
1529 return x % 2 == 0
1530end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
1531 return value .. '!'
1532end):subscribe(print)
1533local str = strA .. strB .. strC
1534func(3000, "192.168.1.1")
1535local str = strA .. strB .. strC
1536func(3000, "192.168.1.1")
1537xpcall(function() 411xpcall(function()
1538 return func(1, 2, 3) 412 return func(1, 2, 3)
1539end, function(err) 413end, function(err)
@@ -1694,464 +568,6 @@ f((function()
1694 return e 568 return e
1695 end)) 569 end))
1696end)()) 570end)())
1697local a <const> = 123
1698local _ <close> = setmetatable({ }, {
1699 __close = function()
1700 return print("Out of scope.")
1701 end
1702})
1703local a, b, c, d
1704local _obj_0 = tb
1705a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
1706Constant = 123
1707local a <const> = 123
1708local _ <close> = setmetatable({ }, {
1709 __close = function()
1710 return print("Out of scope.")
1711 end
1712})
1713local a, b, c, d
1714local _obj_0 = tb
1715a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
1716Constant = 123
1717local some_string = "Here is a string\n that has a line break in it."
1718print("I am " .. tostring(math.random() * 100) .. "% sure.")
1719local integer = 1000000
1720local hex = 0xEFBBBF
1721local binary = 19
1722local str = "key: value\nlist:\n - item1\n - " .. tostring(expr)
1723local fn
1724fn = function()
1725 local str = "foo:\n bar: baz"
1726 return str
1727end
1728local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'"
1729local some_string = "Here is a string\n that has a line break in it."
1730print("I am " .. tostring(math.random() * 100) .. "% sure.")
1731local integer = 1000000
1732local hex = 0xEFBBBF
1733local binary = 19
1734local str = "key: value\nlist:\n - item1\n - " .. tostring(expr)
1735local fn
1736fn = function()
1737 local str = "foo:\n bar: baz"
1738 return str
1739end
1740local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'"
1741local my_function
1742my_function = function() end
1743my_function()
1744local func_a
1745func_a = function()
1746 return print("hello world")
1747end
1748local func_b
1749func_b = function()
1750 local value = 100
1751 return print("The value:", value)
1752end
1753func_a()
1754func_b()
1755local sum
1756sum = function(x, y)
1757 return print("sum", x + y)
1758end
1759sum(10, 20)
1760print(sum(10, 20))
1761a(b(c("a", "b", "c")))
1762print("x:", sum(10, 20), "y:", sum(30, 40))
1763local sum
1764sum = function(x, y)
1765 return x + y
1766end
1767print("The sum is ", sum(10, 20))
1768local sum
1769sum = function(x, y)
1770 return x + y
1771end
1772local mystery
1773mystery = function(x, y)
1774 return x + y, x - y
1775end
1776local a, b = mystery(10, 20)
1777local func
1778func = function(self, num)
1779 return self.value + num
1780end
1781local my_function
1782my_function = function(name, height)
1783 if name == nil then
1784 name = "something"
1785 end
1786 if height == nil then
1787 height = 100
1788 end
1789 print("Hello I am", name)
1790 return print("My height is", height)
1791end
1792local some_args
1793some_args = function(x, y)
1794 if x == nil then
1795 x = 100
1796 end
1797 if y == nil then
1798 y = x + 1000
1799 end
1800 return print(x + y)
1801end
1802local a = x - 10
1803local b = x - 10
1804local c = x(-y)
1805local d = x - z
1806local x = func("hello") + 100
1807local y = func("hello" + 100)
1808my_func(5, 4, 3, 8, 9, 10)
1809cool_func(1, 2, 3, 4, 5, 6, 7, 8)
1810my_func(5, 6, 7, 6, another_func(6, 7, 8, 9, 1, 2), 5, 4)
1811local x = {
1812 1,
1813 2,
1814 3,
1815 4,
1816 a_func(4, 5, 5, 6),
1817 8,
1818 9,
1819 10
1820}
1821local y = {
1822 my_func(1, 2, 3, 4, 5),
1823 5,
1824 6,
1825 7
1826}
1827if func(1, 2, 3, "hello", "world") then
1828 print("hello")
1829 print("I am inside if")
1830end
1831if func(1, 2, 3, "hello", "world") then
1832 print("hello")
1833 print("I am inside if")
1834end
1835local f1
1836f1 = function(_arg_0)
1837 local a, b, c
1838 a, b, c = _arg_0.a, _arg_0.b, _arg_0.c
1839 return print(a, b, c)
1840end
1841f1({
1842 a = 1,
1843 b = "2",
1844 c = { }
1845})
1846local f2
1847f2 = function(_arg_0, c)
1848 local a1, b
1849 a1, b = _arg_0.a, _arg_0.b
1850 if a1 == nil then
1851 a1 = 123
1852 end
1853 if b == nil then
1854 b = 'abc'
1855 end
1856 if c == nil then
1857 c = { }
1858 end
1859 return print(a1, b, c)
1860end
1861local arg1 = {
1862 a = 0
1863}
1864f2(arg1, arg2)
1865local findFirstEven
1866findFirstEven = function(list)
1867 for _index_0 = 1, #list do
1868 local item = list[_index_0]
1869 if type(item) == "table" then
1870 for _index_1 = 1, #item do
1871 local sub = item[_index_1]
1872 if sub % 2 == 0 then
1873 return sub
1874 end
1875 end
1876 end
1877 end
1878 return nil
1879end
1880local findFirstEven
1881findFirstEven = function(list)
1882 for _index_0 = 1, #list do
1883 local item = list[_index_0]
1884 if type(item) == "table" then
1885 for _index_1 = 1, #item do
1886 local sub = item[_index_1]
1887 if sub % 2 == 0 then
1888 return sub
1889 end
1890 end
1891 end
1892 end
1893 return nil
1894end
1895local f
1896f = function(...)
1897 local t = {
1898 n = select("#", ...),
1899 ...
1900 }
1901 print("argument count:", t.n)
1902 print("table length:", #t)
1903 for i = 1, t.n do
1904 print(t[i])
1905 end
1906end
1907f(1, 2, 3)
1908f("a", "b", "c", "d")
1909f()
1910local process
1911process = function(...)
1912 local args = {
1913 n = select("#", ...),
1914 ...
1915 }
1916 local sum = 0
1917 for i = 1, args.n do
1918 if args[i] ~= nil and type(args[i]) == "number" then
1919 sum = sum + args[i]
1920 end
1921 end
1922 return sum
1923end
1924process(1, nil, 3, nil, 5)
1925local my_function
1926my_function = function() end
1927my_function()
1928local func_a
1929func_a = function()
1930 return print("hello world")
1931end
1932local func_b
1933func_b = function()
1934 local value = 100
1935 return print("The value:", value)
1936end
1937func_a()
1938func_b()
1939local sum
1940sum = function(x, y)
1941 return print("sum", x + y)
1942end
1943sum(10, 20)
1944print(sum(10, 20))
1945a(b(c("a", "b", "c")))
1946print("x:", sum(10, 20), "y:", sum(30, 40))
1947local sum
1948sum = function(x, y)
1949 return x + y
1950end
1951print("The sum is ", sum(10, 20))
1952local sum
1953sum = function(x, y)
1954 return x + y
1955end
1956local mystery
1957mystery = function(x, y)
1958 return x + y, x - y
1959end
1960local a, b = mystery(10, 20)
1961local func
1962func = function(self, num)
1963 return self.value + num
1964end
1965local my_function
1966my_function = function(name, height)
1967 if name == nil then
1968 name = "something"
1969 end
1970 if height == nil then
1971 height = 100
1972 end
1973 print("Hello I am", name)
1974 return print("My height is", height)
1975end
1976local some_args
1977some_args = function(x, y)
1978 if x == nil then
1979 x = 100
1980 end
1981 if y == nil then
1982 y = x + 1000
1983 end
1984 return print(x + y)
1985end
1986local a = x - 10
1987local b = x - 10
1988local c = x(-y)
1989local d = x - z
1990local x = func("hello") + 100
1991local y = func("hello" + 100)
1992my_func(5, 4, 3, 8, 9, 10)
1993cool_func(1, 2, 3, 4, 5, 6, 7, 8)
1994my_func(5, 6, 7, 6, another_func(6, 7, 8, 9, 1, 2), 5, 4)
1995local x = {
1996 1,
1997 2,
1998 3,
1999 4,
2000 a_func(4, 5, 5, 6),
2001 8,
2002 9,
2003 10
2004}
2005local y = {
2006 my_func(1, 2, 3, 4, 5),
2007 5,
2008 6,
2009 7
2010}
2011if func(1, 2, 3, "hello", "world") then
2012 print("hello")
2013 print("I am inside if")
2014end
2015if func(1, 2, 3, "hello", "world") then
2016 print("hello")
2017 print("I am inside if")
2018end
2019local f1
2020f1 = function(_arg_0)
2021 local a, b, c
2022 a, b, c = _arg_0.a, _arg_0.b, _arg_0.c
2023 return print(a, b, c)
2024end
2025f1({
2026 a = 1,
2027 b = "2",
2028 c = { }
2029})
2030local f2
2031f2 = function(_arg_0, c)
2032 local a1, b
2033 a1, b = _arg_0.a, _arg_0.b
2034 if a1 == nil then
2035 a1 = 123
2036 end
2037 if b == nil then
2038 b = 'abc'
2039 end
2040 if c == nil then
2041 c = { }
2042 end
2043end
2044print(a1, b, c)
2045local arg1 = {
2046 a = 0
2047}
2048f2(arg1, arg2)
2049local findFirstEven
2050findFirstEven = function(list)
2051 for _index_0 = 1, #list do
2052 local item = list[_index_0]
2053 if type(item) == "table" then
2054 for _index_1 = 1, #item do
2055 local sub = item[_index_1]
2056 if sub % 2 == 0 then
2057 return sub
2058 end
2059 end
2060 end
2061 end
2062 return nil
2063end
2064local findFirstEven
2065findFirstEven = function(list)
2066 for _index_0 = 1, #list do
2067 local item = list[_index_0]
2068 if type(item) == "table" then
2069 for _index_1 = 1, #item do
2070 local sub = item[_index_1]
2071 if sub % 2 == 0 then
2072 return sub
2073 end
2074 end
2075 end
2076 end
2077 return nil
2078end
2079local f
2080f = function(...)
2081 local t = {
2082 n = select("#", ...),
2083 ...
2084 }
2085 print("argument count:", t.n)
2086 print("table length:", #t)
2087 for i = 1, t.n do
2088 print(t[i])
2089 end
2090end
2091f(1, 2, 3)
2092f("a", "b", "c", "d")
2093f()
2094local process
2095process = function(...)
2096 local args = {
2097 n = select("#", ...),
2098 ...
2099 }
2100 local sum = 0
2101 for i = 1, args.n do
2102 if args[i] ~= nil and type(args[i]) == "number" then
2103 sum = sum + args[i]
2104 end
2105 end
2106 return sum
2107end
2108process(1, nil, 3, nil, 5)
2109f(function(x)
2110 return print("hello" .. x)
2111end)
2112f(function(self)
2113 return print(self.value)
2114end)
2115map(function(x)
2116 return x * 2
2117end, {
2118 1,
2119 2,
2120 3
2121})
2122local result, msg
2123do
2124 result, msg = readAsync("filename.txt", function(data)
2125 print(data)
2126 return processAsync(data, function(info)
2127 return check(info)
2128 end)
2129 end)
2130end
2131print(result, msg)
2132f(function(x)
2133 return print("hello" .. x)
2134end)
2135f(function(self)
2136 return print(self.value)
2137end)
2138map(function(x)
2139 return x * 2
2140end, {
2141 1,
2142 2,
2143 3
2144})
2145local result, msg
2146do
2147 result, msg = readAsync("filename.txt", function(data)
2148 print(data)
2149 return processAsync(data, function(info)
2150 return check(info)
2151 end)
2152 end)
2153end
2154print(result, msg)
2155local some_values = { 571local some_values = {
2156 1, 572 1,
2157 2, 573 2,
@@ -2730,966 +1146,6 @@ for _index_0 = _min_0, _max_0 do
2730 _len_0 = _len_0 + 1 1146 _len_0 = _len_0 + 1
2731end 1147end
2732last_four_items = _accum_0 1148last_four_items = _accum_0
2733for i = 10, 20 do
2734 print(i)
2735end
2736for k = 1, 15, 2 do
2737 print(k)
2738end
2739for key, value in pairs(object) do
2740 print(key, value)
2741end
2742local _list_0 = items
2743for _index_0 = 2, 4 do
2744 local item = _list_0[_index_0]
2745 print(item)
2746end
2747local _list_0 = items
2748for _index_0 = 1, #_list_0 do
2749 local item = _list_0[_index_0]
2750 print(item)
2751end
2752for j = 1, 10, 3 do
2753 print(j)
2754end
2755local doubled_evens
2756local _accum_0 = { }
2757local _len_0 = 1
2758for i = 1, 20 do
2759 if i % 2 == 0 then
2760 _accum_0[_len_0] = i * 2
2761 _len_0 = _len_0 + 1
2762 else
2763 _accum_0[_len_0] = i
2764 _len_0 = _len_0 + 1
2765 end
2766end
2767doubled_evens = _accum_0
2768local first_large
2769local _accum_0
2770local _list_0 = numbers
2771for _index_0 = 1, #_list_0 do
2772 local n = _list_0[_index_0]
2773 if n > 10 then
2774 _accum_0 = n
2775 break
2776 end
2777end
2778first_large = _accum_0
2779local func_a
2780func_a = function()
2781 for i = 1, 10 do
2782 print(i)
2783 end
2784end
2785local func_b
2786func_b = function()
2787 local _accum_0 = { }
2788 local _len_0 = 1
2789 for i = 1, 10 do
2790 _accum_0[_len_0] = i
2791 _len_0 = _len_0 + 1
2792 end
2793 return _accum_0
2794end
2795print(func_a())
2796print(func_b())
2797for i = 10, 20 do
2798 print(i)
2799end
2800for k = 1, 15, 2 do
2801 print(k)
2802end
2803for key, value in pairs(object) do
2804 print(key, value)
2805end
2806local _list_0 = items
2807for _index_0 = 2, 4 do
2808 local item = _list_0[_index_0]
2809 print(item)
2810end
2811local _list_0 = items
2812for _index_0 = 1, #_list_0 do
2813 local item = _list_0[_index_0]
2814 print(item)
2815end
2816for j = 1, 10, 3 do
2817 print(j)
2818end
2819local doubled_evens
2820local _accum_0 = { }
2821local _len_0 = 1
2822for i = 1, 20 do
2823 if i % 2 == 0 then
2824 _accum_0[_len_0] = i * 2
2825 _len_0 = _len_0 + 1
2826 else
2827 _accum_0[_len_0] = i
2828 _len_0 = _len_0 + 1
2829 end
2830end
2831doubled_evens = _accum_0
2832local first_large
2833local _accum_0
2834local _list_0 = numbers
2835for _index_0 = 1, #_list_0 do
2836 local n = _list_0[_index_0]
2837 if n > 10 then
2838 _accum_0 = n
2839 break
2840 end
2841end
2842first_large = _accum_0
2843local func_a
2844func_a = function()
2845 for i = 1, 10 do
2846 print(i)
2847 end
2848end
2849local func_b
2850func_b = function()
2851 local _accum_0 = { }
2852 local _len_0 = 1
2853 for i = 1, 10 do
2854 _accum_0[_len_0] = i
2855 _len_0 = _len_0 + 1
2856 end
2857 return _accum_0
2858end
2859print(func_a())
2860print(func_b())
2861local i = 10
2862while i > 0 do
2863 print(i)
2864 i = i - 1
2865end
2866while running == true do
2867 my_function()
2868end
2869local i = 10
2870while not (i == 0) do
2871 print(i)
2872 i = i - 1
2873end
2874while not (running == false) do
2875 my_function()
2876end
2877local i = 10
2878repeat
2879 print(i)
2880 i = i - 1
2881until i == 0
2882local i = 10
2883while i > 0 do
2884 print(i)
2885 i = i - 1
2886end
2887while running == true do
2888 my_function()
2889end
2890local i = 10
2891while not (i == 0) do
2892 print(i)
2893 i = i - 1
2894end
2895while not (running == false) do
2896 my_function()
2897end
2898local i = 10
2899repeat
2900 print(i)
2901 i = i - 1
2902until i == 0
2903local i = 0
2904while i < 10 do
2905 i = i + 1
2906 if i % 2 == 0 then
2907 goto _continue_0
2908 end
2909 print(i)
2910 ::_continue_0::
2911end
2912local my_numbers = {
2913 1,
2914 2,
2915 3,
2916 4,
2917 5,
2918 6
2919}
2920local odds
2921local _accum_0 = { }
2922local _len_0 = 1
2923for _index_0 = 1, #my_numbers do
2924 local x = my_numbers[_index_0]
2925 if x % 2 == 1 then
2926 goto _continue_0
2927 end
2928 _accum_0[_len_0] = x
2929 _len_0 = _len_0 + 1
2930 ::_continue_0::
2931end
2932odds = _accum_0
2933local i = 0
2934while i < 10 do
2935 i = i + 1
2936 if i % 2 == 0 then
2937 goto _continue_0
2938 end
2939 print(i)
2940 ::_continue_0::
2941end
2942local my_numbers = {
2943 1,
2944 2,
2945 3,
2946 4,
2947 5,
2948 6
2949}
2950local odds
2951local _accum_0 = { }
2952local _len_0 = 1
2953for _index_0 = 1, #my_numbers do
2954 local x = my_numbers[_index_0]
2955 if x % 2 == 1 then
2956 goto _continue_0
2957 end
2958 _accum_0[_len_0] = x
2959 _len_0 = _len_0 + 1
2960 ::_continue_0::
2961end
2962odds = _accum_0
2963local have_coins = false
2964if have_coins then
2965 print("Got coins")
2966else
2967 print("No coins")
2968end
2969local have_coins = false
2970if have_coins then
2971 print("Got coins")
2972else
2973 print("No coins")
2974end
2975local have_coins = false
2976print((function()
2977 if have_coins then
2978 return "Got coins"
2979 else
2980 return "No coins"
2981 end
2982end)())
2983local is_tall
2984is_tall = function(name)
2985 if name == "Rob" then
2986 return true
2987 else
2988 return false
2989 end
2990end
2991local message
2992if is_tall("Rob") then
2993 message = "I am very tall"
2994else
2995 message = "I am not so tall"
2996end
2997print(message)
2998if not (os.date("%A") == "Monday") then
2999 print("it is not Monday!")
3000end
3001if not (math.random() > 0.1) then
3002 print("You're lucky!")
3003end
3004local a = 5
3005if (1 == a or 3 == a or 5 == a or 7 == a) then
3006 print("checking equality with discrete values")
3007end
3008if (function()
3009 local _check_0 = list
3010 for _index_0 = 1, #_check_0 do
3011 if _check_0[_index_0] == a then
3012 return true
3013 end
3014 end
3015 return false
3016end)() then
3017 print("checking if `a` is in a list")
3018end
3019if not (math.random() > 0.1) then
3020 print("You're lucky!")
3021end
3022local have_coins = false
3023if have_coins then
3024 print("Got coins")
3025else
3026 print("No coins")
3027end
3028local have_coins = false
3029if have_coins then
3030 print("Got coins")
3031else
3032 print("No coins")
3033end
3034local have_coins = false
3035print((function()
3036 if have_coins then
3037 return "Got coins"
3038 else
3039 return "No coins"
3040 end
3041end)())
3042local is_tall
3043is_tall = function(name)
3044 if name == "Rob" then
3045 return true
3046 else
3047 return false
3048 end
3049end
3050local message
3051if is_tall("Rob") then
3052 message = "I am very tall"
3053else
3054 message = "I am not so tall"
3055end
3056print(message)
3057if not (os.date("%A") == "Monday") then
3058 print("it is not Monday!")
3059end
3060if not (math.random() > 0.1) then
3061 print("You're lucky!")
3062end
3063local a = 5
3064if (1 == a or 3 == a or 5 == a or 7 == a) then
3065 print("checking equality with discrete values")
3066end
3067if (function()
3068 local _check_0 = list
3069 for _index_0 = 1, #_check_0 do
3070 if _check_0[_index_0] == a then
3071 return true
3072 end
3073 end
3074 return false
3075end)() then
3076 print("checking if `a` is in a list")
3077end
3078if not (math.random() > 0.1) then
3079 print("You're lucky!")
3080end
3081if name == "Rob" then
3082 print("hello world")
3083end
3084local _list_0 = items
3085for _index_0 = 1, #_list_0 do
3086 local item = _list_0[_index_0]
3087 print("item: ", item)
3088end
3089while game:isRunning() do
3090 game:update()
3091end
3092while not reader:eof() do
3093 reader:parse_line()
3094end
3095if name == "Rob" then
3096 print("hello world")
3097end
3098local _list_0 = items
3099for _index_0 = 1, #_list_0 do
3100 local item = _list_0[_index_0]
3101 print("item: ", item)
3102end
3103while game:isRunning() do
3104 game:update()
3105end
3106while not reader:eof() do
3107 reader:parse_line()
3108end
3109local name = "Dan"
3110if "Robert" == name then
3111 print("You are Robert")
3112elseif "Dan" == name or "Daniel" == name then
3113 print("Your name, it's Dan")
3114else
3115 print("I don't know about you with name " .. tostring(name))
3116end
3117local b = 1
3118local next_number
3119if 1 == b then
3120 next_number = 2
3121elseif 2 == b then
3122 next_number = 3
3123else
3124 next_number = error("can't count that high!")
3125end
3126local msg
3127local _exp_0 = math.random(1, 5)
3128if 1 == _exp_0 then
3129 msg = "you are lucky"
3130elseif 2 == _exp_0 then
3131 msg = "you are almost lucky"
3132else
3133 msg = "not so lucky"
3134end
3135do
3136 local _exp_0 = math.random(1, 5)
3137 if 1 == _exp_0 then
3138 print("you are lucky")
3139 else
3140 print("not so lucky")
3141 end
3142end
3143local _exp_0 = math.random(1, 5)
3144if 1 == _exp_0 then
3145 print("you are lucky")
3146else
3147 print("not so lucky")
3148end
3149local items = {
3150 {
3151 x = 100,
3152 y = 200
3153 },
3154 {
3155 width = 300,
3156 height = 400
3157 }
3158}
3159for _index_0 = 1, #items do
3160 local item = items[_index_0]
3161 local _type_0 = type(item)
3162 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3163 local _match_0 = false
3164 if _tab_0 then
3165 local x = item.x
3166 local y = item.y
3167 if x ~= nil and y ~= nil then
3168 _match_0 = true
3169 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3170 end
3171 end
3172 if not _match_0 then
3173 if _tab_0 then
3174 local width = item.width
3175 local height = item.height
3176 if width ~= nil and height ~= nil then
3177 print("size " .. tostring(width) .. ", " .. tostring(height))
3178 end
3179 end
3180 end
3181end
3182local item = { }
3183local x, y = item.pos.x, item.pos.y
3184if x == nil then
3185 x = 50
3186end
3187if y == nil then
3188 y = 200
3189end
3190local _type_0 = type(item)
3191local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3192if _tab_0 then
3193 do
3194 local _obj_0 = item.pos
3195 local _type_1 = type(_obj_0)
3196 if "table" == _type_1 or "userdata" == _type_1 then
3197 x = _obj_0.x
3198 end
3199 end
3200 do
3201 local _obj_0 = item.pos
3202 local _type_1 = type(_obj_0)
3203 if "table" == _type_1 or "userdata" == _type_1 then
3204 y = _obj_0.y
3205 end
3206 end
3207 if x == nil then
3208 x = 50
3209 end
3210 if y == nil then
3211 y = 200
3212 end
3213 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3214end
3215local _exp_0 = tb
3216local _type_0 = type(_exp_0)
3217local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3218local _match_0 = false
3219if _tab_0 then
3220 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
3221 _match_0 = true
3222 print("1, 2, 3")
3223 end
3224end
3225if not _match_0 then
3226 local _match_1 = false
3227 if _tab_0 then
3228 local b = _exp_0[2]
3229 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
3230 _match_1 = true
3231 print("1, " .. tostring(b) .. ", 3")
3232 end
3233 end
3234 if not _match_1 then
3235 if _tab_0 then
3236 local b = _exp_0[3]
3237 if b == nil then
3238 b = 3
3239 end
3240 if 1 == _exp_0[1] and 2 == _exp_0[2] then
3241 print("1, 2, " .. tostring(b))
3242 end
3243 end
3244 end
3245end
3246local _exp_0 = tb
3247local _type_0 = type(_exp_0)
3248local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3249local _match_0 = false
3250if _tab_0 then
3251 local result = _exp_0.result
3252 if true == _exp_0.success and result ~= nil then
3253 _match_0 = true
3254 print("success", result)
3255 end
3256end
3257if not _match_0 then
3258 local _match_1 = false
3259 if _tab_0 then
3260 if false == _exp_0.success then
3261 _match_1 = true
3262 print("failed", result)
3263 end
3264 end
3265 if not _match_1 then
3266 print("invalid")
3267 end
3268end
3269local _exp_0 = tb
3270local _type_0 = type(_exp_0)
3271local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3272local _match_0 = false
3273if _tab_0 then
3274 local content
3275 do
3276 local _obj_0 = _exp_0.data
3277 local _type_1 = type(_obj_0)
3278 if "table" == _type_1 or "userdata" == _type_1 then
3279 content = _obj_0.content
3280 end
3281 end
3282 local _val_0
3283 do
3284 local _obj_0 = _exp_0.data
3285 if _obj_0 ~= nil then
3286 _val_0 = _obj_0.type
3287 end
3288 end
3289 if "success" == _val_0 and content ~= nil then
3290 _match_0 = true
3291 print("success", content)
3292 end
3293end
3294if not _match_0 then
3295 local _match_1 = false
3296 if _tab_0 then
3297 local content
3298 do
3299 local _obj_0 = _exp_0.data
3300 local _type_1 = type(_obj_0)
3301 if "table" == _type_1 or "userdata" == _type_1 then
3302 content = _obj_0.content
3303 end
3304 end
3305 local _val_0
3306 do
3307 local _obj_0 = _exp_0.data
3308 if _obj_0 ~= nil then
3309 _val_0 = _obj_0.type
3310 end
3311 end
3312 if "error" == _val_0 and content ~= nil then
3313 _match_1 = true
3314 print("failed", content)
3315 end
3316 end
3317 if not _match_1 then
3318 print("invalid")
3319 end
3320end
3321local _exp_0 = tb
3322local _type_0 = type(_exp_0)
3323local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3324if _tab_0 then
3325 local fourth = _exp_0[4]
3326 local _val_0
3327 do
3328 local _obj_0 = _exp_0[1]
3329 if _obj_0 ~= nil then
3330 _val_0 = _obj_0.a
3331 end
3332 end
3333 local _val_1
3334 do
3335 local _obj_0 = _exp_0[1]
3336 if _obj_0 ~= nil then
3337 _val_1 = _obj_0.b
3338 end
3339 end
3340 local _val_2
3341 do
3342 local _obj_0 = _exp_0[2]
3343 if _obj_0 ~= nil then
3344 _val_2 = _obj_0.a
3345 end
3346 end
3347 local _val_3
3348 do
3349 local _obj_0 = _exp_0[2]
3350 if _obj_0 ~= nil then
3351 _val_3 = _obj_0.b
3352 end
3353 end
3354 local _val_4
3355 do
3356 local _obj_0 = _exp_0[3]
3357 if _obj_0 ~= nil then
3358 _val_4 = _obj_0.a
3359 end
3360 end
3361 local _val_5
3362 do
3363 local _obj_0 = _exp_0[3]
3364 if _obj_0 ~= nil then
3365 _val_5 = _obj_0.b
3366 end
3367 end
3368 if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and fourth ~= nil then
3369 print("matched", fourth)
3370 end
3371end
3372local segments = {
3373 "admin",
3374 "users",
3375 "logs",
3376 "view"
3377}
3378local _type_0 = type(segments)
3379local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3380if _tab_0 then
3381 local groups
3382 do
3383 local _accum_0 = { }
3384 local _len_0 = 1
3385 local _max_0 = #segments + -3 + 1
3386 for _index_0 = 1, _max_0 do
3387 local _item_0 = segments[_index_0]
3388 _accum_0[_len_0] = _item_0
3389 _len_0 = _len_0 + 1
3390 end
3391 groups = _accum_0
3392 end
3393 local resource = segments[#segments - 1]
3394 local action = segments[#segments]
3395 if resource ~= nil and action ~= nil then
3396 print("Group:", groups)
3397 print("Resource:", resource)
3398 print("Action:", action)
3399 end
3400end
3401local name = "Dan"
3402if "Robert" == name then
3403 print("You are Robert")
3404elseif "Dan" == name or "Daniel" == name then
3405 print("Your name, it's Dan")
3406else
3407 print("I don't know about you with name " .. tostring(name))
3408end
3409local b = 1
3410local next_number
3411if 1 == b then
3412 next_number = 2
3413elseif 2 == b then
3414 next_number = 3
3415else
3416 next_number = error("can't count that high!")
3417end
3418local msg
3419local _exp_0 = math.random(1, 5)
3420if 1 == _exp_0 then
3421 msg = "you are lucky"
3422elseif 2 == _exp_0 then
3423 msg = "you are almost lucky"
3424else
3425 msg = "not so lucky"
3426end
3427do
3428 local _exp_0 = math.random(1, 5)
3429 if 1 == _exp_0 then
3430 print("you are lucky")
3431 else
3432 print("not so lucky")
3433 end
3434end
3435local _exp_0 = math.random(1, 5)
3436if 1 == _exp_0 then
3437 print("you are lucky")
3438else
3439 print("not so lucky")
3440end
3441local items = {
3442 {
3443 x = 100,
3444 y = 200
3445 },
3446 {
3447 width = 300,
3448 height = 400
3449 }
3450}
3451for _index_0 = 1, #items do
3452 local item = items[_index_0]
3453 local _type_0 = type(item)
3454 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3455 local _match_0 = false
3456 if _tab_0 then
3457 local x = item.x
3458 local y = item.y
3459 if x ~= nil and y ~= nil then
3460 _match_0 = true
3461 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3462 end
3463 end
3464 if not _match_0 then
3465 if _tab_0 then
3466 local width = item.width
3467 local height = item.height
3468 if width ~= nil and height ~= nil then
3469 print("size " .. tostring(width) .. ", " .. tostring(height))
3470 end
3471 end
3472 end
3473end
3474local item = { }
3475local x, y = item.pos.x, item.pos.y
3476if x == nil then
3477 x = 50
3478end
3479if y == nil then
3480 y = 200
3481end
3482local _type_0 = type(item)
3483local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3484if _tab_0 then
3485 do
3486 local _obj_0 = item.pos
3487 local _type_1 = type(_obj_0)
3488 if "table" == _type_1 or "userdata" == _type_1 then
3489 x = _obj_0.x
3490 end
3491 end
3492 do
3493 local _obj_0 = item.pos
3494 local _type_1 = type(_obj_0)
3495 if "table" == _type_1 or "userdata" == _type_1 then
3496 y = _obj_0.y
3497 end
3498 end
3499 if x == nil then
3500 x = 50
3501 end
3502 if y == nil then
3503 y = 200
3504 end
3505 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3506end
3507local _exp_0 = tb
3508local _type_0 = type(_exp_0)
3509local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3510local _match_0 = false
3511if _tab_0 then
3512 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
3513 _match_0 = true
3514 print("1, 2, 3")
3515 end
3516end
3517if not _match_0 then
3518 local _match_1 = false
3519 if _tab_0 then
3520 local b = _exp_0[2]
3521 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
3522 _match_1 = true
3523 print("1, " .. tostring(b) .. ", 3")
3524 end
3525 end
3526 if not _match_1 then
3527 if _tab_0 then
3528 local b = _exp_0[3]
3529 if b == nil then
3530 b = 3
3531 end
3532 if 1 == _exp_0[1] and 2 == _exp_0[2] then
3533 print("1, 2, " .. tostring(b))
3534 end
3535 end
3536 end
3537end
3538local _exp_0 = tb
3539local _type_0 = type(_exp_0)
3540local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3541local _match_0 = false
3542if _tab_0 then
3543 local result = _exp_0.result
3544 if true == _exp_0.success and result ~= nil then
3545 _match_0 = true
3546 print("success", result)
3547 end
3548end
3549if not _match_0 then
3550 local _match_1 = false
3551 if _tab_0 then
3552 if false == _exp_0.success then
3553 _match_1 = true
3554 print("failed", result)
3555 end
3556 end
3557 if not _match_1 then
3558 print("invalid")
3559 end
3560end
3561local _exp_0 = tb
3562local _type_0 = type(_exp_0)
3563local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3564local _match_0 = false
3565if _tab_0 then
3566 local content
3567 do
3568 local _obj_0 = _exp_0.data
3569 local _type_1 = type(_obj_0)
3570 if "table" == _type_1 or "userdata" == _type_1 then
3571 content = _obj_0.content
3572 end
3573 end
3574 local _val_0
3575 do
3576 local _obj_0 = _exp_0.data
3577 if _obj_0 ~= nil then
3578 _val_0 = _obj_0.type
3579 end
3580 end
3581 if "success" == _val_0 and content ~= nil then
3582 _match_0 = true
3583 print("success", content)
3584 end
3585end
3586if not _match_0 then
3587 local _match_1 = false
3588 if _tab_0 then
3589 local content
3590 do
3591 local _obj_0 = _exp_0.data
3592 local _type_1 = type(_obj_0)
3593 if "table" == _type_1 or "userdata" == _type_1 then
3594 content = _obj_0.content
3595 end
3596 end
3597 local _val_0
3598 do
3599 local _obj_0 = _exp_0.data
3600 if _obj_0 ~= nil then
3601 _val_0 = _obj_0.type
3602 end
3603 end
3604 if "error" == _val_0 and content ~= nil then
3605 _match_1 = true
3606 print("failed", content)
3607 end
3608 end
3609 if not _match_1 then
3610 print("invalid")
3611 end
3612end
3613local _exp_0 = tb
3614local _type_0 = type(_exp_0)
3615local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3616if _tab_0 then
3617 local fourth = _exp_0[4]
3618 local _val_0
3619 do
3620 local _obj_0 = _exp_0[1]
3621 if _obj_0 ~= nil then
3622 _val_0 = _obj_0.a
3623 end
3624 end
3625 local _val_1
3626 do
3627 local _obj_0 = _exp_0[1]
3628 if _obj_0 ~= nil then
3629 _val_1 = _obj_0.b
3630 end
3631 end
3632 local _val_2
3633 do
3634 local _obj_0 = _exp_0[2]
3635 if _obj_0 ~= nil then
3636 _val_2 = _obj_0.a
3637 end
3638 end
3639 local _val_3
3640 do
3641 local _obj_0 = _exp_0[2]
3642 if _obj_0 ~= nil then
3643 _val_3 = _obj_0.b
3644 end
3645 end
3646 local _val_4
3647 do
3648 local _obj_0 = _exp_0[3]
3649 if _obj_0 ~= nil then
3650 _val_4 = _obj_0.a
3651 end
3652 end
3653 local _val_5
3654 do
3655 local _obj_0 = _exp_0[3]
3656 if _obj_0 ~= nil then
3657 _val_5 = _obj_0.b
3658 end
3659 end
3660 if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and fourth ~= nil then
3661 print("matched", fourth)
3662 end
3663end
3664local segments = {
3665 "admin",
3666 "users",
3667 "logs",
3668 "view"
3669}
3670local _type_0 = type(segments)
3671local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3672if _tab_0 then
3673 local groups
3674 do
3675 local _accum_0 = { }
3676 local _len_0 = 1
3677 local _max_0 = #segments + -3 + 1
3678 for _index_0 = 1, _max_0 do
3679 local _item_0 = segments[_index_0]
3680 _accum_0[_len_0] = _item_0
3681 _len_0 = _len_0 + 1
3682 end
3683 groups = _accum_0
3684 end
3685 local resource = segments[#segments - 1]
3686 local action = segments[#segments]
3687 if resource ~= nil and action ~= nil then
3688 print("Group:", groups)
3689 print("Resource:", resource)
3690 print("Action:", action)
3691 end
3692end
3693local Inventory 1149local Inventory
3694local _class_0 1150local _class_0
3695local _base_0 = { 1151local _base_0 = {
@@ -5010,86 +2466,440 @@ local _with_0 = obj
5010if _with_0 ~= nil then 2466if _with_0 ~= nil then
5011 print(obj.name) 2467 print(obj.name)
5012end 2468end
2469local hello = "world"
2470local a, b, c = 1, 2, 3
2471hello = 123
2472local x = 1
2473x = x + 1
2474x = x - 1
2475x = x * 10
2476x = x / 10
2477x = x % 10
2478local s = s .. "world"
2479local arg = arg or "default value"
2480local a = 0
2481local b = 0
2482local c = 0
2483local d = 0
2484local e = 0
2485local x = f()
2486local y = x
2487local z = x
2488do
2489 local a = 1
2490 local x, y, z
2491 print("forward declare all variables as locals")
2492 x = function()
2493 return 1 + y + z
2494 end
2495 y, z = 2, 3
2496 instance = Item:new()
2497end
5013do 2498do
5014 local var = "hello" 2499 local X = 1
5015 print(var) 2500 local B
2501 print("only forward declare upper case variables")
2502 local a = 1
2503 B = 2
5016end 2504end
5017print(var)
5018local counter
5019do 2505do
5020 local i = 0 2506 a = 1
5021 counter = function() 2507 print("declare all variables as globals")
5022 i = i + 1 2508 x = function()
5023 return i 2509 return 1 + y + z
5024 end 2510 end
2511 y, z = 2, 3
5025end 2512end
5026print(counter())
5027print(counter())
5028local tbl = {
5029 key = (function()
5030 print("assigning key!")
5031 return 1234
5032 end)()
5033}
5034do 2513do
5035 local var = "hello" 2514 X = 1
5036 print(var) 2515 print("only declare upper case variables as globals")
2516 local a = 1
2517 B = 2
2518 local Temp = "a local value"
5037end 2519end
5038print(var) 2520local hello = "world"
5039local counter 2521local a, b, c = 1, 2, 3
2522hello = 123
2523local x = 1
2524x = x + 1
2525x = x - 1
2526x = x * 10
2527x = x / 10
2528x = x % 10
2529local s = s .. "world"
2530local arg = arg or "default value"
2531local a = 0
2532local b = 0
2533local c = 0
2534local d = 0
2535local e = 0
2536local x = f()
2537local y = x
2538local z = x
5040do 2539do
5041 local i = 0 2540 local a = 1
5042 counter = function() 2541 local x, y, z
5043 i = i + 1 2542 print("forward declare all variables as locals")
5044 return i 2543 x = function()
2544 return 1 + y + z
5045 end 2545 end
2546 y, z = 2, 3
2547 instance = Item:new()
5046end 2548end
5047print(counter()) 2549do
5048print(counter()) 2550 local X = 1
5049local tbl = { 2551 local B
5050 key = (function() 2552 print("only forward declare upper case variables")
5051 print("assigning key!") 2553 local a = 1
5052 return 1234 2554 B = 2
5053 end)() 2555end
5054} 2556do
5055local my_object = { 2557 a = 1
5056 value = 1000, 2558 print("declare all variables as globals")
5057 write = function(self) 2559 x = function()
5058 return print("the value:", self.value) 2560 return 1 + y + z
5059 end 2561 end
2562 y, z = 2, 3
2563end
2564do
2565 X = 1
2566 print("only declare upper case variables as globals")
2567 local a = 1
2568 B = 2
2569 local Temp = "a local value"
2570end
2571local list = {
2572 1,
2573 2,
2574 3,
2575 4,
2576 5
5060} 2577}
5061local run_callback 2578local fn
5062run_callback = function(func) 2579fn = function(ok)
5063 print("running callback...") 2580 return ok, table.unpack(list)
5064 return func()
5065end 2581end
5066run_callback(my_object.write) 2582(function(_arg_0, ...)
5067run_callback((function() 2583 local ok = _arg_0
5068 local _base_0 = my_object 2584 local count = select('#', ...)
5069 local _fn_0 = _base_0.write 2585 local first = select(1, ...)
5070 return _fn_0 and function(...) 2586 return print(ok, count, first)
5071 return _fn_0(_base_0, ...) 2587end)(fn(true))
2588local list = {
2589 1,
2590 2,
2591 3,
2592 4,
2593 5
2594}
2595local fn
2596fn = function(ok)
2597 return ok, table.unpack(list)
2598end
2599(function(_arg_0, ...)
2600 local ok = _arg_0
2601 local count = select('#', ...)
2602 local first = select(1, ...)
2603 return print(ok, count, first)
2604end)(fn(true))
2605local user = database.find_user("moon")
2606if user then
2607 print(user.name)
2608end
2609local hello = os.getenv("hello")
2610if hello then
2611 print("You have hello", hello)
2612else
2613 local world = os.getenv("world")
2614 if world then
2615 print("you have world", world)
2616 else
2617 print("nothing :(")
5072 end 2618 end
5073end)()) 2619end
5074local my_object = { 2620do
5075 value = 1000, 2621 local success, result = pcall(function()
5076 write = function(self) 2622 return "get result without problems"
5077 return print("the value:", self.value) 2623 end)
2624 if success then
2625 print(result)
5078 end 2626 end
2627end
2628print("OK")
2629repeat
2630 local byte = stream:read_one()
2631 if byte then
2632 print(byte)
2633 else
2634 break
2635 end
2636until false
2637local user = database.find_user("moon")
2638if user then
2639 print(user.name)
2640end
2641local hello = os.getenv("hello")
2642if hello then
2643 print("You have hello", hello)
2644else
2645 local world = os.getenv("world")
2646 if world then
2647 print("you have world", world)
2648 else
2649 print("nothing :(")
2650 end
2651end
2652do
2653 local success, result = pcall(function()
2654 return "get result without problems"
2655 end)
2656 if success then
2657 print(result)
2658 end
2659end
2660print("OK")
2661repeat
2662 local byte = stream:read_one()
2663 if byte then
2664 print(byte)
2665 else
2666 break
2667 end
2668until false
2669local thing = {
2670 1,
2671 2
5079} 2672}
5080local run_callback 2673local a, b = thing[1], thing[2]
5081run_callback = function(func) 2674print(a, b)
5082 print("running callback...") 2675local obj = {
5083 return func() 2676 hello = "world",
2677 day = "tuesday",
2678 length = 20
2679}
2680local hello, the_day = obj.hello, obj.day
2681print(hello, the_day)
2682local day = obj.day
2683local obj2 = {
2684 numbers = {
2685 1,
2686 2,
2687 3,
2688 4
2689 },
2690 properties = {
2691 color = "green",
2692 height = 13.5
2693 }
2694}
2695local first, second, color = obj2.numbers[1], obj2.numbers[2], obj2.properties.color
2696print(first, second, color)
2697local first, second, color
2698local _obj_0 = obj2
2699first, second, color = _obj_0.numbers[1], _obj_0.numbers[2], _obj_0.properties.color
2700local concat, insert
2701local _obj_0 = table
2702concat, insert = _obj_0.concat, _obj_0.insert
2703local mix, max, rand
2704local _obj_0 = math
2705mix, max, rand = _obj_0.mix, _obj_0.max, _obj_0.random
2706local name, job
2707local _obj_0 = person
2708name, job = _obj_0.name, _obj_0.job
2709if name == nil then
2710 name = "nameless"
5084end 2711end
5085run_callback(my_object.write) 2712if job == nil then
5086run_callback((function() 2713 job = "jobless"
5087 local _base_0 = my_object 2714end
5088 local _fn_0 = _base_0.write 2715local two, four
5089 return _fn_0 and function(...) 2716local _obj_0 = items
5090 return _fn_0(_base_0, ...) 2717two, four = _obj_0[2], _obj_0[4]
2718local orders = {
2719 "first",
2720 "second",
2721 "third",
2722 "fourth",
2723 "last"
2724}
2725local first, bulk, last = orders[1], (function()
2726 local _accum_0 = { }
2727 local _len_0 = 1
2728 local _max_0 = #orders + -2 + 1
2729 for _index_0 = 2, _max_0 do
2730 local _item_0 = orders[_index_0]
2731 _accum_0[_len_0] = _item_0
2732 _len_0 = _len_0 + 1
5091 end 2733 end
5092end)()) 2734 return _accum_0
2735end)(), orders[#orders]
2736print(first)
2737print(bulk)
2738print(last)
2739local first, rest
2740do
2741 local _obj_0 = orders
2742 first, rest = _obj_0[1], (function()
2743 local _accum_0 = { }
2744 local _len_0 = 1
2745 local _max_0 = #_obj_0
2746 for _index_0 = 2, _max_0 do
2747 local _item_0 = _obj_0[_index_0]
2748 _accum_0[_len_0] = _item_0
2749 _len_0 = _len_0 + 1
2750 end
2751 return _accum_0
2752 end)()
2753end
2754local start, last
2755do
2756 local _obj_0 = orders
2757 start, last = (function()
2758 local _accum_0 = { }
2759 local _len_0 = 1
2760 local _max_0 = #_obj_0 + -2 + 1
2761 for _index_0 = 1, _max_0 do
2762 local _item_0 = _obj_0[_index_0]
2763 _accum_0[_len_0] = _item_0
2764 _len_0 = _len_0 + 1
2765 end
2766 return _accum_0
2767 end)(), _obj_0[#_obj_0]
2768end
2769local _obj_0 = orders
2770first, last = _obj_0[1], _obj_0[#_obj_0]
2771local tuples = {
2772 {
2773 "hello",
2774 "world"
2775 },
2776 {
2777 "egg",
2778 "head"
2779 }
2780}
2781for _index_0 = 1, #tuples do
2782 local _des_0 = tuples[_index_0]
2783 local left, right = _des_0[1], _des_0[2]
2784 print(left, right)
2785end
2786local thing = {
2787 1,
2788 2
2789}
2790local a, b = thing[1], thing[2]
2791print(a, b)
2792local obj = {
2793 hello = "world",
2794 day = "tuesday",
2795 length = 20
2796}
2797local hello, the_day = obj.hello, obj.day
2798print(hello, the_day)
2799local day = obj.day
2800local obj2 = {
2801 numbers = {
2802 1,
2803 2,
2804 3,
2805 4
2806 },
2807 properties = {
2808 color = "green",
2809 height = 13.5
2810 }
2811}
2812local first, second, color = obj2.numbers[1], obj2.numbers[2], obj2.properties.color
2813print(first, second, color)
2814local first, second, color
2815local _obj_0 = obj2
2816first, second, color = _obj_0.numbers[1], _obj_0.numbers[2], _obj_0.properties.color
2817local concat, insert
2818local _obj_0 = table
2819concat, insert = _obj_0.concat, _obj_0.insert
2820local mix, max, rand
2821local _obj_0 = math
2822mix, max, rand = _obj_0.mix, _obj_0.max, _obj_0.random
2823local name, job
2824local _obj_0 = person
2825name, job = _obj_0.name, _obj_0.job
2826if name == nil then
2827 name = "nameless"
2828end
2829if job == nil then
2830 job = "jobless"
2831end
2832local two, four
2833local _obj_0 = items
2834two, four = _obj_0[2], _obj_0[4]
2835local orders = {
2836 "first",
2837 "second",
2838 "third",
2839 "fourth",
2840 "last"
2841}
2842local first, bulk, last = orders[1], (function()
2843 local _accum_0 = { }
2844 local _len_0 = 1
2845 local _max_0 = #orders + -2 + 1
2846 for _index_0 = 2, _max_0 do
2847 local _item_0 = orders[_index_0]
2848 _accum_0[_len_0] = _item_0
2849 _len_0 = _len_0 + 1
2850 end
2851 return _accum_0
2852end)(), orders[#orders]
2853print(first)
2854print(bulk)
2855print(last)
2856local first, rest
2857do
2858 local _obj_0 = orders
2859 first, rest = _obj_0[1], (function()
2860 local _accum_0 = { }
2861 local _len_0 = 1
2862 local _max_0 = #_obj_0
2863 for _index_0 = 2, _max_0 do
2864 local _item_0 = _obj_0[_index_0]
2865 _accum_0[_len_0] = _item_0
2866 _len_0 = _len_0 + 1
2867 end
2868 return _accum_0
2869 end)()
2870end
2871local start, last
2872do
2873 local _obj_0 = orders
2874 start, last = (function()
2875 local _accum_0 = { }
2876 local _len_0 = 1
2877 local _max_0 = #_obj_0 + -2 + 1
2878 for _index_0 = 1, _max_0 do
2879 local _item_0 = _obj_0[_index_0]
2880 _accum_0[_len_0] = _item_0
2881 _len_0 = _len_0 + 1
2882 end
2883 return _accum_0
2884 end)(), _obj_0[#_obj_0]
2885end
2886local _obj_0 = orders
2887first, last = _obj_0[1], _obj_0[#_obj_0]
2888local tuples = {
2889 {
2890 "hello",
2891 "world"
2892 },
2893 {
2894 "egg",
2895 "head"
2896 }
2897}
2898for _index_0 = 1, #tuples do
2899 local _des_0 = tuples[_index_0]
2900 local left, right = _des_0[1], _des_0[2]
2901 print(left, right)
2902end
5093local i = 100 2903local i = 100
5094local my_func 2904local my_func
5095my_func = function() 2905my_func = function()
@@ -5146,3 +2956,2193 @@ my_func = function(add)
5146end 2956end
5147my_func(22) 2957my_func(22)
5148print(i, k) 2958print(i, k)
2959local _module_0 = { }
2960local p, to_lua
2961do
2962 local _obj_0 = require("yue")
2963 p, to_lua = _obj_0.p, _obj_0.to_lua
2964end
2965local inventory = {
2966 equipment = {
2967 "sword",
2968 "shield"
2969 },
2970 items = {
2971 {
2972 name = "potion",
2973 count = 10
2974 },
2975 {
2976 name = "bread",
2977 count = 3
2978 }
2979 }
2980}
2981local map
2982map = function(arr, action)
2983 local _accum_0 = { }
2984 local _len_0 = 1
2985 for _index_0 = 1, #arr do
2986 local item = arr[_index_0]
2987 _accum_0[_len_0] = action(item)
2988 _len_0 = _len_0 + 1
2989 end
2990 return _accum_0
2991end
2992local filter
2993filter = function(arr, cond)
2994 local _accum_0 = { }
2995 local _len_0 = 1
2996 for _index_0 = 1, #arr do
2997 local item = arr[_index_0]
2998 if cond(item) then
2999 _accum_0[_len_0] = item
3000 _len_0 = _len_0 + 1
3001 end
3002 end
3003 return _accum_0
3004end
3005local reduce
3006reduce = function(arr, init, action)
3007 for _index_0 = 1, #arr do
3008 local item = arr[_index_0]
3009 init = action(init, item)
3010 end
3011 return init
3012end
3013print(reduce(filter(map({
3014 1,
3015 2,
3016 3
3017}, function(x)
3018 return x * 2
3019end), function(x)
3020 return x > 4
3021end), 0, function(a, b)
3022 return a + b
3023end))
3024local apple = setmetatable({
3025 size = 15,
3026}, {
3027 __index = {
3028 color = 0x00ffff
3029 }
3030})
3031if (getmetatable(apple) ~= nil) then
3032 p(apple.size, apple.color, getmetatable(apple).__index)
3033end
3034local _u1f31b = "月之脚本"
3035_module_0["🌛"] = _u1f31b
3036return _module_0
3037local _module_0 = { }
3038local p, to_lua
3039do
3040 local _obj_0 = require("yue")
3041 p, to_lua = _obj_0.p, _obj_0.to_lua
3042end
3043local inventory = {
3044 equipment = {
3045 "sword",
3046 "shield"
3047 },
3048 items = {
3049 {
3050 name = "potion",
3051 count = 10
3052 },
3053 {
3054 name = "bread",
3055 count = 3
3056 }
3057 }
3058}
3059local map
3060map = function(arr, action)
3061 local _accum_0 = { }
3062 local _len_0 = 1
3063 for _index_0 = 1, #arr do
3064 local item = arr[_index_0]
3065 _accum_0[_len_0] = action(item)
3066 _len_0 = _len_0 + 1
3067 end
3068 return _accum_0
3069end
3070local filter
3071filter = function(arr, cond)
3072 local _accum_0 = { }
3073 local _len_0 = 1
3074 for _index_0 = 1, #arr do
3075 local item = arr[_index_0]
3076 if cond(item) then
3077 _accum_0[_len_0] = item
3078 _len_0 = _len_0 + 1
3079 end
3080 end
3081 return _accum_0
3082end
3083local reduce
3084reduce = function(arr, init, action)
3085 for _index_0 = 1, #arr do
3086 local item = arr[_index_0]
3087 init = action(init, item)
3088 end
3089 return init
3090end
3091print(reduce(filter(map({
3092 1,
3093 2,
3094 3
3095}, function(x)
3096 return x * 2
3097end), function(x)
3098 return x > 4
3099end), 0, function(a, b)
3100 return a + b
3101end))
3102local apple = setmetatable({
3103 size = 15,
3104}, {
3105 __index = {
3106 color = 0x00ffff
3107 }
3108})
3109if (getmetatable(apple) ~= nil) then
3110 p(apple.size, apple.color, getmetatable(apple).__index)
3111end
3112local _u1f31b = "月之脚本"
3113_module_0["🌛"] = _u1f31b
3114return _module_0
3115local have_coins = false
3116if have_coins then
3117 print("Got coins")
3118else
3119 print("No coins")
3120end
3121local have_coins = false
3122if have_coins then
3123 print("Got coins")
3124else
3125 print("No coins")
3126end
3127local have_coins = false
3128print((function()
3129 if have_coins then
3130 return "Got coins"
3131 else
3132 return "No coins"
3133 end
3134end)())
3135local is_tall
3136is_tall = function(name)
3137 if name == "Rob" then
3138 return true
3139 else
3140 return false
3141 end
3142end
3143local message
3144if is_tall("Rob") then
3145 message = "I am very tall"
3146else
3147 message = "I am not so tall"
3148end
3149print(message)
3150if not (os.date("%A") == "Monday") then
3151 print("it is not Monday!")
3152end
3153if not (math.random() > 0.1) then
3154 print("You're lucky!")
3155end
3156local a = 5
3157if (1 == a or 3 == a or 5 == a or 7 == a) then
3158 print("checking equality with discrete values")
3159end
3160if (function()
3161 local _check_0 = list
3162 for _index_0 = 1, #_check_0 do
3163 if _check_0[_index_0] == a then
3164 return true
3165 end
3166 end
3167 return false
3168end)() then
3169 print("checking if `a` is in a list")
3170end
3171if not (math.random() > 0.1) then
3172 print("You're lucky!")
3173end
3174local have_coins = false
3175if have_coins then
3176 print("Got coins")
3177else
3178 print("No coins")
3179end
3180local have_coins = false
3181if have_coins then
3182 print("Got coins")
3183else
3184 print("No coins")
3185end
3186local have_coins = false
3187print((function()
3188 if have_coins then
3189 return "Got coins"
3190 else
3191 return "No coins"
3192 end
3193end)())
3194local is_tall
3195is_tall = function(name)
3196 if name == "Rob" then
3197 return true
3198 else
3199 return false
3200 end
3201end
3202local message
3203if is_tall("Rob") then
3204 message = "I am very tall"
3205else
3206 message = "I am not so tall"
3207end
3208print(message)
3209if not (os.date("%A") == "Monday") then
3210 print("it is not Monday!")
3211end
3212if not (math.random() > 0.1) then
3213 print("You're lucky!")
3214end
3215local a = 5
3216if (1 == a or 3 == a or 5 == a or 7 == a) then
3217 print("checking equality with discrete values")
3218end
3219if (function()
3220 local _check_0 = list
3221 for _index_0 = 1, #_check_0 do
3222 if _check_0[_index_0] == a then
3223 return true
3224 end
3225 end
3226 return false
3227end)() then
3228 print("checking if `a` is in a list")
3229end
3230if not (math.random() > 0.1) then
3231 print("You're lucky!")
3232end
3233for i = 10, 20 do
3234 print(i)
3235end
3236for k = 1, 15, 2 do
3237 print(k)
3238end
3239for key, value in pairs(object) do
3240 print(key, value)
3241end
3242local _list_0 = items
3243for _index_0 = 2, 4 do
3244 local item = _list_0[_index_0]
3245 print(item)
3246end
3247local _list_0 = items
3248for _index_0 = 1, #_list_0 do
3249 local item = _list_0[_index_0]
3250 print(item)
3251end
3252for j = 1, 10, 3 do
3253 print(j)
3254end
3255local doubled_evens
3256local _accum_0 = { }
3257local _len_0 = 1
3258for i = 1, 20 do
3259 if i % 2 == 0 then
3260 _accum_0[_len_0] = i * 2
3261 _len_0 = _len_0 + 1
3262 else
3263 _accum_0[_len_0] = i
3264 _len_0 = _len_0 + 1
3265 end
3266end
3267doubled_evens = _accum_0
3268local first_large
3269local _accum_0
3270local _list_0 = numbers
3271for _index_0 = 1, #_list_0 do
3272 local n = _list_0[_index_0]
3273 if n > 10 then
3274 _accum_0 = n
3275 break
3276 end
3277end
3278first_large = _accum_0
3279local func_a
3280func_a = function()
3281 for i = 1, 10 do
3282 print(i)
3283 end
3284end
3285local func_b
3286func_b = function()
3287 local _accum_0 = { }
3288 local _len_0 = 1
3289 for i = 1, 10 do
3290 _accum_0[_len_0] = i
3291 _len_0 = _len_0 + 1
3292 end
3293 return _accum_0
3294end
3295print(func_a())
3296print(func_b())
3297for i = 10, 20 do
3298 print(i)
3299end
3300for k = 1, 15, 2 do
3301 print(k)
3302end
3303for key, value in pairs(object) do
3304 print(key, value)
3305end
3306local _list_0 = items
3307for _index_0 = 2, 4 do
3308 local item = _list_0[_index_0]
3309 print(item)
3310end
3311local _list_0 = items
3312for _index_0 = 1, #_list_0 do
3313 local item = _list_0[_index_0]
3314 print(item)
3315end
3316for j = 1, 10, 3 do
3317 print(j)
3318end
3319local doubled_evens
3320local _accum_0 = { }
3321local _len_0 = 1
3322for i = 1, 20 do
3323 if i % 2 == 0 then
3324 _accum_0[_len_0] = i * 2
3325 _len_0 = _len_0 + 1
3326 else
3327 _accum_0[_len_0] = i
3328 _len_0 = _len_0 + 1
3329 end
3330end
3331doubled_evens = _accum_0
3332local first_large
3333local _accum_0
3334local _list_0 = numbers
3335for _index_0 = 1, #_list_0 do
3336 local n = _list_0[_index_0]
3337 if n > 10 then
3338 _accum_0 = n
3339 break
3340 end
3341end
3342first_large = _accum_0
3343local func_a
3344func_a = function()
3345 for i = 1, 10 do
3346 print(i)
3347 end
3348end
3349local func_b
3350func_b = function()
3351 local _accum_0 = { }
3352 local _len_0 = 1
3353 for i = 1, 10 do
3354 _accum_0[_len_0] = i
3355 _len_0 = _len_0 + 1
3356 end
3357 return _accum_0
3358end
3359print(func_a())
3360print(func_b())
3361local i = 0
3362while i < 10 do
3363 i = i + 1
3364 if i % 2 == 0 then
3365 goto _continue_0
3366 end
3367 print(i)
3368 ::_continue_0::
3369end
3370local my_numbers = {
3371 1,
3372 2,
3373 3,
3374 4,
3375 5,
3376 6
3377}
3378local odds
3379local _accum_0 = { }
3380local _len_0 = 1
3381for _index_0 = 1, #my_numbers do
3382 local x = my_numbers[_index_0]
3383 if x % 2 == 1 then
3384 goto _continue_0
3385 end
3386 _accum_0[_len_0] = x
3387 _len_0 = _len_0 + 1
3388 ::_continue_0::
3389end
3390odds = _accum_0
3391local i = 0
3392while i < 10 do
3393 i = i + 1
3394 if i % 2 == 0 then
3395 goto _continue_0
3396 end
3397 print(i)
3398 ::_continue_0::
3399end
3400local my_numbers = {
3401 1,
3402 2,
3403 3,
3404 4,
3405 5,
3406 6
3407}
3408local odds
3409local _accum_0 = { }
3410local _len_0 = 1
3411for _index_0 = 1, #my_numbers do
3412 local x = my_numbers[_index_0]
3413 if x % 2 == 1 then
3414 goto _continue_0
3415 end
3416 _accum_0[_len_0] = x
3417 _len_0 = _len_0 + 1
3418 ::_continue_0::
3419end
3420odds = _accum_0
3421local name = "Dan"
3422if "Robert" == name then
3423 print("You are Robert")
3424elseif "Dan" == name or "Daniel" == name then
3425 print("Your name, it's Dan")
3426else
3427 print("I don't know about you with name " .. tostring(name))
3428end
3429local b = 1
3430local next_number
3431if 1 == b then
3432 next_number = 2
3433elseif 2 == b then
3434 next_number = 3
3435else
3436 next_number = error("can't count that high!")
3437end
3438local msg
3439local _exp_0 = math.random(1, 5)
3440if 1 == _exp_0 then
3441 msg = "you are lucky"
3442elseif 2 == _exp_0 then
3443 msg = "you are almost lucky"
3444else
3445 msg = "not so lucky"
3446end
3447do
3448 local _exp_0 = math.random(1, 5)
3449 if 1 == _exp_0 then
3450 print("you are lucky")
3451 else
3452 print("not so lucky")
3453 end
3454end
3455local _exp_0 = math.random(1, 5)
3456if 1 == _exp_0 then
3457 print("you are lucky")
3458else
3459 print("not so lucky")
3460end
3461local items = {
3462 {
3463 x = 100,
3464 y = 200
3465 },
3466 {
3467 width = 300,
3468 height = 400
3469 }
3470}
3471for _index_0 = 1, #items do
3472 local item = items[_index_0]
3473 local _type_0 = type(item)
3474 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3475 local _match_0 = false
3476 if _tab_0 then
3477 local x = item.x
3478 local y = item.y
3479 if x ~= nil and y ~= nil then
3480 _match_0 = true
3481 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3482 end
3483 end
3484 if not _match_0 then
3485 if _tab_0 then
3486 local width = item.width
3487 local height = item.height
3488 if width ~= nil and height ~= nil then
3489 print("size " .. tostring(width) .. ", " .. tostring(height))
3490 end
3491 end
3492 end
3493end
3494local item = { }
3495local x, y = item.pos.x, item.pos.y
3496if x == nil then
3497 x = 50
3498end
3499if y == nil then
3500 y = 200
3501end
3502local _type_0 = type(item)
3503local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3504if _tab_0 then
3505 do
3506 local _obj_0 = item.pos
3507 local _type_1 = type(_obj_0)
3508 if "table" == _type_1 or "userdata" == _type_1 then
3509 x = _obj_0.x
3510 end
3511 end
3512 do
3513 local _obj_0 = item.pos
3514 local _type_1 = type(_obj_0)
3515 if "table" == _type_1 or "userdata" == _type_1 then
3516 y = _obj_0.y
3517 end
3518 end
3519 if x == nil then
3520 x = 50
3521 end
3522 if y == nil then
3523 y = 200
3524 end
3525 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3526end
3527local _exp_0 = tb
3528local _type_0 = type(_exp_0)
3529local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3530local _match_0 = false
3531if _tab_0 then
3532 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
3533 _match_0 = true
3534 print("1, 2, 3")
3535 end
3536end
3537if not _match_0 then
3538 local _match_1 = false
3539 if _tab_0 then
3540 local b = _exp_0[2]
3541 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
3542 _match_1 = true
3543 print("1, " .. tostring(b) .. ", 3")
3544 end
3545 end
3546 if not _match_1 then
3547 if _tab_0 then
3548 local b = _exp_0[3]
3549 if b == nil then
3550 b = 3
3551 end
3552 if 1 == _exp_0[1] and 2 == _exp_0[2] then
3553 print("1, 2, " .. tostring(b))
3554 end
3555 end
3556 end
3557end
3558local _exp_0 = tb
3559local _type_0 = type(_exp_0)
3560local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3561local _match_0 = false
3562if _tab_0 then
3563 local result = _exp_0.result
3564 if true == _exp_0.success and result ~= nil then
3565 _match_0 = true
3566 print("success", result)
3567 end
3568end
3569if not _match_0 then
3570 local _match_1 = false
3571 if _tab_0 then
3572 if false == _exp_0.success then
3573 _match_1 = true
3574 print("failed", result)
3575 end
3576 end
3577 if not _match_1 then
3578 print("invalid")
3579 end
3580end
3581local _exp_0 = tb
3582local _type_0 = type(_exp_0)
3583local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3584local _match_0 = false
3585if _tab_0 then
3586 local content
3587 do
3588 local _obj_0 = _exp_0.data
3589 local _type_1 = type(_obj_0)
3590 if "table" == _type_1 or "userdata" == _type_1 then
3591 content = _obj_0.content
3592 end
3593 end
3594 local _val_0
3595 do
3596 local _obj_0 = _exp_0.data
3597 if _obj_0 ~= nil then
3598 _val_0 = _obj_0.type
3599 end
3600 end
3601 if "success" == _val_0 and content ~= nil then
3602 _match_0 = true
3603 print("success", content)
3604 end
3605end
3606if not _match_0 then
3607 local _match_1 = false
3608 if _tab_0 then
3609 local content
3610 do
3611 local _obj_0 = _exp_0.data
3612 local _type_1 = type(_obj_0)
3613 if "table" == _type_1 or "userdata" == _type_1 then
3614 content = _obj_0.content
3615 end
3616 end
3617 local _val_0
3618 do
3619 local _obj_0 = _exp_0.data
3620 if _obj_0 ~= nil then
3621 _val_0 = _obj_0.type
3622 end
3623 end
3624 if "error" == _val_0 and content ~= nil then
3625 _match_1 = true
3626 print("failed", content)
3627 end
3628 end
3629 if not _match_1 then
3630 print("invalid")
3631 end
3632end
3633local _exp_0 = tb
3634local _type_0 = type(_exp_0)
3635local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3636if _tab_0 then
3637 local fourth = _exp_0[4]
3638 local _val_0
3639 do
3640 local _obj_0 = _exp_0[1]
3641 if _obj_0 ~= nil then
3642 _val_0 = _obj_0.a
3643 end
3644 end
3645 local _val_1
3646 do
3647 local _obj_0 = _exp_0[1]
3648 if _obj_0 ~= nil then
3649 _val_1 = _obj_0.b
3650 end
3651 end
3652 local _val_2
3653 do
3654 local _obj_0 = _exp_0[2]
3655 if _obj_0 ~= nil then
3656 _val_2 = _obj_0.a
3657 end
3658 end
3659 local _val_3
3660 do
3661 local _obj_0 = _exp_0[2]
3662 if _obj_0 ~= nil then
3663 _val_3 = _obj_0.b
3664 end
3665 end
3666 local _val_4
3667 do
3668 local _obj_0 = _exp_0[3]
3669 if _obj_0 ~= nil then
3670 _val_4 = _obj_0.a
3671 end
3672 end
3673 local _val_5
3674 do
3675 local _obj_0 = _exp_0[3]
3676 if _obj_0 ~= nil then
3677 _val_5 = _obj_0.b
3678 end
3679 end
3680 if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and fourth ~= nil then
3681 print("matched", fourth)
3682 end
3683end
3684local segments = {
3685 "admin",
3686 "users",
3687 "logs",
3688 "view"
3689}
3690local _type_0 = type(segments)
3691local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3692if _tab_0 then
3693 local groups
3694 do
3695 local _accum_0 = { }
3696 local _len_0 = 1
3697 local _max_0 = #segments + -3 + 1
3698 for _index_0 = 1, _max_0 do
3699 local _item_0 = segments[_index_0]
3700 _accum_0[_len_0] = _item_0
3701 _len_0 = _len_0 + 1
3702 end
3703 groups = _accum_0
3704 end
3705 local resource = segments[#segments - 1]
3706 local action = segments[#segments]
3707 if resource ~= nil and action ~= nil then
3708 print("Group:", groups)
3709 print("Resource:", resource)
3710 print("Action:", action)
3711 end
3712end
3713local name = "Dan"
3714if "Robert" == name then
3715 print("You are Robert")
3716elseif "Dan" == name or "Daniel" == name then
3717 print("Your name, it's Dan")
3718else
3719 print("I don't know about you with name " .. tostring(name))
3720end
3721local b = 1
3722local next_number
3723if 1 == b then
3724 next_number = 2
3725elseif 2 == b then
3726 next_number = 3
3727else
3728 next_number = error("can't count that high!")
3729end
3730local msg
3731local _exp_0 = math.random(1, 5)
3732if 1 == _exp_0 then
3733 msg = "you are lucky"
3734elseif 2 == _exp_0 then
3735 msg = "you are almost lucky"
3736else
3737 msg = "not so lucky"
3738end
3739do
3740 local _exp_0 = math.random(1, 5)
3741 if 1 == _exp_0 then
3742 print("you are lucky")
3743 else
3744 print("not so lucky")
3745 end
3746end
3747local _exp_0 = math.random(1, 5)
3748if 1 == _exp_0 then
3749 print("you are lucky")
3750else
3751 print("not so lucky")
3752end
3753local items = {
3754 {
3755 x = 100,
3756 y = 200
3757 },
3758 {
3759 width = 300,
3760 height = 400
3761 }
3762}
3763for _index_0 = 1, #items do
3764 local item = items[_index_0]
3765 local _type_0 = type(item)
3766 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3767 local _match_0 = false
3768 if _tab_0 then
3769 local x = item.x
3770 local y = item.y
3771 if x ~= nil and y ~= nil then
3772 _match_0 = true
3773 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3774 end
3775 end
3776 if not _match_0 then
3777 if _tab_0 then
3778 local width = item.width
3779 local height = item.height
3780 if width ~= nil and height ~= nil then
3781 print("size " .. tostring(width) .. ", " .. tostring(height))
3782 end
3783 end
3784 end
3785end
3786local item = { }
3787local x, y = item.pos.x, item.pos.y
3788if x == nil then
3789 x = 50
3790end
3791if y == nil then
3792 y = 200
3793end
3794local _type_0 = type(item)
3795local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3796if _tab_0 then
3797 do
3798 local _obj_0 = item.pos
3799 local _type_1 = type(_obj_0)
3800 if "table" == _type_1 or "userdata" == _type_1 then
3801 x = _obj_0.x
3802 end
3803 end
3804 do
3805 local _obj_0 = item.pos
3806 local _type_1 = type(_obj_0)
3807 if "table" == _type_1 or "userdata" == _type_1 then
3808 y = _obj_0.y
3809 end
3810 end
3811 if x == nil then
3812 x = 50
3813 end
3814 if y == nil then
3815 y = 200
3816 end
3817 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3818end
3819local _exp_0 = tb
3820local _type_0 = type(_exp_0)
3821local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3822local _match_0 = false
3823if _tab_0 then
3824 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
3825 _match_0 = true
3826 print("1, 2, 3")
3827 end
3828end
3829if not _match_0 then
3830 local _match_1 = false
3831 if _tab_0 then
3832 local b = _exp_0[2]
3833 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
3834 _match_1 = true
3835 print("1, " .. tostring(b) .. ", 3")
3836 end
3837 end
3838 if not _match_1 then
3839 if _tab_0 then
3840 local b = _exp_0[3]
3841 if b == nil then
3842 b = 3
3843 end
3844 if 1 == _exp_0[1] and 2 == _exp_0[2] then
3845 print("1, 2, " .. tostring(b))
3846 end
3847 end
3848 end
3849end
3850local _exp_0 = tb
3851local _type_0 = type(_exp_0)
3852local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3853local _match_0 = false
3854if _tab_0 then
3855 local result = _exp_0.result
3856 if true == _exp_0.success and result ~= nil then
3857 _match_0 = true
3858 print("success", result)
3859 end
3860end
3861if not _match_0 then
3862 local _match_1 = false
3863 if _tab_0 then
3864 if false == _exp_0.success then
3865 _match_1 = true
3866 print("failed", result)
3867 end
3868 end
3869 if not _match_1 then
3870 print("invalid")
3871 end
3872end
3873local _exp_0 = tb
3874local _type_0 = type(_exp_0)
3875local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3876local _match_0 = false
3877if _tab_0 then
3878 local content
3879 do
3880 local _obj_0 = _exp_0.data
3881 local _type_1 = type(_obj_0)
3882 if "table" == _type_1 or "userdata" == _type_1 then
3883 content = _obj_0.content
3884 end
3885 end
3886 local _val_0
3887 do
3888 local _obj_0 = _exp_0.data
3889 if _obj_0 ~= nil then
3890 _val_0 = _obj_0.type
3891 end
3892 end
3893 if "success" == _val_0 and content ~= nil then
3894 _match_0 = true
3895 print("success", content)
3896 end
3897end
3898if not _match_0 then
3899 local _match_1 = false
3900 if _tab_0 then
3901 local content
3902 do
3903 local _obj_0 = _exp_0.data
3904 local _type_1 = type(_obj_0)
3905 if "table" == _type_1 or "userdata" == _type_1 then
3906 content = _obj_0.content
3907 end
3908 end
3909 local _val_0
3910 do
3911 local _obj_0 = _exp_0.data
3912 if _obj_0 ~= nil then
3913 _val_0 = _obj_0.type
3914 end
3915 end
3916 if "error" == _val_0 and content ~= nil then
3917 _match_1 = true
3918 print("failed", content)
3919 end
3920 end
3921 if not _match_1 then
3922 print("invalid")
3923 end
3924end
3925local _exp_0 = tb
3926local _type_0 = type(_exp_0)
3927local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3928if _tab_0 then
3929 local fourth = _exp_0[4]
3930 local _val_0
3931 do
3932 local _obj_0 = _exp_0[1]
3933 if _obj_0 ~= nil then
3934 _val_0 = _obj_0.a
3935 end
3936 end
3937 local _val_1
3938 do
3939 local _obj_0 = _exp_0[1]
3940 if _obj_0 ~= nil then
3941 _val_1 = _obj_0.b
3942 end
3943 end
3944 local _val_2
3945 do
3946 local _obj_0 = _exp_0[2]
3947 if _obj_0 ~= nil then
3948 _val_2 = _obj_0.a
3949 end
3950 end
3951 local _val_3
3952 do
3953 local _obj_0 = _exp_0[2]
3954 if _obj_0 ~= nil then
3955 _val_3 = _obj_0.b
3956 end
3957 end
3958 local _val_4
3959 do
3960 local _obj_0 = _exp_0[3]
3961 if _obj_0 ~= nil then
3962 _val_4 = _obj_0.a
3963 end
3964 end
3965 local _val_5
3966 do
3967 local _obj_0 = _exp_0[3]
3968 if _obj_0 ~= nil then
3969 _val_5 = _obj_0.b
3970 end
3971 end
3972 if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and fourth ~= nil then
3973 print("matched", fourth)
3974 end
3975end
3976local segments = {
3977 "admin",
3978 "users",
3979 "logs",
3980 "view"
3981}
3982local _type_0 = type(segments)
3983local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3984if _tab_0 then
3985 local groups
3986 do
3987 local _accum_0 = { }
3988 local _len_0 = 1
3989 local _max_0 = #segments + -3 + 1
3990 for _index_0 = 1, _max_0 do
3991 local _item_0 = segments[_index_0]
3992 _accum_0[_len_0] = _item_0
3993 _len_0 = _len_0 + 1
3994 end
3995 groups = _accum_0
3996 end
3997 local resource = segments[#segments - 1]
3998 local action = segments[#segments]
3999 if resource ~= nil and action ~= nil then
4000 print("Group:", groups)
4001 print("Resource:", resource)
4002 print("Action:", action)
4003 end
4004end
4005local i = 10
4006while i > 0 do
4007 print(i)
4008 i = i - 1
4009end
4010while running == true do
4011 my_function()
4012end
4013local i = 10
4014while not (i == 0) do
4015 print(i)
4016 i = i - 1
4017end
4018while not (running == false) do
4019 my_function()
4020end
4021local i = 10
4022repeat
4023 print(i)
4024 i = i - 1
4025until i == 0
4026local i = 10
4027while i > 0 do
4028 print(i)
4029 i = i - 1
4030end
4031while running == true do
4032 my_function()
4033end
4034local i = 10
4035while not (i == 0) do
4036 print(i)
4037 i = i - 1
4038end
4039while not (running == false) do
4040 my_function()
4041end
4042local i = 10
4043repeat
4044 print(i)
4045 i = i - 1
4046until i == 0
4047local my_object = {
4048 value = 1000,
4049 write = function(self)
4050 return print("the value:", self.value)
4051 end
4052}
4053local run_callback
4054run_callback = function(func)
4055 print("running callback...")
4056 return func()
4057end
4058run_callback(my_object.write)
4059run_callback((function()
4060 local _base_0 = my_object
4061 local _fn_0 = _base_0.write
4062 return _fn_0 and function(...)
4063 return _fn_0(_base_0, ...)
4064 end
4065end)())
4066local my_object = {
4067 value = 1000,
4068 write = function(self)
4069 return print("the value:", self.value)
4070 end
4071}
4072local run_callback
4073run_callback = function(func)
4074 print("running callback...")
4075 return func()
4076end
4077run_callback(my_object.write)
4078run_callback((function()
4079 local _base_0 = my_object
4080 local _fn_0 = _base_0.write
4081 return _fn_0 and function(...)
4082 return _fn_0(_base_0, ...)
4083 end
4084end)())
4085f(function(x)
4086 return print("hello" .. x)
4087end)
4088f(function(self)
4089 return print(self.value)
4090end)
4091map(function(x)
4092 return x * 2
4093end, {
4094 1,
4095 2,
4096 3
4097})
4098local result, msg
4099do
4100 result, msg = readAsync("filename.txt", function(data)
4101 print(data)
4102 return processAsync(data, function(info)
4103 return check(info)
4104 end)
4105 end)
4106end
4107print(result, msg)
4108f(function(x)
4109 return print("hello" .. x)
4110end)
4111f(function(self)
4112 return print(self.value)
4113end)
4114map(function(x)
4115 return x * 2
4116end, {
4117 1,
4118 2,
4119 3
4120})
4121local result, msg
4122do
4123 result, msg = readAsync("filename.txt", function(data)
4124 print(data)
4125 return processAsync(data, function(info)
4126 return check(info)
4127 end)
4128 end)
4129end
4130print(result, msg)
4131local my_function
4132my_function = function() end
4133my_function()
4134local func_a
4135func_a = function()
4136 return print("hello world")
4137end
4138local func_b
4139func_b = function()
4140 local value = 100
4141 return print("The value:", value)
4142end
4143func_a()
4144func_b()
4145local sum
4146sum = function(x, y)
4147 return print("sum", x + y)
4148end
4149sum(10, 20)
4150print(sum(10, 20))
4151a(b(c("a", "b", "c")))
4152print("x:", sum(10, 20), "y:", sum(30, 40))
4153local sum
4154sum = function(x, y)
4155 return x + y
4156end
4157print("The sum is ", sum(10, 20))
4158local sum
4159sum = function(x, y)
4160 return x + y
4161end
4162local mystery
4163mystery = function(x, y)
4164 return x + y, x - y
4165end
4166local a, b = mystery(10, 20)
4167local func
4168func = function(self, num)
4169 return self.value + num
4170end
4171local my_function
4172my_function = function(name, height)
4173 if name == nil then
4174 name = "something"
4175 end
4176 if height == nil then
4177 height = 100
4178 end
4179 print("Hello I am", name)
4180 return print("My height is", height)
4181end
4182local some_args
4183some_args = function(x, y)
4184 if x == nil then
4185 x = 100
4186 end
4187 if y == nil then
4188 y = x + 1000
4189 end
4190 return print(x + y)
4191end
4192local a = x - 10
4193local b = x - 10
4194local c = x(-y)
4195local d = x - z
4196local x = func("hello") + 100
4197local y = func("hello" + 100)
4198my_func(5, 4, 3, 8, 9, 10)
4199cool_func(1, 2, 3, 4, 5, 6, 7, 8)
4200my_func(5, 6, 7, 6, another_func(6, 7, 8, 9, 1, 2), 5, 4)
4201local x = {
4202 1,
4203 2,
4204 3,
4205 4,
4206 a_func(4, 5, 5, 6),
4207 8,
4208 9,
4209 10
4210}
4211local y = {
4212 my_func(1, 2, 3, 4, 5),
4213 5,
4214 6,
4215 7
4216}
4217if func(1, 2, 3, "hello", "world") then
4218 print("hello")
4219 print("I am inside if")
4220end
4221if func(1, 2, 3, "hello", "world") then
4222 print("hello")
4223 print("I am inside if")
4224end
4225local f1
4226f1 = function(_arg_0)
4227 local a, b, c
4228 a, b, c = _arg_0.a, _arg_0.b, _arg_0.c
4229 return print(a, b, c)
4230end
4231f1({
4232 a = 1,
4233 b = "2",
4234 c = { }
4235})
4236local f2
4237f2 = function(_arg_0, c)
4238 local a1, b
4239 a1, b = _arg_0.a, _arg_0.b
4240 if a1 == nil then
4241 a1 = 123
4242 end
4243 if b == nil then
4244 b = 'abc'
4245 end
4246 if c == nil then
4247 c = { }
4248 end
4249 return print(a1, b, c)
4250end
4251local arg1 = {
4252 a = 0
4253}
4254f2(arg1, arg2)
4255local findFirstEven
4256findFirstEven = function(list)
4257 for _index_0 = 1, #list do
4258 local item = list[_index_0]
4259 if type(item) == "table" then
4260 for _index_1 = 1, #item do
4261 local sub = item[_index_1]
4262 if sub % 2 == 0 then
4263 return sub
4264 end
4265 end
4266 end
4267 end
4268 return nil
4269end
4270local findFirstEven
4271findFirstEven = function(list)
4272 for _index_0 = 1, #list do
4273 local item = list[_index_0]
4274 if type(item) == "table" then
4275 for _index_1 = 1, #item do
4276 local sub = item[_index_1]
4277 if sub % 2 == 0 then
4278 return sub
4279 end
4280 end
4281 end
4282 end
4283 return nil
4284end
4285local f
4286f = function(...)
4287 local t = {
4288 n = select("#", ...),
4289 ...
4290 }
4291 print("argument count:", t.n)
4292 print("table length:", #t)
4293 for i = 1, t.n do
4294 print(t[i])
4295 end
4296end
4297f(1, 2, 3)
4298f("a", "b", "c", "d")
4299f()
4300local process
4301process = function(...)
4302 local args = {
4303 n = select("#", ...),
4304 ...
4305 }
4306 local sum = 0
4307 for i = 1, args.n do
4308 if args[i] ~= nil and type(args[i]) == "number" then
4309 sum = sum + args[i]
4310 end
4311 end
4312 return sum
4313end
4314process(1, nil, 3, nil, 5)
4315local my_function
4316my_function = function() end
4317my_function()
4318local func_a
4319func_a = function()
4320 return print("hello world")
4321end
4322local func_b
4323func_b = function()
4324 local value = 100
4325 return print("The value:", value)
4326end
4327func_a()
4328func_b()
4329local sum
4330sum = function(x, y)
4331 return print("sum", x + y)
4332end
4333sum(10, 20)
4334print(sum(10, 20))
4335a(b(c("a", "b", "c")))
4336print("x:", sum(10, 20), "y:", sum(30, 40))
4337local sum
4338sum = function(x, y)
4339 return x + y
4340end
4341print("The sum is ", sum(10, 20))
4342local sum
4343sum = function(x, y)
4344 return x + y
4345end
4346local mystery
4347mystery = function(x, y)
4348 return x + y, x - y
4349end
4350local a, b = mystery(10, 20)
4351local func
4352func = function(self, num)
4353 return self.value + num
4354end
4355local my_function
4356my_function = function(name, height)
4357 if name == nil then
4358 name = "something"
4359 end
4360 if height == nil then
4361 height = 100
4362 end
4363 print("Hello I am", name)
4364 return print("My height is", height)
4365end
4366local some_args
4367some_args = function(x, y)
4368 if x == nil then
4369 x = 100
4370 end
4371 if y == nil then
4372 y = x + 1000
4373 end
4374 return print(x + y)
4375end
4376local a = x - 10
4377local b = x - 10
4378local c = x(-y)
4379local d = x - z
4380local x = func("hello") + 100
4381local y = func("hello" + 100)
4382my_func(5, 4, 3, 8, 9, 10)
4383cool_func(1, 2, 3, 4, 5, 6, 7, 8)
4384my_func(5, 6, 7, 6, another_func(6, 7, 8, 9, 1, 2), 5, 4)
4385local x = {
4386 1,
4387 2,
4388 3,
4389 4,
4390 a_func(4, 5, 5, 6),
4391 8,
4392 9,
4393 10
4394}
4395local y = {
4396 my_func(1, 2, 3, 4, 5),
4397 5,
4398 6,
4399 7
4400}
4401if func(1, 2, 3, "hello", "world") then
4402 print("hello")
4403 print("I am inside if")
4404end
4405if func(1, 2, 3, "hello", "world") then
4406 print("hello")
4407 print("I am inside if")
4408end
4409local f1
4410f1 = function(_arg_0)
4411 local a, b, c
4412 a, b, c = _arg_0.a, _arg_0.b, _arg_0.c
4413 return print(a, b, c)
4414end
4415f1({
4416 a = 1,
4417 b = "2",
4418 c = { }
4419})
4420local f2
4421f2 = function(_arg_0, c)
4422 local a1, b
4423 a1, b = _arg_0.a, _arg_0.b
4424 if a1 == nil then
4425 a1 = 123
4426 end
4427 if b == nil then
4428 b = 'abc'
4429 end
4430 if c == nil then
4431 c = { }
4432 end
4433end
4434print(a1, b, c)
4435local arg1 = {
4436 a = 0
4437}
4438f2(arg1, arg2)
4439local findFirstEven
4440findFirstEven = function(list)
4441 for _index_0 = 1, #list do
4442 local item = list[_index_0]
4443 if type(item) == "table" then
4444 for _index_1 = 1, #item do
4445 local sub = item[_index_1]
4446 if sub % 2 == 0 then
4447 return sub
4448 end
4449 end
4450 end
4451 end
4452 return nil
4453end
4454local findFirstEven
4455findFirstEven = function(list)
4456 for _index_0 = 1, #list do
4457 local item = list[_index_0]
4458 if type(item) == "table" then
4459 for _index_1 = 1, #item do
4460 local sub = item[_index_1]
4461 if sub % 2 == 0 then
4462 return sub
4463 end
4464 end
4465 end
4466 end
4467 return nil
4468end
4469local f
4470f = function(...)
4471 local t = {
4472 n = select("#", ...),
4473 ...
4474 }
4475 print("argument count:", t.n)
4476 print("table length:", #t)
4477 for i = 1, t.n do
4478 print(t[i])
4479 end
4480end
4481f(1, 2, 3)
4482f("a", "b", "c", "d")
4483f()
4484local process
4485process = function(...)
4486 local args = {
4487 n = select("#", ...),
4488 ...
4489 }
4490 local sum = 0
4491 for i = 1, args.n do
4492 if args[i] ~= nil and type(args[i]) == "number" then
4493 sum = sum + args[i]
4494 end
4495 end
4496 return sum
4497end
4498process(1, nil, 3, nil, 5)
4499local a = 1
4500local b = 2
4501print(a + b)
4502Rx.Observable.fromRange(1, 8):filter(function(x)
4503 return x % 2 == 0
4504end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
4505 return value .. '!'
4506end):subscribe(print)
4507local a = 1
4508local b = 2
4509print(a + b)
4510Rx.Observable.fromRange(1, 8):filter(function(x)
4511 return x % 2 == 0
4512end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
4513 return value .. '!'
4514end):subscribe(print)
4515local str = strA .. strB .. strC
4516func(3000, "192.168.1.1")
4517local str = strA .. strB .. strC
4518func(3000, "192.168.1.1")
4519local a <const> = 123
4520local _ <close> = setmetatable({ }, {
4521 __close = function()
4522 return print("Out of scope.")
4523 end
4524})
4525local a, b, c, d
4526local _obj_0 = tb
4527a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
4528Constant = 123
4529local a <const> = 123
4530local _ <close> = setmetatable({ }, {
4531 __close = function()
4532 return print("Out of scope.")
4533 end
4534})
4535local a, b, c, d
4536local _obj_0 = tb
4537a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
4538Constant = 123
4539if tb ~= nil then
4540 tb:func()
4541end
4542if tb ~= nil then
4543 tb:func()
4544end
4545print(1 < 2 and 2 <= 2 and 2 < 3 and 3 == 3 and 3 > 2 and 2 >= 1 and 1 == 1 and 1 < 3 and 3 ~= 5)
4546local a = 5
4547print(1 <= a and a <= 10)
4548local v
4549v = function(x)
4550 print(x)
4551 return x
4552end
4553print((function()
4554 local _cond_0 = v(2)
4555 if not (v(1) < _cond_0) then
4556 return false
4557 else
4558 return _cond_0 <= v(3)
4559 end
4560end)())
4561print((function()
4562 local _cond_0 = v(2)
4563 if not (v(1) > _cond_0) then
4564 return false
4565 else
4566 return _cond_0 <= v(3)
4567 end
4568end)())
4569local tab = { }
4570tab[#tab + 1] = "Value"
4571local tbA = {
4572 1,
4573 2,
4574 3
4575}
4576local tbB = {
4577 4,
4578 5,
4579 6
4580}
4581local _len_0 = #tbA + 1
4582for _index_0 = 1, #tbB do
4583 local _elm_0 = tbB[_index_0]
4584 tbA[_len_0], _len_0 = _elm_0, _len_0 + 1
4585end
4586local parts = {
4587 "shoulders",
4588 "knees"
4589}
4590local lyrics
4591do
4592 local _tab_0 = {
4593 "head"
4594 }
4595 local _idx_0 = 1
4596 for _key_0, _value_0 in pairs(parts) do
4597 if _idx_0 == _key_0 then
4598 _tab_0[#_tab_0 + 1] = _value_0
4599 _idx_0 = _idx_0 + 1
4600 else
4601 _tab_0[_key_0] = _value_0
4602 end
4603 end
4604 _tab_0[#_tab_0 + 1] = "and"
4605 _tab_0[#_tab_0 + 1] = "toes"
4606 lyrics = _tab_0
4607end
4608local copy
4609do
4610 local _tab_0 = { }
4611 local _idx_0 = 1
4612 for _key_0, _value_0 in pairs(other) do
4613 if _idx_0 == _key_0 then
4614 _tab_0[#_tab_0 + 1] = _value_0
4615 _idx_0 = _idx_0 + 1
4616 else
4617 _tab_0[_key_0] = _value_0
4618 end
4619 end
4620 copy = _tab_0
4621end
4622local a = {
4623 1,
4624 2,
4625 3,
4626 x = 1
4627}
4628local b = {
4629 4,
4630 5,
4631 y = 1
4632}
4633local merge
4634local _tab_0 = { }
4635local _idx_0 = 1
4636for _key_0, _value_0 in pairs(a) do
4637 if _idx_0 == _key_0 then
4638 _tab_0[#_tab_0 + 1] = _value_0
4639 _idx_0 = _idx_0 + 1
4640 else
4641 _tab_0[_key_0] = _value_0
4642 end
4643end
4644local _idx_1 = 1
4645for _key_0, _value_0 in pairs(b) do
4646 if _idx_1 == _key_0 then
4647 _tab_0[#_tab_0 + 1] = _value_0
4648 _idx_1 = _idx_1 + 1
4649 else
4650 _tab_0[_key_0] = _value_0
4651 end
4652end
4653merge = _tab_0
4654local last
4655do
4656 local _item_0 = data.items
4657 last = _item_0[#_item_0]
4658end
4659local second_last
4660do
4661 local _item_0 = data.items
4662 second_last = _item_0[#_item_0 - 1]
4663end
4664local _obj_0 = data.items
4665_obj_0[#_obj_0] = 1
4666local mt = { }
4667local add
4668add = function(self, right)
4669 return setmetatable({
4670 value = self.value + right.value
4671 }, mt)
4672end
4673mt.__add = add
4674local a = setmetatable({
4675 value = 1
4676}, mt)
4677local b = setmetatable({
4678 value = 2
4679}, {
4680 __add = add
4681})
4682local c = setmetatable({
4683 value = 3
4684}, {
4685 __add = mt.__add
4686})
4687local d = a + b + c
4688print(d.value)
4689local _ <close> = setmetatable({ }, {
4690 __close = function()
4691 return print("out of scope")
4692 end
4693})
4694local tb = setmetatable({ }, {
4695 ["value"] = 123
4696})
4697getmetatable(tb).__index = getmetatable(tb)
4698print(tb.value)
4699setmetatable(tb, {
4700 __index = {
4701 item = "hello"
4702 }
4703})
4704print(tb.item)
4705local item, new, close, getter
4706do
4707 local _obj_0 = tb
4708 item, new = _obj_0[1], _obj_0.new
4709 do
4710 local _obj_1 = getmetatable(_obj_0)
4711 close, getter = _obj_1.__close, _obj_1.__index
4712 end
4713end
4714print(item, new, close, getter)
4715do
4716 local _obj_0 = func
4717 if _obj_0 ~= nil then
4718 _obj_0()
4719 end
4720end
4721print((function()
4722 local _obj_0 = abc
4723 if _obj_0 ~= nil then
4724 local _obj_1 = _obj_0["hello world"]
4725 if _obj_1 ~= nil then
4726 return _obj_1.xyz
4727 end
4728 return nil
4729 end
4730 return nil
4731end)())
4732local x
4733do
4734 local _obj_0 = tab
4735 if _obj_0 ~= nil then
4736 x = _obj_0.value
4737 end
4738end
4739local len = (function()
4740 local _obj_0 = utf8
4741 if _obj_0 ~= nil then
4742 return _obj_0.len
4743 end
4744 return nil
4745end)() or (function()
4746 local _obj_0 = string
4747 if _obj_0 ~= nil then
4748 return _obj_0.len
4749 end
4750 return nil
4751end)() or function(o)
4752 return #o
4753end
4754if print and (x ~= nil) then
4755 print(x)
4756end
4757local _with_0 = io.open("test.txt", "w")
4758if _with_0 ~= nil then
4759 _with_0:write("hello")
4760 _with_0:close()
4761end
4762print("hello")
4763print(1, 2)
4764print(1, 2, 3)
4765print(render(emit(parse(extract(readFile("example.txt"), language, { }), language))))
4766local a, b, c, d
4767if b ~= nil then
4768 a = b
4769else
4770 if c ~= nil then
4771 a = c
4772 else
4773 a = d
4774 end
4775end
4776func((function()
4777 if a ~= nil then
4778 return a
4779 else
4780 return { }
4781 end
4782end)())
4783if a == nil then
4784 a = false
4785end
4786local list = {
4787 1,
4788 2,
4789 3
4790}
4791func({
4792 1,
4793 2,
4794 3
4795})
4796local f
4797f = function()
4798 return {
4799 1,
4800 2,
4801 3
4802 }
4803end
4804local tb = {
4805 name = "abc",
4806 values = {
4807 "a",
4808 "b",
4809 "c"
4810 },
4811 objects = {
4812 {
4813 name = "a",
4814 value = 1,
4815 func = function(self)
4816 return self.value + 1
4817 end,
4818 tb = {
4819 fieldA = 1
4820 }
4821 },
4822 {
4823 name = "b",
4824 value = 2,
4825 func = function(self)
4826 return self.value + 2
4827 end,
4828 tb = { }
4829 }
4830 }
4831}
4832if tb ~= nil then
4833 tb:func()
4834end
4835if tb ~= nil then
4836 tb:func()
4837end
4838print(1 < 2 and 2 <= 2 and 2 < 3 and 3 == 3 and 3 > 2 and 2 >= 1 and 1 == 1 and 1 < 3 and 3 ~= 5)
4839local a = 5
4840print(1 <= a and a <= 10)
4841local v
4842v = function(x)
4843 print(x)
4844 return x
4845end
4846print((function()
4847 local _cond_0 = v(2)
4848 if not (v(1) < _cond_0) then
4849 return false
4850 else
4851 return _cond_0 <= v(3)
4852 end
4853end)())
4854print((function()
4855 local _cond_0 = v(2)
4856 if not (v(1) > _cond_0) then
4857 return false
4858 else
4859 return _cond_0 <= v(3)
4860 end
4861end)())
4862local tab = { }
4863tab[#tab + 1] = "Value"
4864local tbA = {
4865 1,
4866 2,
4867 3
4868}
4869local tbB = {
4870 4,
4871 5,
4872 6
4873}
4874local _len_0 = #tbA + 1
4875for _index_0 = 1, #tbB do
4876 local _elm_0 = tbB[_index_0]
4877 tbA[_len_0], _len_0 = _elm_0, _len_0 + 1
4878end
4879local parts = {
4880 "shoulders",
4881 "knees"
4882}
4883local lyrics
4884do
4885 local _tab_0 = {
4886 "head"
4887 }
4888 local _idx_0 = 1
4889 for _key_0, _value_0 in pairs(parts) do
4890 if _idx_0 == _key_0 then
4891 _tab_0[#_tab_0 + 1] = _value_0
4892 _idx_0 = _idx_0 + 1
4893 else
4894 _tab_0[_key_0] = _value_0
4895 end
4896 end
4897 _tab_0[#_tab_0 + 1] = "and"
4898 _tab_0[#_tab_0 + 1] = "toes"
4899 lyrics = _tab_0
4900end
4901local copy
4902do
4903 local _tab_0 = { }
4904 local _idx_0 = 1
4905 for _key_0, _value_0 in pairs(other) do
4906 if _idx_0 == _key_0 then
4907 _tab_0[#_tab_0 + 1] = _value_0
4908 _idx_0 = _idx_0 + 1
4909 else
4910 _tab_0[_key_0] = _value_0
4911 end
4912 end
4913 copy = _tab_0
4914end
4915local a = {
4916 1,
4917 2,
4918 3,
4919 x = 1
4920}
4921local b = {
4922 4,
4923 5,
4924 y = 1
4925}
4926local merge
4927local _tab_0 = { }
4928local _idx_0 = 1
4929for _key_0, _value_0 in pairs(a) do
4930 if _idx_0 == _key_0 then
4931 _tab_0[#_tab_0 + 1] = _value_0
4932 _idx_0 = _idx_0 + 1
4933 else
4934 _tab_0[_key_0] = _value_0
4935 end
4936end
4937local _idx_1 = 1
4938for _key_0, _value_0 in pairs(b) do
4939 if _idx_1 == _key_0 then
4940 _tab_0[#_tab_0 + 1] = _value_0
4941 _idx_1 = _idx_1 + 1
4942 else
4943 _tab_0[_key_0] = _value_0
4944 end
4945end
4946merge = _tab_0
4947local last
4948do
4949 local _item_0 = data.items
4950 last = _item_0[#_item_0]
4951end
4952local second_last
4953do
4954 local _item_0 = data.items
4955 second_last = _item_0[#_item_0 - 1]
4956end
4957local _obj_0 = data.items
4958_obj_0[#_obj_0] = 1
4959local mt = { }
4960local add
4961add = function(self, right)
4962 return setmetatable({
4963 value = self.value + right.value
4964 }, mt)
4965end
4966mt.__add = add
4967local a = setmetatable({
4968 value = 1
4969}, mt)
4970local b = setmetatable({
4971 value = 2
4972}, {
4973 __add = add
4974})
4975local c = setmetatable({
4976 value = 3
4977}, {
4978 __add = mt.__add
4979})
4980local d = a + b + c
4981print(d.value)
4982local _ <close> = setmetatable({ }, {
4983 __close = function()
4984 return print("out of scope")
4985 end
4986})
4987local tb = setmetatable({ }, {
4988 ["value"] = 123
4989})
4990getmetatable(tb).__index = getmetatable(tb)
4991print(tb.value)
4992setmetatable(tb, {
4993 __index = {
4994 item = "hello"
4995 }
4996})
4997print(tb.item)
4998local item, new, close, getter
4999do
5000 local _obj_0 = tb
5001 item, new = _obj_0[1], _obj_0.new
5002 do
5003 local _obj_1 = getmetatable(_obj_0)
5004 close, getter = _obj_1.__close, _obj_1.__index
5005 end
5006end
5007print(item, new, close, getter)
5008do
5009 local _obj_0 = func
5010 if _obj_0 ~= nil then
5011 _obj_0()
5012 end
5013end
5014print((function()
5015 local _obj_0 = abc
5016 if _obj_0 ~= nil then
5017 local _obj_1 = _obj_0["hello world"]
5018 if _obj_1 ~= nil then
5019 return _obj_1.xyz
5020 end
5021 return nil
5022 end
5023 return nil
5024end)())
5025local x
5026do
5027 local _obj_0 = tab
5028 if _obj_0 ~= nil then
5029 x = _obj_0.value
5030 end
5031end
5032local len = (function()
5033 local _obj_0 = utf8
5034 if _obj_0 ~= nil then
5035 return _obj_0.len
5036 end
5037 return nil
5038end)() or (function()
5039 local _obj_0 = string
5040 if _obj_0 ~= nil then
5041 return _obj_0.len
5042 end
5043 return nil
5044end)() or function(o)
5045 return #o
5046end
5047if print and (x ~= nil) then
5048 print(x)
5049end
5050local _with_0 = io.open("test.txt", "w")
5051if _with_0 ~= nil then
5052 _with_0:write("hello")
5053 _with_0:close()
5054end
5055print("hello")
5056print(1, 2)
5057print(1, 2, 3)
5058print(render(emit(parse(extract(readFile("example.txt"), language, { }), language))))
5059local a, b, c, d
5060if b ~= nil then
5061 a = b
5062else
5063 if c ~= nil then
5064 a = c
5065 else
5066 a = d
5067 end
5068end
5069func((function()
5070 if a ~= nil then
5071 return a
5072 else
5073 return { }
5074 end
5075end)())
5076if a == nil then
5077 a = false
5078end
5079local list = {
5080 1,
5081 2,
5082 3
5083}
5084func({
5085 1,
5086 2,
5087 3
5088})
5089local f
5090f = function()
5091 return {
5092 1,
5093 2,
5094 3
5095 }
5096end
5097local tb = {
5098 name = "abc",
5099 values = {
5100 "a",
5101 "b",
5102 "c"
5103 },
5104 objects = {
5105 {
5106 name = "a",
5107 value = 1,
5108 func = function(self)
5109 return self.value + 1
5110 end,
5111 tb = {
5112 fieldA = 1
5113 }
5114 },
5115 {
5116 name = "b",
5117 value = 2,
5118 func = function(self)
5119 return self.value + 2
5120 end,
5121 tb = { }
5122 }
5123 }
5124}
5125local some_string = "Here is a string\n that has a line break in it."
5126print("I am " .. tostring(math.random() * 100) .. "% sure.")
5127local integer = 1000000
5128local hex = 0xEFBBBF
5129local binary = 19
5130local str = "key: value\nlist:\n - item1\n - " .. tostring(expr)
5131local fn
5132fn = function()
5133 local str = "foo:\n bar: baz"
5134 return str
5135end
5136local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'"
5137local some_string = "Here is a string\n that has a line break in it."
5138print("I am " .. tostring(math.random() * 100) .. "% sure.")
5139local integer = 1000000
5140local hex = 0xEFBBBF
5141local binary = 19
5142local str = "key: value\nlist:\n - item1\n - " .. tostring(expr)
5143local fn
5144fn = function()
5145 local str = "foo:\n bar: baz"
5146 return str
5147end
5148local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'"
diff --git a/spec/outputs/codes_from_doc_en.lua b/spec/outputs/codes_from_doc_en.lua
new file mode 100644
index 0000000..0b3670c
--- /dev/null
+++ b/spec/outputs/codes_from_doc_en.lua
@@ -0,0 +1,5148 @@
1do
2 local var = "hello"
3 print(var)
4end
5print(var)
6local counter
7do
8 local i = 0
9 counter = function()
10 i = i + 1
11 return i
12 end
13end
14print(counter())
15print(counter())
16local tbl = {
17 key = (function()
18 print("assigning key!")
19 return 1234
20 end)()
21}
22do
23 local var = "hello"
24 print(var)
25end
26print(var)
27local counter
28do
29 local i = 0
30 counter = function()
31 i = i + 1
32 return i
33 end
34end
35print(counter())
36print(counter())
37local tbl = {
38 key = (function()
39 print("assigning key!")
40 return 1234
41 end)()
42}
43if name == "Rob" then
44 print("hello world")
45end
46local _list_0 = items
47for _index_0 = 1, #_list_0 do
48 local item = _list_0[_index_0]
49 print("item: ", item)
50end
51while game:isRunning() do
52 game:update()
53end
54while not reader:eof() do
55 reader:parse_line()
56end
57if name == "Rob" then
58 print("hello world")
59end
60local _list_0 = items
61for _index_0 = 1, #_list_0 do
62 local item = _list_0[_index_0]
63 print("item: ", item)
64end
65while game:isRunning() do
66 game:update()
67end
68while not reader:eof() do
69 reader:parse_line()
70end
71local area = 6.2831853071796 * 5
72print('hello world')
73do
74 assert(item ~= nil)
75end
76local value = item
77if (f1() and f2() and f3()) then
78 print("OK")
79end
80do
81 local funcA
82 funcA = function() end
83end
84local funcA
85funcA = function()
86 return "fail to assign to the Yue macro defined variable"
87end
88do
89local function funcB() end
90end
91local funcB
92funcB = function()
93 return "fail to assign to the Lua macro defined variable"
94end
95do
96-- raw Lua codes insertion
97if cond then
98 print("output")
99end
100end
101print("yuescript")
102print(2)
103print("Valid enum type:", "Static")
104do
105 print(123, "hello")
106end
107do
108 print(123, "hello")
109end
110local area = 6.2831853071796 * 5
111print('hello world')
112do
113 assert(item ~= nil)
114end
115local value = item
116if (f1() and f2() and f3()) then
117 print("OK")
118end
119do
120 local funcA
121 funcA = function() end
122end
123local funcA
124funcA = function()
125 return "fail to assign to the Yue macro defined variable"
126end
127do
128local function funcB() end
129end
130local funcB
131funcB = function()
132 return "fail to assign to the Lua macro defined variable"
133end
134do
135-- raw Lua codes insertion
136if cond then
137 print("output")
138end
139end
140print("yuescript")
141print(2)
142print("Valid enum type:", "Static")
143do
144 print(123, "hello")
145end
146do
147 print(123, "hello")
148end
149do
150 local insert, concat = table.insert, table.concat
151 local C, Ct, Cmt
152 do
153 local _obj_0 = require("lpeg")
154 C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt
155 end
156 local x, y, z
157 do
158 local _obj_0 = require('mymodule')
159 x, y, z = _obj_0.x, _obj_0.y, _obj_0.z
160 end
161 local a, b, c
162 local _obj_0 = require('module')
163 a, b, c = _obj_0.a, _obj_0.b, _obj_0.c
164end
165do
166 local module = require('module')
167 local module_x = require('module_x')
168 local d_a_s_h_e_s = require("d-a-s-h-e-s")
169 local part = require("module.part")
170end
171do
172 local PlayerModule = require("player")
173 local C, Ct, Cmt
174 do
175 local _obj_0 = require("lpeg")
176 C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt
177 end
178 local one, two, ch
179 local _obj_0 = require("export")
180 one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1]
181end
182do
183 local tostring <const> = tostring
184 local concat <const> = table.concat
185 print(concat({
186 "a",
187 tostring(1)
188 }))
189end
190do
191 local print <const> = print
192 local math <const> = math
193 print("hello")
194 math.random(3)
195end
196do
197 local print <const> = print
198 print(FLAG)
199 FLAG = 123
200end
201local _module_0 = { }
202local a, b, c = 1, 2, 3
203_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c
204local cool = "cat"
205_module_0["cool"] = cool
206local What
207if this then
208 What = "abc"
209else
210 What = "def"
211end
212_module_0["What"] = What
213local y
214y = function()
215 local hallo = 3434
216end
217_module_0["y"] = y
218local Something
219local _class_0
220local _base_0 = {
221 umm = "cool"
222}
223if _base_0.__index == nil then
224 _base_0.__index = _base_0
225end
226_class_0 = setmetatable({
227 __init = function() end,
228 __base = _base_0,
229 __name = "Something"
230}, {
231 __index = _base_0,
232 __call = function(cls, ...)
233 local _self_0 = setmetatable({ }, _base_0)
234 cls.__init(_self_0, ...)
235 return _self_0
236 end
237})
238_base_0.__class = _class_0
239Something = _class_0
240_module_0["Something"] = Something
241return _module_0
242local _module_0 = { }
243local loadstring, tolua
244do
245 local _obj_0 = yue
246 loadstring, tolua = _obj_0.loadstring, _obj_0.to_lua
247end
248_module_0["loadstring"], _module_0["tolua"] = loadstring, tolua
249local fieldA = tb.itemA.fieldA
250if fieldA == nil then
251 fieldA = 'default'
252end
253_module_0["fieldA"] = fieldA
254return _module_0
255local _module_0 = setmetatable({ }, { })
256_module_0.itemA = tb
257getmetatable(_module_0).__index = items
258_module_0["a-b-c"] = 123
259return _module_0
260local _module_0 = { }
261local d, e, f = 3, 2, 1
262_module_0[#_module_0 + 1] = d
263_module_0[#_module_0 + 1] = e
264_module_0[#_module_0 + 1] = f
265if this then
266 _module_0[#_module_0 + 1] = 123
267else
268 _module_0[#_module_0 + 1] = 456
269end
270local _with_0 = tmp
271local j = 2000
272_module_0[#_module_0 + 1] = _with_0
273return _module_0
274local _module_0 = nil
275_module_0 = function()
276 print("hello")
277 return 123
278end
279return _module_0
280do
281 local insert, concat = table.insert, table.concat
282 local C, Ct, Cmt
283 do
284 local _obj_0 = require("lpeg")
285 C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt
286 end
287 local x, y, z
288 do
289 local _obj_0 = require('mymodule')
290 x, y, z = _obj_0.x, _obj_0.y, _obj_0.z
291 end
292 local a, b, c
293 local _obj_0 = require('module')
294 a, b, c = _obj_0.a, _obj_0.b, _obj_0.c
295end
296do
297 local module = require('module')
298 local module_x = require('module_x')
299 local d_a_s_h_e_s = require("d-a-s-h-e-s")
300 local part = require("module.part")
301end
302do
303 local PlayerModule = require("player")
304 local C, Ct, Cmt
305 do
306 local _obj_0 = require("lpeg")
307 C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt
308 end
309 local one, two, ch
310 local _obj_0 = require("export")
311 one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1]
312end
313do
314 local tostring <const> = tostring
315 local concat <const> = table.concat
316 print(concat({
317 "a",
318 tostring(1)
319 }))
320end
321do
322 local print <const> = print
323 local math <const> = math
324 print("hello")
325 math.random(3)
326end
327do
328 local print <const> = print
329 print(FLAG)
330 FLAG = 123
331end
332local _module_0 = { }
333local a, b, c = 1, 2, 3
334_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c
335local cool = "cat"
336_module_0["cool"] = cool
337local What
338if this then
339 What = "abc"
340else
341 What = "def"
342end
343_module_0["What"] = What
344local y
345y = function()
346 local hallo = 3434
347end
348_module_0["y"] = y
349local Something
350local _class_0
351local _base_0 = {
352 umm = "cool"
353}
354if _base_0.__index == nil then
355 _base_0.__index = _base_0
356end
357_class_0 = setmetatable({
358 __init = function() end,
359 __base = _base_0,
360 __name = "Something"
361}, {
362 __index = _base_0,
363 __call = function(cls, ...)
364 local _self_0 = setmetatable({ }, _base_0)
365 cls.__init(_self_0, ...)
366 return _self_0
367 end
368})
369_base_0.__class = _class_0
370Something = _class_0
371_module_0["Something"] = Something
372return _module_0
373local _module_0 = { }
374local loadstring, tolua
375do
376 local _obj_0 = yue
377 loadstring, tolua = _obj_0.loadstring, _obj_0.to_lua
378end
379_module_0["loadstring"], _module_0["tolua"] = loadstring, tolua
380local fieldA = tb.itemA.fieldA
381if fieldA == nil then
382 fieldA = 'default'
383end
384_module_0["fieldA"] = fieldA
385return _module_0
386local _module_0 = setmetatable({ }, { })
387_module_0.itemA = tb
388getmetatable(_module_0).__index = items
389_module_0["a-b-c"] = 123
390return _module_0
391local _module_0 = { }
392local d, e, f = 3, 2, 1
393_module_0[#_module_0 + 1] = d
394_module_0[#_module_0 + 1] = e
395_module_0[#_module_0 + 1] = f
396if this then
397 _module_0[#_module_0 + 1] = 123
398else
399 _module_0[#_module_0 + 1] = 456
400end
401local _with_0 = tmp
402local j = 2000
403_module_0[#_module_0 + 1] = _with_0
404return _module_0
405local _module_0 = nil
406_module_0 = function()
407 print("hello")
408 return 123
409end
410return _module_0
411xpcall(function()
412 return func(1, 2, 3)
413end, function(err)
414 return print(yue.traceback(err))
415end)
416local success, result = xpcall(function()
417 return func(1, 2, 3)
418end, function(err)
419 return yue.traceback(err)
420end)
421xpcall(function()
422 return func(1, 2, 3)
423end, function(err)
424 return print(yue.traceback(err))
425end)
426success, result = pcall(function()
427 return func(1, 2, 3)
428end)
429pcall(function()
430 print("trying")
431 return func(1, 2, 3)
432end)
433success, result = xpcall(function()
434 return func(1, 2, 3)
435end, function(err)
436 return print(yue.traceback(err))
437end)
438if success then
439 print(result)
440end
441local a, b, c
442do
443 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function()
444 return func()
445 end)
446 if _ok_0 then
447 a, b, c = _ret_0, _ret_1, _ret_2
448 end
449end
450do
451 local _exp_0 = ((function()
452 return (function(_arg_0, ...)
453 local _ok_0 = _arg_0
454 if _ok_0 then
455 return ...
456 end
457 end)(pcall(function()
458 return func()
459 end))
460 end)())
461 if _exp_0 ~= nil then
462 a = _exp_0
463 else
464 a = "default"
465 end
466end
467f((function()
468 return (function(_arg_0, ...)
469 local _ok_0 = _arg_0
470 if _ok_0 then
471 return ...
472 end
473 end)(pcall(function()
474 return func()
475 end))
476end)())
477f((function()
478 return (function(_arg_0, ...)
479 local _ok_0 = _arg_0
480 if _ok_0 then
481 return ...
482 end
483 end)(xpcall(function()
484 print(123)
485 return func()
486 end, function(e)
487 print(e)
488 return e
489 end))
490end)())
491xpcall(function()
492 return func(1, 2, 3)
493end, function(err)
494 return print(yue.traceback(err))
495end)
496local success, result = xpcall(function()
497 return func(1, 2, 3)
498end, function(err)
499 return yue.traceback(err)
500end)
501xpcall(function()
502 return func(1, 2, 3)
503end, function(err)
504 return print(yue.traceback(err))
505end)
506success, result = pcall(function()
507 return func(1, 2, 3)
508end)
509pcall(function()
510 print("trying")
511 return func(1, 2, 3)
512end)
513success, result = xpcall(function()
514 return func(1, 2, 3)
515end, function(err)
516 return print(yue.traceback(err))
517end)
518if success then
519 print(result)
520end
521local a, b, c
522do
523 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function()
524 return func()
525 end)
526 if _ok_0 then
527 a, b, c = _ret_0, _ret_1, _ret_2
528 end
529end
530do
531 local _exp_0 = ((function()
532 return (function(_arg_0, ...)
533 local _ok_0 = _arg_0
534 if _ok_0 then
535 return ...
536 end
537 end)(pcall(function()
538 return func()
539 end))
540 end)())
541 if _exp_0 ~= nil then
542 a = _exp_0
543 else
544 a = "default"
545 end
546end
547f((function()
548 return (function(_arg_0, ...)
549 local _ok_0 = _arg_0
550 if _ok_0 then
551 return ...
552 end
553 end)(pcall(function()
554 return func()
555 end))
556end)())
557f((function()
558 return (function(_arg_0, ...)
559 local _ok_0 = _arg_0
560 if _ok_0 then
561 return ...
562 end
563 end)(xpcall(function()
564 print(123)
565 return func()
566 end, function(e)
567 print(e)
568 return e
569 end))
570end)())
571local some_values = {
572 1,
573 2,
574 3,
575 4
576}
577local some_values = {
578 name = "Bill",
579 age = 200,
580 ["favorite food"] = "rice"
581}
582local profile = {
583 height = "4 feet",
584 shoe_size = 13,
585 favorite_foods = {
586 "ice cream",
587 "donuts"
588 }
589}
590local values = {
591 1,
592 2,
593 3,
594 4,
595 5,
596 6,
597 7,
598 8,
599 name = "superman",
600 occupation = "crime fighting"
601}
602my_function({
603 dance = "Tango",
604 partner = "none"
605})
606local y = {
607 type = "dog",
608 legs = 4,
609 tails = 1
610}
611local tbl = {
612 ["do"] = "something",
613 ["end"] = "hunger"
614}
615local hair = "golden"
616local height = 200
617local person = {
618 hair = hair,
619 height = height,
620 shoe_size = 40
621}
622print_table({
623 hair = hair,
624 height = height
625})
626local t = {
627 [1 + 2] = "hello",
628 ["hello world"] = true
629}
630local some_values = {
631 1,
632 2,
633 3,
634 4
635}
636local list_with_one_element = {
637 1
638}
639local some_values = {
640 1,
641 2,
642 3,
643 4
644}
645local some_values = {
646 name = "Bill",
647 age = 200,
648 ["favorite food"] = "rice"
649}
650local profile = {
651 height = "4 feet",
652 shoe_size = 13,
653 favorite_foods = {
654 "ice cream",
655 "donuts"
656 }
657}
658local values = {
659 1,
660 2,
661 3,
662 4,
663 5,
664 6,
665 7,
666 8,
667 name = "superman",
668 occupation = "crime fighting"
669}
670my_function({
671 dance = "Tango",
672 partner = "none"
673})
674local y = {
675 type = "dog",
676 legs = 4,
677 tails = 1
678}
679local tbl = {
680 ["do"] = "something",
681 ["end"] = "hunger"
682}
683local hair = "golden"
684local height = 200
685local person = {
686 hair = hair,
687 height = height,
688 shoe_size = 40
689}
690print_table({
691 hair = hair,
692 height = height
693})
694local t = {
695 [1 + 2] = "hello",
696 ["hello world"] = true
697}
698local some_values = {
699 1,
700 2,
701 3,
702 4
703}
704local list_with_one_element = {
705 1
706}
707local items = {
708 1,
709 2,
710 3,
711 4
712}
713local doubled
714local _accum_0 = { }
715local _len_0 = 1
716for i, item in ipairs(items) do
717 _accum_0[_len_0] = item * 2
718 _len_0 = _len_0 + 1
719end
720doubled = _accum_0
721local slice
722local _accum_0 = { }
723local _len_0 = 1
724for i, item in ipairs(items) do
725 if i > 1 and i < 3 then
726 _accum_0[_len_0] = item
727 _len_0 = _len_0 + 1
728 end
729end
730slice = _accum_0
731local doubled
732local _accum_0 = { }
733local _len_0 = 1
734local _list_0 = items
735for _index_0 = 1, #_list_0 do
736 local item = _list_0[_index_0]
737 _accum_0[_len_0] = item * 2
738 _len_0 = _len_0 + 1
739end
740doubled = _accum_0
741local data = {
742 a = {
743 1,
744 2,
745 3
746 },
747 b = {
748 4,
749 5,
750 6
751 }
752}
753local flat
754local _accum_0 = { }
755for k, v in pairs(data) do
756 local _len_0 = #_accum_0 + 1
757 for _index_0 = 1, #v do
758 local _elm_0 = v[_index_0]
759 _accum_0[_len_0], _len_0 = _elm_0, _len_0 + 1
760 end
761end
762flat = _accum_0
763local x_coords = {
764 4,
765 5,
766 6,
767 7
768}
769local y_coords = {
770 9,
771 2,
772 3
773}
774local points
775local _accum_0 = { }
776local _len_0 = 1
777for _index_0 = 1, #x_coords do
778 local x = x_coords[_index_0]
779 for _index_1 = 1, #y_coords do
780 local y = y_coords[_index_1]
781 _accum_0[_len_0] = {
782 x,
783 y
784 }
785 _len_0 = _len_0 + 1
786 end
787end
788points = _accum_0
789local evens
790local _accum_0 = { }
791local _len_0 = 1
792for i = 1, 100 do
793 if i % 2 == 0 then
794 _accum_0[_len_0] = i
795 _len_0 = _len_0 + 1
796 end
797end
798evens = _accum_0
799local thing = {
800 color = "red",
801 name = "fast",
802 width = 123
803}
804local thing_copy
805local _tbl_0 = { }
806for k, v in pairs(thing) do
807 _tbl_0[k] = v
808end
809thing_copy = _tbl_0
810local no_color
811local _tbl_0 = { }
812for k, v in pairs(thing) do
813 if k ~= "color" then
814 _tbl_0[k] = v
815 end
816end
817no_color = _tbl_0
818local numbers = {
819 1,
820 2,
821 3,
822 4
823}
824local sqrts
825local _tbl_0 = { }
826for _index_0 = 1, #numbers do
827 local i = numbers[_index_0]
828 _tbl_0[i] = math.sqrt(i)
829end
830sqrts = _tbl_0
831local tuples = {
832 {
833 "hello",
834 "world"
835 },
836 {
837 "foo",
838 "bar"
839 }
840}
841local tbl
842local _tbl_0 = { }
843for _index_0 = 1, #tuples do
844 local tuple = tuples[_index_0]
845 local _key_0, _val_0 = unpack(tuple)
846 _tbl_0[_key_0] = _val_0
847end
848tbl = _tbl_0
849local slice
850local _accum_0 = { }
851local _len_0 = 1
852local _list_0 = items
853for _index_0 = 1, 5 do
854 local item = _list_0[_index_0]
855 _accum_0[_len_0] = item
856 _len_0 = _len_0 + 1
857end
858slice = _accum_0
859local slice
860local _accum_0 = { }
861local _len_0 = 1
862local _list_0 = items
863local _max_0 = #_list_0
864for _index_0 = 2, _max_0 do
865 local item = _list_0[_index_0]
866 _accum_0[_len_0] = item
867 _len_0 = _len_0 + 1
868end
869slice = _accum_0
870local slice
871local _accum_0 = { }
872local _len_0 = 1
873local _list_0 = items
874local _max_0 = #_list_0
875for _index_0 = 1, _max_0, 2 do
876 local item = _list_0[_index_0]
877 _accum_0[_len_0] = item
878 _len_0 = _len_0 + 1
879end
880slice = _accum_0
881local slice
882local _accum_0 = { }
883local _len_0 = 1
884local _list_0 = items
885local _min_0 = #_list_0 + -4 + 1
886local _max_0 = #_list_0 + -1 + 1
887for _index_0 = _min_0, _max_0 do
888 local item = _list_0[_index_0]
889 _accum_0[_len_0] = item
890 _len_0 = _len_0 + 1
891end
892slice = _accum_0
893local reverse_slice
894local _accum_0 = { }
895local _len_0 = 1
896local _list_0 = items
897local _min_0 = #_list_0 + -1 + 1
898for _index_0 = _min_0, 1, -1 do
899 local item = _list_0[_index_0]
900 _accum_0[_len_0] = item
901 _len_0 = _len_0 + 1
902end
903reverse_slice = _accum_0
904local sub_list
905do
906 local _accum_0 = { }
907 local _len_0 = 1
908 local _list_0 = items
909 for _index_0 = 2, 4 do
910 local _item_0 = _list_0[_index_0]
911 _accum_0[_len_0] = _item_0
912 _len_0 = _len_0 + 1
913 end
914 sub_list = _accum_0
915end
916local last_four_items
917local _accum_0 = { }
918local _len_0 = 1
919local _list_0 = items
920local _min_0 = #_list_0 + -4 + 1
921local _max_0 = #_list_0 + -1 + 1
922for _index_0 = _min_0, _max_0 do
923 local _item_0 = _list_0[_index_0]
924 _accum_0[_len_0] = _item_0
925 _len_0 = _len_0 + 1
926end
927last_four_items = _accum_0
928local items = {
929 1,
930 2,
931 3,
932 4
933}
934local doubled
935local _accum_0 = { }
936local _len_0 = 1
937for i, item in ipairs(items) do
938 _accum_0[_len_0] = item * 2
939 _len_0 = _len_0 + 1
940end
941doubled = _accum_0
942local slice
943local _accum_0 = { }
944local _len_0 = 1
945for i, item in ipairs(items) do
946 if i > 1 and i < 3 then
947 _accum_0[_len_0] = item
948 _len_0 = _len_0 + 1
949 end
950end
951slice = _accum_0
952local doubled
953local _accum_0 = { }
954local _len_0 = 1
955local _list_0 = items
956for _index_0 = 1, #_list_0 do
957 local item = _list_0[_index_0]
958 _accum_0[_len_0] = item * 2
959 _len_0 = _len_0 + 1
960end
961doubled = _accum_0
962local data = {
963 a = {
964 1,
965 2,
966 3
967 },
968 b = {
969 4,
970 5,
971 6
972 }
973}
974local flat
975local _accum_0 = { }
976for k, v in pairs(data) do
977 local _len_0 = #_accum_0 + 1
978 for _index_0 = 1, #v do
979 local _elm_0 = v[_index_0]
980 _accum_0[_len_0], _len_0 = _elm_0, _len_0 + 1
981 end
982end
983flat = _accum_0
984local x_coords = {
985 4,
986 5,
987 6,
988 7
989}
990local y_coords = {
991 9,
992 2,
993 3
994}
995local points
996local _accum_0 = { }
997local _len_0 = 1
998for _index_0 = 1, #x_coords do
999 local x = x_coords[_index_0]
1000 for _index_1 = 1, #y_coords do
1001 local y = y_coords[_index_1]
1002 _accum_0[_len_0] = {
1003 x,
1004 y
1005 }
1006 _len_0 = _len_0 + 1
1007 end
1008end
1009points = _accum_0
1010local evens
1011local _accum_0 = { }
1012local _len_0 = 1
1013for i = 1, 100 do
1014 if i % 2 == 0 then
1015 _accum_0[_len_0] = i
1016 _len_0 = _len_0 + 1
1017 end
1018end
1019evens = _accum_0
1020local thing = {
1021 color = "red",
1022 name = "fast",
1023 width = 123
1024}
1025local thing_copy
1026local _tbl_0 = { }
1027for k, v in pairs(thing) do
1028 _tbl_0[k] = v
1029end
1030thing_copy = _tbl_0
1031local no_color
1032local _tbl_0 = { }
1033for k, v in pairs(thing) do
1034 if k ~= "color" then
1035 _tbl_0[k] = v
1036 end
1037end
1038no_color = _tbl_0
1039local numbers = {
1040 1,
1041 2,
1042 3,
1043 4
1044}
1045local sqrts
1046local _tbl_0 = { }
1047for _index_0 = 1, #numbers do
1048 local i = numbers[_index_0]
1049 _tbl_0[i] = math.sqrt(i)
1050end
1051sqrts = _tbl_0
1052local tuples = {
1053 {
1054 "hello",
1055 "world"
1056 },
1057 {
1058 "foo",
1059 "bar"
1060 }
1061}
1062local tbl
1063local _tbl_0 = { }
1064for _index_0 = 1, #tuples do
1065 local tuple = tuples[_index_0]
1066 local _key_0, _val_0 = unpack(tuple)
1067 _tbl_0[_key_0] = _val_0
1068end
1069tbl = _tbl_0
1070local slice
1071local _accum_0 = { }
1072local _len_0 = 1
1073local _list_0 = items
1074for _index_0 = 1, 5 do
1075 local item = _list_0[_index_0]
1076 _accum_0[_len_0] = item
1077 _len_0 = _len_0 + 1
1078end
1079slice = _accum_0
1080local slice
1081local _accum_0 = { }
1082local _len_0 = 1
1083local _list_0 = items
1084local _max_0 = #_list_0
1085for _index_0 = 2, _max_0 do
1086 local item = _list_0[_index_0]
1087 _accum_0[_len_0] = item
1088 _len_0 = _len_0 + 1
1089end
1090slice = _accum_0
1091local slice
1092local _accum_0 = { }
1093local _len_0 = 1
1094local _list_0 = items
1095local _max_0 = #_list_0
1096for _index_0 = 1, _max_0, 2 do
1097 local item = _list_0[_index_0]
1098 _accum_0[_len_0] = item
1099 _len_0 = _len_0 + 1
1100end
1101slice = _accum_0
1102local slice
1103local _accum_0 = { }
1104local _len_0 = 1
1105local _list_0 = items
1106local _min_0 = #_list_0 + -4 + 1
1107local _max_0 = #_list_0 + -1 + 1
1108for _index_0 = _min_0, _max_0 do
1109 local item = _list_0[_index_0]
1110 _accum_0[_len_0] = item
1111 _len_0 = _len_0 + 1
1112end
1113slice = _accum_0
1114local reverse_slice
1115local _accum_0 = { }
1116local _len_0 = 1
1117local _list_0 = items
1118local _min_0 = #_list_0 + -1 + 1
1119for _index_0 = _min_0, 1, -1 do
1120 local item = _list_0[_index_0]
1121 _accum_0[_len_0] = item
1122 _len_0 = _len_0 + 1
1123end
1124reverse_slice = _accum_0
1125local sub_list
1126do
1127 local _accum_0 = { }
1128 local _len_0 = 1
1129 local _list_0 = items
1130 for _index_0 = 2, 4 do
1131 local _item_0 = _list_0[_index_0]
1132 _accum_0[_len_0] = _item_0
1133 _len_0 = _len_0 + 1
1134 end
1135 sub_list = _accum_0
1136end
1137local last_four_items
1138local _accum_0 = { }
1139local _len_0 = 1
1140local _list_0 = items
1141local _min_0 = #_list_0 + -4 + 1
1142local _max_0 = #_list_0 + -1 + 1
1143for _index_0 = _min_0, _max_0 do
1144 local _item_0 = _list_0[_index_0]
1145 _accum_0[_len_0] = _item_0
1146 _len_0 = _len_0 + 1
1147end
1148last_four_items = _accum_0
1149local Inventory
1150local _class_0
1151local _base_0 = {
1152 add_item = function(self, name)
1153 if self.items[name] then
1154 local _obj_0 = self.items
1155 _obj_0[name] = _obj_0[name] + 1
1156 else
1157 self.items[name] = 1
1158 end
1159 end
1160}
1161if _base_0.__index == nil then
1162 _base_0.__index = _base_0
1163end
1164_class_0 = setmetatable({
1165 __init = function(self)
1166 self.items = { }
1167 end,
1168 __base = _base_0,
1169 __name = "Inventory"
1170}, {
1171 __index = _base_0,
1172 __call = function(cls, ...)
1173 local _self_0 = setmetatable({ }, _base_0)
1174 cls.__init(_self_0, ...)
1175 return _self_0
1176 end
1177})
1178_base_0.__class = _class_0
1179Inventory = _class_0
1180local inv = Inventory()
1181inv:add_item("t-shirt")
1182inv:add_item("pants")
1183local Person
1184do
1185 local _class_0
1186 local _base_0 = {
1187 clothes = { },
1188 give_item = function(self, name)
1189 return table.insert(self.clothes, name)
1190 end
1191 }
1192 if _base_0.__index == nil then
1193 _base_0.__index = _base_0
1194 end
1195 _class_0 = setmetatable({
1196 __init = function() end,
1197 __base = _base_0,
1198 __name = "Person"
1199 }, {
1200 __index = _base_0,
1201 __call = function(cls, ...)
1202 local _self_0 = setmetatable({ }, _base_0)
1203 cls.__init(_self_0, ...)
1204 return _self_0
1205 end
1206 })
1207 _base_0.__class = _class_0
1208 Person = _class_0
1209end
1210local a = Person()
1211local b = Person()
1212a:give_item("pants")
1213b:give_item("shirt")
1214local _list_0 = a.clothes
1215for _index_0 = 1, #_list_0 do
1216 local item = _list_0[_index_0]
1217 print(item)
1218end
1219local Person
1220local _class_0
1221local _base_0 = { }
1222if _base_0.__index == nil then
1223 _base_0.__index = _base_0
1224end
1225_class_0 = setmetatable({
1226 __init = function(self)
1227 self.clothes = { }
1228 end,
1229 __base = _base_0,
1230 __name = "Person"
1231}, {
1232 __index = _base_0,
1233 __call = function(cls, ...)
1234 local _self_0 = setmetatable({ }, _base_0)
1235 cls.__init(_self_0, ...)
1236 return _self_0
1237 end
1238})
1239_base_0.__class = _class_0
1240Person = _class_0
1241local BackPack
1242local _class_0
1243local _parent_0 = Inventory
1244local _base_0 = {
1245 size = 10,
1246 add_item = function(self, name)
1247 if #self.items > size then
1248 error("backpack is full")
1249 end
1250 return _class_0.__parent.__base.add_item(self, name)
1251 end
1252}
1253for _key_0, _val_0 in pairs(_parent_0.__base) do
1254 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
1255 _base_0[_key_0] = _val_0
1256 end
1257end
1258if _base_0.__index == nil then
1259 _base_0.__index = _base_0
1260end
1261setmetatable(_base_0, _parent_0.__base)
1262_class_0 = setmetatable({
1263 __init = function(self, ...)
1264 return _class_0.__parent.__init(self, ...)
1265 end,
1266 __base = _base_0,
1267 __name = "BackPack",
1268 __parent = _parent_0
1269}, {
1270 __index = function(cls, name)
1271 local val = rawget(_base_0, name)
1272 if val == nil then
1273 local parent = rawget(cls, "__parent")
1274 if parent then
1275 return parent[name]
1276 end
1277 else
1278 return val
1279 end
1280 end,
1281 __call = function(cls, ...)
1282 local _self_0 = setmetatable({ }, _base_0)
1283 cls.__init(_self_0, ...)
1284 return _self_0
1285 end
1286})
1287_base_0.__class = _class_0
1288if _parent_0.__inherited then
1289 _parent_0.__inherited(_parent_0, _class_0)
1290end
1291BackPack = _class_0
1292local Shelf
1293do
1294 local _class_0
1295 local _base_0 = { }
1296 if _base_0.__index == nil then
1297 _base_0.__index = _base_0
1298 end
1299 _class_0 = setmetatable({
1300 __init = function() end,
1301 __base = _base_0,
1302 __name = "Shelf"
1303 }, {
1304 __index = _base_0,
1305 __call = function(cls, ...)
1306 local _self_0 = setmetatable({ }, _base_0)
1307 cls.__init(_self_0, ...)
1308 return _self_0
1309 end
1310 })
1311 _base_0.__class = _class_0
1312 local self = _class_0;
1313 self.__inherited = function(self, child)
1314 return print(self.__name, "was inherited by", child.__name)
1315 end
1316 Shelf = _class_0
1317end
1318local Cupboard
1319local _class_0
1320local _parent_0 = Shelf
1321local _base_0 = { }
1322for _key_0, _val_0 in pairs(_parent_0.__base) do
1323 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
1324 _base_0[_key_0] = _val_0
1325 end
1326end
1327if _base_0.__index == nil then
1328 _base_0.__index = _base_0
1329end
1330setmetatable(_base_0, _parent_0.__base)
1331_class_0 = setmetatable({
1332 __init = function(self, ...)
1333 return _class_0.__parent.__init(self, ...)
1334 end,
1335 __base = _base_0,
1336 __name = "Cupboard",
1337 __parent = _parent_0
1338}, {
1339 __index = function(cls, name)
1340 local val = rawget(_base_0, name)
1341 if val == nil then
1342 local parent = rawget(cls, "__parent")
1343 if parent then
1344 return parent[name]
1345 end
1346 else
1347 return val
1348 end
1349 end,
1350 __call = function(cls, ...)
1351 local _self_0 = setmetatable({ }, _base_0)
1352 cls.__init(_self_0, ...)
1353 return _self_0
1354 end
1355})
1356_base_0.__class = _class_0
1357if _parent_0.__inherited then
1358 _parent_0.__inherited(_parent_0, _class_0)
1359end
1360Cupboard = _class_0
1361local MyClass
1362local _class_0
1363local _parent_0 = ParentClass
1364local _base_0 = {
1365 a_method = function(self)
1366 _class_0.__parent.__base.a_method(self, "hello", "world")
1367 _class_0.__parent.a_method(self, "hello", "world")
1368 _class_0.__parent.a_method(self, "hello", "world")
1369 return assert(_class_0.__parent == ParentClass)
1370 end
1371}
1372for _key_0, _val_0 in pairs(_parent_0.__base) do
1373 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
1374 _base_0[_key_0] = _val_0
1375 end
1376end
1377if _base_0.__index == nil then
1378 _base_0.__index = _base_0
1379end
1380setmetatable(_base_0, _parent_0.__base)
1381_class_0 = setmetatable({
1382 __init = function(self, ...)
1383 return _class_0.__parent.__init(self, ...)
1384 end,
1385 __base = _base_0,
1386 __name = "MyClass",
1387 __parent = _parent_0
1388}, {
1389 __index = function(cls, name)
1390 local val = rawget(_base_0, name)
1391 if val == nil then
1392 local parent = rawget(cls, "__parent")
1393 if parent then
1394 return parent[name]
1395 end
1396 else
1397 return val
1398 end
1399 end,
1400 __call = function(cls, ...)
1401 local _self_0 = setmetatable({ }, _base_0)
1402 cls.__init(_self_0, ...)
1403 return _self_0
1404 end
1405})
1406_base_0.__class = _class_0
1407if _parent_0.__inherited then
1408 _parent_0.__inherited(_parent_0, _class_0)
1409end
1410MyClass = _class_0
1411local b = BackPack()
1412assert(b.__class == BackPack)
1413print(BackPack.size)
1414print(BackPack.__name)
1415local Things
1416do
1417 local _class_0
1418 local _base_0 = { }
1419 if _base_0.__index == nil then
1420 _base_0.__index = _base_0
1421 end
1422 _class_0 = setmetatable({
1423 __init = function() end,
1424 __base = _base_0,
1425 __name = "Things"
1426 }, {
1427 __index = _base_0,
1428 __call = function(cls, ...)
1429 local _self_0 = setmetatable({ }, _base_0)
1430 cls.__init(_self_0, ...)
1431 return _self_0
1432 end
1433 })
1434 _base_0.__class = _class_0
1435 local self = _class_0;
1436 self.some_func = function(self)
1437 return print("Hello from", self.__name)
1438 end
1439 Things = _class_0
1440end
1441Things:some_func()
1442assert(Things().some_func == nil)
1443local Counter
1444do
1445 local _class_0
1446 local _base_0 = { }
1447 if _base_0.__index == nil then
1448 _base_0.__index = _base_0
1449 end
1450 _class_0 = setmetatable({
1451 __init = function(self)
1452 self.__class.count = self.__class.count + 1
1453 end,
1454 __base = _base_0,
1455 __name = "Counter"
1456 }, {
1457 __index = _base_0,
1458 __call = function(cls, ...)
1459 local _self_0 = setmetatable({ }, _base_0)
1460 cls.__init(_self_0, ...)
1461 return _self_0
1462 end
1463 })
1464 _base_0.__class = _class_0
1465 local self = _class_0;
1466 self.count = 0
1467 Counter = _class_0
1468end
1469Counter()
1470Counter()
1471print(Counter.count)
1472self.__class:hello(1, 2, 3, 4)
1473local Things
1474local _class_0
1475local _base_0 = { }
1476if _base_0.__index == nil then
1477 _base_0.__index = _base_0
1478end
1479_class_0 = setmetatable({
1480 __init = function() end,
1481 __base = _base_0,
1482 __name = "Things"
1483}, {
1484 __index = _base_0,
1485 __call = function(cls, ...)
1486 local _self_0 = setmetatable({ }, _base_0)
1487 cls.__init(_self_0, ...)
1488 return _self_0
1489 end
1490})
1491_base_0.__class = _class_0
1492local self = _class_0;
1493self.class_var = "hello world"
1494Things = _class_0
1495local MoreThings
1496local _class_0
1497local secret, log
1498local _base_0 = {
1499 some_method = function(self)
1500 return log("hello world: " .. secret)
1501 end
1502}
1503if _base_0.__index == nil then
1504 _base_0.__index = _base_0
1505end
1506_class_0 = setmetatable({
1507 __init = function() end,
1508 __base = _base_0,
1509 __name = "MoreThings"
1510}, {
1511 __index = _base_0,
1512 __call = function(cls, ...)
1513 local _self_0 = setmetatable({ }, _base_0)
1514 cls.__init(_self_0, ...)
1515 return _self_0
1516 end
1517})
1518_base_0.__class = _class_0
1519local self = _class_0;
1520secret = 123
1521log = function(msg)
1522 return print("LOG:", msg)
1523end
1524MoreThings = _class_0
1525assert(self == self)
1526assert(self.__class == self.__class)
1527local some_instance_method
1528some_instance_method = function(self, ...)
1529 return self.__class(...)
1530end
1531local Something
1532do
1533 local _class_0
1534 local _base_0 = { }
1535 if _base_0.__index == nil then
1536 _base_0.__index = _base_0
1537 end
1538 _class_0 = setmetatable({
1539 __init = function(self, foo, bar, biz, baz)
1540 self.foo = foo
1541 self.bar = bar
1542 self.__class.biz = biz
1543 self.__class.baz = baz
1544 end,
1545 __base = _base_0,
1546 __name = "Something"
1547 }, {
1548 __index = _base_0,
1549 __call = function(cls, ...)
1550 local _self_0 = setmetatable({ }, _base_0)
1551 cls.__init(_self_0, ...)
1552 return _self_0
1553 end
1554 })
1555 _base_0.__class = _class_0
1556 Something = _class_0
1557end
1558local _class_0
1559local _base_0 = { }
1560if _base_0.__index == nil then
1561 _base_0.__index = _base_0
1562end
1563_class_0 = setmetatable({
1564 __init = function(self, foo, bar, biz, baz)
1565 self.foo = foo
1566 self.bar = bar
1567 self.__class.biz = biz
1568 self.__class.baz = baz
1569 end,
1570 __base = _base_0,
1571 __name = "Something"
1572}, {
1573 __index = _base_0,
1574 __call = function(cls, ...)
1575 local _self_0 = setmetatable({ }, _base_0)
1576 cls.__init(_self_0, ...)
1577 return _self_0
1578 end
1579})
1580_base_0.__class = _class_0
1581Something = _class_0
1582local new
1583new = function(self, fieldA, fieldB)
1584 self.fieldA = fieldA
1585 self.fieldB = fieldB
1586 return self
1587end
1588local obj = new({ }, 123, "abc")
1589print(obj)
1590local x
1591local Bucket
1592local _class_0
1593local _base_0 = {
1594 drops = 0,
1595 add_drop = function(self)
1596 self.drops = self.drops + 1
1597 end
1598}
1599if _base_0.__index == nil then
1600 _base_0.__index = _base_0
1601end
1602_class_0 = setmetatable({
1603 __init = function() end,
1604 __base = _base_0,
1605 __name = "Bucket"
1606}, {
1607 __index = _base_0,
1608 __call = function(cls, ...)
1609 local _self_0 = setmetatable({ }, _base_0)
1610 cls.__init(_self_0, ...)
1611 return _self_0
1612 end
1613})
1614_base_0.__class = _class_0
1615Bucket = _class_0
1616x = _class_0
1617local BigBucket
1618do
1619 local _class_0
1620 local _parent_0 = Bucket
1621 local _base_0 = {
1622 add_drop = function(self)
1623 self.drops = self.drops + 10
1624 end
1625 }
1626 for _key_0, _val_0 in pairs(_parent_0.__base) do
1627 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
1628 _base_0[_key_0] = _val_0
1629 end
1630 end
1631 if _base_0.__index == nil then
1632 _base_0.__index = _base_0
1633 end
1634 setmetatable(_base_0, _parent_0.__base)
1635 _class_0 = setmetatable({
1636 __init = function(self, ...)
1637 return _class_0.__parent.__init(self, ...)
1638 end,
1639 __base = _base_0,
1640 __name = "BigBucket",
1641 __parent = _parent_0
1642 }, {
1643 __index = function(cls, name)
1644 local val = rawget(_base_0, name)
1645 if val == nil then
1646 local parent = rawget(cls, "__parent")
1647 if parent then
1648 return parent[name]
1649 end
1650 else
1651 return val
1652 end
1653 end,
1654 __call = function(cls, ...)
1655 local _self_0 = setmetatable({ }, _base_0)
1656 cls.__init(_self_0, ...)
1657 return _self_0
1658 end
1659 })
1660 _base_0.__class = _class_0
1661 if _parent_0.__inherited then
1662 _parent_0.__inherited(_parent_0, _class_0)
1663 end
1664 BigBucket = _class_0
1665end
1666assert(Bucket.__name == "BigBucket")
1667local x
1668local _class_0
1669local _base_0 = { }
1670if _base_0.__index == nil then
1671 _base_0.__index = _base_0
1672end
1673_class_0 = setmetatable({
1674 __init = function() end,
1675 __base = _base_0,
1676 __name = "x"
1677}, {
1678 __index = _base_0,
1679 __call = function(cls, ...)
1680 local _self_0 = setmetatable({ }, _base_0)
1681 cls.__init(_self_0, ...)
1682 return _self_0
1683 end
1684})
1685_base_0.__class = _class_0
1686x = _class_0
1687local MyIndex = {
1688 __index = {
1689 var = 1
1690 }
1691}
1692local X
1693do
1694 local _class_0
1695 local _base_0 = {
1696 func = function(self)
1697 return print(123)
1698 end
1699 }
1700 local _list_0 = {
1701 MyIndex
1702 }
1703 for _index_0 = 1, #_list_0 do
1704 local _item_0 = _list_0[_index_0]
1705 local _cls_0, _mixin_0 = (_item_0.__base ~= nil), _item_0.__base or _item_0
1706 for _key_0, _val_0 in pairs(_mixin_0) do
1707 if _base_0[_key_0] == nil and (not _cls_0 or not _key_0:match("^__")) then
1708 _base_0[_key_0] = _val_0
1709 end
1710 end
1711 end
1712 if _base_0.__index == nil then
1713 _base_0.__index = _base_0
1714 end
1715 _class_0 = setmetatable({
1716 __init = function() end,
1717 __base = _base_0,
1718 __name = "X"
1719 }, {
1720 __index = _base_0,
1721 __call = function(cls, ...)
1722 local _self_0 = setmetatable({ }, _base_0)
1723 cls.__init(_self_0, ...)
1724 return _self_0
1725 end
1726 })
1727 _base_0.__class = _class_0
1728 X = _class_0
1729end
1730local x = X()
1731print(x.var)
1732local Y
1733do
1734 local _class_0
1735 local _base_0 = { }
1736 local _list_0 = {
1737 X
1738 }
1739 for _index_0 = 1, #_list_0 do
1740 local _item_0 = _list_0[_index_0]
1741 local _cls_0, _mixin_0 = (_item_0.__base ~= nil), _item_0.__base or _item_0
1742 for _key_0, _val_0 in pairs(_mixin_0) do
1743 if _base_0[_key_0] == nil and (not _cls_0 or not _key_0:match("^__")) then
1744 _base_0[_key_0] = _val_0
1745 end
1746 end
1747 end
1748 if _base_0.__index == nil then
1749 _base_0.__index = _base_0
1750 end
1751 _class_0 = setmetatable({
1752 __init = function() end,
1753 __base = _base_0,
1754 __name = "Y"
1755 }, {
1756 __index = _base_0,
1757 __call = function(cls, ...)
1758 local _self_0 = setmetatable({ }, _base_0)
1759 cls.__init(_self_0, ...)
1760 return _self_0
1761 end
1762 })
1763 _base_0.__class = _class_0
1764 Y = _class_0
1765end
1766local y = Y()
1767y:func()
1768assert(y.__class.__parent ~= X)
1769local Inventory
1770local _class_0
1771local _base_0 = {
1772 add_item = function(self, name)
1773 if self.items[name] then
1774 local _obj_0 = self.items
1775 _obj_0[name] = _obj_0[name] + 1
1776 else
1777 self.items[name] = 1
1778 end
1779 end
1780}
1781if _base_0.__index == nil then
1782 _base_0.__index = _base_0
1783end
1784_class_0 = setmetatable({
1785 __init = function(self)
1786 self.items = { }
1787 end,
1788 __base = _base_0,
1789 __name = "Inventory"
1790}, {
1791 __index = _base_0,
1792 __call = function(cls, ...)
1793 local _self_0 = setmetatable({ }, _base_0)
1794 cls.__init(_self_0, ...)
1795 return _self_0
1796 end
1797})
1798_base_0.__class = _class_0
1799Inventory = _class_0
1800local inv = Inventory()
1801inv:add_item("t-shirt")
1802inv:add_item("pants")
1803local Person
1804do
1805 local _class_0
1806 local _base_0 = {
1807 clothes = { },
1808 give_item = function(self, name)
1809 return table.insert(self.clothes, name)
1810 end
1811 }
1812 if _base_0.__index == nil then
1813 _base_0.__index = _base_0
1814 end
1815 _class_0 = setmetatable({
1816 __init = function() end,
1817 __base = _base_0,
1818 __name = "Person"
1819 }, {
1820 __index = _base_0,
1821 __call = function(cls, ...)
1822 local _self_0 = setmetatable({ }, _base_0)
1823 cls.__init(_self_0, ...)
1824 return _self_0
1825 end
1826 })
1827 _base_0.__class = _class_0
1828 Person = _class_0
1829end
1830local a = Person()
1831local b = Person()
1832a:give_item("pants")
1833b:give_item("shirt")
1834local _list_0 = a.clothes
1835for _index_0 = 1, #_list_0 do
1836 local item = _list_0[_index_0]
1837 print(item)
1838end
1839local Person
1840local _class_0
1841local _base_0 = { }
1842if _base_0.__index == nil then
1843 _base_0.__index = _base_0
1844end
1845_class_0 = setmetatable({
1846 __init = function(self)
1847 self.clothes = { }
1848 end,
1849 __base = _base_0,
1850 __name = "Person"
1851}, {
1852 __index = _base_0,
1853 __call = function(cls, ...)
1854 local _self_0 = setmetatable({ }, _base_0)
1855 cls.__init(_self_0, ...)
1856 return _self_0
1857 end
1858})
1859_base_0.__class = _class_0
1860Person = _class_0
1861local BackPack
1862local _class_0
1863local _parent_0 = Inventory
1864local _base_0 = {
1865 size = 10,
1866 add_item = function(self, name)
1867 if #self.items > size then
1868 error("backpack is full")
1869 end
1870 return _class_0.__parent.__base.add_item(self, name)
1871 end
1872}
1873for _key_0, _val_0 in pairs(_parent_0.__base) do
1874 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
1875 _base_0[_key_0] = _val_0
1876 end
1877end
1878if _base_0.__index == nil then
1879 _base_0.__index = _base_0
1880end
1881setmetatable(_base_0, _parent_0.__base)
1882_class_0 = setmetatable({
1883 __init = function(self, ...)
1884 return _class_0.__parent.__init(self, ...)
1885 end,
1886 __base = _base_0,
1887 __name = "BackPack",
1888 __parent = _parent_0
1889}, {
1890 __index = function(cls, name)
1891 local val = rawget(_base_0, name)
1892 if val == nil then
1893 local parent = rawget(cls, "__parent")
1894 if parent then
1895 return parent[name]
1896 end
1897 else
1898 return val
1899 end
1900 end,
1901 __call = function(cls, ...)
1902 local _self_0 = setmetatable({ }, _base_0)
1903 cls.__init(_self_0, ...)
1904 return _self_0
1905 end
1906})
1907_base_0.__class = _class_0
1908if _parent_0.__inherited then
1909 _parent_0.__inherited(_parent_0, _class_0)
1910end
1911BackPack = _class_0
1912local Shelf
1913do
1914 local _class_0
1915 local _base_0 = { }
1916 if _base_0.__index == nil then
1917 _base_0.__index = _base_0
1918 end
1919 _class_0 = setmetatable({
1920 __init = function() end,
1921 __base = _base_0,
1922 __name = "Shelf"
1923 }, {
1924 __index = _base_0,
1925 __call = function(cls, ...)
1926 local _self_0 = setmetatable({ }, _base_0)
1927 cls.__init(_self_0, ...)
1928 return _self_0
1929 end
1930 })
1931 _base_0.__class = _class_0
1932 local self = _class_0;
1933 self.__inherited = function(self, child)
1934 return print(self.__name, "was inherited by", child.__name)
1935 end
1936 Shelf = _class_0
1937end
1938local Cupboard
1939local _class_0
1940local _parent_0 = Shelf
1941local _base_0 = { }
1942for _key_0, _val_0 in pairs(_parent_0.__base) do
1943 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
1944 _base_0[_key_0] = _val_0
1945 end
1946end
1947if _base_0.__index == nil then
1948 _base_0.__index = _base_0
1949end
1950setmetatable(_base_0, _parent_0.__base)
1951_class_0 = setmetatable({
1952 __init = function(self, ...)
1953 return _class_0.__parent.__init(self, ...)
1954 end,
1955 __base = _base_0,
1956 __name = "Cupboard",
1957 __parent = _parent_0
1958}, {
1959 __index = function(cls, name)
1960 local val = rawget(_base_0, name)
1961 if val == nil then
1962 local parent = rawget(cls, "__parent")
1963 if parent then
1964 return parent[name]
1965 end
1966 else
1967 return val
1968 end
1969 end,
1970 __call = function(cls, ...)
1971 local _self_0 = setmetatable({ }, _base_0)
1972 cls.__init(_self_0, ...)
1973 return _self_0
1974 end
1975})
1976_base_0.__class = _class_0
1977if _parent_0.__inherited then
1978 _parent_0.__inherited(_parent_0, _class_0)
1979end
1980Cupboard = _class_0
1981local MyClass
1982local _class_0
1983local _parent_0 = ParentClass
1984local _base_0 = {
1985 a_method = function(self)
1986 _class_0.__parent.__base.a_method(self, "hello", "world")
1987 _class_0.__parent.a_method(self, "hello", "world")
1988 _class_0.__parent.a_method(self, "hello", "world")
1989 return assert(_class_0.__parent == ParentClass)
1990 end
1991}
1992for _key_0, _val_0 in pairs(_parent_0.__base) do
1993 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
1994 _base_0[_key_0] = _val_0
1995 end
1996end
1997if _base_0.__index == nil then
1998 _base_0.__index = _base_0
1999end
2000setmetatable(_base_0, _parent_0.__base)
2001_class_0 = setmetatable({
2002 __init = function(self, ...)
2003 return _class_0.__parent.__init(self, ...)
2004 end,
2005 __base = _base_0,
2006 __name = "MyClass",
2007 __parent = _parent_0
2008}, {
2009 __index = function(cls, name)
2010 local val = rawget(_base_0, name)
2011 if val == nil then
2012 local parent = rawget(cls, "__parent")
2013 if parent then
2014 return parent[name]
2015 end
2016 else
2017 return val
2018 end
2019 end,
2020 __call = function(cls, ...)
2021 local _self_0 = setmetatable({ }, _base_0)
2022 cls.__init(_self_0, ...)
2023 return _self_0
2024 end
2025})
2026_base_0.__class = _class_0
2027if _parent_0.__inherited then
2028 _parent_0.__inherited(_parent_0, _class_0)
2029end
2030MyClass = _class_0
2031local b = BackPack()
2032assert(b.__class == BackPack)
2033print(BackPack.size)
2034print(BackPack.__name)
2035local Things
2036do
2037 local _class_0
2038 local _base_0 = { }
2039 if _base_0.__index == nil then
2040 _base_0.__index = _base_0
2041 end
2042 _class_0 = setmetatable({
2043 __init = function() end,
2044 __base = _base_0,
2045 __name = "Things"
2046 }, {
2047 __index = _base_0,
2048 __call = function(cls, ...)
2049 local _self_0 = setmetatable({ }, _base_0)
2050 cls.__init(_self_0, ...)
2051 return _self_0
2052 end
2053 })
2054 _base_0.__class = _class_0
2055 local self = _class_0;
2056 self.some_func = function(self)
2057 return print("Hello from", self.__name)
2058 end
2059 Things = _class_0
2060end
2061Things:some_func()
2062assert(Things().some_func == nil)
2063local Counter
2064do
2065 local _class_0
2066 local _base_0 = { }
2067 if _base_0.__index == nil then
2068 _base_0.__index = _base_0
2069 end
2070 _class_0 = setmetatable({
2071 __init = function(self)
2072 self.__class.count = self.__class.count + 1
2073 end,
2074 __base = _base_0,
2075 __name = "Counter"
2076 }, {
2077 __index = _base_0,
2078 __call = function(cls, ...)
2079 local _self_0 = setmetatable({ }, _base_0)
2080 cls.__init(_self_0, ...)
2081 return _self_0
2082 end
2083 })
2084 _base_0.__class = _class_0
2085 local self = _class_0;
2086 self.count = 0
2087 Counter = _class_0
2088end
2089Counter()
2090Counter()
2091print(Counter.count)
2092self.__class:hello(1, 2, 3, 4)
2093local Things
2094local _class_0
2095local _base_0 = { }
2096if _base_0.__index == nil then
2097 _base_0.__index = _base_0
2098end
2099_class_0 = setmetatable({
2100 __init = function() end,
2101 __base = _base_0,
2102 __name = "Things"
2103}, {
2104 __index = _base_0,
2105 __call = function(cls, ...)
2106 local _self_0 = setmetatable({ }, _base_0)
2107 cls.__init(_self_0, ...)
2108 return _self_0
2109 end
2110})
2111_base_0.__class = _class_0
2112local self = _class_0;
2113self.class_var = "hello world"
2114Things = _class_0
2115local MoreThings
2116local _class_0
2117local secret, log
2118local _base_0 = {
2119 some_method = function(self)
2120 return log("hello world: " .. secret)
2121 end
2122}
2123if _base_0.__index == nil then
2124 _base_0.__index = _base_0
2125end
2126_class_0 = setmetatable({
2127 __init = function() end,
2128 __base = _base_0,
2129 __name = "MoreThings"
2130}, {
2131 __index = _base_0,
2132 __call = function(cls, ...)
2133 local _self_0 = setmetatable({ }, _base_0)
2134 cls.__init(_self_0, ...)
2135 return _self_0
2136 end
2137})
2138_base_0.__class = _class_0
2139local self = _class_0;
2140secret = 123
2141log = function(msg)
2142 return print("LOG:", msg)
2143end
2144MoreThings = _class_0
2145assert(self == self)
2146assert(self.__class == self.__class)
2147local some_instance_method
2148some_instance_method = function(self, ...)
2149 return self.__class(...)
2150end
2151local Something
2152do
2153 local _class_0
2154 local _base_0 = { }
2155 if _base_0.__index == nil then
2156 _base_0.__index = _base_0
2157 end
2158 _class_0 = setmetatable({
2159 __init = function(self, foo, bar, biz, baz)
2160 self.foo = foo
2161 self.bar = bar
2162 self.__class.biz = biz
2163 self.__class.baz = baz
2164 end,
2165 __base = _base_0,
2166 __name = "Something"
2167 }, {
2168 __index = _base_0,
2169 __call = function(cls, ...)
2170 local _self_0 = setmetatable({ }, _base_0)
2171 cls.__init(_self_0, ...)
2172 return _self_0
2173 end
2174 })
2175 _base_0.__class = _class_0
2176 Something = _class_0
2177end
2178local _class_0
2179local _base_0 = { }
2180if _base_0.__index == nil then
2181 _base_0.__index = _base_0
2182end
2183_class_0 = setmetatable({
2184 __init = function(self, foo, bar, biz, baz)
2185 self.foo = foo
2186 self.bar = bar
2187 self.__class.biz = biz
2188 self.__class.baz = baz
2189 end,
2190 __base = _base_0,
2191 __name = "Something"
2192}, {
2193 __index = _base_0,
2194 __call = function(cls, ...)
2195 local _self_0 = setmetatable({ }, _base_0)
2196 cls.__init(_self_0, ...)
2197 return _self_0
2198 end
2199})
2200_base_0.__class = _class_0
2201Something = _class_0
2202local new
2203new = function(self, fieldA, fieldB)
2204 self.fieldA = fieldA
2205 self.fieldB = fieldB
2206 return self
2207end
2208local obj = new({ }, 123, "abc")
2209print(obj)
2210local x
2211local Bucket
2212local _class_0
2213local _base_0 = {
2214 drops = 0,
2215 add_drop = function(self)
2216 self.drops = self.drops + 1
2217 end
2218}
2219if _base_0.__index == nil then
2220 _base_0.__index = _base_0
2221end
2222_class_0 = setmetatable({
2223 __init = function() end,
2224 __base = _base_0,
2225 __name = "Bucket"
2226}, {
2227 __index = _base_0,
2228 __call = function(cls, ...)
2229 local _self_0 = setmetatable({ }, _base_0)
2230 cls.__init(_self_0, ...)
2231 return _self_0
2232 end
2233})
2234_base_0.__class = _class_0
2235Bucket = _class_0
2236x = _class_0
2237local BigBucket
2238do
2239 local _class_0
2240 local _parent_0 = Bucket
2241 local _base_0 = {
2242 add_drop = function(self)
2243 self.drops = self.drops + 10
2244 end
2245 }
2246 for _key_0, _val_0 in pairs(_parent_0.__base) do
2247 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
2248 _base_0[_key_0] = _val_0
2249 end
2250 end
2251 if _base_0.__index == nil then
2252 _base_0.__index = _base_0
2253 end
2254 setmetatable(_base_0, _parent_0.__base)
2255 _class_0 = setmetatable({
2256 __init = function(self, ...)
2257 return _class_0.__parent.__init(self, ...)
2258 end,
2259 __base = _base_0,
2260 __name = "BigBucket",
2261 __parent = _parent_0
2262 }, {
2263 __index = function(cls, name)
2264 local val = rawget(_base_0, name)
2265 if val == nil then
2266 local parent = rawget(cls, "__parent")
2267 if parent then
2268 return parent[name]
2269 end
2270 else
2271 return val
2272 end
2273 end,
2274 __call = function(cls, ...)
2275 local _self_0 = setmetatable({ }, _base_0)
2276 cls.__init(_self_0, ...)
2277 return _self_0
2278 end
2279 })
2280 _base_0.__class = _class_0
2281 if _parent_0.__inherited then
2282 _parent_0.__inherited(_parent_0, _class_0)
2283 end
2284 BigBucket = _class_0
2285end
2286assert(Bucket.__name == "BigBucket")
2287local x
2288local _class_0
2289local _base_0 = { }
2290if _base_0.__index == nil then
2291 _base_0.__index = _base_0
2292end
2293_class_0 = setmetatable({
2294 __init = function() end,
2295 __base = _base_0,
2296 __name = "x"
2297}, {
2298 __index = _base_0,
2299 __call = function(cls, ...)
2300 local _self_0 = setmetatable({ }, _base_0)
2301 cls.__init(_self_0, ...)
2302 return _self_0
2303 end
2304})
2305_base_0.__class = _class_0
2306x = _class_0
2307local MyIndex = {
2308 __index = {
2309 var = 1
2310 }
2311}
2312local X
2313do
2314 local _class_0
2315 local _base_0 = {
2316 func = function(self)
2317 return print(123)
2318 end
2319 }
2320 local _list_0 = {
2321 MyIndex
2322 }
2323 for _index_0 = 1, #_list_0 do
2324 local _item_0 = _list_0[_index_0]
2325 local _cls_0, _mixin_0 = (_item_0.__base ~= nil), _item_0.__base or _item_0
2326 for _key_0, _val_0 in pairs(_mixin_0) do
2327 if _base_0[_key_0] == nil and (not _cls_0 or not _key_0:match("^__")) then
2328 _base_0[_key_0] = _val_0
2329 end
2330 end
2331 end
2332 if _base_0.__index == nil then
2333 _base_0.__index = _base_0
2334 end
2335 _class_0 = setmetatable({
2336 __init = function() end,
2337 __base = _base_0,
2338 __name = "X"
2339 }, {
2340 __index = _base_0,
2341 __call = function(cls, ...)
2342 local _self_0 = setmetatable({ }, _base_0)
2343 cls.__init(_self_0, ...)
2344 return _self_0
2345 end
2346 })
2347 _base_0.__class = _class_0
2348 X = _class_0
2349end
2350local x = X()
2351print(x.var)
2352local Y
2353do
2354 local _class_0
2355 local _base_0 = { }
2356 local _list_0 = {
2357 X
2358 }
2359 for _index_0 = 1, #_list_0 do
2360 local _item_0 = _list_0[_index_0]
2361 local _cls_0, _mixin_0 = (_item_0.__base ~= nil), _item_0.__base or _item_0
2362 for _key_0, _val_0 in pairs(_mixin_0) do
2363 if _base_0[_key_0] == nil and (not _cls_0 or not _key_0:match("^__")) then
2364 _base_0[_key_0] = _val_0
2365 end
2366 end
2367 end
2368 if _base_0.__index == nil then
2369 _base_0.__index = _base_0
2370 end
2371 _class_0 = setmetatable({
2372 __init = function() end,
2373 __base = _base_0,
2374 __name = "Y"
2375 }, {
2376 __index = _base_0,
2377 __call = function(cls, ...)
2378 local _self_0 = setmetatable({ }, _base_0)
2379 cls.__init(_self_0, ...)
2380 return _self_0
2381 end
2382 })
2383 _base_0.__class = _class_0
2384 Y = _class_0
2385end
2386local y = Y()
2387y:func()
2388assert(y.__class.__parent ~= X)
2389local _with_0 = Person()
2390_with_0.name = "Oswald"
2391_with_0:add_relative(my_dad)
2392_with_0:save()
2393print(_with_0.name)
2394local file
2395local _with_0 = File("favorite_foods.txt")
2396_with_0:set_encoding("utf8")
2397file = _with_0
2398local create_person
2399create_person = function(name, relatives)
2400 local _with_0 = Person()
2401 _with_0.name = name
2402 for _index_0 = 1, #relatives do
2403 local relative = relatives[_index_0]
2404 _with_0:add_relative(relative)
2405 end
2406 return _with_0
2407end
2408local me = create_person("Leaf", {
2409 dad,
2410 mother,
2411 sister
2412})
2413local str = "Hello"
2414print("original:", str)
2415print("upper:", str:upper())
2416local _with_0 = tb
2417_with_0[1] = 1
2418print(_with_0[2])
2419do
2420 local _with_1 = _with_0[abc]
2421 _with_1[3] = _with_1[2]:func()
2422 _with_1["key-name"] = value
2423end
2424_with_0[#_with_0 + 1] = "abc"
2425local _with_0 = obj
2426if _with_0 ~= nil then
2427 print(obj.name)
2428end
2429local _with_0 = Person()
2430_with_0.name = "Oswald"
2431_with_0:add_relative(my_dad)
2432_with_0:save()
2433print(_with_0.name)
2434local file
2435local _with_0 = File("favorite_foods.txt")
2436_with_0:set_encoding("utf8")
2437file = _with_0
2438local create_person
2439create_person = function(name, relatives)
2440 local _with_0 = Person()
2441 _with_0.name = name
2442 for _index_0 = 1, #relatives do
2443 local relative = relatives[_index_0]
2444 _with_0:add_relative(relative)
2445 end
2446 return _with_0
2447end
2448local me = create_person("Leaf", {
2449 dad,
2450 mother,
2451 sister
2452})
2453local str = "Hello"
2454print("original:", str)
2455print("upper:", str:upper())
2456local _with_0 = tb
2457_with_0[1] = 1
2458print(_with_0[2])
2459do
2460 local _with_1 = _with_0[abc]
2461 _with_1[3] = _with_1[2]:func()
2462 _with_1["key-name"] = value
2463end
2464_with_0[#_with_0 + 1] = "abc"
2465local _with_0 = obj
2466if _with_0 ~= nil then
2467 print(obj.name)
2468end
2469local hello = "world"
2470local a, b, c = 1, 2, 3
2471hello = 123
2472local x = 1
2473x = x + 1
2474x = x - 1
2475x = x * 10
2476x = x / 10
2477x = x % 10
2478local s = s .. "world"
2479local arg = arg or "default value"
2480local a = 0
2481local b = 0
2482local c = 0
2483local d = 0
2484local e = 0
2485local x = f()
2486local y = x
2487local z = x
2488do
2489 local a = 1
2490 local x, y, z
2491 print("forward declare all variables as locals")
2492 x = function()
2493 return 1 + y + z
2494 end
2495 y, z = 2, 3
2496 instance = Item:new()
2497end
2498do
2499 local X = 1
2500 local B
2501 print("only forward declare upper case variables")
2502 local a = 1
2503 B = 2
2504end
2505do
2506 a = 1
2507 print("declare all variables as globals")
2508 x = function()
2509 return 1 + y + z
2510 end
2511 y, z = 2, 3
2512end
2513do
2514 X = 1
2515 print("only declare upper case variables as globals")
2516 local a = 1
2517 B = 2
2518 local Temp = "a local value"
2519end
2520local hello = "world"
2521local a, b, c = 1, 2, 3
2522hello = 123
2523local x = 1
2524x = x + 1
2525x = x - 1
2526x = x * 10
2527x = x / 10
2528x = x % 10
2529local s = s .. "world"
2530local arg = arg or "default value"
2531local a = 0
2532local b = 0
2533local c = 0
2534local d = 0
2535local e = 0
2536local x = f()
2537local y = x
2538local z = x
2539do
2540 local a = 1
2541 local x, y, z
2542 print("forward declare all variables as locals")
2543 x = function()
2544 return 1 + y + z
2545 end
2546 y, z = 2, 3
2547 instance = Item:new()
2548end
2549do
2550 local X = 1
2551 local B
2552 print("only forward declare upper case variables")
2553 local a = 1
2554 B = 2
2555end
2556do
2557 a = 1
2558 print("declare all variables as globals")
2559 x = function()
2560 return 1 + y + z
2561 end
2562 y, z = 2, 3
2563end
2564do
2565 X = 1
2566 print("only declare upper case variables as globals")
2567 local a = 1
2568 B = 2
2569 local Temp = "a local value"
2570end
2571local list = {
2572 1,
2573 2,
2574 3,
2575 4,
2576 5
2577}
2578local fn
2579fn = function(ok)
2580 return ok, table.unpack(list)
2581end
2582(function(_arg_0, ...)
2583 local ok = _arg_0
2584 local count = select('#', ...)
2585 local first = select(1, ...)
2586 return print(ok, count, first)
2587end)(fn(true))
2588local list = {
2589 1,
2590 2,
2591 3,
2592 4,
2593 5
2594}
2595local fn
2596fn = function(ok)
2597 return ok, table.unpack(list)
2598end
2599(function(_arg_0, ...)
2600 local ok = _arg_0
2601 local count = select('#', ...)
2602 local first = select(1, ...)
2603 return print(ok, count, first)
2604end)(fn(true))
2605local user = database.find_user("moon")
2606if user then
2607 print(user.name)
2608end
2609local hello = os.getenv("hello")
2610if hello then
2611 print("You have hello", hello)
2612else
2613 local world = os.getenv("world")
2614 if world then
2615 print("you have world", world)
2616 else
2617 print("nothing :(")
2618 end
2619end
2620do
2621 local success, result = pcall(function()
2622 return "get result without problems"
2623 end)
2624 if success then
2625 print(result)
2626 end
2627end
2628print("OK")
2629repeat
2630 local byte = stream:read_one()
2631 if byte then
2632 print(byte)
2633 else
2634 break
2635 end
2636until false
2637local user = database.find_user("moon")
2638if user then
2639 print(user.name)
2640end
2641local hello = os.getenv("hello")
2642if hello then
2643 print("You have hello", hello)
2644else
2645 local world = os.getenv("world")
2646 if world then
2647 print("you have world", world)
2648 else
2649 print("nothing :(")
2650 end
2651end
2652do
2653 local success, result = pcall(function()
2654 return "get result without problems"
2655 end)
2656 if success then
2657 print(result)
2658 end
2659end
2660print("OK")
2661repeat
2662 local byte = stream:read_one()
2663 if byte then
2664 print(byte)
2665 else
2666 break
2667 end
2668until false
2669local thing = {
2670 1,
2671 2
2672}
2673local a, b = thing[1], thing[2]
2674print(a, b)
2675local obj = {
2676 hello = "world",
2677 day = "tuesday",
2678 length = 20
2679}
2680local hello, the_day = obj.hello, obj.day
2681print(hello, the_day)
2682local day = obj.day
2683local obj2 = {
2684 numbers = {
2685 1,
2686 2,
2687 3,
2688 4
2689 },
2690 properties = {
2691 color = "green",
2692 height = 13.5
2693 }
2694}
2695local first, second, color = obj2.numbers[1], obj2.numbers[2], obj2.properties.color
2696print(first, second, color)
2697local first, second, color
2698local _obj_0 = obj2
2699first, second, color = _obj_0.numbers[1], _obj_0.numbers[2], _obj_0.properties.color
2700local concat, insert
2701local _obj_0 = table
2702concat, insert = _obj_0.concat, _obj_0.insert
2703local mix, max, rand
2704local _obj_0 = math
2705mix, max, rand = _obj_0.mix, _obj_0.max, _obj_0.random
2706local name, job
2707local _obj_0 = person
2708name, job = _obj_0.name, _obj_0.job
2709if name == nil then
2710 name = "nameless"
2711end
2712if job == nil then
2713 job = "jobless"
2714end
2715local two, four
2716local _obj_0 = items
2717two, four = _obj_0[2], _obj_0[4]
2718local orders = {
2719 "first",
2720 "second",
2721 "third",
2722 "fourth",
2723 "last"
2724}
2725local first, bulk, last = orders[1], (function()
2726 local _accum_0 = { }
2727 local _len_0 = 1
2728 local _max_0 = #orders + -2 + 1
2729 for _index_0 = 2, _max_0 do
2730 local _item_0 = orders[_index_0]
2731 _accum_0[_len_0] = _item_0
2732 _len_0 = _len_0 + 1
2733 end
2734 return _accum_0
2735end)(), orders[#orders]
2736print(first)
2737print(bulk)
2738print(last)
2739local first, rest
2740do
2741 local _obj_0 = orders
2742 first, rest = _obj_0[1], (function()
2743 local _accum_0 = { }
2744 local _len_0 = 1
2745 local _max_0 = #_obj_0
2746 for _index_0 = 2, _max_0 do
2747 local _item_0 = _obj_0[_index_0]
2748 _accum_0[_len_0] = _item_0
2749 _len_0 = _len_0 + 1
2750 end
2751 return _accum_0
2752 end)()
2753end
2754local start, last
2755do
2756 local _obj_0 = orders
2757 start, last = (function()
2758 local _accum_0 = { }
2759 local _len_0 = 1
2760 local _max_0 = #_obj_0 + -2 + 1
2761 for _index_0 = 1, _max_0 do
2762 local _item_0 = _obj_0[_index_0]
2763 _accum_0[_len_0] = _item_0
2764 _len_0 = _len_0 + 1
2765 end
2766 return _accum_0
2767 end)(), _obj_0[#_obj_0]
2768end
2769local _obj_0 = orders
2770first, last = _obj_0[1], _obj_0[#_obj_0]
2771local tuples = {
2772 {
2773 "hello",
2774 "world"
2775 },
2776 {
2777 "egg",
2778 "head"
2779 }
2780}
2781for _index_0 = 1, #tuples do
2782 local _des_0 = tuples[_index_0]
2783 local left, right = _des_0[1], _des_0[2]
2784 print(left, right)
2785end
2786local thing = {
2787 1,
2788 2
2789}
2790local a, b = thing[1], thing[2]
2791print(a, b)
2792local obj = {
2793 hello = "world",
2794 day = "tuesday",
2795 length = 20
2796}
2797local hello, the_day = obj.hello, obj.day
2798print(hello, the_day)
2799local day = obj.day
2800local obj2 = {
2801 numbers = {
2802 1,
2803 2,
2804 3,
2805 4
2806 },
2807 properties = {
2808 color = "green",
2809 height = 13.5
2810 }
2811}
2812local first, second, color = obj2.numbers[1], obj2.numbers[2], obj2.properties.color
2813print(first, second, color)
2814local first, second, color
2815local _obj_0 = obj2
2816first, second, color = _obj_0.numbers[1], _obj_0.numbers[2], _obj_0.properties.color
2817local concat, insert
2818local _obj_0 = table
2819concat, insert = _obj_0.concat, _obj_0.insert
2820local mix, max, rand
2821local _obj_0 = math
2822mix, max, rand = _obj_0.mix, _obj_0.max, _obj_0.random
2823local name, job
2824local _obj_0 = person
2825name, job = _obj_0.name, _obj_0.job
2826if name == nil then
2827 name = "nameless"
2828end
2829if job == nil then
2830 job = "jobless"
2831end
2832local two, four
2833local _obj_0 = items
2834two, four = _obj_0[2], _obj_0[4]
2835local orders = {
2836 "first",
2837 "second",
2838 "third",
2839 "fourth",
2840 "last"
2841}
2842local first, bulk, last = orders[1], (function()
2843 local _accum_0 = { }
2844 local _len_0 = 1
2845 local _max_0 = #orders + -2 + 1
2846 for _index_0 = 2, _max_0 do
2847 local _item_0 = orders[_index_0]
2848 _accum_0[_len_0] = _item_0
2849 _len_0 = _len_0 + 1
2850 end
2851 return _accum_0
2852end)(), orders[#orders]
2853print(first)
2854print(bulk)
2855print(last)
2856local first, rest
2857do
2858 local _obj_0 = orders
2859 first, rest = _obj_0[1], (function()
2860 local _accum_0 = { }
2861 local _len_0 = 1
2862 local _max_0 = #_obj_0
2863 for _index_0 = 2, _max_0 do
2864 local _item_0 = _obj_0[_index_0]
2865 _accum_0[_len_0] = _item_0
2866 _len_0 = _len_0 + 1
2867 end
2868 return _accum_0
2869 end)()
2870end
2871local start, last
2872do
2873 local _obj_0 = orders
2874 start, last = (function()
2875 local _accum_0 = { }
2876 local _len_0 = 1
2877 local _max_0 = #_obj_0 + -2 + 1
2878 for _index_0 = 1, _max_0 do
2879 local _item_0 = _obj_0[_index_0]
2880 _accum_0[_len_0] = _item_0
2881 _len_0 = _len_0 + 1
2882 end
2883 return _accum_0
2884 end)(), _obj_0[#_obj_0]
2885end
2886local _obj_0 = orders
2887first, last = _obj_0[1], _obj_0[#_obj_0]
2888local tuples = {
2889 {
2890 "hello",
2891 "world"
2892 },
2893 {
2894 "egg",
2895 "head"
2896 }
2897}
2898for _index_0 = 1, #tuples do
2899 local _des_0 = tuples[_index_0]
2900 local left, right = _des_0[1], _des_0[2]
2901 print(left, right)
2902end
2903local i = 100
2904local my_func
2905my_func = function()
2906 i = 10
2907 while i > 0 do
2908 print(i)
2909 i = i - 1
2910 end
2911end
2912my_func()
2913print(i)
2914local i = 100
2915local my_func
2916my_func = function()
2917 local i = "hello"
2918end
2919my_func()
2920print(i)
2921local tmp = 1213
2922local i, k = 100, 50
2923local my_func
2924my_func = function(add)
2925 local tmp = tmp + add
2926 i = i + tmp
2927 k = k + tmp
2928end
2929my_func(22)
2930print(i, k)
2931local i = 100
2932local my_func
2933my_func = function()
2934 i = 10
2935 while i > 0 do
2936 print(i)
2937 i = i - 1
2938 end
2939end
2940my_func()
2941print(i)
2942local i = 100
2943local my_func
2944my_func = function()
2945 local i = "hello"
2946end
2947my_func()
2948print(i)
2949local tmp = 1213
2950local i, k = 100, 50
2951local my_func
2952my_func = function(add)
2953 local tmp = tmp + add
2954 i = i + tmp
2955 k = k + tmp
2956end
2957my_func(22)
2958print(i, k)
2959local _module_0 = { }
2960local p, to_lua
2961do
2962 local _obj_0 = require("yue")
2963 p, to_lua = _obj_0.p, _obj_0.to_lua
2964end
2965local inventory = {
2966 equipment = {
2967 "sword",
2968 "shield"
2969 },
2970 items = {
2971 {
2972 name = "potion",
2973 count = 10
2974 },
2975 {
2976 name = "bread",
2977 count = 3
2978 }
2979 }
2980}
2981local map
2982map = function(arr, action)
2983 local _accum_0 = { }
2984 local _len_0 = 1
2985 for _index_0 = 1, #arr do
2986 local item = arr[_index_0]
2987 _accum_0[_len_0] = action(item)
2988 _len_0 = _len_0 + 1
2989 end
2990 return _accum_0
2991end
2992local filter
2993filter = function(arr, cond)
2994 local _accum_0 = { }
2995 local _len_0 = 1
2996 for _index_0 = 1, #arr do
2997 local item = arr[_index_0]
2998 if cond(item) then
2999 _accum_0[_len_0] = item
3000 _len_0 = _len_0 + 1
3001 end
3002 end
3003 return _accum_0
3004end
3005local reduce
3006reduce = function(arr, init, action)
3007 for _index_0 = 1, #arr do
3008 local item = arr[_index_0]
3009 init = action(init, item)
3010 end
3011 return init
3012end
3013print(reduce(filter(map({
3014 1,
3015 2,
3016 3
3017}, function(x)
3018 return x * 2
3019end), function(x)
3020 return x > 4
3021end), 0, function(a, b)
3022 return a + b
3023end))
3024local apple = setmetatable({
3025 size = 15,
3026}, {
3027 __index = {
3028 color = 0x00ffff
3029 }
3030})
3031if (getmetatable(apple) ~= nil) then
3032 p(apple.size, apple.color, getmetatable(apple).__index)
3033end
3034local _u1f31b = "月之脚本"
3035_module_0["🌛"] = _u1f31b
3036return _module_0
3037local _module_0 = { }
3038local p, to_lua
3039do
3040 local _obj_0 = require("yue")
3041 p, to_lua = _obj_0.p, _obj_0.to_lua
3042end
3043local inventory = {
3044 equipment = {
3045 "sword",
3046 "shield"
3047 },
3048 items = {
3049 {
3050 name = "potion",
3051 count = 10
3052 },
3053 {
3054 name = "bread",
3055 count = 3
3056 }
3057 }
3058}
3059local map
3060map = function(arr, action)
3061 local _accum_0 = { }
3062 local _len_0 = 1
3063 for _index_0 = 1, #arr do
3064 local item = arr[_index_0]
3065 _accum_0[_len_0] = action(item)
3066 _len_0 = _len_0 + 1
3067 end
3068 return _accum_0
3069end
3070local filter
3071filter = function(arr, cond)
3072 local _accum_0 = { }
3073 local _len_0 = 1
3074 for _index_0 = 1, #arr do
3075 local item = arr[_index_0]
3076 if cond(item) then
3077 _accum_0[_len_0] = item
3078 _len_0 = _len_0 + 1
3079 end
3080 end
3081 return _accum_0
3082end
3083local reduce
3084reduce = function(arr, init, action)
3085 for _index_0 = 1, #arr do
3086 local item = arr[_index_0]
3087 init = action(init, item)
3088 end
3089 return init
3090end
3091print(reduce(filter(map({
3092 1,
3093 2,
3094 3
3095}, function(x)
3096 return x * 2
3097end), function(x)
3098 return x > 4
3099end), 0, function(a, b)
3100 return a + b
3101end))
3102local apple = setmetatable({
3103 size = 15,
3104}, {
3105 __index = {
3106 color = 0x00ffff
3107 }
3108})
3109if (getmetatable(apple) ~= nil) then
3110 p(apple.size, apple.color, getmetatable(apple).__index)
3111end
3112local _u1f31b = "月之脚本"
3113_module_0["🌛"] = _u1f31b
3114return _module_0
3115local have_coins = false
3116if have_coins then
3117 print("Got coins")
3118else
3119 print("No coins")
3120end
3121local have_coins = false
3122if have_coins then
3123 print("Got coins")
3124else
3125 print("No coins")
3126end
3127local have_coins = false
3128print((function()
3129 if have_coins then
3130 return "Got coins"
3131 else
3132 return "No coins"
3133 end
3134end)())
3135local is_tall
3136is_tall = function(name)
3137 if name == "Rob" then
3138 return true
3139 else
3140 return false
3141 end
3142end
3143local message
3144if is_tall("Rob") then
3145 message = "I am very tall"
3146else
3147 message = "I am not so tall"
3148end
3149print(message)
3150if not (os.date("%A") == "Monday") then
3151 print("it is not Monday!")
3152end
3153if not (math.random() > 0.1) then
3154 print("You're lucky!")
3155end
3156local a = 5
3157if (1 == a or 3 == a or 5 == a or 7 == a) then
3158 print("checking equality with discrete values")
3159end
3160if (function()
3161 local _check_0 = list
3162 for _index_0 = 1, #_check_0 do
3163 if _check_0[_index_0] == a then
3164 return true
3165 end
3166 end
3167 return false
3168end)() then
3169 print("checking if `a` is in a list")
3170end
3171if not (math.random() > 0.1) then
3172 print("You're lucky!")
3173end
3174local have_coins = false
3175if have_coins then
3176 print("Got coins")
3177else
3178 print("No coins")
3179end
3180local have_coins = false
3181if have_coins then
3182 print("Got coins")
3183else
3184 print("No coins")
3185end
3186local have_coins = false
3187print((function()
3188 if have_coins then
3189 return "Got coins"
3190 else
3191 return "No coins"
3192 end
3193end)())
3194local is_tall
3195is_tall = function(name)
3196 if name == "Rob" then
3197 return true
3198 else
3199 return false
3200 end
3201end
3202local message
3203if is_tall("Rob") then
3204 message = "I am very tall"
3205else
3206 message = "I am not so tall"
3207end
3208print(message)
3209if not (os.date("%A") == "Monday") then
3210 print("it is not Monday!")
3211end
3212if not (math.random() > 0.1) then
3213 print("You're lucky!")
3214end
3215local a = 5
3216if (1 == a or 3 == a or 5 == a or 7 == a) then
3217 print("checking equality with discrete values")
3218end
3219if (function()
3220 local _check_0 = list
3221 for _index_0 = 1, #_check_0 do
3222 if _check_0[_index_0] == a then
3223 return true
3224 end
3225 end
3226 return false
3227end)() then
3228 print("checking if `a` is in a list")
3229end
3230if not (math.random() > 0.1) then
3231 print("You're lucky!")
3232end
3233for i = 10, 20 do
3234 print(i)
3235end
3236for k = 1, 15, 2 do
3237 print(k)
3238end
3239for key, value in pairs(object) do
3240 print(key, value)
3241end
3242local _list_0 = items
3243for _index_0 = 2, 4 do
3244 local item = _list_0[_index_0]
3245 print(item)
3246end
3247local _list_0 = items
3248for _index_0 = 1, #_list_0 do
3249 local item = _list_0[_index_0]
3250 print(item)
3251end
3252for j = 1, 10, 3 do
3253 print(j)
3254end
3255local doubled_evens
3256local _accum_0 = { }
3257local _len_0 = 1
3258for i = 1, 20 do
3259 if i % 2 == 0 then
3260 _accum_0[_len_0] = i * 2
3261 _len_0 = _len_0 + 1
3262 else
3263 _accum_0[_len_0] = i
3264 _len_0 = _len_0 + 1
3265 end
3266end
3267doubled_evens = _accum_0
3268local first_large
3269local _accum_0
3270local _list_0 = numbers
3271for _index_0 = 1, #_list_0 do
3272 local n = _list_0[_index_0]
3273 if n > 10 then
3274 _accum_0 = n
3275 break
3276 end
3277end
3278first_large = _accum_0
3279local func_a
3280func_a = function()
3281 for i = 1, 10 do
3282 print(i)
3283 end
3284end
3285local func_b
3286func_b = function()
3287 local _accum_0 = { }
3288 local _len_0 = 1
3289 for i = 1, 10 do
3290 _accum_0[_len_0] = i
3291 _len_0 = _len_0 + 1
3292 end
3293 return _accum_0
3294end
3295print(func_a())
3296print(func_b())
3297for i = 10, 20 do
3298 print(i)
3299end
3300for k = 1, 15, 2 do
3301 print(k)
3302end
3303for key, value in pairs(object) do
3304 print(key, value)
3305end
3306local _list_0 = items
3307for _index_0 = 2, 4 do
3308 local item = _list_0[_index_0]
3309 print(item)
3310end
3311local _list_0 = items
3312for _index_0 = 1, #_list_0 do
3313 local item = _list_0[_index_0]
3314 print(item)
3315end
3316for j = 1, 10, 3 do
3317 print(j)
3318end
3319local doubled_evens
3320local _accum_0 = { }
3321local _len_0 = 1
3322for i = 1, 20 do
3323 if i % 2 == 0 then
3324 _accum_0[_len_0] = i * 2
3325 _len_0 = _len_0 + 1
3326 else
3327 _accum_0[_len_0] = i
3328 _len_0 = _len_0 + 1
3329 end
3330end
3331doubled_evens = _accum_0
3332local first_large
3333local _accum_0
3334local _list_0 = numbers
3335for _index_0 = 1, #_list_0 do
3336 local n = _list_0[_index_0]
3337 if n > 10 then
3338 _accum_0 = n
3339 break
3340 end
3341end
3342first_large = _accum_0
3343local func_a
3344func_a = function()
3345 for i = 1, 10 do
3346 print(i)
3347 end
3348end
3349local func_b
3350func_b = function()
3351 local _accum_0 = { }
3352 local _len_0 = 1
3353 for i = 1, 10 do
3354 _accum_0[_len_0] = i
3355 _len_0 = _len_0 + 1
3356 end
3357 return _accum_0
3358end
3359print(func_a())
3360print(func_b())
3361local i = 0
3362while i < 10 do
3363 i = i + 1
3364 if i % 2 == 0 then
3365 goto _continue_0
3366 end
3367 print(i)
3368 ::_continue_0::
3369end
3370local my_numbers = {
3371 1,
3372 2,
3373 3,
3374 4,
3375 5,
3376 6
3377}
3378local odds
3379local _accum_0 = { }
3380local _len_0 = 1
3381for _index_0 = 1, #my_numbers do
3382 local x = my_numbers[_index_0]
3383 if x % 2 == 1 then
3384 goto _continue_0
3385 end
3386 _accum_0[_len_0] = x
3387 _len_0 = _len_0 + 1
3388 ::_continue_0::
3389end
3390odds = _accum_0
3391local i = 0
3392while i < 10 do
3393 i = i + 1
3394 if i % 2 == 0 then
3395 goto _continue_0
3396 end
3397 print(i)
3398 ::_continue_0::
3399end
3400local my_numbers = {
3401 1,
3402 2,
3403 3,
3404 4,
3405 5,
3406 6
3407}
3408local odds
3409local _accum_0 = { }
3410local _len_0 = 1
3411for _index_0 = 1, #my_numbers do
3412 local x = my_numbers[_index_0]
3413 if x % 2 == 1 then
3414 goto _continue_0
3415 end
3416 _accum_0[_len_0] = x
3417 _len_0 = _len_0 + 1
3418 ::_continue_0::
3419end
3420odds = _accum_0
3421local name = "Dan"
3422if "Robert" == name then
3423 print("You are Robert")
3424elseif "Dan" == name or "Daniel" == name then
3425 print("Your name, it's Dan")
3426else
3427 print("I don't know about you with name " .. tostring(name))
3428end
3429local b = 1
3430local next_number
3431if 1 == b then
3432 next_number = 2
3433elseif 2 == b then
3434 next_number = 3
3435else
3436 next_number = error("can't count that high!")
3437end
3438local msg
3439local _exp_0 = math.random(1, 5)
3440if 1 == _exp_0 then
3441 msg = "you are lucky"
3442elseif 2 == _exp_0 then
3443 msg = "you are almost lucky"
3444else
3445 msg = "not so lucky"
3446end
3447do
3448 local _exp_0 = math.random(1, 5)
3449 if 1 == _exp_0 then
3450 print("you are lucky")
3451 else
3452 print("not so lucky")
3453 end
3454end
3455local _exp_0 = math.random(1, 5)
3456if 1 == _exp_0 then
3457 print("you are lucky")
3458else
3459 print("not so lucky")
3460end
3461local items = {
3462 {
3463 x = 100,
3464 y = 200
3465 },
3466 {
3467 width = 300,
3468 height = 400
3469 }
3470}
3471for _index_0 = 1, #items do
3472 local item = items[_index_0]
3473 local _type_0 = type(item)
3474 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3475 local _match_0 = false
3476 if _tab_0 then
3477 local x = item.x
3478 local y = item.y
3479 if x ~= nil and y ~= nil then
3480 _match_0 = true
3481 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3482 end
3483 end
3484 if not _match_0 then
3485 if _tab_0 then
3486 local width = item.width
3487 local height = item.height
3488 if width ~= nil and height ~= nil then
3489 print("size " .. tostring(width) .. ", " .. tostring(height))
3490 end
3491 end
3492 end
3493end
3494local item = { }
3495local x, y = item.pos.x, item.pos.y
3496if x == nil then
3497 x = 50
3498end
3499if y == nil then
3500 y = 200
3501end
3502local _type_0 = type(item)
3503local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3504if _tab_0 then
3505 do
3506 local _obj_0 = item.pos
3507 local _type_1 = type(_obj_0)
3508 if "table" == _type_1 or "userdata" == _type_1 then
3509 x = _obj_0.x
3510 end
3511 end
3512 do
3513 local _obj_0 = item.pos
3514 local _type_1 = type(_obj_0)
3515 if "table" == _type_1 or "userdata" == _type_1 then
3516 y = _obj_0.y
3517 end
3518 end
3519 if x == nil then
3520 x = 50
3521 end
3522 if y == nil then
3523 y = 200
3524 end
3525 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3526end
3527local _exp_0 = tb
3528local _type_0 = type(_exp_0)
3529local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3530local _match_0 = false
3531if _tab_0 then
3532 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
3533 _match_0 = true
3534 print("1, 2, 3")
3535 end
3536end
3537if not _match_0 then
3538 local _match_1 = false
3539 if _tab_0 then
3540 local b = _exp_0[2]
3541 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
3542 _match_1 = true
3543 print("1, " .. tostring(b) .. ", 3")
3544 end
3545 end
3546 if not _match_1 then
3547 if _tab_0 then
3548 local b = _exp_0[3]
3549 if b == nil then
3550 b = 3
3551 end
3552 if 1 == _exp_0[1] and 2 == _exp_0[2] then
3553 print("1, 2, " .. tostring(b))
3554 end
3555 end
3556 end
3557end
3558local _exp_0 = tb
3559local _type_0 = type(_exp_0)
3560local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3561local _match_0 = false
3562if _tab_0 then
3563 local result = _exp_0.result
3564 if true == _exp_0.success and result ~= nil then
3565 _match_0 = true
3566 print("success", result)
3567 end
3568end
3569if not _match_0 then
3570 local _match_1 = false
3571 if _tab_0 then
3572 if false == _exp_0.success then
3573 _match_1 = true
3574 print("failed", result)
3575 end
3576 end
3577 if not _match_1 then
3578 print("invalid")
3579 end
3580end
3581local _exp_0 = tb
3582local _type_0 = type(_exp_0)
3583local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3584local _match_0 = false
3585if _tab_0 then
3586 local content
3587 do
3588 local _obj_0 = _exp_0.data
3589 local _type_1 = type(_obj_0)
3590 if "table" == _type_1 or "userdata" == _type_1 then
3591 content = _obj_0.content
3592 end
3593 end
3594 local _val_0
3595 do
3596 local _obj_0 = _exp_0.data
3597 if _obj_0 ~= nil then
3598 _val_0 = _obj_0.type
3599 end
3600 end
3601 if "success" == _val_0 and content ~= nil then
3602 _match_0 = true
3603 print("success", content)
3604 end
3605end
3606if not _match_0 then
3607 local _match_1 = false
3608 if _tab_0 then
3609 local content
3610 do
3611 local _obj_0 = _exp_0.data
3612 local _type_1 = type(_obj_0)
3613 if "table" == _type_1 or "userdata" == _type_1 then
3614 content = _obj_0.content
3615 end
3616 end
3617 local _val_0
3618 do
3619 local _obj_0 = _exp_0.data
3620 if _obj_0 ~= nil then
3621 _val_0 = _obj_0.type
3622 end
3623 end
3624 if "error" == _val_0 and content ~= nil then
3625 _match_1 = true
3626 print("failed", content)
3627 end
3628 end
3629 if not _match_1 then
3630 print("invalid")
3631 end
3632end
3633local _exp_0 = tb
3634local _type_0 = type(_exp_0)
3635local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3636if _tab_0 then
3637 local fourth = _exp_0[4]
3638 local _val_0
3639 do
3640 local _obj_0 = _exp_0[1]
3641 if _obj_0 ~= nil then
3642 _val_0 = _obj_0.a
3643 end
3644 end
3645 local _val_1
3646 do
3647 local _obj_0 = _exp_0[1]
3648 if _obj_0 ~= nil then
3649 _val_1 = _obj_0.b
3650 end
3651 end
3652 local _val_2
3653 do
3654 local _obj_0 = _exp_0[2]
3655 if _obj_0 ~= nil then
3656 _val_2 = _obj_0.a
3657 end
3658 end
3659 local _val_3
3660 do
3661 local _obj_0 = _exp_0[2]
3662 if _obj_0 ~= nil then
3663 _val_3 = _obj_0.b
3664 end
3665 end
3666 local _val_4
3667 do
3668 local _obj_0 = _exp_0[3]
3669 if _obj_0 ~= nil then
3670 _val_4 = _obj_0.a
3671 end
3672 end
3673 local _val_5
3674 do
3675 local _obj_0 = _exp_0[3]
3676 if _obj_0 ~= nil then
3677 _val_5 = _obj_0.b
3678 end
3679 end
3680 if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and fourth ~= nil then
3681 print("matched", fourth)
3682 end
3683end
3684local segments = {
3685 "admin",
3686 "users",
3687 "logs",
3688 "view"
3689}
3690local _type_0 = type(segments)
3691local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3692if _tab_0 then
3693 local groups
3694 do
3695 local _accum_0 = { }
3696 local _len_0 = 1
3697 local _max_0 = #segments + -3 + 1
3698 for _index_0 = 1, _max_0 do
3699 local _item_0 = segments[_index_0]
3700 _accum_0[_len_0] = _item_0
3701 _len_0 = _len_0 + 1
3702 end
3703 groups = _accum_0
3704 end
3705 local resource = segments[#segments - 1]
3706 local action = segments[#segments]
3707 if resource ~= nil and action ~= nil then
3708 print("Group:", groups)
3709 print("Resource:", resource)
3710 print("Action:", action)
3711 end
3712end
3713local name = "Dan"
3714if "Robert" == name then
3715 print("You are Robert")
3716elseif "Dan" == name or "Daniel" == name then
3717 print("Your name, it's Dan")
3718else
3719 print("I don't know about you with name " .. tostring(name))
3720end
3721local b = 1
3722local next_number
3723if 1 == b then
3724 next_number = 2
3725elseif 2 == b then
3726 next_number = 3
3727else
3728 next_number = error("can't count that high!")
3729end
3730local msg
3731local _exp_0 = math.random(1, 5)
3732if 1 == _exp_0 then
3733 msg = "you are lucky"
3734elseif 2 == _exp_0 then
3735 msg = "you are almost lucky"
3736else
3737 msg = "not so lucky"
3738end
3739do
3740 local _exp_0 = math.random(1, 5)
3741 if 1 == _exp_0 then
3742 print("you are lucky")
3743 else
3744 print("not so lucky")
3745 end
3746end
3747local _exp_0 = math.random(1, 5)
3748if 1 == _exp_0 then
3749 print("you are lucky")
3750else
3751 print("not so lucky")
3752end
3753local items = {
3754 {
3755 x = 100,
3756 y = 200
3757 },
3758 {
3759 width = 300,
3760 height = 400
3761 }
3762}
3763for _index_0 = 1, #items do
3764 local item = items[_index_0]
3765 local _type_0 = type(item)
3766 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3767 local _match_0 = false
3768 if _tab_0 then
3769 local x = item.x
3770 local y = item.y
3771 if x ~= nil and y ~= nil then
3772 _match_0 = true
3773 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3774 end
3775 end
3776 if not _match_0 then
3777 if _tab_0 then
3778 local width = item.width
3779 local height = item.height
3780 if width ~= nil and height ~= nil then
3781 print("size " .. tostring(width) .. ", " .. tostring(height))
3782 end
3783 end
3784 end
3785end
3786local item = { }
3787local x, y = item.pos.x, item.pos.y
3788if x == nil then
3789 x = 50
3790end
3791if y == nil then
3792 y = 200
3793end
3794local _type_0 = type(item)
3795local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3796if _tab_0 then
3797 do
3798 local _obj_0 = item.pos
3799 local _type_1 = type(_obj_0)
3800 if "table" == _type_1 or "userdata" == _type_1 then
3801 x = _obj_0.x
3802 end
3803 end
3804 do
3805 local _obj_0 = item.pos
3806 local _type_1 = type(_obj_0)
3807 if "table" == _type_1 or "userdata" == _type_1 then
3808 y = _obj_0.y
3809 end
3810 end
3811 if x == nil then
3812 x = 50
3813 end
3814 if y == nil then
3815 y = 200
3816 end
3817 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3818end
3819local _exp_0 = tb
3820local _type_0 = type(_exp_0)
3821local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3822local _match_0 = false
3823if _tab_0 then
3824 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
3825 _match_0 = true
3826 print("1, 2, 3")
3827 end
3828end
3829if not _match_0 then
3830 local _match_1 = false
3831 if _tab_0 then
3832 local b = _exp_0[2]
3833 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
3834 _match_1 = true
3835 print("1, " .. tostring(b) .. ", 3")
3836 end
3837 end
3838 if not _match_1 then
3839 if _tab_0 then
3840 local b = _exp_0[3]
3841 if b == nil then
3842 b = 3
3843 end
3844 if 1 == _exp_0[1] and 2 == _exp_0[2] then
3845 print("1, 2, " .. tostring(b))
3846 end
3847 end
3848 end
3849end
3850local _exp_0 = tb
3851local _type_0 = type(_exp_0)
3852local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3853local _match_0 = false
3854if _tab_0 then
3855 local result = _exp_0.result
3856 if true == _exp_0.success and result ~= nil then
3857 _match_0 = true
3858 print("success", result)
3859 end
3860end
3861if not _match_0 then
3862 local _match_1 = false
3863 if _tab_0 then
3864 if false == _exp_0.success then
3865 _match_1 = true
3866 print("failed", result)
3867 end
3868 end
3869 if not _match_1 then
3870 print("invalid")
3871 end
3872end
3873local _exp_0 = tb
3874local _type_0 = type(_exp_0)
3875local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3876local _match_0 = false
3877if _tab_0 then
3878 local content
3879 do
3880 local _obj_0 = _exp_0.data
3881 local _type_1 = type(_obj_0)
3882 if "table" == _type_1 or "userdata" == _type_1 then
3883 content = _obj_0.content
3884 end
3885 end
3886 local _val_0
3887 do
3888 local _obj_0 = _exp_0.data
3889 if _obj_0 ~= nil then
3890 _val_0 = _obj_0.type
3891 end
3892 end
3893 if "success" == _val_0 and content ~= nil then
3894 _match_0 = true
3895 print("success", content)
3896 end
3897end
3898if not _match_0 then
3899 local _match_1 = false
3900 if _tab_0 then
3901 local content
3902 do
3903 local _obj_0 = _exp_0.data
3904 local _type_1 = type(_obj_0)
3905 if "table" == _type_1 or "userdata" == _type_1 then
3906 content = _obj_0.content
3907 end
3908 end
3909 local _val_0
3910 do
3911 local _obj_0 = _exp_0.data
3912 if _obj_0 ~= nil then
3913 _val_0 = _obj_0.type
3914 end
3915 end
3916 if "error" == _val_0 and content ~= nil then
3917 _match_1 = true
3918 print("failed", content)
3919 end
3920 end
3921 if not _match_1 then
3922 print("invalid")
3923 end
3924end
3925local _exp_0 = tb
3926local _type_0 = type(_exp_0)
3927local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3928if _tab_0 then
3929 local fourth = _exp_0[4]
3930 local _val_0
3931 do
3932 local _obj_0 = _exp_0[1]
3933 if _obj_0 ~= nil then
3934 _val_0 = _obj_0.a
3935 end
3936 end
3937 local _val_1
3938 do
3939 local _obj_0 = _exp_0[1]
3940 if _obj_0 ~= nil then
3941 _val_1 = _obj_0.b
3942 end
3943 end
3944 local _val_2
3945 do
3946 local _obj_0 = _exp_0[2]
3947 if _obj_0 ~= nil then
3948 _val_2 = _obj_0.a
3949 end
3950 end
3951 local _val_3
3952 do
3953 local _obj_0 = _exp_0[2]
3954 if _obj_0 ~= nil then
3955 _val_3 = _obj_0.b
3956 end
3957 end
3958 local _val_4
3959 do
3960 local _obj_0 = _exp_0[3]
3961 if _obj_0 ~= nil then
3962 _val_4 = _obj_0.a
3963 end
3964 end
3965 local _val_5
3966 do
3967 local _obj_0 = _exp_0[3]
3968 if _obj_0 ~= nil then
3969 _val_5 = _obj_0.b
3970 end
3971 end
3972 if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and fourth ~= nil then
3973 print("matched", fourth)
3974 end
3975end
3976local segments = {
3977 "admin",
3978 "users",
3979 "logs",
3980 "view"
3981}
3982local _type_0 = type(segments)
3983local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3984if _tab_0 then
3985 local groups
3986 do
3987 local _accum_0 = { }
3988 local _len_0 = 1
3989 local _max_0 = #segments + -3 + 1
3990 for _index_0 = 1, _max_0 do
3991 local _item_0 = segments[_index_0]
3992 _accum_0[_len_0] = _item_0
3993 _len_0 = _len_0 + 1
3994 end
3995 groups = _accum_0
3996 end
3997 local resource = segments[#segments - 1]
3998 local action = segments[#segments]
3999 if resource ~= nil and action ~= nil then
4000 print("Group:", groups)
4001 print("Resource:", resource)
4002 print("Action:", action)
4003 end
4004end
4005local i = 10
4006while i > 0 do
4007 print(i)
4008 i = i - 1
4009end
4010while running == true do
4011 my_function()
4012end
4013local i = 10
4014while not (i == 0) do
4015 print(i)
4016 i = i - 1
4017end
4018while not (running == false) do
4019 my_function()
4020end
4021local i = 10
4022repeat
4023 print(i)
4024 i = i - 1
4025until i == 0
4026local i = 10
4027while i > 0 do
4028 print(i)
4029 i = i - 1
4030end
4031while running == true do
4032 my_function()
4033end
4034local i = 10
4035while not (i == 0) do
4036 print(i)
4037 i = i - 1
4038end
4039while not (running == false) do
4040 my_function()
4041end
4042local i = 10
4043repeat
4044 print(i)
4045 i = i - 1
4046until i == 0
4047local my_object = {
4048 value = 1000,
4049 write = function(self)
4050 return print("the value:", self.value)
4051 end
4052}
4053local run_callback
4054run_callback = function(func)
4055 print("running callback...")
4056 return func()
4057end
4058run_callback(my_object.write)
4059run_callback((function()
4060 local _base_0 = my_object
4061 local _fn_0 = _base_0.write
4062 return _fn_0 and function(...)
4063 return _fn_0(_base_0, ...)
4064 end
4065end)())
4066local my_object = {
4067 value = 1000,
4068 write = function(self)
4069 return print("the value:", self.value)
4070 end
4071}
4072local run_callback
4073run_callback = function(func)
4074 print("running callback...")
4075 return func()
4076end
4077run_callback(my_object.write)
4078run_callback((function()
4079 local _base_0 = my_object
4080 local _fn_0 = _base_0.write
4081 return _fn_0 and function(...)
4082 return _fn_0(_base_0, ...)
4083 end
4084end)())
4085f(function(x)
4086 return print("hello" .. x)
4087end)
4088f(function(self)
4089 return print(self.value)
4090end)
4091map(function(x)
4092 return x * 2
4093end, {
4094 1,
4095 2,
4096 3
4097})
4098local result, msg
4099do
4100 result, msg = readAsync("filename.txt", function(data)
4101 print(data)
4102 return processAsync(data, function(info)
4103 return check(info)
4104 end)
4105 end)
4106end
4107print(result, msg)
4108f(function(x)
4109 return print("hello" .. x)
4110end)
4111f(function(self)
4112 return print(self.value)
4113end)
4114map(function(x)
4115 return x * 2
4116end, {
4117 1,
4118 2,
4119 3
4120})
4121local result, msg
4122do
4123 result, msg = readAsync("filename.txt", function(data)
4124 print(data)
4125 return processAsync(data, function(info)
4126 return check(info)
4127 end)
4128 end)
4129end
4130print(result, msg)
4131local my_function
4132my_function = function() end
4133my_function()
4134local func_a
4135func_a = function()
4136 return print("hello world")
4137end
4138local func_b
4139func_b = function()
4140 local value = 100
4141 return print("The value:", value)
4142end
4143func_a()
4144func_b()
4145local sum
4146sum = function(x, y)
4147 return print("sum", x + y)
4148end
4149sum(10, 20)
4150print(sum(10, 20))
4151a(b(c("a", "b", "c")))
4152print("x:", sum(10, 20), "y:", sum(30, 40))
4153local sum
4154sum = function(x, y)
4155 return x + y
4156end
4157print("The sum is ", sum(10, 20))
4158local sum
4159sum = function(x, y)
4160 return x + y
4161end
4162local mystery
4163mystery = function(x, y)
4164 return x + y, x - y
4165end
4166local a, b = mystery(10, 20)
4167local func
4168func = function(self, num)
4169 return self.value + num
4170end
4171local my_function
4172my_function = function(name, height)
4173 if name == nil then
4174 name = "something"
4175 end
4176 if height == nil then
4177 height = 100
4178 end
4179 print("Hello I am", name)
4180 return print("My height is", height)
4181end
4182local some_args
4183some_args = function(x, y)
4184 if x == nil then
4185 x = 100
4186 end
4187 if y == nil then
4188 y = x + 1000
4189 end
4190 return print(x + y)
4191end
4192local a = x - 10
4193local b = x - 10
4194local c = x(-y)
4195local d = x - z
4196local x = func("hello") + 100
4197local y = func("hello" + 100)
4198my_func(5, 4, 3, 8, 9, 10)
4199cool_func(1, 2, 3, 4, 5, 6, 7, 8)
4200my_func(5, 6, 7, 6, another_func(6, 7, 8, 9, 1, 2), 5, 4)
4201local x = {
4202 1,
4203 2,
4204 3,
4205 4,
4206 a_func(4, 5, 5, 6),
4207 8,
4208 9,
4209 10
4210}
4211local y = {
4212 my_func(1, 2, 3, 4, 5),
4213 5,
4214 6,
4215 7
4216}
4217if func(1, 2, 3, "hello", "world") then
4218 print("hello")
4219 print("I am inside if")
4220end
4221if func(1, 2, 3, "hello", "world") then
4222 print("hello")
4223 print("I am inside if")
4224end
4225local f1
4226f1 = function(_arg_0)
4227 local a, b, c
4228 a, b, c = _arg_0.a, _arg_0.b, _arg_0.c
4229 return print(a, b, c)
4230end
4231f1({
4232 a = 1,
4233 b = "2",
4234 c = { }
4235})
4236local f2
4237f2 = function(_arg_0, c)
4238 local a1, b
4239 a1, b = _arg_0.a, _arg_0.b
4240 if a1 == nil then
4241 a1 = 123
4242 end
4243 if b == nil then
4244 b = 'abc'
4245 end
4246 if c == nil then
4247 c = { }
4248 end
4249 return print(a1, b, c)
4250end
4251local arg1 = {
4252 a = 0
4253}
4254f2(arg1, arg2)
4255local findFirstEven
4256findFirstEven = function(list)
4257 for _index_0 = 1, #list do
4258 local item = list[_index_0]
4259 if type(item) == "table" then
4260 for _index_1 = 1, #item do
4261 local sub = item[_index_1]
4262 if sub % 2 == 0 then
4263 return sub
4264 end
4265 end
4266 end
4267 end
4268 return nil
4269end
4270local findFirstEven
4271findFirstEven = function(list)
4272 for _index_0 = 1, #list do
4273 local item = list[_index_0]
4274 if type(item) == "table" then
4275 for _index_1 = 1, #item do
4276 local sub = item[_index_1]
4277 if sub % 2 == 0 then
4278 return sub
4279 end
4280 end
4281 end
4282 end
4283 return nil
4284end
4285local f
4286f = function(...)
4287 local t = {
4288 n = select("#", ...),
4289 ...
4290 }
4291 print("argument count:", t.n)
4292 print("table length:", #t)
4293 for i = 1, t.n do
4294 print(t[i])
4295 end
4296end
4297f(1, 2, 3)
4298f("a", "b", "c", "d")
4299f()
4300local process
4301process = function(...)
4302 local args = {
4303 n = select("#", ...),
4304 ...
4305 }
4306 local sum = 0
4307 for i = 1, args.n do
4308 if args[i] ~= nil and type(args[i]) == "number" then
4309 sum = sum + args[i]
4310 end
4311 end
4312 return sum
4313end
4314process(1, nil, 3, nil, 5)
4315local my_function
4316my_function = function() end
4317my_function()
4318local func_a
4319func_a = function()
4320 return print("hello world")
4321end
4322local func_b
4323func_b = function()
4324 local value = 100
4325 return print("The value:", value)
4326end
4327func_a()
4328func_b()
4329local sum
4330sum = function(x, y)
4331 return print("sum", x + y)
4332end
4333sum(10, 20)
4334print(sum(10, 20))
4335a(b(c("a", "b", "c")))
4336print("x:", sum(10, 20), "y:", sum(30, 40))
4337local sum
4338sum = function(x, y)
4339 return x + y
4340end
4341print("The sum is ", sum(10, 20))
4342local sum
4343sum = function(x, y)
4344 return x + y
4345end
4346local mystery
4347mystery = function(x, y)
4348 return x + y, x - y
4349end
4350local a, b = mystery(10, 20)
4351local func
4352func = function(self, num)
4353 return self.value + num
4354end
4355local my_function
4356my_function = function(name, height)
4357 if name == nil then
4358 name = "something"
4359 end
4360 if height == nil then
4361 height = 100
4362 end
4363 print("Hello I am", name)
4364 return print("My height is", height)
4365end
4366local some_args
4367some_args = function(x, y)
4368 if x == nil then
4369 x = 100
4370 end
4371 if y == nil then
4372 y = x + 1000
4373 end
4374 return print(x + y)
4375end
4376local a = x - 10
4377local b = x - 10
4378local c = x(-y)
4379local d = x - z
4380local x = func("hello") + 100
4381local y = func("hello" + 100)
4382my_func(5, 4, 3, 8, 9, 10)
4383cool_func(1, 2, 3, 4, 5, 6, 7, 8)
4384my_func(5, 6, 7, 6, another_func(6, 7, 8, 9, 1, 2), 5, 4)
4385local x = {
4386 1,
4387 2,
4388 3,
4389 4,
4390 a_func(4, 5, 5, 6),
4391 8,
4392 9,
4393 10
4394}
4395local y = {
4396 my_func(1, 2, 3, 4, 5),
4397 5,
4398 6,
4399 7
4400}
4401if func(1, 2, 3, "hello", "world") then
4402 print("hello")
4403 print("I am inside if")
4404end
4405if func(1, 2, 3, "hello", "world") then
4406 print("hello")
4407 print("I am inside if")
4408end
4409local f1
4410f1 = function(_arg_0)
4411 local a, b, c
4412 a, b, c = _arg_0.a, _arg_0.b, _arg_0.c
4413 return print(a, b, c)
4414end
4415f1({
4416 a = 1,
4417 b = "2",
4418 c = { }
4419})
4420local f2
4421f2 = function(_arg_0, c)
4422 local a1, b
4423 a1, b = _arg_0.a, _arg_0.b
4424 if a1 == nil then
4425 a1 = 123
4426 end
4427 if b == nil then
4428 b = 'abc'
4429 end
4430 if c == nil then
4431 c = { }
4432 end
4433end
4434print(a1, b, c)
4435local arg1 = {
4436 a = 0
4437}
4438f2(arg1, arg2)
4439local findFirstEven
4440findFirstEven = function(list)
4441 for _index_0 = 1, #list do
4442 local item = list[_index_0]
4443 if type(item) == "table" then
4444 for _index_1 = 1, #item do
4445 local sub = item[_index_1]
4446 if sub % 2 == 0 then
4447 return sub
4448 end
4449 end
4450 end
4451 end
4452 return nil
4453end
4454local findFirstEven
4455findFirstEven = function(list)
4456 for _index_0 = 1, #list do
4457 local item = list[_index_0]
4458 if type(item) == "table" then
4459 for _index_1 = 1, #item do
4460 local sub = item[_index_1]
4461 if sub % 2 == 0 then
4462 return sub
4463 end
4464 end
4465 end
4466 end
4467 return nil
4468end
4469local f
4470f = function(...)
4471 local t = {
4472 n = select("#", ...),
4473 ...
4474 }
4475 print("argument count:", t.n)
4476 print("table length:", #t)
4477 for i = 1, t.n do
4478 print(t[i])
4479 end
4480end
4481f(1, 2, 3)
4482f("a", "b", "c", "d")
4483f()
4484local process
4485process = function(...)
4486 local args = {
4487 n = select("#", ...),
4488 ...
4489 }
4490 local sum = 0
4491 for i = 1, args.n do
4492 if args[i] ~= nil and type(args[i]) == "number" then
4493 sum = sum + args[i]
4494 end
4495 end
4496 return sum
4497end
4498process(1, nil, 3, nil, 5)
4499local a = 1
4500local b = 2
4501print(a + b)
4502Rx.Observable.fromRange(1, 8):filter(function(x)
4503 return x % 2 == 0
4504end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
4505 return value .. '!'
4506end):subscribe(print)
4507local a = 1
4508local b = 2
4509print(a + b)
4510Rx.Observable.fromRange(1, 8):filter(function(x)
4511 return x % 2 == 0
4512end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
4513 return value .. '!'
4514end):subscribe(print)
4515local str = strA .. strB .. strC
4516func(3000, "192.168.1.1")
4517local str = strA .. strB .. strC
4518func(3000, "192.168.1.1")
4519local a <const> = 123
4520local _ <close> = setmetatable({ }, {
4521 __close = function()
4522 return print("Out of scope.")
4523 end
4524})
4525local a, b, c, d
4526local _obj_0 = tb
4527a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
4528Constant = 123
4529local a <const> = 123
4530local _ <close> = setmetatable({ }, {
4531 __close = function()
4532 return print("Out of scope.")
4533 end
4534})
4535local a, b, c, d
4536local _obj_0 = tb
4537a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
4538Constant = 123
4539if tb ~= nil then
4540 tb:func()
4541end
4542if tb ~= nil then
4543 tb:func()
4544end
4545print(1 < 2 and 2 <= 2 and 2 < 3 and 3 == 3 and 3 > 2 and 2 >= 1 and 1 == 1 and 1 < 3 and 3 ~= 5)
4546local a = 5
4547print(1 <= a and a <= 10)
4548local v
4549v = function(x)
4550 print(x)
4551 return x
4552end
4553print((function()
4554 local _cond_0 = v(2)
4555 if not (v(1) < _cond_0) then
4556 return false
4557 else
4558 return _cond_0 <= v(3)
4559 end
4560end)())
4561print((function()
4562 local _cond_0 = v(2)
4563 if not (v(1) > _cond_0) then
4564 return false
4565 else
4566 return _cond_0 <= v(3)
4567 end
4568end)())
4569local tab = { }
4570tab[#tab + 1] = "Value"
4571local tbA = {
4572 1,
4573 2,
4574 3
4575}
4576local tbB = {
4577 4,
4578 5,
4579 6
4580}
4581local _len_0 = #tbA + 1
4582for _index_0 = 1, #tbB do
4583 local _elm_0 = tbB[_index_0]
4584 tbA[_len_0], _len_0 = _elm_0, _len_0 + 1
4585end
4586local parts = {
4587 "shoulders",
4588 "knees"
4589}
4590local lyrics
4591do
4592 local _tab_0 = {
4593 "head"
4594 }
4595 local _idx_0 = 1
4596 for _key_0, _value_0 in pairs(parts) do
4597 if _idx_0 == _key_0 then
4598 _tab_0[#_tab_0 + 1] = _value_0
4599 _idx_0 = _idx_0 + 1
4600 else
4601 _tab_0[_key_0] = _value_0
4602 end
4603 end
4604 _tab_0[#_tab_0 + 1] = "and"
4605 _tab_0[#_tab_0 + 1] = "toes"
4606 lyrics = _tab_0
4607end
4608local copy
4609do
4610 local _tab_0 = { }
4611 local _idx_0 = 1
4612 for _key_0, _value_0 in pairs(other) do
4613 if _idx_0 == _key_0 then
4614 _tab_0[#_tab_0 + 1] = _value_0
4615 _idx_0 = _idx_0 + 1
4616 else
4617 _tab_0[_key_0] = _value_0
4618 end
4619 end
4620 copy = _tab_0
4621end
4622local a = {
4623 1,
4624 2,
4625 3,
4626 x = 1
4627}
4628local b = {
4629 4,
4630 5,
4631 y = 1
4632}
4633local merge
4634local _tab_0 = { }
4635local _idx_0 = 1
4636for _key_0, _value_0 in pairs(a) do
4637 if _idx_0 == _key_0 then
4638 _tab_0[#_tab_0 + 1] = _value_0
4639 _idx_0 = _idx_0 + 1
4640 else
4641 _tab_0[_key_0] = _value_0
4642 end
4643end
4644local _idx_1 = 1
4645for _key_0, _value_0 in pairs(b) do
4646 if _idx_1 == _key_0 then
4647 _tab_0[#_tab_0 + 1] = _value_0
4648 _idx_1 = _idx_1 + 1
4649 else
4650 _tab_0[_key_0] = _value_0
4651 end
4652end
4653merge = _tab_0
4654local last
4655do
4656 local _item_0 = data.items
4657 last = _item_0[#_item_0]
4658end
4659local second_last
4660do
4661 local _item_0 = data.items
4662 second_last = _item_0[#_item_0 - 1]
4663end
4664local _obj_0 = data.items
4665_obj_0[#_obj_0] = 1
4666local mt = { }
4667local add
4668add = function(self, right)
4669 return setmetatable({
4670 value = self.value + right.value
4671 }, mt)
4672end
4673mt.__add = add
4674local a = setmetatable({
4675 value = 1
4676}, mt)
4677local b = setmetatable({
4678 value = 2
4679}, {
4680 __add = add
4681})
4682local c = setmetatable({
4683 value = 3
4684}, {
4685 __add = mt.__add
4686})
4687local d = a + b + c
4688print(d.value)
4689local _ <close> = setmetatable({ }, {
4690 __close = function()
4691 return print("out of scope")
4692 end
4693})
4694local tb = setmetatable({ }, {
4695 ["value"] = 123
4696})
4697getmetatable(tb).__index = getmetatable(tb)
4698print(tb.value)
4699setmetatable(tb, {
4700 __index = {
4701 item = "hello"
4702 }
4703})
4704print(tb.item)
4705local item, new, close, getter
4706do
4707 local _obj_0 = tb
4708 item, new = _obj_0[1], _obj_0.new
4709 do
4710 local _obj_1 = getmetatable(_obj_0)
4711 close, getter = _obj_1.__close, _obj_1.__index
4712 end
4713end
4714print(item, new, close, getter)
4715do
4716 local _obj_0 = func
4717 if _obj_0 ~= nil then
4718 _obj_0()
4719 end
4720end
4721print((function()
4722 local _obj_0 = abc
4723 if _obj_0 ~= nil then
4724 local _obj_1 = _obj_0["hello world"]
4725 if _obj_1 ~= nil then
4726 return _obj_1.xyz
4727 end
4728 return nil
4729 end
4730 return nil
4731end)())
4732local x
4733do
4734 local _obj_0 = tab
4735 if _obj_0 ~= nil then
4736 x = _obj_0.value
4737 end
4738end
4739local len = (function()
4740 local _obj_0 = utf8
4741 if _obj_0 ~= nil then
4742 return _obj_0.len
4743 end
4744 return nil
4745end)() or (function()
4746 local _obj_0 = string
4747 if _obj_0 ~= nil then
4748 return _obj_0.len
4749 end
4750 return nil
4751end)() or function(o)
4752 return #o
4753end
4754if print and (x ~= nil) then
4755 print(x)
4756end
4757local _with_0 = io.open("test.txt", "w")
4758if _with_0 ~= nil then
4759 _with_0:write("hello")
4760 _with_0:close()
4761end
4762print("hello")
4763print(1, 2)
4764print(1, 2, 3)
4765print(render(emit(parse(extract(readFile("example.txt"), language, { }), language))))
4766local a, b, c, d
4767if b ~= nil then
4768 a = b
4769else
4770 if c ~= nil then
4771 a = c
4772 else
4773 a = d
4774 end
4775end
4776func((function()
4777 if a ~= nil then
4778 return a
4779 else
4780 return { }
4781 end
4782end)())
4783if a == nil then
4784 a = false
4785end
4786local list = {
4787 1,
4788 2,
4789 3
4790}
4791func({
4792 1,
4793 2,
4794 3
4795})
4796local f
4797f = function()
4798 return {
4799 1,
4800 2,
4801 3
4802 }
4803end
4804local tb = {
4805 name = "abc",
4806 values = {
4807 "a",
4808 "b",
4809 "c"
4810 },
4811 objects = {
4812 {
4813 name = "a",
4814 value = 1,
4815 func = function(self)
4816 return self.value + 1
4817 end,
4818 tb = {
4819 fieldA = 1
4820 }
4821 },
4822 {
4823 name = "b",
4824 value = 2,
4825 func = function(self)
4826 return self.value + 2
4827 end,
4828 tb = { }
4829 }
4830 }
4831}
4832if tb ~= nil then
4833 tb:func()
4834end
4835if tb ~= nil then
4836 tb:func()
4837end
4838print(1 < 2 and 2 <= 2 and 2 < 3 and 3 == 3 and 3 > 2 and 2 >= 1 and 1 == 1 and 1 < 3 and 3 ~= 5)
4839local a = 5
4840print(1 <= a and a <= 10)
4841local v
4842v = function(x)
4843 print(x)
4844 return x
4845end
4846print((function()
4847 local _cond_0 = v(2)
4848 if not (v(1) < _cond_0) then
4849 return false
4850 else
4851 return _cond_0 <= v(3)
4852 end
4853end)())
4854print((function()
4855 local _cond_0 = v(2)
4856 if not (v(1) > _cond_0) then
4857 return false
4858 else
4859 return _cond_0 <= v(3)
4860 end
4861end)())
4862local tab = { }
4863tab[#tab + 1] = "Value"
4864local tbA = {
4865 1,
4866 2,
4867 3
4868}
4869local tbB = {
4870 4,
4871 5,
4872 6
4873}
4874local _len_0 = #tbA + 1
4875for _index_0 = 1, #tbB do
4876 local _elm_0 = tbB[_index_0]
4877 tbA[_len_0], _len_0 = _elm_0, _len_0 + 1
4878end
4879local parts = {
4880 "shoulders",
4881 "knees"
4882}
4883local lyrics
4884do
4885 local _tab_0 = {
4886 "head"
4887 }
4888 local _idx_0 = 1
4889 for _key_0, _value_0 in pairs(parts) do
4890 if _idx_0 == _key_0 then
4891 _tab_0[#_tab_0 + 1] = _value_0
4892 _idx_0 = _idx_0 + 1
4893 else
4894 _tab_0[_key_0] = _value_0
4895 end
4896 end
4897 _tab_0[#_tab_0 + 1] = "and"
4898 _tab_0[#_tab_0 + 1] = "toes"
4899 lyrics = _tab_0
4900end
4901local copy
4902do
4903 local _tab_0 = { }
4904 local _idx_0 = 1
4905 for _key_0, _value_0 in pairs(other) do
4906 if _idx_0 == _key_0 then
4907 _tab_0[#_tab_0 + 1] = _value_0
4908 _idx_0 = _idx_0 + 1
4909 else
4910 _tab_0[_key_0] = _value_0
4911 end
4912 end
4913 copy = _tab_0
4914end
4915local a = {
4916 1,
4917 2,
4918 3,
4919 x = 1
4920}
4921local b = {
4922 4,
4923 5,
4924 y = 1
4925}
4926local merge
4927local _tab_0 = { }
4928local _idx_0 = 1
4929for _key_0, _value_0 in pairs(a) do
4930 if _idx_0 == _key_0 then
4931 _tab_0[#_tab_0 + 1] = _value_0
4932 _idx_0 = _idx_0 + 1
4933 else
4934 _tab_0[_key_0] = _value_0
4935 end
4936end
4937local _idx_1 = 1
4938for _key_0, _value_0 in pairs(b) do
4939 if _idx_1 == _key_0 then
4940 _tab_0[#_tab_0 + 1] = _value_0
4941 _idx_1 = _idx_1 + 1
4942 else
4943 _tab_0[_key_0] = _value_0
4944 end
4945end
4946merge = _tab_0
4947local last
4948do
4949 local _item_0 = data.items
4950 last = _item_0[#_item_0]
4951end
4952local second_last
4953do
4954 local _item_0 = data.items
4955 second_last = _item_0[#_item_0 - 1]
4956end
4957local _obj_0 = data.items
4958_obj_0[#_obj_0] = 1
4959local mt = { }
4960local add
4961add = function(self, right)
4962 return setmetatable({
4963 value = self.value + right.value
4964 }, mt)
4965end
4966mt.__add = add
4967local a = setmetatable({
4968 value = 1
4969}, mt)
4970local b = setmetatable({
4971 value = 2
4972}, {
4973 __add = add
4974})
4975local c = setmetatable({
4976 value = 3
4977}, {
4978 __add = mt.__add
4979})
4980local d = a + b + c
4981print(d.value)
4982local _ <close> = setmetatable({ }, {
4983 __close = function()
4984 return print("out of scope")
4985 end
4986})
4987local tb = setmetatable({ }, {
4988 ["value"] = 123
4989})
4990getmetatable(tb).__index = getmetatable(tb)
4991print(tb.value)
4992setmetatable(tb, {
4993 __index = {
4994 item = "hello"
4995 }
4996})
4997print(tb.item)
4998local item, new, close, getter
4999do
5000 local _obj_0 = tb
5001 item, new = _obj_0[1], _obj_0.new
5002 do
5003 local _obj_1 = getmetatable(_obj_0)
5004 close, getter = _obj_1.__close, _obj_1.__index
5005 end
5006end
5007print(item, new, close, getter)
5008do
5009 local _obj_0 = func
5010 if _obj_0 ~= nil then
5011 _obj_0()
5012 end
5013end
5014print((function()
5015 local _obj_0 = abc
5016 if _obj_0 ~= nil then
5017 local _obj_1 = _obj_0["hello world"]
5018 if _obj_1 ~= nil then
5019 return _obj_1.xyz
5020 end
5021 return nil
5022 end
5023 return nil
5024end)())
5025local x
5026do
5027 local _obj_0 = tab
5028 if _obj_0 ~= nil then
5029 x = _obj_0.value
5030 end
5031end
5032local len = (function()
5033 local _obj_0 = utf8
5034 if _obj_0 ~= nil then
5035 return _obj_0.len
5036 end
5037 return nil
5038end)() or (function()
5039 local _obj_0 = string
5040 if _obj_0 ~= nil then
5041 return _obj_0.len
5042 end
5043 return nil
5044end)() or function(o)
5045 return #o
5046end
5047if print and (x ~= nil) then
5048 print(x)
5049end
5050local _with_0 = io.open("test.txt", "w")
5051if _with_0 ~= nil then
5052 _with_0:write("hello")
5053 _with_0:close()
5054end
5055print("hello")
5056print(1, 2)
5057print(1, 2, 3)
5058print(render(emit(parse(extract(readFile("example.txt"), language, { }), language))))
5059local a, b, c, d
5060if b ~= nil then
5061 a = b
5062else
5063 if c ~= nil then
5064 a = c
5065 else
5066 a = d
5067 end
5068end
5069func((function()
5070 if a ~= nil then
5071 return a
5072 else
5073 return { }
5074 end
5075end)())
5076if a == nil then
5077 a = false
5078end
5079local list = {
5080 1,
5081 2,
5082 3
5083}
5084func({
5085 1,
5086 2,
5087 3
5088})
5089local f
5090f = function()
5091 return {
5092 1,
5093 2,
5094 3
5095 }
5096end
5097local tb = {
5098 name = "abc",
5099 values = {
5100 "a",
5101 "b",
5102 "c"
5103 },
5104 objects = {
5105 {
5106 name = "a",
5107 value = 1,
5108 func = function(self)
5109 return self.value + 1
5110 end,
5111 tb = {
5112 fieldA = 1
5113 }
5114 },
5115 {
5116 name = "b",
5117 value = 2,
5118 func = function(self)
5119 return self.value + 2
5120 end,
5121 tb = { }
5122 }
5123 }
5124}
5125local some_string = "Here is a string\n that has a line break in it."
5126print("I am " .. tostring(math.random() * 100) .. "% sure.")
5127local integer = 1000000
5128local hex = 0xEFBBBF
5129local binary = 19
5130local str = "key: value\nlist:\n - item1\n - " .. tostring(expr)
5131local fn
5132fn = function()
5133 local str = "foo:\n bar: baz"
5134 return str
5135end
5136local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'"
5137local some_string = "Here is a string\n that has a line break in it."
5138print("I am " .. tostring(math.random() * 100) .. "% sure.")
5139local integer = 1000000
5140local hex = 0xEFBBBF
5141local binary = 19
5142local str = "key: value\nlist:\n - item1\n - " .. tostring(expr)
5143local fn
5144fn = function()
5145 local str = "foo:\n bar: baz"
5146 return str
5147end
5148local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'"
diff --git a/spec/outputs/codes_from_doc_id-id.lua b/spec/outputs/codes_from_doc_id-id.lua
new file mode 100644
index 0000000..0b3670c
--- /dev/null
+++ b/spec/outputs/codes_from_doc_id-id.lua
@@ -0,0 +1,5148 @@
1do
2 local var = "hello"
3 print(var)
4end
5print(var)
6local counter
7do
8 local i = 0
9 counter = function()
10 i = i + 1
11 return i
12 end
13end
14print(counter())
15print(counter())
16local tbl = {
17 key = (function()
18 print("assigning key!")
19 return 1234
20 end)()
21}
22do
23 local var = "hello"
24 print(var)
25end
26print(var)
27local counter
28do
29 local i = 0
30 counter = function()
31 i = i + 1
32 return i
33 end
34end
35print(counter())
36print(counter())
37local tbl = {
38 key = (function()
39 print("assigning key!")
40 return 1234
41 end)()
42}
43if name == "Rob" then
44 print("hello world")
45end
46local _list_0 = items
47for _index_0 = 1, #_list_0 do
48 local item = _list_0[_index_0]
49 print("item: ", item)
50end
51while game:isRunning() do
52 game:update()
53end
54while not reader:eof() do
55 reader:parse_line()
56end
57if name == "Rob" then
58 print("hello world")
59end
60local _list_0 = items
61for _index_0 = 1, #_list_0 do
62 local item = _list_0[_index_0]
63 print("item: ", item)
64end
65while game:isRunning() do
66 game:update()
67end
68while not reader:eof() do
69 reader:parse_line()
70end
71local area = 6.2831853071796 * 5
72print('hello world')
73do
74 assert(item ~= nil)
75end
76local value = item
77if (f1() and f2() and f3()) then
78 print("OK")
79end
80do
81 local funcA
82 funcA = function() end
83end
84local funcA
85funcA = function()
86 return "fail to assign to the Yue macro defined variable"
87end
88do
89local function funcB() end
90end
91local funcB
92funcB = function()
93 return "fail to assign to the Lua macro defined variable"
94end
95do
96-- raw Lua codes insertion
97if cond then
98 print("output")
99end
100end
101print("yuescript")
102print(2)
103print("Valid enum type:", "Static")
104do
105 print(123, "hello")
106end
107do
108 print(123, "hello")
109end
110local area = 6.2831853071796 * 5
111print('hello world')
112do
113 assert(item ~= nil)
114end
115local value = item
116if (f1() and f2() and f3()) then
117 print("OK")
118end
119do
120 local funcA
121 funcA = function() end
122end
123local funcA
124funcA = function()
125 return "fail to assign to the Yue macro defined variable"
126end
127do
128local function funcB() end
129end
130local funcB
131funcB = function()
132 return "fail to assign to the Lua macro defined variable"
133end
134do
135-- raw Lua codes insertion
136if cond then
137 print("output")
138end
139end
140print("yuescript")
141print(2)
142print("Valid enum type:", "Static")
143do
144 print(123, "hello")
145end
146do
147 print(123, "hello")
148end
149do
150 local insert, concat = table.insert, table.concat
151 local C, Ct, Cmt
152 do
153 local _obj_0 = require("lpeg")
154 C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt
155 end
156 local x, y, z
157 do
158 local _obj_0 = require('mymodule')
159 x, y, z = _obj_0.x, _obj_0.y, _obj_0.z
160 end
161 local a, b, c
162 local _obj_0 = require('module')
163 a, b, c = _obj_0.a, _obj_0.b, _obj_0.c
164end
165do
166 local module = require('module')
167 local module_x = require('module_x')
168 local d_a_s_h_e_s = require("d-a-s-h-e-s")
169 local part = require("module.part")
170end
171do
172 local PlayerModule = require("player")
173 local C, Ct, Cmt
174 do
175 local _obj_0 = require("lpeg")
176 C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt
177 end
178 local one, two, ch
179 local _obj_0 = require("export")
180 one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1]
181end
182do
183 local tostring <const> = tostring
184 local concat <const> = table.concat
185 print(concat({
186 "a",
187 tostring(1)
188 }))
189end
190do
191 local print <const> = print
192 local math <const> = math
193 print("hello")
194 math.random(3)
195end
196do
197 local print <const> = print
198 print(FLAG)
199 FLAG = 123
200end
201local _module_0 = { }
202local a, b, c = 1, 2, 3
203_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c
204local cool = "cat"
205_module_0["cool"] = cool
206local What
207if this then
208 What = "abc"
209else
210 What = "def"
211end
212_module_0["What"] = What
213local y
214y = function()
215 local hallo = 3434
216end
217_module_0["y"] = y
218local Something
219local _class_0
220local _base_0 = {
221 umm = "cool"
222}
223if _base_0.__index == nil then
224 _base_0.__index = _base_0
225end
226_class_0 = setmetatable({
227 __init = function() end,
228 __base = _base_0,
229 __name = "Something"
230}, {
231 __index = _base_0,
232 __call = function(cls, ...)
233 local _self_0 = setmetatable({ }, _base_0)
234 cls.__init(_self_0, ...)
235 return _self_0
236 end
237})
238_base_0.__class = _class_0
239Something = _class_0
240_module_0["Something"] = Something
241return _module_0
242local _module_0 = { }
243local loadstring, tolua
244do
245 local _obj_0 = yue
246 loadstring, tolua = _obj_0.loadstring, _obj_0.to_lua
247end
248_module_0["loadstring"], _module_0["tolua"] = loadstring, tolua
249local fieldA = tb.itemA.fieldA
250if fieldA == nil then
251 fieldA = 'default'
252end
253_module_0["fieldA"] = fieldA
254return _module_0
255local _module_0 = setmetatable({ }, { })
256_module_0.itemA = tb
257getmetatable(_module_0).__index = items
258_module_0["a-b-c"] = 123
259return _module_0
260local _module_0 = { }
261local d, e, f = 3, 2, 1
262_module_0[#_module_0 + 1] = d
263_module_0[#_module_0 + 1] = e
264_module_0[#_module_0 + 1] = f
265if this then
266 _module_0[#_module_0 + 1] = 123
267else
268 _module_0[#_module_0 + 1] = 456
269end
270local _with_0 = tmp
271local j = 2000
272_module_0[#_module_0 + 1] = _with_0
273return _module_0
274local _module_0 = nil
275_module_0 = function()
276 print("hello")
277 return 123
278end
279return _module_0
280do
281 local insert, concat = table.insert, table.concat
282 local C, Ct, Cmt
283 do
284 local _obj_0 = require("lpeg")
285 C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt
286 end
287 local x, y, z
288 do
289 local _obj_0 = require('mymodule')
290 x, y, z = _obj_0.x, _obj_0.y, _obj_0.z
291 end
292 local a, b, c
293 local _obj_0 = require('module')
294 a, b, c = _obj_0.a, _obj_0.b, _obj_0.c
295end
296do
297 local module = require('module')
298 local module_x = require('module_x')
299 local d_a_s_h_e_s = require("d-a-s-h-e-s")
300 local part = require("module.part")
301end
302do
303 local PlayerModule = require("player")
304 local C, Ct, Cmt
305 do
306 local _obj_0 = require("lpeg")
307 C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt
308 end
309 local one, two, ch
310 local _obj_0 = require("export")
311 one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1]
312end
313do
314 local tostring <const> = tostring
315 local concat <const> = table.concat
316 print(concat({
317 "a",
318 tostring(1)
319 }))
320end
321do
322 local print <const> = print
323 local math <const> = math
324 print("hello")
325 math.random(3)
326end
327do
328 local print <const> = print
329 print(FLAG)
330 FLAG = 123
331end
332local _module_0 = { }
333local a, b, c = 1, 2, 3
334_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c
335local cool = "cat"
336_module_0["cool"] = cool
337local What
338if this then
339 What = "abc"
340else
341 What = "def"
342end
343_module_0["What"] = What
344local y
345y = function()
346 local hallo = 3434
347end
348_module_0["y"] = y
349local Something
350local _class_0
351local _base_0 = {
352 umm = "cool"
353}
354if _base_0.__index == nil then
355 _base_0.__index = _base_0
356end
357_class_0 = setmetatable({
358 __init = function() end,
359 __base = _base_0,
360 __name = "Something"
361}, {
362 __index = _base_0,
363 __call = function(cls, ...)
364 local _self_0 = setmetatable({ }, _base_0)
365 cls.__init(_self_0, ...)
366 return _self_0
367 end
368})
369_base_0.__class = _class_0
370Something = _class_0
371_module_0["Something"] = Something
372return _module_0
373local _module_0 = { }
374local loadstring, tolua
375do
376 local _obj_0 = yue
377 loadstring, tolua = _obj_0.loadstring, _obj_0.to_lua
378end
379_module_0["loadstring"], _module_0["tolua"] = loadstring, tolua
380local fieldA = tb.itemA.fieldA
381if fieldA == nil then
382 fieldA = 'default'
383end
384_module_0["fieldA"] = fieldA
385return _module_0
386local _module_0 = setmetatable({ }, { })
387_module_0.itemA = tb
388getmetatable(_module_0).__index = items
389_module_0["a-b-c"] = 123
390return _module_0
391local _module_0 = { }
392local d, e, f = 3, 2, 1
393_module_0[#_module_0 + 1] = d
394_module_0[#_module_0 + 1] = e
395_module_0[#_module_0 + 1] = f
396if this then
397 _module_0[#_module_0 + 1] = 123
398else
399 _module_0[#_module_0 + 1] = 456
400end
401local _with_0 = tmp
402local j = 2000
403_module_0[#_module_0 + 1] = _with_0
404return _module_0
405local _module_0 = nil
406_module_0 = function()
407 print("hello")
408 return 123
409end
410return _module_0
411xpcall(function()
412 return func(1, 2, 3)
413end, function(err)
414 return print(yue.traceback(err))
415end)
416local success, result = xpcall(function()
417 return func(1, 2, 3)
418end, function(err)
419 return yue.traceback(err)
420end)
421xpcall(function()
422 return func(1, 2, 3)
423end, function(err)
424 return print(yue.traceback(err))
425end)
426success, result = pcall(function()
427 return func(1, 2, 3)
428end)
429pcall(function()
430 print("trying")
431 return func(1, 2, 3)
432end)
433success, result = xpcall(function()
434 return func(1, 2, 3)
435end, function(err)
436 return print(yue.traceback(err))
437end)
438if success then
439 print(result)
440end
441local a, b, c
442do
443 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function()
444 return func()
445 end)
446 if _ok_0 then
447 a, b, c = _ret_0, _ret_1, _ret_2
448 end
449end
450do
451 local _exp_0 = ((function()
452 return (function(_arg_0, ...)
453 local _ok_0 = _arg_0
454 if _ok_0 then
455 return ...
456 end
457 end)(pcall(function()
458 return func()
459 end))
460 end)())
461 if _exp_0 ~= nil then
462 a = _exp_0
463 else
464 a = "default"
465 end
466end
467f((function()
468 return (function(_arg_0, ...)
469 local _ok_0 = _arg_0
470 if _ok_0 then
471 return ...
472 end
473 end)(pcall(function()
474 return func()
475 end))
476end)())
477f((function()
478 return (function(_arg_0, ...)
479 local _ok_0 = _arg_0
480 if _ok_0 then
481 return ...
482 end
483 end)(xpcall(function()
484 print(123)
485 return func()
486 end, function(e)
487 print(e)
488 return e
489 end))
490end)())
491xpcall(function()
492 return func(1, 2, 3)
493end, function(err)
494 return print(yue.traceback(err))
495end)
496local success, result = xpcall(function()
497 return func(1, 2, 3)
498end, function(err)
499 return yue.traceback(err)
500end)
501xpcall(function()
502 return func(1, 2, 3)
503end, function(err)
504 return print(yue.traceback(err))
505end)
506success, result = pcall(function()
507 return func(1, 2, 3)
508end)
509pcall(function()
510 print("trying")
511 return func(1, 2, 3)
512end)
513success, result = xpcall(function()
514 return func(1, 2, 3)
515end, function(err)
516 return print(yue.traceback(err))
517end)
518if success then
519 print(result)
520end
521local a, b, c
522do
523 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function()
524 return func()
525 end)
526 if _ok_0 then
527 a, b, c = _ret_0, _ret_1, _ret_2
528 end
529end
530do
531 local _exp_0 = ((function()
532 return (function(_arg_0, ...)
533 local _ok_0 = _arg_0
534 if _ok_0 then
535 return ...
536 end
537 end)(pcall(function()
538 return func()
539 end))
540 end)())
541 if _exp_0 ~= nil then
542 a = _exp_0
543 else
544 a = "default"
545 end
546end
547f((function()
548 return (function(_arg_0, ...)
549 local _ok_0 = _arg_0
550 if _ok_0 then
551 return ...
552 end
553 end)(pcall(function()
554 return func()
555 end))
556end)())
557f((function()
558 return (function(_arg_0, ...)
559 local _ok_0 = _arg_0
560 if _ok_0 then
561 return ...
562 end
563 end)(xpcall(function()
564 print(123)
565 return func()
566 end, function(e)
567 print(e)
568 return e
569 end))
570end)())
571local some_values = {
572 1,
573 2,
574 3,
575 4
576}
577local some_values = {
578 name = "Bill",
579 age = 200,
580 ["favorite food"] = "rice"
581}
582local profile = {
583 height = "4 feet",
584 shoe_size = 13,
585 favorite_foods = {
586 "ice cream",
587 "donuts"
588 }
589}
590local values = {
591 1,
592 2,
593 3,
594 4,
595 5,
596 6,
597 7,
598 8,
599 name = "superman",
600 occupation = "crime fighting"
601}
602my_function({
603 dance = "Tango",
604 partner = "none"
605})
606local y = {
607 type = "dog",
608 legs = 4,
609 tails = 1
610}
611local tbl = {
612 ["do"] = "something",
613 ["end"] = "hunger"
614}
615local hair = "golden"
616local height = 200
617local person = {
618 hair = hair,
619 height = height,
620 shoe_size = 40
621}
622print_table({
623 hair = hair,
624 height = height
625})
626local t = {
627 [1 + 2] = "hello",
628 ["hello world"] = true
629}
630local some_values = {
631 1,
632 2,
633 3,
634 4
635}
636local list_with_one_element = {
637 1
638}
639local some_values = {
640 1,
641 2,
642 3,
643 4
644}
645local some_values = {
646 name = "Bill",
647 age = 200,
648 ["favorite food"] = "rice"
649}
650local profile = {
651 height = "4 feet",
652 shoe_size = 13,
653 favorite_foods = {
654 "ice cream",
655 "donuts"
656 }
657}
658local values = {
659 1,
660 2,
661 3,
662 4,
663 5,
664 6,
665 7,
666 8,
667 name = "superman",
668 occupation = "crime fighting"
669}
670my_function({
671 dance = "Tango",
672 partner = "none"
673})
674local y = {
675 type = "dog",
676 legs = 4,
677 tails = 1
678}
679local tbl = {
680 ["do"] = "something",
681 ["end"] = "hunger"
682}
683local hair = "golden"
684local height = 200
685local person = {
686 hair = hair,
687 height = height,
688 shoe_size = 40
689}
690print_table({
691 hair = hair,
692 height = height
693})
694local t = {
695 [1 + 2] = "hello",
696 ["hello world"] = true
697}
698local some_values = {
699 1,
700 2,
701 3,
702 4
703}
704local list_with_one_element = {
705 1
706}
707local items = {
708 1,
709 2,
710 3,
711 4
712}
713local doubled
714local _accum_0 = { }
715local _len_0 = 1
716for i, item in ipairs(items) do
717 _accum_0[_len_0] = item * 2
718 _len_0 = _len_0 + 1
719end
720doubled = _accum_0
721local slice
722local _accum_0 = { }
723local _len_0 = 1
724for i, item in ipairs(items) do
725 if i > 1 and i < 3 then
726 _accum_0[_len_0] = item
727 _len_0 = _len_0 + 1
728 end
729end
730slice = _accum_0
731local doubled
732local _accum_0 = { }
733local _len_0 = 1
734local _list_0 = items
735for _index_0 = 1, #_list_0 do
736 local item = _list_0[_index_0]
737 _accum_0[_len_0] = item * 2
738 _len_0 = _len_0 + 1
739end
740doubled = _accum_0
741local data = {
742 a = {
743 1,
744 2,
745 3
746 },
747 b = {
748 4,
749 5,
750 6
751 }
752}
753local flat
754local _accum_0 = { }
755for k, v in pairs(data) do
756 local _len_0 = #_accum_0 + 1
757 for _index_0 = 1, #v do
758 local _elm_0 = v[_index_0]
759 _accum_0[_len_0], _len_0 = _elm_0, _len_0 + 1
760 end
761end
762flat = _accum_0
763local x_coords = {
764 4,
765 5,
766 6,
767 7
768}
769local y_coords = {
770 9,
771 2,
772 3
773}
774local points
775local _accum_0 = { }
776local _len_0 = 1
777for _index_0 = 1, #x_coords do
778 local x = x_coords[_index_0]
779 for _index_1 = 1, #y_coords do
780 local y = y_coords[_index_1]
781 _accum_0[_len_0] = {
782 x,
783 y
784 }
785 _len_0 = _len_0 + 1
786 end
787end
788points = _accum_0
789local evens
790local _accum_0 = { }
791local _len_0 = 1
792for i = 1, 100 do
793 if i % 2 == 0 then
794 _accum_0[_len_0] = i
795 _len_0 = _len_0 + 1
796 end
797end
798evens = _accum_0
799local thing = {
800 color = "red",
801 name = "fast",
802 width = 123
803}
804local thing_copy
805local _tbl_0 = { }
806for k, v in pairs(thing) do
807 _tbl_0[k] = v
808end
809thing_copy = _tbl_0
810local no_color
811local _tbl_0 = { }
812for k, v in pairs(thing) do
813 if k ~= "color" then
814 _tbl_0[k] = v
815 end
816end
817no_color = _tbl_0
818local numbers = {
819 1,
820 2,
821 3,
822 4
823}
824local sqrts
825local _tbl_0 = { }
826for _index_0 = 1, #numbers do
827 local i = numbers[_index_0]
828 _tbl_0[i] = math.sqrt(i)
829end
830sqrts = _tbl_0
831local tuples = {
832 {
833 "hello",
834 "world"
835 },
836 {
837 "foo",
838 "bar"
839 }
840}
841local tbl
842local _tbl_0 = { }
843for _index_0 = 1, #tuples do
844 local tuple = tuples[_index_0]
845 local _key_0, _val_0 = unpack(tuple)
846 _tbl_0[_key_0] = _val_0
847end
848tbl = _tbl_0
849local slice
850local _accum_0 = { }
851local _len_0 = 1
852local _list_0 = items
853for _index_0 = 1, 5 do
854 local item = _list_0[_index_0]
855 _accum_0[_len_0] = item
856 _len_0 = _len_0 + 1
857end
858slice = _accum_0
859local slice
860local _accum_0 = { }
861local _len_0 = 1
862local _list_0 = items
863local _max_0 = #_list_0
864for _index_0 = 2, _max_0 do
865 local item = _list_0[_index_0]
866 _accum_0[_len_0] = item
867 _len_0 = _len_0 + 1
868end
869slice = _accum_0
870local slice
871local _accum_0 = { }
872local _len_0 = 1
873local _list_0 = items
874local _max_0 = #_list_0
875for _index_0 = 1, _max_0, 2 do
876 local item = _list_0[_index_0]
877 _accum_0[_len_0] = item
878 _len_0 = _len_0 + 1
879end
880slice = _accum_0
881local slice
882local _accum_0 = { }
883local _len_0 = 1
884local _list_0 = items
885local _min_0 = #_list_0 + -4 + 1
886local _max_0 = #_list_0 + -1 + 1
887for _index_0 = _min_0, _max_0 do
888 local item = _list_0[_index_0]
889 _accum_0[_len_0] = item
890 _len_0 = _len_0 + 1
891end
892slice = _accum_0
893local reverse_slice
894local _accum_0 = { }
895local _len_0 = 1
896local _list_0 = items
897local _min_0 = #_list_0 + -1 + 1
898for _index_0 = _min_0, 1, -1 do
899 local item = _list_0[_index_0]
900 _accum_0[_len_0] = item
901 _len_0 = _len_0 + 1
902end
903reverse_slice = _accum_0
904local sub_list
905do
906 local _accum_0 = { }
907 local _len_0 = 1
908 local _list_0 = items
909 for _index_0 = 2, 4 do
910 local _item_0 = _list_0[_index_0]
911 _accum_0[_len_0] = _item_0
912 _len_0 = _len_0 + 1
913 end
914 sub_list = _accum_0
915end
916local last_four_items
917local _accum_0 = { }
918local _len_0 = 1
919local _list_0 = items
920local _min_0 = #_list_0 + -4 + 1
921local _max_0 = #_list_0 + -1 + 1
922for _index_0 = _min_0, _max_0 do
923 local _item_0 = _list_0[_index_0]
924 _accum_0[_len_0] = _item_0
925 _len_0 = _len_0 + 1
926end
927last_four_items = _accum_0
928local items = {
929 1,
930 2,
931 3,
932 4
933}
934local doubled
935local _accum_0 = { }
936local _len_0 = 1
937for i, item in ipairs(items) do
938 _accum_0[_len_0] = item * 2
939 _len_0 = _len_0 + 1
940end
941doubled = _accum_0
942local slice
943local _accum_0 = { }
944local _len_0 = 1
945for i, item in ipairs(items) do
946 if i > 1 and i < 3 then
947 _accum_0[_len_0] = item
948 _len_0 = _len_0 + 1
949 end
950end
951slice = _accum_0
952local doubled
953local _accum_0 = { }
954local _len_0 = 1
955local _list_0 = items
956for _index_0 = 1, #_list_0 do
957 local item = _list_0[_index_0]
958 _accum_0[_len_0] = item * 2
959 _len_0 = _len_0 + 1
960end
961doubled = _accum_0
962local data = {
963 a = {
964 1,
965 2,
966 3
967 },
968 b = {
969 4,
970 5,
971 6
972 }
973}
974local flat
975local _accum_0 = { }
976for k, v in pairs(data) do
977 local _len_0 = #_accum_0 + 1
978 for _index_0 = 1, #v do
979 local _elm_0 = v[_index_0]
980 _accum_0[_len_0], _len_0 = _elm_0, _len_0 + 1
981 end
982end
983flat = _accum_0
984local x_coords = {
985 4,
986 5,
987 6,
988 7
989}
990local y_coords = {
991 9,
992 2,
993 3
994}
995local points
996local _accum_0 = { }
997local _len_0 = 1
998for _index_0 = 1, #x_coords do
999 local x = x_coords[_index_0]
1000 for _index_1 = 1, #y_coords do
1001 local y = y_coords[_index_1]
1002 _accum_0[_len_0] = {
1003 x,
1004 y
1005 }
1006 _len_0 = _len_0 + 1
1007 end
1008end
1009points = _accum_0
1010local evens
1011local _accum_0 = { }
1012local _len_0 = 1
1013for i = 1, 100 do
1014 if i % 2 == 0 then
1015 _accum_0[_len_0] = i
1016 _len_0 = _len_0 + 1
1017 end
1018end
1019evens = _accum_0
1020local thing = {
1021 color = "red",
1022 name = "fast",
1023 width = 123
1024}
1025local thing_copy
1026local _tbl_0 = { }
1027for k, v in pairs(thing) do
1028 _tbl_0[k] = v
1029end
1030thing_copy = _tbl_0
1031local no_color
1032local _tbl_0 = { }
1033for k, v in pairs(thing) do
1034 if k ~= "color" then
1035 _tbl_0[k] = v
1036 end
1037end
1038no_color = _tbl_0
1039local numbers = {
1040 1,
1041 2,
1042 3,
1043 4
1044}
1045local sqrts
1046local _tbl_0 = { }
1047for _index_0 = 1, #numbers do
1048 local i = numbers[_index_0]
1049 _tbl_0[i] = math.sqrt(i)
1050end
1051sqrts = _tbl_0
1052local tuples = {
1053 {
1054 "hello",
1055 "world"
1056 },
1057 {
1058 "foo",
1059 "bar"
1060 }
1061}
1062local tbl
1063local _tbl_0 = { }
1064for _index_0 = 1, #tuples do
1065 local tuple = tuples[_index_0]
1066 local _key_0, _val_0 = unpack(tuple)
1067 _tbl_0[_key_0] = _val_0
1068end
1069tbl = _tbl_0
1070local slice
1071local _accum_0 = { }
1072local _len_0 = 1
1073local _list_0 = items
1074for _index_0 = 1, 5 do
1075 local item = _list_0[_index_0]
1076 _accum_0[_len_0] = item
1077 _len_0 = _len_0 + 1
1078end
1079slice = _accum_0
1080local slice
1081local _accum_0 = { }
1082local _len_0 = 1
1083local _list_0 = items
1084local _max_0 = #_list_0
1085for _index_0 = 2, _max_0 do
1086 local item = _list_0[_index_0]
1087 _accum_0[_len_0] = item
1088 _len_0 = _len_0 + 1
1089end
1090slice = _accum_0
1091local slice
1092local _accum_0 = { }
1093local _len_0 = 1
1094local _list_0 = items
1095local _max_0 = #_list_0
1096for _index_0 = 1, _max_0, 2 do
1097 local item = _list_0[_index_0]
1098 _accum_0[_len_0] = item
1099 _len_0 = _len_0 + 1
1100end
1101slice = _accum_0
1102local slice
1103local _accum_0 = { }
1104local _len_0 = 1
1105local _list_0 = items
1106local _min_0 = #_list_0 + -4 + 1
1107local _max_0 = #_list_0 + -1 + 1
1108for _index_0 = _min_0, _max_0 do
1109 local item = _list_0[_index_0]
1110 _accum_0[_len_0] = item
1111 _len_0 = _len_0 + 1
1112end
1113slice = _accum_0
1114local reverse_slice
1115local _accum_0 = { }
1116local _len_0 = 1
1117local _list_0 = items
1118local _min_0 = #_list_0 + -1 + 1
1119for _index_0 = _min_0, 1, -1 do
1120 local item = _list_0[_index_0]
1121 _accum_0[_len_0] = item
1122 _len_0 = _len_0 + 1
1123end
1124reverse_slice = _accum_0
1125local sub_list
1126do
1127 local _accum_0 = { }
1128 local _len_0 = 1
1129 local _list_0 = items
1130 for _index_0 = 2, 4 do
1131 local _item_0 = _list_0[_index_0]
1132 _accum_0[_len_0] = _item_0
1133 _len_0 = _len_0 + 1
1134 end
1135 sub_list = _accum_0
1136end
1137local last_four_items
1138local _accum_0 = { }
1139local _len_0 = 1
1140local _list_0 = items
1141local _min_0 = #_list_0 + -4 + 1
1142local _max_0 = #_list_0 + -1 + 1
1143for _index_0 = _min_0, _max_0 do
1144 local _item_0 = _list_0[_index_0]
1145 _accum_0[_len_0] = _item_0
1146 _len_0 = _len_0 + 1
1147end
1148last_four_items = _accum_0
1149local Inventory
1150local _class_0
1151local _base_0 = {
1152 add_item = function(self, name)
1153 if self.items[name] then
1154 local _obj_0 = self.items
1155 _obj_0[name] = _obj_0[name] + 1
1156 else
1157 self.items[name] = 1
1158 end
1159 end
1160}
1161if _base_0.__index == nil then
1162 _base_0.__index = _base_0
1163end
1164_class_0 = setmetatable({
1165 __init = function(self)
1166 self.items = { }
1167 end,
1168 __base = _base_0,
1169 __name = "Inventory"
1170}, {
1171 __index = _base_0,
1172 __call = function(cls, ...)
1173 local _self_0 = setmetatable({ }, _base_0)
1174 cls.__init(_self_0, ...)
1175 return _self_0
1176 end
1177})
1178_base_0.__class = _class_0
1179Inventory = _class_0
1180local inv = Inventory()
1181inv:add_item("t-shirt")
1182inv:add_item("pants")
1183local Person
1184do
1185 local _class_0
1186 local _base_0 = {
1187 clothes = { },
1188 give_item = function(self, name)
1189 return table.insert(self.clothes, name)
1190 end
1191 }
1192 if _base_0.__index == nil then
1193 _base_0.__index = _base_0
1194 end
1195 _class_0 = setmetatable({
1196 __init = function() end,
1197 __base = _base_0,
1198 __name = "Person"
1199 }, {
1200 __index = _base_0,
1201 __call = function(cls, ...)
1202 local _self_0 = setmetatable({ }, _base_0)
1203 cls.__init(_self_0, ...)
1204 return _self_0
1205 end
1206 })
1207 _base_0.__class = _class_0
1208 Person = _class_0
1209end
1210local a = Person()
1211local b = Person()
1212a:give_item("pants")
1213b:give_item("shirt")
1214local _list_0 = a.clothes
1215for _index_0 = 1, #_list_0 do
1216 local item = _list_0[_index_0]
1217 print(item)
1218end
1219local Person
1220local _class_0
1221local _base_0 = { }
1222if _base_0.__index == nil then
1223 _base_0.__index = _base_0
1224end
1225_class_0 = setmetatable({
1226 __init = function(self)
1227 self.clothes = { }
1228 end,
1229 __base = _base_0,
1230 __name = "Person"
1231}, {
1232 __index = _base_0,
1233 __call = function(cls, ...)
1234 local _self_0 = setmetatable({ }, _base_0)
1235 cls.__init(_self_0, ...)
1236 return _self_0
1237 end
1238})
1239_base_0.__class = _class_0
1240Person = _class_0
1241local BackPack
1242local _class_0
1243local _parent_0 = Inventory
1244local _base_0 = {
1245 size = 10,
1246 add_item = function(self, name)
1247 if #self.items > size then
1248 error("backpack is full")
1249 end
1250 return _class_0.__parent.__base.add_item(self, name)
1251 end
1252}
1253for _key_0, _val_0 in pairs(_parent_0.__base) do
1254 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
1255 _base_0[_key_0] = _val_0
1256 end
1257end
1258if _base_0.__index == nil then
1259 _base_0.__index = _base_0
1260end
1261setmetatable(_base_0, _parent_0.__base)
1262_class_0 = setmetatable({
1263 __init = function(self, ...)
1264 return _class_0.__parent.__init(self, ...)
1265 end,
1266 __base = _base_0,
1267 __name = "BackPack",
1268 __parent = _parent_0
1269}, {
1270 __index = function(cls, name)
1271 local val = rawget(_base_0, name)
1272 if val == nil then
1273 local parent = rawget(cls, "__parent")
1274 if parent then
1275 return parent[name]
1276 end
1277 else
1278 return val
1279 end
1280 end,
1281 __call = function(cls, ...)
1282 local _self_0 = setmetatable({ }, _base_0)
1283 cls.__init(_self_0, ...)
1284 return _self_0
1285 end
1286})
1287_base_0.__class = _class_0
1288if _parent_0.__inherited then
1289 _parent_0.__inherited(_parent_0, _class_0)
1290end
1291BackPack = _class_0
1292local Shelf
1293do
1294 local _class_0
1295 local _base_0 = { }
1296 if _base_0.__index == nil then
1297 _base_0.__index = _base_0
1298 end
1299 _class_0 = setmetatable({
1300 __init = function() end,
1301 __base = _base_0,
1302 __name = "Shelf"
1303 }, {
1304 __index = _base_0,
1305 __call = function(cls, ...)
1306 local _self_0 = setmetatable({ }, _base_0)
1307 cls.__init(_self_0, ...)
1308 return _self_0
1309 end
1310 })
1311 _base_0.__class = _class_0
1312 local self = _class_0;
1313 self.__inherited = function(self, child)
1314 return print(self.__name, "was inherited by", child.__name)
1315 end
1316 Shelf = _class_0
1317end
1318local Cupboard
1319local _class_0
1320local _parent_0 = Shelf
1321local _base_0 = { }
1322for _key_0, _val_0 in pairs(_parent_0.__base) do
1323 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
1324 _base_0[_key_0] = _val_0
1325 end
1326end
1327if _base_0.__index == nil then
1328 _base_0.__index = _base_0
1329end
1330setmetatable(_base_0, _parent_0.__base)
1331_class_0 = setmetatable({
1332 __init = function(self, ...)
1333 return _class_0.__parent.__init(self, ...)
1334 end,
1335 __base = _base_0,
1336 __name = "Cupboard",
1337 __parent = _parent_0
1338}, {
1339 __index = function(cls, name)
1340 local val = rawget(_base_0, name)
1341 if val == nil then
1342 local parent = rawget(cls, "__parent")
1343 if parent then
1344 return parent[name]
1345 end
1346 else
1347 return val
1348 end
1349 end,
1350 __call = function(cls, ...)
1351 local _self_0 = setmetatable({ }, _base_0)
1352 cls.__init(_self_0, ...)
1353 return _self_0
1354 end
1355})
1356_base_0.__class = _class_0
1357if _parent_0.__inherited then
1358 _parent_0.__inherited(_parent_0, _class_0)
1359end
1360Cupboard = _class_0
1361local MyClass
1362local _class_0
1363local _parent_0 = ParentClass
1364local _base_0 = {
1365 a_method = function(self)
1366 _class_0.__parent.__base.a_method(self, "hello", "world")
1367 _class_0.__parent.a_method(self, "hello", "world")
1368 _class_0.__parent.a_method(self, "hello", "world")
1369 return assert(_class_0.__parent == ParentClass)
1370 end
1371}
1372for _key_0, _val_0 in pairs(_parent_0.__base) do
1373 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
1374 _base_0[_key_0] = _val_0
1375 end
1376end
1377if _base_0.__index == nil then
1378 _base_0.__index = _base_0
1379end
1380setmetatable(_base_0, _parent_0.__base)
1381_class_0 = setmetatable({
1382 __init = function(self, ...)
1383 return _class_0.__parent.__init(self, ...)
1384 end,
1385 __base = _base_0,
1386 __name = "MyClass",
1387 __parent = _parent_0
1388}, {
1389 __index = function(cls, name)
1390 local val = rawget(_base_0, name)
1391 if val == nil then
1392 local parent = rawget(cls, "__parent")
1393 if parent then
1394 return parent[name]
1395 end
1396 else
1397 return val
1398 end
1399 end,
1400 __call = function(cls, ...)
1401 local _self_0 = setmetatable({ }, _base_0)
1402 cls.__init(_self_0, ...)
1403 return _self_0
1404 end
1405})
1406_base_0.__class = _class_0
1407if _parent_0.__inherited then
1408 _parent_0.__inherited(_parent_0, _class_0)
1409end
1410MyClass = _class_0
1411local b = BackPack()
1412assert(b.__class == BackPack)
1413print(BackPack.size)
1414print(BackPack.__name)
1415local Things
1416do
1417 local _class_0
1418 local _base_0 = { }
1419 if _base_0.__index == nil then
1420 _base_0.__index = _base_0
1421 end
1422 _class_0 = setmetatable({
1423 __init = function() end,
1424 __base = _base_0,
1425 __name = "Things"
1426 }, {
1427 __index = _base_0,
1428 __call = function(cls, ...)
1429 local _self_0 = setmetatable({ }, _base_0)
1430 cls.__init(_self_0, ...)
1431 return _self_0
1432 end
1433 })
1434 _base_0.__class = _class_0
1435 local self = _class_0;
1436 self.some_func = function(self)
1437 return print("Hello from", self.__name)
1438 end
1439 Things = _class_0
1440end
1441Things:some_func()
1442assert(Things().some_func == nil)
1443local Counter
1444do
1445 local _class_0
1446 local _base_0 = { }
1447 if _base_0.__index == nil then
1448 _base_0.__index = _base_0
1449 end
1450 _class_0 = setmetatable({
1451 __init = function(self)
1452 self.__class.count = self.__class.count + 1
1453 end,
1454 __base = _base_0,
1455 __name = "Counter"
1456 }, {
1457 __index = _base_0,
1458 __call = function(cls, ...)
1459 local _self_0 = setmetatable({ }, _base_0)
1460 cls.__init(_self_0, ...)
1461 return _self_0
1462 end
1463 })
1464 _base_0.__class = _class_0
1465 local self = _class_0;
1466 self.count = 0
1467 Counter = _class_0
1468end
1469Counter()
1470Counter()
1471print(Counter.count)
1472self.__class:hello(1, 2, 3, 4)
1473local Things
1474local _class_0
1475local _base_0 = { }
1476if _base_0.__index == nil then
1477 _base_0.__index = _base_0
1478end
1479_class_0 = setmetatable({
1480 __init = function() end,
1481 __base = _base_0,
1482 __name = "Things"
1483}, {
1484 __index = _base_0,
1485 __call = function(cls, ...)
1486 local _self_0 = setmetatable({ }, _base_0)
1487 cls.__init(_self_0, ...)
1488 return _self_0
1489 end
1490})
1491_base_0.__class = _class_0
1492local self = _class_0;
1493self.class_var = "hello world"
1494Things = _class_0
1495local MoreThings
1496local _class_0
1497local secret, log
1498local _base_0 = {
1499 some_method = function(self)
1500 return log("hello world: " .. secret)
1501 end
1502}
1503if _base_0.__index == nil then
1504 _base_0.__index = _base_0
1505end
1506_class_0 = setmetatable({
1507 __init = function() end,
1508 __base = _base_0,
1509 __name = "MoreThings"
1510}, {
1511 __index = _base_0,
1512 __call = function(cls, ...)
1513 local _self_0 = setmetatable({ }, _base_0)
1514 cls.__init(_self_0, ...)
1515 return _self_0
1516 end
1517})
1518_base_0.__class = _class_0
1519local self = _class_0;
1520secret = 123
1521log = function(msg)
1522 return print("LOG:", msg)
1523end
1524MoreThings = _class_0
1525assert(self == self)
1526assert(self.__class == self.__class)
1527local some_instance_method
1528some_instance_method = function(self, ...)
1529 return self.__class(...)
1530end
1531local Something
1532do
1533 local _class_0
1534 local _base_0 = { }
1535 if _base_0.__index == nil then
1536 _base_0.__index = _base_0
1537 end
1538 _class_0 = setmetatable({
1539 __init = function(self, foo, bar, biz, baz)
1540 self.foo = foo
1541 self.bar = bar
1542 self.__class.biz = biz
1543 self.__class.baz = baz
1544 end,
1545 __base = _base_0,
1546 __name = "Something"
1547 }, {
1548 __index = _base_0,
1549 __call = function(cls, ...)
1550 local _self_0 = setmetatable({ }, _base_0)
1551 cls.__init(_self_0, ...)
1552 return _self_0
1553 end
1554 })
1555 _base_0.__class = _class_0
1556 Something = _class_0
1557end
1558local _class_0
1559local _base_0 = { }
1560if _base_0.__index == nil then
1561 _base_0.__index = _base_0
1562end
1563_class_0 = setmetatable({
1564 __init = function(self, foo, bar, biz, baz)
1565 self.foo = foo
1566 self.bar = bar
1567 self.__class.biz = biz
1568 self.__class.baz = baz
1569 end,
1570 __base = _base_0,
1571 __name = "Something"
1572}, {
1573 __index = _base_0,
1574 __call = function(cls, ...)
1575 local _self_0 = setmetatable({ }, _base_0)
1576 cls.__init(_self_0, ...)
1577 return _self_0
1578 end
1579})
1580_base_0.__class = _class_0
1581Something = _class_0
1582local new
1583new = function(self, fieldA, fieldB)
1584 self.fieldA = fieldA
1585 self.fieldB = fieldB
1586 return self
1587end
1588local obj = new({ }, 123, "abc")
1589print(obj)
1590local x
1591local Bucket
1592local _class_0
1593local _base_0 = {
1594 drops = 0,
1595 add_drop = function(self)
1596 self.drops = self.drops + 1
1597 end
1598}
1599if _base_0.__index == nil then
1600 _base_0.__index = _base_0
1601end
1602_class_0 = setmetatable({
1603 __init = function() end,
1604 __base = _base_0,
1605 __name = "Bucket"
1606}, {
1607 __index = _base_0,
1608 __call = function(cls, ...)
1609 local _self_0 = setmetatable({ }, _base_0)
1610 cls.__init(_self_0, ...)
1611 return _self_0
1612 end
1613})
1614_base_0.__class = _class_0
1615Bucket = _class_0
1616x = _class_0
1617local BigBucket
1618do
1619 local _class_0
1620 local _parent_0 = Bucket
1621 local _base_0 = {
1622 add_drop = function(self)
1623 self.drops = self.drops + 10
1624 end
1625 }
1626 for _key_0, _val_0 in pairs(_parent_0.__base) do
1627 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
1628 _base_0[_key_0] = _val_0
1629 end
1630 end
1631 if _base_0.__index == nil then
1632 _base_0.__index = _base_0
1633 end
1634 setmetatable(_base_0, _parent_0.__base)
1635 _class_0 = setmetatable({
1636 __init = function(self, ...)
1637 return _class_0.__parent.__init(self, ...)
1638 end,
1639 __base = _base_0,
1640 __name = "BigBucket",
1641 __parent = _parent_0
1642 }, {
1643 __index = function(cls, name)
1644 local val = rawget(_base_0, name)
1645 if val == nil then
1646 local parent = rawget(cls, "__parent")
1647 if parent then
1648 return parent[name]
1649 end
1650 else
1651 return val
1652 end
1653 end,
1654 __call = function(cls, ...)
1655 local _self_0 = setmetatable({ }, _base_0)
1656 cls.__init(_self_0, ...)
1657 return _self_0
1658 end
1659 })
1660 _base_0.__class = _class_0
1661 if _parent_0.__inherited then
1662 _parent_0.__inherited(_parent_0, _class_0)
1663 end
1664 BigBucket = _class_0
1665end
1666assert(Bucket.__name == "BigBucket")
1667local x
1668local _class_0
1669local _base_0 = { }
1670if _base_0.__index == nil then
1671 _base_0.__index = _base_0
1672end
1673_class_0 = setmetatable({
1674 __init = function() end,
1675 __base = _base_0,
1676 __name = "x"
1677}, {
1678 __index = _base_0,
1679 __call = function(cls, ...)
1680 local _self_0 = setmetatable({ }, _base_0)
1681 cls.__init(_self_0, ...)
1682 return _self_0
1683 end
1684})
1685_base_0.__class = _class_0
1686x = _class_0
1687local MyIndex = {
1688 __index = {
1689 var = 1
1690 }
1691}
1692local X
1693do
1694 local _class_0
1695 local _base_0 = {
1696 func = function(self)
1697 return print(123)
1698 end
1699 }
1700 local _list_0 = {
1701 MyIndex
1702 }
1703 for _index_0 = 1, #_list_0 do
1704 local _item_0 = _list_0[_index_0]
1705 local _cls_0, _mixin_0 = (_item_0.__base ~= nil), _item_0.__base or _item_0
1706 for _key_0, _val_0 in pairs(_mixin_0) do
1707 if _base_0[_key_0] == nil and (not _cls_0 or not _key_0:match("^__")) then
1708 _base_0[_key_0] = _val_0
1709 end
1710 end
1711 end
1712 if _base_0.__index == nil then
1713 _base_0.__index = _base_0
1714 end
1715 _class_0 = setmetatable({
1716 __init = function() end,
1717 __base = _base_0,
1718 __name = "X"
1719 }, {
1720 __index = _base_0,
1721 __call = function(cls, ...)
1722 local _self_0 = setmetatable({ }, _base_0)
1723 cls.__init(_self_0, ...)
1724 return _self_0
1725 end
1726 })
1727 _base_0.__class = _class_0
1728 X = _class_0
1729end
1730local x = X()
1731print(x.var)
1732local Y
1733do
1734 local _class_0
1735 local _base_0 = { }
1736 local _list_0 = {
1737 X
1738 }
1739 for _index_0 = 1, #_list_0 do
1740 local _item_0 = _list_0[_index_0]
1741 local _cls_0, _mixin_0 = (_item_0.__base ~= nil), _item_0.__base or _item_0
1742 for _key_0, _val_0 in pairs(_mixin_0) do
1743 if _base_0[_key_0] == nil and (not _cls_0 or not _key_0:match("^__")) then
1744 _base_0[_key_0] = _val_0
1745 end
1746 end
1747 end
1748 if _base_0.__index == nil then
1749 _base_0.__index = _base_0
1750 end
1751 _class_0 = setmetatable({
1752 __init = function() end,
1753 __base = _base_0,
1754 __name = "Y"
1755 }, {
1756 __index = _base_0,
1757 __call = function(cls, ...)
1758 local _self_0 = setmetatable({ }, _base_0)
1759 cls.__init(_self_0, ...)
1760 return _self_0
1761 end
1762 })
1763 _base_0.__class = _class_0
1764 Y = _class_0
1765end
1766local y = Y()
1767y:func()
1768assert(y.__class.__parent ~= X)
1769local Inventory
1770local _class_0
1771local _base_0 = {
1772 add_item = function(self, name)
1773 if self.items[name] then
1774 local _obj_0 = self.items
1775 _obj_0[name] = _obj_0[name] + 1
1776 else
1777 self.items[name] = 1
1778 end
1779 end
1780}
1781if _base_0.__index == nil then
1782 _base_0.__index = _base_0
1783end
1784_class_0 = setmetatable({
1785 __init = function(self)
1786 self.items = { }
1787 end,
1788 __base = _base_0,
1789 __name = "Inventory"
1790}, {
1791 __index = _base_0,
1792 __call = function(cls, ...)
1793 local _self_0 = setmetatable({ }, _base_0)
1794 cls.__init(_self_0, ...)
1795 return _self_0
1796 end
1797})
1798_base_0.__class = _class_0
1799Inventory = _class_0
1800local inv = Inventory()
1801inv:add_item("t-shirt")
1802inv:add_item("pants")
1803local Person
1804do
1805 local _class_0
1806 local _base_0 = {
1807 clothes = { },
1808 give_item = function(self, name)
1809 return table.insert(self.clothes, name)
1810 end
1811 }
1812 if _base_0.__index == nil then
1813 _base_0.__index = _base_0
1814 end
1815 _class_0 = setmetatable({
1816 __init = function() end,
1817 __base = _base_0,
1818 __name = "Person"
1819 }, {
1820 __index = _base_0,
1821 __call = function(cls, ...)
1822 local _self_0 = setmetatable({ }, _base_0)
1823 cls.__init(_self_0, ...)
1824 return _self_0
1825 end
1826 })
1827 _base_0.__class = _class_0
1828 Person = _class_0
1829end
1830local a = Person()
1831local b = Person()
1832a:give_item("pants")
1833b:give_item("shirt")
1834local _list_0 = a.clothes
1835for _index_0 = 1, #_list_0 do
1836 local item = _list_0[_index_0]
1837 print(item)
1838end
1839local Person
1840local _class_0
1841local _base_0 = { }
1842if _base_0.__index == nil then
1843 _base_0.__index = _base_0
1844end
1845_class_0 = setmetatable({
1846 __init = function(self)
1847 self.clothes = { }
1848 end,
1849 __base = _base_0,
1850 __name = "Person"
1851}, {
1852 __index = _base_0,
1853 __call = function(cls, ...)
1854 local _self_0 = setmetatable({ }, _base_0)
1855 cls.__init(_self_0, ...)
1856 return _self_0
1857 end
1858})
1859_base_0.__class = _class_0
1860Person = _class_0
1861local BackPack
1862local _class_0
1863local _parent_0 = Inventory
1864local _base_0 = {
1865 size = 10,
1866 add_item = function(self, name)
1867 if #self.items > size then
1868 error("backpack is full")
1869 end
1870 return _class_0.__parent.__base.add_item(self, name)
1871 end
1872}
1873for _key_0, _val_0 in pairs(_parent_0.__base) do
1874 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
1875 _base_0[_key_0] = _val_0
1876 end
1877end
1878if _base_0.__index == nil then
1879 _base_0.__index = _base_0
1880end
1881setmetatable(_base_0, _parent_0.__base)
1882_class_0 = setmetatable({
1883 __init = function(self, ...)
1884 return _class_0.__parent.__init(self, ...)
1885 end,
1886 __base = _base_0,
1887 __name = "BackPack",
1888 __parent = _parent_0
1889}, {
1890 __index = function(cls, name)
1891 local val = rawget(_base_0, name)
1892 if val == nil then
1893 local parent = rawget(cls, "__parent")
1894 if parent then
1895 return parent[name]
1896 end
1897 else
1898 return val
1899 end
1900 end,
1901 __call = function(cls, ...)
1902 local _self_0 = setmetatable({ }, _base_0)
1903 cls.__init(_self_0, ...)
1904 return _self_0
1905 end
1906})
1907_base_0.__class = _class_0
1908if _parent_0.__inherited then
1909 _parent_0.__inherited(_parent_0, _class_0)
1910end
1911BackPack = _class_0
1912local Shelf
1913do
1914 local _class_0
1915 local _base_0 = { }
1916 if _base_0.__index == nil then
1917 _base_0.__index = _base_0
1918 end
1919 _class_0 = setmetatable({
1920 __init = function() end,
1921 __base = _base_0,
1922 __name = "Shelf"
1923 }, {
1924 __index = _base_0,
1925 __call = function(cls, ...)
1926 local _self_0 = setmetatable({ }, _base_0)
1927 cls.__init(_self_0, ...)
1928 return _self_0
1929 end
1930 })
1931 _base_0.__class = _class_0
1932 local self = _class_0;
1933 self.__inherited = function(self, child)
1934 return print(self.__name, "was inherited by", child.__name)
1935 end
1936 Shelf = _class_0
1937end
1938local Cupboard
1939local _class_0
1940local _parent_0 = Shelf
1941local _base_0 = { }
1942for _key_0, _val_0 in pairs(_parent_0.__base) do
1943 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
1944 _base_0[_key_0] = _val_0
1945 end
1946end
1947if _base_0.__index == nil then
1948 _base_0.__index = _base_0
1949end
1950setmetatable(_base_0, _parent_0.__base)
1951_class_0 = setmetatable({
1952 __init = function(self, ...)
1953 return _class_0.__parent.__init(self, ...)
1954 end,
1955 __base = _base_0,
1956 __name = "Cupboard",
1957 __parent = _parent_0
1958}, {
1959 __index = function(cls, name)
1960 local val = rawget(_base_0, name)
1961 if val == nil then
1962 local parent = rawget(cls, "__parent")
1963 if parent then
1964 return parent[name]
1965 end
1966 else
1967 return val
1968 end
1969 end,
1970 __call = function(cls, ...)
1971 local _self_0 = setmetatable({ }, _base_0)
1972 cls.__init(_self_0, ...)
1973 return _self_0
1974 end
1975})
1976_base_0.__class = _class_0
1977if _parent_0.__inherited then
1978 _parent_0.__inherited(_parent_0, _class_0)
1979end
1980Cupboard = _class_0
1981local MyClass
1982local _class_0
1983local _parent_0 = ParentClass
1984local _base_0 = {
1985 a_method = function(self)
1986 _class_0.__parent.__base.a_method(self, "hello", "world")
1987 _class_0.__parent.a_method(self, "hello", "world")
1988 _class_0.__parent.a_method(self, "hello", "world")
1989 return assert(_class_0.__parent == ParentClass)
1990 end
1991}
1992for _key_0, _val_0 in pairs(_parent_0.__base) do
1993 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
1994 _base_0[_key_0] = _val_0
1995 end
1996end
1997if _base_0.__index == nil then
1998 _base_0.__index = _base_0
1999end
2000setmetatable(_base_0, _parent_0.__base)
2001_class_0 = setmetatable({
2002 __init = function(self, ...)
2003 return _class_0.__parent.__init(self, ...)
2004 end,
2005 __base = _base_0,
2006 __name = "MyClass",
2007 __parent = _parent_0
2008}, {
2009 __index = function(cls, name)
2010 local val = rawget(_base_0, name)
2011 if val == nil then
2012 local parent = rawget(cls, "__parent")
2013 if parent then
2014 return parent[name]
2015 end
2016 else
2017 return val
2018 end
2019 end,
2020 __call = function(cls, ...)
2021 local _self_0 = setmetatable({ }, _base_0)
2022 cls.__init(_self_0, ...)
2023 return _self_0
2024 end
2025})
2026_base_0.__class = _class_0
2027if _parent_0.__inherited then
2028 _parent_0.__inherited(_parent_0, _class_0)
2029end
2030MyClass = _class_0
2031local b = BackPack()
2032assert(b.__class == BackPack)
2033print(BackPack.size)
2034print(BackPack.__name)
2035local Things
2036do
2037 local _class_0
2038 local _base_0 = { }
2039 if _base_0.__index == nil then
2040 _base_0.__index = _base_0
2041 end
2042 _class_0 = setmetatable({
2043 __init = function() end,
2044 __base = _base_0,
2045 __name = "Things"
2046 }, {
2047 __index = _base_0,
2048 __call = function(cls, ...)
2049 local _self_0 = setmetatable({ }, _base_0)
2050 cls.__init(_self_0, ...)
2051 return _self_0
2052 end
2053 })
2054 _base_0.__class = _class_0
2055 local self = _class_0;
2056 self.some_func = function(self)
2057 return print("Hello from", self.__name)
2058 end
2059 Things = _class_0
2060end
2061Things:some_func()
2062assert(Things().some_func == nil)
2063local Counter
2064do
2065 local _class_0
2066 local _base_0 = { }
2067 if _base_0.__index == nil then
2068 _base_0.__index = _base_0
2069 end
2070 _class_0 = setmetatable({
2071 __init = function(self)
2072 self.__class.count = self.__class.count + 1
2073 end,
2074 __base = _base_0,
2075 __name = "Counter"
2076 }, {
2077 __index = _base_0,
2078 __call = function(cls, ...)
2079 local _self_0 = setmetatable({ }, _base_0)
2080 cls.__init(_self_0, ...)
2081 return _self_0
2082 end
2083 })
2084 _base_0.__class = _class_0
2085 local self = _class_0;
2086 self.count = 0
2087 Counter = _class_0
2088end
2089Counter()
2090Counter()
2091print(Counter.count)
2092self.__class:hello(1, 2, 3, 4)
2093local Things
2094local _class_0
2095local _base_0 = { }
2096if _base_0.__index == nil then
2097 _base_0.__index = _base_0
2098end
2099_class_0 = setmetatable({
2100 __init = function() end,
2101 __base = _base_0,
2102 __name = "Things"
2103}, {
2104 __index = _base_0,
2105 __call = function(cls, ...)
2106 local _self_0 = setmetatable({ }, _base_0)
2107 cls.__init(_self_0, ...)
2108 return _self_0
2109 end
2110})
2111_base_0.__class = _class_0
2112local self = _class_0;
2113self.class_var = "hello world"
2114Things = _class_0
2115local MoreThings
2116local _class_0
2117local secret, log
2118local _base_0 = {
2119 some_method = function(self)
2120 return log("hello world: " .. secret)
2121 end
2122}
2123if _base_0.__index == nil then
2124 _base_0.__index = _base_0
2125end
2126_class_0 = setmetatable({
2127 __init = function() end,
2128 __base = _base_0,
2129 __name = "MoreThings"
2130}, {
2131 __index = _base_0,
2132 __call = function(cls, ...)
2133 local _self_0 = setmetatable({ }, _base_0)
2134 cls.__init(_self_0, ...)
2135 return _self_0
2136 end
2137})
2138_base_0.__class = _class_0
2139local self = _class_0;
2140secret = 123
2141log = function(msg)
2142 return print("LOG:", msg)
2143end
2144MoreThings = _class_0
2145assert(self == self)
2146assert(self.__class == self.__class)
2147local some_instance_method
2148some_instance_method = function(self, ...)
2149 return self.__class(...)
2150end
2151local Something
2152do
2153 local _class_0
2154 local _base_0 = { }
2155 if _base_0.__index == nil then
2156 _base_0.__index = _base_0
2157 end
2158 _class_0 = setmetatable({
2159 __init = function(self, foo, bar, biz, baz)
2160 self.foo = foo
2161 self.bar = bar
2162 self.__class.biz = biz
2163 self.__class.baz = baz
2164 end,
2165 __base = _base_0,
2166 __name = "Something"
2167 }, {
2168 __index = _base_0,
2169 __call = function(cls, ...)
2170 local _self_0 = setmetatable({ }, _base_0)
2171 cls.__init(_self_0, ...)
2172 return _self_0
2173 end
2174 })
2175 _base_0.__class = _class_0
2176 Something = _class_0
2177end
2178local _class_0
2179local _base_0 = { }
2180if _base_0.__index == nil then
2181 _base_0.__index = _base_0
2182end
2183_class_0 = setmetatable({
2184 __init = function(self, foo, bar, biz, baz)
2185 self.foo = foo
2186 self.bar = bar
2187 self.__class.biz = biz
2188 self.__class.baz = baz
2189 end,
2190 __base = _base_0,
2191 __name = "Something"
2192}, {
2193 __index = _base_0,
2194 __call = function(cls, ...)
2195 local _self_0 = setmetatable({ }, _base_0)
2196 cls.__init(_self_0, ...)
2197 return _self_0
2198 end
2199})
2200_base_0.__class = _class_0
2201Something = _class_0
2202local new
2203new = function(self, fieldA, fieldB)
2204 self.fieldA = fieldA
2205 self.fieldB = fieldB
2206 return self
2207end
2208local obj = new({ }, 123, "abc")
2209print(obj)
2210local x
2211local Bucket
2212local _class_0
2213local _base_0 = {
2214 drops = 0,
2215 add_drop = function(self)
2216 self.drops = self.drops + 1
2217 end
2218}
2219if _base_0.__index == nil then
2220 _base_0.__index = _base_0
2221end
2222_class_0 = setmetatable({
2223 __init = function() end,
2224 __base = _base_0,
2225 __name = "Bucket"
2226}, {
2227 __index = _base_0,
2228 __call = function(cls, ...)
2229 local _self_0 = setmetatable({ }, _base_0)
2230 cls.__init(_self_0, ...)
2231 return _self_0
2232 end
2233})
2234_base_0.__class = _class_0
2235Bucket = _class_0
2236x = _class_0
2237local BigBucket
2238do
2239 local _class_0
2240 local _parent_0 = Bucket
2241 local _base_0 = {
2242 add_drop = function(self)
2243 self.drops = self.drops + 10
2244 end
2245 }
2246 for _key_0, _val_0 in pairs(_parent_0.__base) do
2247 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
2248 _base_0[_key_0] = _val_0
2249 end
2250 end
2251 if _base_0.__index == nil then
2252 _base_0.__index = _base_0
2253 end
2254 setmetatable(_base_0, _parent_0.__base)
2255 _class_0 = setmetatable({
2256 __init = function(self, ...)
2257 return _class_0.__parent.__init(self, ...)
2258 end,
2259 __base = _base_0,
2260 __name = "BigBucket",
2261 __parent = _parent_0
2262 }, {
2263 __index = function(cls, name)
2264 local val = rawget(_base_0, name)
2265 if val == nil then
2266 local parent = rawget(cls, "__parent")
2267 if parent then
2268 return parent[name]
2269 end
2270 else
2271 return val
2272 end
2273 end,
2274 __call = function(cls, ...)
2275 local _self_0 = setmetatable({ }, _base_0)
2276 cls.__init(_self_0, ...)
2277 return _self_0
2278 end
2279 })
2280 _base_0.__class = _class_0
2281 if _parent_0.__inherited then
2282 _parent_0.__inherited(_parent_0, _class_0)
2283 end
2284 BigBucket = _class_0
2285end
2286assert(Bucket.__name == "BigBucket")
2287local x
2288local _class_0
2289local _base_0 = { }
2290if _base_0.__index == nil then
2291 _base_0.__index = _base_0
2292end
2293_class_0 = setmetatable({
2294 __init = function() end,
2295 __base = _base_0,
2296 __name = "x"
2297}, {
2298 __index = _base_0,
2299 __call = function(cls, ...)
2300 local _self_0 = setmetatable({ }, _base_0)
2301 cls.__init(_self_0, ...)
2302 return _self_0
2303 end
2304})
2305_base_0.__class = _class_0
2306x = _class_0
2307local MyIndex = {
2308 __index = {
2309 var = 1
2310 }
2311}
2312local X
2313do
2314 local _class_0
2315 local _base_0 = {
2316 func = function(self)
2317 return print(123)
2318 end
2319 }
2320 local _list_0 = {
2321 MyIndex
2322 }
2323 for _index_0 = 1, #_list_0 do
2324 local _item_0 = _list_0[_index_0]
2325 local _cls_0, _mixin_0 = (_item_0.__base ~= nil), _item_0.__base or _item_0
2326 for _key_0, _val_0 in pairs(_mixin_0) do
2327 if _base_0[_key_0] == nil and (not _cls_0 or not _key_0:match("^__")) then
2328 _base_0[_key_0] = _val_0
2329 end
2330 end
2331 end
2332 if _base_0.__index == nil then
2333 _base_0.__index = _base_0
2334 end
2335 _class_0 = setmetatable({
2336 __init = function() end,
2337 __base = _base_0,
2338 __name = "X"
2339 }, {
2340 __index = _base_0,
2341 __call = function(cls, ...)
2342 local _self_0 = setmetatable({ }, _base_0)
2343 cls.__init(_self_0, ...)
2344 return _self_0
2345 end
2346 })
2347 _base_0.__class = _class_0
2348 X = _class_0
2349end
2350local x = X()
2351print(x.var)
2352local Y
2353do
2354 local _class_0
2355 local _base_0 = { }
2356 local _list_0 = {
2357 X
2358 }
2359 for _index_0 = 1, #_list_0 do
2360 local _item_0 = _list_0[_index_0]
2361 local _cls_0, _mixin_0 = (_item_0.__base ~= nil), _item_0.__base or _item_0
2362 for _key_0, _val_0 in pairs(_mixin_0) do
2363 if _base_0[_key_0] == nil and (not _cls_0 or not _key_0:match("^__")) then
2364 _base_0[_key_0] = _val_0
2365 end
2366 end
2367 end
2368 if _base_0.__index == nil then
2369 _base_0.__index = _base_0
2370 end
2371 _class_0 = setmetatable({
2372 __init = function() end,
2373 __base = _base_0,
2374 __name = "Y"
2375 }, {
2376 __index = _base_0,
2377 __call = function(cls, ...)
2378 local _self_0 = setmetatable({ }, _base_0)
2379 cls.__init(_self_0, ...)
2380 return _self_0
2381 end
2382 })
2383 _base_0.__class = _class_0
2384 Y = _class_0
2385end
2386local y = Y()
2387y:func()
2388assert(y.__class.__parent ~= X)
2389local _with_0 = Person()
2390_with_0.name = "Oswald"
2391_with_0:add_relative(my_dad)
2392_with_0:save()
2393print(_with_0.name)
2394local file
2395local _with_0 = File("favorite_foods.txt")
2396_with_0:set_encoding("utf8")
2397file = _with_0
2398local create_person
2399create_person = function(name, relatives)
2400 local _with_0 = Person()
2401 _with_0.name = name
2402 for _index_0 = 1, #relatives do
2403 local relative = relatives[_index_0]
2404 _with_0:add_relative(relative)
2405 end
2406 return _with_0
2407end
2408local me = create_person("Leaf", {
2409 dad,
2410 mother,
2411 sister
2412})
2413local str = "Hello"
2414print("original:", str)
2415print("upper:", str:upper())
2416local _with_0 = tb
2417_with_0[1] = 1
2418print(_with_0[2])
2419do
2420 local _with_1 = _with_0[abc]
2421 _with_1[3] = _with_1[2]:func()
2422 _with_1["key-name"] = value
2423end
2424_with_0[#_with_0 + 1] = "abc"
2425local _with_0 = obj
2426if _with_0 ~= nil then
2427 print(obj.name)
2428end
2429local _with_0 = Person()
2430_with_0.name = "Oswald"
2431_with_0:add_relative(my_dad)
2432_with_0:save()
2433print(_with_0.name)
2434local file
2435local _with_0 = File("favorite_foods.txt")
2436_with_0:set_encoding("utf8")
2437file = _with_0
2438local create_person
2439create_person = function(name, relatives)
2440 local _with_0 = Person()
2441 _with_0.name = name
2442 for _index_0 = 1, #relatives do
2443 local relative = relatives[_index_0]
2444 _with_0:add_relative(relative)
2445 end
2446 return _with_0
2447end
2448local me = create_person("Leaf", {
2449 dad,
2450 mother,
2451 sister
2452})
2453local str = "Hello"
2454print("original:", str)
2455print("upper:", str:upper())
2456local _with_0 = tb
2457_with_0[1] = 1
2458print(_with_0[2])
2459do
2460 local _with_1 = _with_0[abc]
2461 _with_1[3] = _with_1[2]:func()
2462 _with_1["key-name"] = value
2463end
2464_with_0[#_with_0 + 1] = "abc"
2465local _with_0 = obj
2466if _with_0 ~= nil then
2467 print(obj.name)
2468end
2469local hello = "world"
2470local a, b, c = 1, 2, 3
2471hello = 123
2472local x = 1
2473x = x + 1
2474x = x - 1
2475x = x * 10
2476x = x / 10
2477x = x % 10
2478local s = s .. "world"
2479local arg = arg or "default value"
2480local a = 0
2481local b = 0
2482local c = 0
2483local d = 0
2484local e = 0
2485local x = f()
2486local y = x
2487local z = x
2488do
2489 local a = 1
2490 local x, y, z
2491 print("forward declare all variables as locals")
2492 x = function()
2493 return 1 + y + z
2494 end
2495 y, z = 2, 3
2496 instance = Item:new()
2497end
2498do
2499 local X = 1
2500 local B
2501 print("only forward declare upper case variables")
2502 local a = 1
2503 B = 2
2504end
2505do
2506 a = 1
2507 print("declare all variables as globals")
2508 x = function()
2509 return 1 + y + z
2510 end
2511 y, z = 2, 3
2512end
2513do
2514 X = 1
2515 print("only declare upper case variables as globals")
2516 local a = 1
2517 B = 2
2518 local Temp = "a local value"
2519end
2520local hello = "world"
2521local a, b, c = 1, 2, 3
2522hello = 123
2523local x = 1
2524x = x + 1
2525x = x - 1
2526x = x * 10
2527x = x / 10
2528x = x % 10
2529local s = s .. "world"
2530local arg = arg or "default value"
2531local a = 0
2532local b = 0
2533local c = 0
2534local d = 0
2535local e = 0
2536local x = f()
2537local y = x
2538local z = x
2539do
2540 local a = 1
2541 local x, y, z
2542 print("forward declare all variables as locals")
2543 x = function()
2544 return 1 + y + z
2545 end
2546 y, z = 2, 3
2547 instance = Item:new()
2548end
2549do
2550 local X = 1
2551 local B
2552 print("only forward declare upper case variables")
2553 local a = 1
2554 B = 2
2555end
2556do
2557 a = 1
2558 print("declare all variables as globals")
2559 x = function()
2560 return 1 + y + z
2561 end
2562 y, z = 2, 3
2563end
2564do
2565 X = 1
2566 print("only declare upper case variables as globals")
2567 local a = 1
2568 B = 2
2569 local Temp = "a local value"
2570end
2571local list = {
2572 1,
2573 2,
2574 3,
2575 4,
2576 5
2577}
2578local fn
2579fn = function(ok)
2580 return ok, table.unpack(list)
2581end
2582(function(_arg_0, ...)
2583 local ok = _arg_0
2584 local count = select('#', ...)
2585 local first = select(1, ...)
2586 return print(ok, count, first)
2587end)(fn(true))
2588local list = {
2589 1,
2590 2,
2591 3,
2592 4,
2593 5
2594}
2595local fn
2596fn = function(ok)
2597 return ok, table.unpack(list)
2598end
2599(function(_arg_0, ...)
2600 local ok = _arg_0
2601 local count = select('#', ...)
2602 local first = select(1, ...)
2603 return print(ok, count, first)
2604end)(fn(true))
2605local user = database.find_user("moon")
2606if user then
2607 print(user.name)
2608end
2609local hello = os.getenv("hello")
2610if hello then
2611 print("You have hello", hello)
2612else
2613 local world = os.getenv("world")
2614 if world then
2615 print("you have world", world)
2616 else
2617 print("nothing :(")
2618 end
2619end
2620do
2621 local success, result = pcall(function()
2622 return "get result without problems"
2623 end)
2624 if success then
2625 print(result)
2626 end
2627end
2628print("OK")
2629repeat
2630 local byte = stream:read_one()
2631 if byte then
2632 print(byte)
2633 else
2634 break
2635 end
2636until false
2637local user = database.find_user("moon")
2638if user then
2639 print(user.name)
2640end
2641local hello = os.getenv("hello")
2642if hello then
2643 print("You have hello", hello)
2644else
2645 local world = os.getenv("world")
2646 if world then
2647 print("you have world", world)
2648 else
2649 print("nothing :(")
2650 end
2651end
2652do
2653 local success, result = pcall(function()
2654 return "get result without problems"
2655 end)
2656 if success then
2657 print(result)
2658 end
2659end
2660print("OK")
2661repeat
2662 local byte = stream:read_one()
2663 if byte then
2664 print(byte)
2665 else
2666 break
2667 end
2668until false
2669local thing = {
2670 1,
2671 2
2672}
2673local a, b = thing[1], thing[2]
2674print(a, b)
2675local obj = {
2676 hello = "world",
2677 day = "tuesday",
2678 length = 20
2679}
2680local hello, the_day = obj.hello, obj.day
2681print(hello, the_day)
2682local day = obj.day
2683local obj2 = {
2684 numbers = {
2685 1,
2686 2,
2687 3,
2688 4
2689 },
2690 properties = {
2691 color = "green",
2692 height = 13.5
2693 }
2694}
2695local first, second, color = obj2.numbers[1], obj2.numbers[2], obj2.properties.color
2696print(first, second, color)
2697local first, second, color
2698local _obj_0 = obj2
2699first, second, color = _obj_0.numbers[1], _obj_0.numbers[2], _obj_0.properties.color
2700local concat, insert
2701local _obj_0 = table
2702concat, insert = _obj_0.concat, _obj_0.insert
2703local mix, max, rand
2704local _obj_0 = math
2705mix, max, rand = _obj_0.mix, _obj_0.max, _obj_0.random
2706local name, job
2707local _obj_0 = person
2708name, job = _obj_0.name, _obj_0.job
2709if name == nil then
2710 name = "nameless"
2711end
2712if job == nil then
2713 job = "jobless"
2714end
2715local two, four
2716local _obj_0 = items
2717two, four = _obj_0[2], _obj_0[4]
2718local orders = {
2719 "first",
2720 "second",
2721 "third",
2722 "fourth",
2723 "last"
2724}
2725local first, bulk, last = orders[1], (function()
2726 local _accum_0 = { }
2727 local _len_0 = 1
2728 local _max_0 = #orders + -2 + 1
2729 for _index_0 = 2, _max_0 do
2730 local _item_0 = orders[_index_0]
2731 _accum_0[_len_0] = _item_0
2732 _len_0 = _len_0 + 1
2733 end
2734 return _accum_0
2735end)(), orders[#orders]
2736print(first)
2737print(bulk)
2738print(last)
2739local first, rest
2740do
2741 local _obj_0 = orders
2742 first, rest = _obj_0[1], (function()
2743 local _accum_0 = { }
2744 local _len_0 = 1
2745 local _max_0 = #_obj_0
2746 for _index_0 = 2, _max_0 do
2747 local _item_0 = _obj_0[_index_0]
2748 _accum_0[_len_0] = _item_0
2749 _len_0 = _len_0 + 1
2750 end
2751 return _accum_0
2752 end)()
2753end
2754local start, last
2755do
2756 local _obj_0 = orders
2757 start, last = (function()
2758 local _accum_0 = { }
2759 local _len_0 = 1
2760 local _max_0 = #_obj_0 + -2 + 1
2761 for _index_0 = 1, _max_0 do
2762 local _item_0 = _obj_0[_index_0]
2763 _accum_0[_len_0] = _item_0
2764 _len_0 = _len_0 + 1
2765 end
2766 return _accum_0
2767 end)(), _obj_0[#_obj_0]
2768end
2769local _obj_0 = orders
2770first, last = _obj_0[1], _obj_0[#_obj_0]
2771local tuples = {
2772 {
2773 "hello",
2774 "world"
2775 },
2776 {
2777 "egg",
2778 "head"
2779 }
2780}
2781for _index_0 = 1, #tuples do
2782 local _des_0 = tuples[_index_0]
2783 local left, right = _des_0[1], _des_0[2]
2784 print(left, right)
2785end
2786local thing = {
2787 1,
2788 2
2789}
2790local a, b = thing[1], thing[2]
2791print(a, b)
2792local obj = {
2793 hello = "world",
2794 day = "tuesday",
2795 length = 20
2796}
2797local hello, the_day = obj.hello, obj.day
2798print(hello, the_day)
2799local day = obj.day
2800local obj2 = {
2801 numbers = {
2802 1,
2803 2,
2804 3,
2805 4
2806 },
2807 properties = {
2808 color = "green",
2809 height = 13.5
2810 }
2811}
2812local first, second, color = obj2.numbers[1], obj2.numbers[2], obj2.properties.color
2813print(first, second, color)
2814local first, second, color
2815local _obj_0 = obj2
2816first, second, color = _obj_0.numbers[1], _obj_0.numbers[2], _obj_0.properties.color
2817local concat, insert
2818local _obj_0 = table
2819concat, insert = _obj_0.concat, _obj_0.insert
2820local mix, max, rand
2821local _obj_0 = math
2822mix, max, rand = _obj_0.mix, _obj_0.max, _obj_0.random
2823local name, job
2824local _obj_0 = person
2825name, job = _obj_0.name, _obj_0.job
2826if name == nil then
2827 name = "nameless"
2828end
2829if job == nil then
2830 job = "jobless"
2831end
2832local two, four
2833local _obj_0 = items
2834two, four = _obj_0[2], _obj_0[4]
2835local orders = {
2836 "first",
2837 "second",
2838 "third",
2839 "fourth",
2840 "last"
2841}
2842local first, bulk, last = orders[1], (function()
2843 local _accum_0 = { }
2844 local _len_0 = 1
2845 local _max_0 = #orders + -2 + 1
2846 for _index_0 = 2, _max_0 do
2847 local _item_0 = orders[_index_0]
2848 _accum_0[_len_0] = _item_0
2849 _len_0 = _len_0 + 1
2850 end
2851 return _accum_0
2852end)(), orders[#orders]
2853print(first)
2854print(bulk)
2855print(last)
2856local first, rest
2857do
2858 local _obj_0 = orders
2859 first, rest = _obj_0[1], (function()
2860 local _accum_0 = { }
2861 local _len_0 = 1
2862 local _max_0 = #_obj_0
2863 for _index_0 = 2, _max_0 do
2864 local _item_0 = _obj_0[_index_0]
2865 _accum_0[_len_0] = _item_0
2866 _len_0 = _len_0 + 1
2867 end
2868 return _accum_0
2869 end)()
2870end
2871local start, last
2872do
2873 local _obj_0 = orders
2874 start, last = (function()
2875 local _accum_0 = { }
2876 local _len_0 = 1
2877 local _max_0 = #_obj_0 + -2 + 1
2878 for _index_0 = 1, _max_0 do
2879 local _item_0 = _obj_0[_index_0]
2880 _accum_0[_len_0] = _item_0
2881 _len_0 = _len_0 + 1
2882 end
2883 return _accum_0
2884 end)(), _obj_0[#_obj_0]
2885end
2886local _obj_0 = orders
2887first, last = _obj_0[1], _obj_0[#_obj_0]
2888local tuples = {
2889 {
2890 "hello",
2891 "world"
2892 },
2893 {
2894 "egg",
2895 "head"
2896 }
2897}
2898for _index_0 = 1, #tuples do
2899 local _des_0 = tuples[_index_0]
2900 local left, right = _des_0[1], _des_0[2]
2901 print(left, right)
2902end
2903local i = 100
2904local my_func
2905my_func = function()
2906 i = 10
2907 while i > 0 do
2908 print(i)
2909 i = i - 1
2910 end
2911end
2912my_func()
2913print(i)
2914local i = 100
2915local my_func
2916my_func = function()
2917 local i = "hello"
2918end
2919my_func()
2920print(i)
2921local tmp = 1213
2922local i, k = 100, 50
2923local my_func
2924my_func = function(add)
2925 local tmp = tmp + add
2926 i = i + tmp
2927 k = k + tmp
2928end
2929my_func(22)
2930print(i, k)
2931local i = 100
2932local my_func
2933my_func = function()
2934 i = 10
2935 while i > 0 do
2936 print(i)
2937 i = i - 1
2938 end
2939end
2940my_func()
2941print(i)
2942local i = 100
2943local my_func
2944my_func = function()
2945 local i = "hello"
2946end
2947my_func()
2948print(i)
2949local tmp = 1213
2950local i, k = 100, 50
2951local my_func
2952my_func = function(add)
2953 local tmp = tmp + add
2954 i = i + tmp
2955 k = k + tmp
2956end
2957my_func(22)
2958print(i, k)
2959local _module_0 = { }
2960local p, to_lua
2961do
2962 local _obj_0 = require("yue")
2963 p, to_lua = _obj_0.p, _obj_0.to_lua
2964end
2965local inventory = {
2966 equipment = {
2967 "sword",
2968 "shield"
2969 },
2970 items = {
2971 {
2972 name = "potion",
2973 count = 10
2974 },
2975 {
2976 name = "bread",
2977 count = 3
2978 }
2979 }
2980}
2981local map
2982map = function(arr, action)
2983 local _accum_0 = { }
2984 local _len_0 = 1
2985 for _index_0 = 1, #arr do
2986 local item = arr[_index_0]
2987 _accum_0[_len_0] = action(item)
2988 _len_0 = _len_0 + 1
2989 end
2990 return _accum_0
2991end
2992local filter
2993filter = function(arr, cond)
2994 local _accum_0 = { }
2995 local _len_0 = 1
2996 for _index_0 = 1, #arr do
2997 local item = arr[_index_0]
2998 if cond(item) then
2999 _accum_0[_len_0] = item
3000 _len_0 = _len_0 + 1
3001 end
3002 end
3003 return _accum_0
3004end
3005local reduce
3006reduce = function(arr, init, action)
3007 for _index_0 = 1, #arr do
3008 local item = arr[_index_0]
3009 init = action(init, item)
3010 end
3011 return init
3012end
3013print(reduce(filter(map({
3014 1,
3015 2,
3016 3
3017}, function(x)
3018 return x * 2
3019end), function(x)
3020 return x > 4
3021end), 0, function(a, b)
3022 return a + b
3023end))
3024local apple = setmetatable({
3025 size = 15,
3026}, {
3027 __index = {
3028 color = 0x00ffff
3029 }
3030})
3031if (getmetatable(apple) ~= nil) then
3032 p(apple.size, apple.color, getmetatable(apple).__index)
3033end
3034local _u1f31b = "月之脚本"
3035_module_0["🌛"] = _u1f31b
3036return _module_0
3037local _module_0 = { }
3038local p, to_lua
3039do
3040 local _obj_0 = require("yue")
3041 p, to_lua = _obj_0.p, _obj_0.to_lua
3042end
3043local inventory = {
3044 equipment = {
3045 "sword",
3046 "shield"
3047 },
3048 items = {
3049 {
3050 name = "potion",
3051 count = 10
3052 },
3053 {
3054 name = "bread",
3055 count = 3
3056 }
3057 }
3058}
3059local map
3060map = function(arr, action)
3061 local _accum_0 = { }
3062 local _len_0 = 1
3063 for _index_0 = 1, #arr do
3064 local item = arr[_index_0]
3065 _accum_0[_len_0] = action(item)
3066 _len_0 = _len_0 + 1
3067 end
3068 return _accum_0
3069end
3070local filter
3071filter = function(arr, cond)
3072 local _accum_0 = { }
3073 local _len_0 = 1
3074 for _index_0 = 1, #arr do
3075 local item = arr[_index_0]
3076 if cond(item) then
3077 _accum_0[_len_0] = item
3078 _len_0 = _len_0 + 1
3079 end
3080 end
3081 return _accum_0
3082end
3083local reduce
3084reduce = function(arr, init, action)
3085 for _index_0 = 1, #arr do
3086 local item = arr[_index_0]
3087 init = action(init, item)
3088 end
3089 return init
3090end
3091print(reduce(filter(map({
3092 1,
3093 2,
3094 3
3095}, function(x)
3096 return x * 2
3097end), function(x)
3098 return x > 4
3099end), 0, function(a, b)
3100 return a + b
3101end))
3102local apple = setmetatable({
3103 size = 15,
3104}, {
3105 __index = {
3106 color = 0x00ffff
3107 }
3108})
3109if (getmetatable(apple) ~= nil) then
3110 p(apple.size, apple.color, getmetatable(apple).__index)
3111end
3112local _u1f31b = "月之脚本"
3113_module_0["🌛"] = _u1f31b
3114return _module_0
3115local have_coins = false
3116if have_coins then
3117 print("Got coins")
3118else
3119 print("No coins")
3120end
3121local have_coins = false
3122if have_coins then
3123 print("Got coins")
3124else
3125 print("No coins")
3126end
3127local have_coins = false
3128print((function()
3129 if have_coins then
3130 return "Got coins"
3131 else
3132 return "No coins"
3133 end
3134end)())
3135local is_tall
3136is_tall = function(name)
3137 if name == "Rob" then
3138 return true
3139 else
3140 return false
3141 end
3142end
3143local message
3144if is_tall("Rob") then
3145 message = "I am very tall"
3146else
3147 message = "I am not so tall"
3148end
3149print(message)
3150if not (os.date("%A") == "Monday") then
3151 print("it is not Monday!")
3152end
3153if not (math.random() > 0.1) then
3154 print("You're lucky!")
3155end
3156local a = 5
3157if (1 == a or 3 == a or 5 == a or 7 == a) then
3158 print("checking equality with discrete values")
3159end
3160if (function()
3161 local _check_0 = list
3162 for _index_0 = 1, #_check_0 do
3163 if _check_0[_index_0] == a then
3164 return true
3165 end
3166 end
3167 return false
3168end)() then
3169 print("checking if `a` is in a list")
3170end
3171if not (math.random() > 0.1) then
3172 print("You're lucky!")
3173end
3174local have_coins = false
3175if have_coins then
3176 print("Got coins")
3177else
3178 print("No coins")
3179end
3180local have_coins = false
3181if have_coins then
3182 print("Got coins")
3183else
3184 print("No coins")
3185end
3186local have_coins = false
3187print((function()
3188 if have_coins then
3189 return "Got coins"
3190 else
3191 return "No coins"
3192 end
3193end)())
3194local is_tall
3195is_tall = function(name)
3196 if name == "Rob" then
3197 return true
3198 else
3199 return false
3200 end
3201end
3202local message
3203if is_tall("Rob") then
3204 message = "I am very tall"
3205else
3206 message = "I am not so tall"
3207end
3208print(message)
3209if not (os.date("%A") == "Monday") then
3210 print("it is not Monday!")
3211end
3212if not (math.random() > 0.1) then
3213 print("You're lucky!")
3214end
3215local a = 5
3216if (1 == a or 3 == a or 5 == a or 7 == a) then
3217 print("checking equality with discrete values")
3218end
3219if (function()
3220 local _check_0 = list
3221 for _index_0 = 1, #_check_0 do
3222 if _check_0[_index_0] == a then
3223 return true
3224 end
3225 end
3226 return false
3227end)() then
3228 print("checking if `a` is in a list")
3229end
3230if not (math.random() > 0.1) then
3231 print("You're lucky!")
3232end
3233for i = 10, 20 do
3234 print(i)
3235end
3236for k = 1, 15, 2 do
3237 print(k)
3238end
3239for key, value in pairs(object) do
3240 print(key, value)
3241end
3242local _list_0 = items
3243for _index_0 = 2, 4 do
3244 local item = _list_0[_index_0]
3245 print(item)
3246end
3247local _list_0 = items
3248for _index_0 = 1, #_list_0 do
3249 local item = _list_0[_index_0]
3250 print(item)
3251end
3252for j = 1, 10, 3 do
3253 print(j)
3254end
3255local doubled_evens
3256local _accum_0 = { }
3257local _len_0 = 1
3258for i = 1, 20 do
3259 if i % 2 == 0 then
3260 _accum_0[_len_0] = i * 2
3261 _len_0 = _len_0 + 1
3262 else
3263 _accum_0[_len_0] = i
3264 _len_0 = _len_0 + 1
3265 end
3266end
3267doubled_evens = _accum_0
3268local first_large
3269local _accum_0
3270local _list_0 = numbers
3271for _index_0 = 1, #_list_0 do
3272 local n = _list_0[_index_0]
3273 if n > 10 then
3274 _accum_0 = n
3275 break
3276 end
3277end
3278first_large = _accum_0
3279local func_a
3280func_a = function()
3281 for i = 1, 10 do
3282 print(i)
3283 end
3284end
3285local func_b
3286func_b = function()
3287 local _accum_0 = { }
3288 local _len_0 = 1
3289 for i = 1, 10 do
3290 _accum_0[_len_0] = i
3291 _len_0 = _len_0 + 1
3292 end
3293 return _accum_0
3294end
3295print(func_a())
3296print(func_b())
3297for i = 10, 20 do
3298 print(i)
3299end
3300for k = 1, 15, 2 do
3301 print(k)
3302end
3303for key, value in pairs(object) do
3304 print(key, value)
3305end
3306local _list_0 = items
3307for _index_0 = 2, 4 do
3308 local item = _list_0[_index_0]
3309 print(item)
3310end
3311local _list_0 = items
3312for _index_0 = 1, #_list_0 do
3313 local item = _list_0[_index_0]
3314 print(item)
3315end
3316for j = 1, 10, 3 do
3317 print(j)
3318end
3319local doubled_evens
3320local _accum_0 = { }
3321local _len_0 = 1
3322for i = 1, 20 do
3323 if i % 2 == 0 then
3324 _accum_0[_len_0] = i * 2
3325 _len_0 = _len_0 + 1
3326 else
3327 _accum_0[_len_0] = i
3328 _len_0 = _len_0 + 1
3329 end
3330end
3331doubled_evens = _accum_0
3332local first_large
3333local _accum_0
3334local _list_0 = numbers
3335for _index_0 = 1, #_list_0 do
3336 local n = _list_0[_index_0]
3337 if n > 10 then
3338 _accum_0 = n
3339 break
3340 end
3341end
3342first_large = _accum_0
3343local func_a
3344func_a = function()
3345 for i = 1, 10 do
3346 print(i)
3347 end
3348end
3349local func_b
3350func_b = function()
3351 local _accum_0 = { }
3352 local _len_0 = 1
3353 for i = 1, 10 do
3354 _accum_0[_len_0] = i
3355 _len_0 = _len_0 + 1
3356 end
3357 return _accum_0
3358end
3359print(func_a())
3360print(func_b())
3361local i = 0
3362while i < 10 do
3363 i = i + 1
3364 if i % 2 == 0 then
3365 goto _continue_0
3366 end
3367 print(i)
3368 ::_continue_0::
3369end
3370local my_numbers = {
3371 1,
3372 2,
3373 3,
3374 4,
3375 5,
3376 6
3377}
3378local odds
3379local _accum_0 = { }
3380local _len_0 = 1
3381for _index_0 = 1, #my_numbers do
3382 local x = my_numbers[_index_0]
3383 if x % 2 == 1 then
3384 goto _continue_0
3385 end
3386 _accum_0[_len_0] = x
3387 _len_0 = _len_0 + 1
3388 ::_continue_0::
3389end
3390odds = _accum_0
3391local i = 0
3392while i < 10 do
3393 i = i + 1
3394 if i % 2 == 0 then
3395 goto _continue_0
3396 end
3397 print(i)
3398 ::_continue_0::
3399end
3400local my_numbers = {
3401 1,
3402 2,
3403 3,
3404 4,
3405 5,
3406 6
3407}
3408local odds
3409local _accum_0 = { }
3410local _len_0 = 1
3411for _index_0 = 1, #my_numbers do
3412 local x = my_numbers[_index_0]
3413 if x % 2 == 1 then
3414 goto _continue_0
3415 end
3416 _accum_0[_len_0] = x
3417 _len_0 = _len_0 + 1
3418 ::_continue_0::
3419end
3420odds = _accum_0
3421local name = "Dan"
3422if "Robert" == name then
3423 print("You are Robert")
3424elseif "Dan" == name or "Daniel" == name then
3425 print("Your name, it's Dan")
3426else
3427 print("I don't know about you with name " .. tostring(name))
3428end
3429local b = 1
3430local next_number
3431if 1 == b then
3432 next_number = 2
3433elseif 2 == b then
3434 next_number = 3
3435else
3436 next_number = error("can't count that high!")
3437end
3438local msg
3439local _exp_0 = math.random(1, 5)
3440if 1 == _exp_0 then
3441 msg = "you are lucky"
3442elseif 2 == _exp_0 then
3443 msg = "you are almost lucky"
3444else
3445 msg = "not so lucky"
3446end
3447do
3448 local _exp_0 = math.random(1, 5)
3449 if 1 == _exp_0 then
3450 print("you are lucky")
3451 else
3452 print("not so lucky")
3453 end
3454end
3455local _exp_0 = math.random(1, 5)
3456if 1 == _exp_0 then
3457 print("you are lucky")
3458else
3459 print("not so lucky")
3460end
3461local items = {
3462 {
3463 x = 100,
3464 y = 200
3465 },
3466 {
3467 width = 300,
3468 height = 400
3469 }
3470}
3471for _index_0 = 1, #items do
3472 local item = items[_index_0]
3473 local _type_0 = type(item)
3474 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3475 local _match_0 = false
3476 if _tab_0 then
3477 local x = item.x
3478 local y = item.y
3479 if x ~= nil and y ~= nil then
3480 _match_0 = true
3481 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3482 end
3483 end
3484 if not _match_0 then
3485 if _tab_0 then
3486 local width = item.width
3487 local height = item.height
3488 if width ~= nil and height ~= nil then
3489 print("size " .. tostring(width) .. ", " .. tostring(height))
3490 end
3491 end
3492 end
3493end
3494local item = { }
3495local x, y = item.pos.x, item.pos.y
3496if x == nil then
3497 x = 50
3498end
3499if y == nil then
3500 y = 200
3501end
3502local _type_0 = type(item)
3503local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3504if _tab_0 then
3505 do
3506 local _obj_0 = item.pos
3507 local _type_1 = type(_obj_0)
3508 if "table" == _type_1 or "userdata" == _type_1 then
3509 x = _obj_0.x
3510 end
3511 end
3512 do
3513 local _obj_0 = item.pos
3514 local _type_1 = type(_obj_0)
3515 if "table" == _type_1 or "userdata" == _type_1 then
3516 y = _obj_0.y
3517 end
3518 end
3519 if x == nil then
3520 x = 50
3521 end
3522 if y == nil then
3523 y = 200
3524 end
3525 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3526end
3527local _exp_0 = tb
3528local _type_0 = type(_exp_0)
3529local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3530local _match_0 = false
3531if _tab_0 then
3532 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
3533 _match_0 = true
3534 print("1, 2, 3")
3535 end
3536end
3537if not _match_0 then
3538 local _match_1 = false
3539 if _tab_0 then
3540 local b = _exp_0[2]
3541 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
3542 _match_1 = true
3543 print("1, " .. tostring(b) .. ", 3")
3544 end
3545 end
3546 if not _match_1 then
3547 if _tab_0 then
3548 local b = _exp_0[3]
3549 if b == nil then
3550 b = 3
3551 end
3552 if 1 == _exp_0[1] and 2 == _exp_0[2] then
3553 print("1, 2, " .. tostring(b))
3554 end
3555 end
3556 end
3557end
3558local _exp_0 = tb
3559local _type_0 = type(_exp_0)
3560local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3561local _match_0 = false
3562if _tab_0 then
3563 local result = _exp_0.result
3564 if true == _exp_0.success and result ~= nil then
3565 _match_0 = true
3566 print("success", result)
3567 end
3568end
3569if not _match_0 then
3570 local _match_1 = false
3571 if _tab_0 then
3572 if false == _exp_0.success then
3573 _match_1 = true
3574 print("failed", result)
3575 end
3576 end
3577 if not _match_1 then
3578 print("invalid")
3579 end
3580end
3581local _exp_0 = tb
3582local _type_0 = type(_exp_0)
3583local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3584local _match_0 = false
3585if _tab_0 then
3586 local content
3587 do
3588 local _obj_0 = _exp_0.data
3589 local _type_1 = type(_obj_0)
3590 if "table" == _type_1 or "userdata" == _type_1 then
3591 content = _obj_0.content
3592 end
3593 end
3594 local _val_0
3595 do
3596 local _obj_0 = _exp_0.data
3597 if _obj_0 ~= nil then
3598 _val_0 = _obj_0.type
3599 end
3600 end
3601 if "success" == _val_0 and content ~= nil then
3602 _match_0 = true
3603 print("success", content)
3604 end
3605end
3606if not _match_0 then
3607 local _match_1 = false
3608 if _tab_0 then
3609 local content
3610 do
3611 local _obj_0 = _exp_0.data
3612 local _type_1 = type(_obj_0)
3613 if "table" == _type_1 or "userdata" == _type_1 then
3614 content = _obj_0.content
3615 end
3616 end
3617 local _val_0
3618 do
3619 local _obj_0 = _exp_0.data
3620 if _obj_0 ~= nil then
3621 _val_0 = _obj_0.type
3622 end
3623 end
3624 if "error" == _val_0 and content ~= nil then
3625 _match_1 = true
3626 print("failed", content)
3627 end
3628 end
3629 if not _match_1 then
3630 print("invalid")
3631 end
3632end
3633local _exp_0 = tb
3634local _type_0 = type(_exp_0)
3635local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3636if _tab_0 then
3637 local fourth = _exp_0[4]
3638 local _val_0
3639 do
3640 local _obj_0 = _exp_0[1]
3641 if _obj_0 ~= nil then
3642 _val_0 = _obj_0.a
3643 end
3644 end
3645 local _val_1
3646 do
3647 local _obj_0 = _exp_0[1]
3648 if _obj_0 ~= nil then
3649 _val_1 = _obj_0.b
3650 end
3651 end
3652 local _val_2
3653 do
3654 local _obj_0 = _exp_0[2]
3655 if _obj_0 ~= nil then
3656 _val_2 = _obj_0.a
3657 end
3658 end
3659 local _val_3
3660 do
3661 local _obj_0 = _exp_0[2]
3662 if _obj_0 ~= nil then
3663 _val_3 = _obj_0.b
3664 end
3665 end
3666 local _val_4
3667 do
3668 local _obj_0 = _exp_0[3]
3669 if _obj_0 ~= nil then
3670 _val_4 = _obj_0.a
3671 end
3672 end
3673 local _val_5
3674 do
3675 local _obj_0 = _exp_0[3]
3676 if _obj_0 ~= nil then
3677 _val_5 = _obj_0.b
3678 end
3679 end
3680 if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and fourth ~= nil then
3681 print("matched", fourth)
3682 end
3683end
3684local segments = {
3685 "admin",
3686 "users",
3687 "logs",
3688 "view"
3689}
3690local _type_0 = type(segments)
3691local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3692if _tab_0 then
3693 local groups
3694 do
3695 local _accum_0 = { }
3696 local _len_0 = 1
3697 local _max_0 = #segments + -3 + 1
3698 for _index_0 = 1, _max_0 do
3699 local _item_0 = segments[_index_0]
3700 _accum_0[_len_0] = _item_0
3701 _len_0 = _len_0 + 1
3702 end
3703 groups = _accum_0
3704 end
3705 local resource = segments[#segments - 1]
3706 local action = segments[#segments]
3707 if resource ~= nil and action ~= nil then
3708 print("Group:", groups)
3709 print("Resource:", resource)
3710 print("Action:", action)
3711 end
3712end
3713local name = "Dan"
3714if "Robert" == name then
3715 print("You are Robert")
3716elseif "Dan" == name or "Daniel" == name then
3717 print("Your name, it's Dan")
3718else
3719 print("I don't know about you with name " .. tostring(name))
3720end
3721local b = 1
3722local next_number
3723if 1 == b then
3724 next_number = 2
3725elseif 2 == b then
3726 next_number = 3
3727else
3728 next_number = error("can't count that high!")
3729end
3730local msg
3731local _exp_0 = math.random(1, 5)
3732if 1 == _exp_0 then
3733 msg = "you are lucky"
3734elseif 2 == _exp_0 then
3735 msg = "you are almost lucky"
3736else
3737 msg = "not so lucky"
3738end
3739do
3740 local _exp_0 = math.random(1, 5)
3741 if 1 == _exp_0 then
3742 print("you are lucky")
3743 else
3744 print("not so lucky")
3745 end
3746end
3747local _exp_0 = math.random(1, 5)
3748if 1 == _exp_0 then
3749 print("you are lucky")
3750else
3751 print("not so lucky")
3752end
3753local items = {
3754 {
3755 x = 100,
3756 y = 200
3757 },
3758 {
3759 width = 300,
3760 height = 400
3761 }
3762}
3763for _index_0 = 1, #items do
3764 local item = items[_index_0]
3765 local _type_0 = type(item)
3766 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3767 local _match_0 = false
3768 if _tab_0 then
3769 local x = item.x
3770 local y = item.y
3771 if x ~= nil and y ~= nil then
3772 _match_0 = true
3773 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3774 end
3775 end
3776 if not _match_0 then
3777 if _tab_0 then
3778 local width = item.width
3779 local height = item.height
3780 if width ~= nil and height ~= nil then
3781 print("size " .. tostring(width) .. ", " .. tostring(height))
3782 end
3783 end
3784 end
3785end
3786local item = { }
3787local x, y = item.pos.x, item.pos.y
3788if x == nil then
3789 x = 50
3790end
3791if y == nil then
3792 y = 200
3793end
3794local _type_0 = type(item)
3795local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3796if _tab_0 then
3797 do
3798 local _obj_0 = item.pos
3799 local _type_1 = type(_obj_0)
3800 if "table" == _type_1 or "userdata" == _type_1 then
3801 x = _obj_0.x
3802 end
3803 end
3804 do
3805 local _obj_0 = item.pos
3806 local _type_1 = type(_obj_0)
3807 if "table" == _type_1 or "userdata" == _type_1 then
3808 y = _obj_0.y
3809 end
3810 end
3811 if x == nil then
3812 x = 50
3813 end
3814 if y == nil then
3815 y = 200
3816 end
3817 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3818end
3819local _exp_0 = tb
3820local _type_0 = type(_exp_0)
3821local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3822local _match_0 = false
3823if _tab_0 then
3824 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
3825 _match_0 = true
3826 print("1, 2, 3")
3827 end
3828end
3829if not _match_0 then
3830 local _match_1 = false
3831 if _tab_0 then
3832 local b = _exp_0[2]
3833 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
3834 _match_1 = true
3835 print("1, " .. tostring(b) .. ", 3")
3836 end
3837 end
3838 if not _match_1 then
3839 if _tab_0 then
3840 local b = _exp_0[3]
3841 if b == nil then
3842 b = 3
3843 end
3844 if 1 == _exp_0[1] and 2 == _exp_0[2] then
3845 print("1, 2, " .. tostring(b))
3846 end
3847 end
3848 end
3849end
3850local _exp_0 = tb
3851local _type_0 = type(_exp_0)
3852local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3853local _match_0 = false
3854if _tab_0 then
3855 local result = _exp_0.result
3856 if true == _exp_0.success and result ~= nil then
3857 _match_0 = true
3858 print("success", result)
3859 end
3860end
3861if not _match_0 then
3862 local _match_1 = false
3863 if _tab_0 then
3864 if false == _exp_0.success then
3865 _match_1 = true
3866 print("failed", result)
3867 end
3868 end
3869 if not _match_1 then
3870 print("invalid")
3871 end
3872end
3873local _exp_0 = tb
3874local _type_0 = type(_exp_0)
3875local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3876local _match_0 = false
3877if _tab_0 then
3878 local content
3879 do
3880 local _obj_0 = _exp_0.data
3881 local _type_1 = type(_obj_0)
3882 if "table" == _type_1 or "userdata" == _type_1 then
3883 content = _obj_0.content
3884 end
3885 end
3886 local _val_0
3887 do
3888 local _obj_0 = _exp_0.data
3889 if _obj_0 ~= nil then
3890 _val_0 = _obj_0.type
3891 end
3892 end
3893 if "success" == _val_0 and content ~= nil then
3894 _match_0 = true
3895 print("success", content)
3896 end
3897end
3898if not _match_0 then
3899 local _match_1 = false
3900 if _tab_0 then
3901 local content
3902 do
3903 local _obj_0 = _exp_0.data
3904 local _type_1 = type(_obj_0)
3905 if "table" == _type_1 or "userdata" == _type_1 then
3906 content = _obj_0.content
3907 end
3908 end
3909 local _val_0
3910 do
3911 local _obj_0 = _exp_0.data
3912 if _obj_0 ~= nil then
3913 _val_0 = _obj_0.type
3914 end
3915 end
3916 if "error" == _val_0 and content ~= nil then
3917 _match_1 = true
3918 print("failed", content)
3919 end
3920 end
3921 if not _match_1 then
3922 print("invalid")
3923 end
3924end
3925local _exp_0 = tb
3926local _type_0 = type(_exp_0)
3927local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3928if _tab_0 then
3929 local fourth = _exp_0[4]
3930 local _val_0
3931 do
3932 local _obj_0 = _exp_0[1]
3933 if _obj_0 ~= nil then
3934 _val_0 = _obj_0.a
3935 end
3936 end
3937 local _val_1
3938 do
3939 local _obj_0 = _exp_0[1]
3940 if _obj_0 ~= nil then
3941 _val_1 = _obj_0.b
3942 end
3943 end
3944 local _val_2
3945 do
3946 local _obj_0 = _exp_0[2]
3947 if _obj_0 ~= nil then
3948 _val_2 = _obj_0.a
3949 end
3950 end
3951 local _val_3
3952 do
3953 local _obj_0 = _exp_0[2]
3954 if _obj_0 ~= nil then
3955 _val_3 = _obj_0.b
3956 end
3957 end
3958 local _val_4
3959 do
3960 local _obj_0 = _exp_0[3]
3961 if _obj_0 ~= nil then
3962 _val_4 = _obj_0.a
3963 end
3964 end
3965 local _val_5
3966 do
3967 local _obj_0 = _exp_0[3]
3968 if _obj_0 ~= nil then
3969 _val_5 = _obj_0.b
3970 end
3971 end
3972 if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and fourth ~= nil then
3973 print("matched", fourth)
3974 end
3975end
3976local segments = {
3977 "admin",
3978 "users",
3979 "logs",
3980 "view"
3981}
3982local _type_0 = type(segments)
3983local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3984if _tab_0 then
3985 local groups
3986 do
3987 local _accum_0 = { }
3988 local _len_0 = 1
3989 local _max_0 = #segments + -3 + 1
3990 for _index_0 = 1, _max_0 do
3991 local _item_0 = segments[_index_0]
3992 _accum_0[_len_0] = _item_0
3993 _len_0 = _len_0 + 1
3994 end
3995 groups = _accum_0
3996 end
3997 local resource = segments[#segments - 1]
3998 local action = segments[#segments]
3999 if resource ~= nil and action ~= nil then
4000 print("Group:", groups)
4001 print("Resource:", resource)
4002 print("Action:", action)
4003 end
4004end
4005local i = 10
4006while i > 0 do
4007 print(i)
4008 i = i - 1
4009end
4010while running == true do
4011 my_function()
4012end
4013local i = 10
4014while not (i == 0) do
4015 print(i)
4016 i = i - 1
4017end
4018while not (running == false) do
4019 my_function()
4020end
4021local i = 10
4022repeat
4023 print(i)
4024 i = i - 1
4025until i == 0
4026local i = 10
4027while i > 0 do
4028 print(i)
4029 i = i - 1
4030end
4031while running == true do
4032 my_function()
4033end
4034local i = 10
4035while not (i == 0) do
4036 print(i)
4037 i = i - 1
4038end
4039while not (running == false) do
4040 my_function()
4041end
4042local i = 10
4043repeat
4044 print(i)
4045 i = i - 1
4046until i == 0
4047local my_object = {
4048 value = 1000,
4049 write = function(self)
4050 return print("the value:", self.value)
4051 end
4052}
4053local run_callback
4054run_callback = function(func)
4055 print("running callback...")
4056 return func()
4057end
4058run_callback(my_object.write)
4059run_callback((function()
4060 local _base_0 = my_object
4061 local _fn_0 = _base_0.write
4062 return _fn_0 and function(...)
4063 return _fn_0(_base_0, ...)
4064 end
4065end)())
4066local my_object = {
4067 value = 1000,
4068 write = function(self)
4069 return print("the value:", self.value)
4070 end
4071}
4072local run_callback
4073run_callback = function(func)
4074 print("running callback...")
4075 return func()
4076end
4077run_callback(my_object.write)
4078run_callback((function()
4079 local _base_0 = my_object
4080 local _fn_0 = _base_0.write
4081 return _fn_0 and function(...)
4082 return _fn_0(_base_0, ...)
4083 end
4084end)())
4085f(function(x)
4086 return print("hello" .. x)
4087end)
4088f(function(self)
4089 return print(self.value)
4090end)
4091map(function(x)
4092 return x * 2
4093end, {
4094 1,
4095 2,
4096 3
4097})
4098local result, msg
4099do
4100 result, msg = readAsync("filename.txt", function(data)
4101 print(data)
4102 return processAsync(data, function(info)
4103 return check(info)
4104 end)
4105 end)
4106end
4107print(result, msg)
4108f(function(x)
4109 return print("hello" .. x)
4110end)
4111f(function(self)
4112 return print(self.value)
4113end)
4114map(function(x)
4115 return x * 2
4116end, {
4117 1,
4118 2,
4119 3
4120})
4121local result, msg
4122do
4123 result, msg = readAsync("filename.txt", function(data)
4124 print(data)
4125 return processAsync(data, function(info)
4126 return check(info)
4127 end)
4128 end)
4129end
4130print(result, msg)
4131local my_function
4132my_function = function() end
4133my_function()
4134local func_a
4135func_a = function()
4136 return print("hello world")
4137end
4138local func_b
4139func_b = function()
4140 local value = 100
4141 return print("The value:", value)
4142end
4143func_a()
4144func_b()
4145local sum
4146sum = function(x, y)
4147 return print("sum", x + y)
4148end
4149sum(10, 20)
4150print(sum(10, 20))
4151a(b(c("a", "b", "c")))
4152print("x:", sum(10, 20), "y:", sum(30, 40))
4153local sum
4154sum = function(x, y)
4155 return x + y
4156end
4157print("The sum is ", sum(10, 20))
4158local sum
4159sum = function(x, y)
4160 return x + y
4161end
4162local mystery
4163mystery = function(x, y)
4164 return x + y, x - y
4165end
4166local a, b = mystery(10, 20)
4167local func
4168func = function(self, num)
4169 return self.value + num
4170end
4171local my_function
4172my_function = function(name, height)
4173 if name == nil then
4174 name = "something"
4175 end
4176 if height == nil then
4177 height = 100
4178 end
4179 print("Hello I am", name)
4180 return print("My height is", height)
4181end
4182local some_args
4183some_args = function(x, y)
4184 if x == nil then
4185 x = 100
4186 end
4187 if y == nil then
4188 y = x + 1000
4189 end
4190 return print(x + y)
4191end
4192local a = x - 10
4193local b = x - 10
4194local c = x(-y)
4195local d = x - z
4196local x = func("hello") + 100
4197local y = func("hello" + 100)
4198my_func(5, 4, 3, 8, 9, 10)
4199cool_func(1, 2, 3, 4, 5, 6, 7, 8)
4200my_func(5, 6, 7, 6, another_func(6, 7, 8, 9, 1, 2), 5, 4)
4201local x = {
4202 1,
4203 2,
4204 3,
4205 4,
4206 a_func(4, 5, 5, 6),
4207 8,
4208 9,
4209 10
4210}
4211local y = {
4212 my_func(1, 2, 3, 4, 5),
4213 5,
4214 6,
4215 7
4216}
4217if func(1, 2, 3, "hello", "world") then
4218 print("hello")
4219 print("I am inside if")
4220end
4221if func(1, 2, 3, "hello", "world") then
4222 print("hello")
4223 print("I am inside if")
4224end
4225local f1
4226f1 = function(_arg_0)
4227 local a, b, c
4228 a, b, c = _arg_0.a, _arg_0.b, _arg_0.c
4229 return print(a, b, c)
4230end
4231f1({
4232 a = 1,
4233 b = "2",
4234 c = { }
4235})
4236local f2
4237f2 = function(_arg_0, c)
4238 local a1, b
4239 a1, b = _arg_0.a, _arg_0.b
4240 if a1 == nil then
4241 a1 = 123
4242 end
4243 if b == nil then
4244 b = 'abc'
4245 end
4246 if c == nil then
4247 c = { }
4248 end
4249 return print(a1, b, c)
4250end
4251local arg1 = {
4252 a = 0
4253}
4254f2(arg1, arg2)
4255local findFirstEven
4256findFirstEven = function(list)
4257 for _index_0 = 1, #list do
4258 local item = list[_index_0]
4259 if type(item) == "table" then
4260 for _index_1 = 1, #item do
4261 local sub = item[_index_1]
4262 if sub % 2 == 0 then
4263 return sub
4264 end
4265 end
4266 end
4267 end
4268 return nil
4269end
4270local findFirstEven
4271findFirstEven = function(list)
4272 for _index_0 = 1, #list do
4273 local item = list[_index_0]
4274 if type(item) == "table" then
4275 for _index_1 = 1, #item do
4276 local sub = item[_index_1]
4277 if sub % 2 == 0 then
4278 return sub
4279 end
4280 end
4281 end
4282 end
4283 return nil
4284end
4285local f
4286f = function(...)
4287 local t = {
4288 n = select("#", ...),
4289 ...
4290 }
4291 print("argument count:", t.n)
4292 print("table length:", #t)
4293 for i = 1, t.n do
4294 print(t[i])
4295 end
4296end
4297f(1, 2, 3)
4298f("a", "b", "c", "d")
4299f()
4300local process
4301process = function(...)
4302 local args = {
4303 n = select("#", ...),
4304 ...
4305 }
4306 local sum = 0
4307 for i = 1, args.n do
4308 if args[i] ~= nil and type(args[i]) == "number" then
4309 sum = sum + args[i]
4310 end
4311 end
4312 return sum
4313end
4314process(1, nil, 3, nil, 5)
4315local my_function
4316my_function = function() end
4317my_function()
4318local func_a
4319func_a = function()
4320 return print("hello world")
4321end
4322local func_b
4323func_b = function()
4324 local value = 100
4325 return print("The value:", value)
4326end
4327func_a()
4328func_b()
4329local sum
4330sum = function(x, y)
4331 return print("sum", x + y)
4332end
4333sum(10, 20)
4334print(sum(10, 20))
4335a(b(c("a", "b", "c")))
4336print("x:", sum(10, 20), "y:", sum(30, 40))
4337local sum
4338sum = function(x, y)
4339 return x + y
4340end
4341print("The sum is ", sum(10, 20))
4342local sum
4343sum = function(x, y)
4344 return x + y
4345end
4346local mystery
4347mystery = function(x, y)
4348 return x + y, x - y
4349end
4350local a, b = mystery(10, 20)
4351local func
4352func = function(self, num)
4353 return self.value + num
4354end
4355local my_function
4356my_function = function(name, height)
4357 if name == nil then
4358 name = "something"
4359 end
4360 if height == nil then
4361 height = 100
4362 end
4363 print("Hello I am", name)
4364 return print("My height is", height)
4365end
4366local some_args
4367some_args = function(x, y)
4368 if x == nil then
4369 x = 100
4370 end
4371 if y == nil then
4372 y = x + 1000
4373 end
4374 return print(x + y)
4375end
4376local a = x - 10
4377local b = x - 10
4378local c = x(-y)
4379local d = x - z
4380local x = func("hello") + 100
4381local y = func("hello" + 100)
4382my_func(5, 4, 3, 8, 9, 10)
4383cool_func(1, 2, 3, 4, 5, 6, 7, 8)
4384my_func(5, 6, 7, 6, another_func(6, 7, 8, 9, 1, 2), 5, 4)
4385local x = {
4386 1,
4387 2,
4388 3,
4389 4,
4390 a_func(4, 5, 5, 6),
4391 8,
4392 9,
4393 10
4394}
4395local y = {
4396 my_func(1, 2, 3, 4, 5),
4397 5,
4398 6,
4399 7
4400}
4401if func(1, 2, 3, "hello", "world") then
4402 print("hello")
4403 print("I am inside if")
4404end
4405if func(1, 2, 3, "hello", "world") then
4406 print("hello")
4407 print("I am inside if")
4408end
4409local f1
4410f1 = function(_arg_0)
4411 local a, b, c
4412 a, b, c = _arg_0.a, _arg_0.b, _arg_0.c
4413 return print(a, b, c)
4414end
4415f1({
4416 a = 1,
4417 b = "2",
4418 c = { }
4419})
4420local f2
4421f2 = function(_arg_0, c)
4422 local a1, b
4423 a1, b = _arg_0.a, _arg_0.b
4424 if a1 == nil then
4425 a1 = 123
4426 end
4427 if b == nil then
4428 b = 'abc'
4429 end
4430 if c == nil then
4431 c = { }
4432 end
4433end
4434print(a1, b, c)
4435local arg1 = {
4436 a = 0
4437}
4438f2(arg1, arg2)
4439local findFirstEven
4440findFirstEven = function(list)
4441 for _index_0 = 1, #list do
4442 local item = list[_index_0]
4443 if type(item) == "table" then
4444 for _index_1 = 1, #item do
4445 local sub = item[_index_1]
4446 if sub % 2 == 0 then
4447 return sub
4448 end
4449 end
4450 end
4451 end
4452 return nil
4453end
4454local findFirstEven
4455findFirstEven = function(list)
4456 for _index_0 = 1, #list do
4457 local item = list[_index_0]
4458 if type(item) == "table" then
4459 for _index_1 = 1, #item do
4460 local sub = item[_index_1]
4461 if sub % 2 == 0 then
4462 return sub
4463 end
4464 end
4465 end
4466 end
4467 return nil
4468end
4469local f
4470f = function(...)
4471 local t = {
4472 n = select("#", ...),
4473 ...
4474 }
4475 print("argument count:", t.n)
4476 print("table length:", #t)
4477 for i = 1, t.n do
4478 print(t[i])
4479 end
4480end
4481f(1, 2, 3)
4482f("a", "b", "c", "d")
4483f()
4484local process
4485process = function(...)
4486 local args = {
4487 n = select("#", ...),
4488 ...
4489 }
4490 local sum = 0
4491 for i = 1, args.n do
4492 if args[i] ~= nil and type(args[i]) == "number" then
4493 sum = sum + args[i]
4494 end
4495 end
4496 return sum
4497end
4498process(1, nil, 3, nil, 5)
4499local a = 1
4500local b = 2
4501print(a + b)
4502Rx.Observable.fromRange(1, 8):filter(function(x)
4503 return x % 2 == 0
4504end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
4505 return value .. '!'
4506end):subscribe(print)
4507local a = 1
4508local b = 2
4509print(a + b)
4510Rx.Observable.fromRange(1, 8):filter(function(x)
4511 return x % 2 == 0
4512end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
4513 return value .. '!'
4514end):subscribe(print)
4515local str = strA .. strB .. strC
4516func(3000, "192.168.1.1")
4517local str = strA .. strB .. strC
4518func(3000, "192.168.1.1")
4519local a <const> = 123
4520local _ <close> = setmetatable({ }, {
4521 __close = function()
4522 return print("Out of scope.")
4523 end
4524})
4525local a, b, c, d
4526local _obj_0 = tb
4527a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
4528Constant = 123
4529local a <const> = 123
4530local _ <close> = setmetatable({ }, {
4531 __close = function()
4532 return print("Out of scope.")
4533 end
4534})
4535local a, b, c, d
4536local _obj_0 = tb
4537a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
4538Constant = 123
4539if tb ~= nil then
4540 tb:func()
4541end
4542if tb ~= nil then
4543 tb:func()
4544end
4545print(1 < 2 and 2 <= 2 and 2 < 3 and 3 == 3 and 3 > 2 and 2 >= 1 and 1 == 1 and 1 < 3 and 3 ~= 5)
4546local a = 5
4547print(1 <= a and a <= 10)
4548local v
4549v = function(x)
4550 print(x)
4551 return x
4552end
4553print((function()
4554 local _cond_0 = v(2)
4555 if not (v(1) < _cond_0) then
4556 return false
4557 else
4558 return _cond_0 <= v(3)
4559 end
4560end)())
4561print((function()
4562 local _cond_0 = v(2)
4563 if not (v(1) > _cond_0) then
4564 return false
4565 else
4566 return _cond_0 <= v(3)
4567 end
4568end)())
4569local tab = { }
4570tab[#tab + 1] = "Value"
4571local tbA = {
4572 1,
4573 2,
4574 3
4575}
4576local tbB = {
4577 4,
4578 5,
4579 6
4580}
4581local _len_0 = #tbA + 1
4582for _index_0 = 1, #tbB do
4583 local _elm_0 = tbB[_index_0]
4584 tbA[_len_0], _len_0 = _elm_0, _len_0 + 1
4585end
4586local parts = {
4587 "shoulders",
4588 "knees"
4589}
4590local lyrics
4591do
4592 local _tab_0 = {
4593 "head"
4594 }
4595 local _idx_0 = 1
4596 for _key_0, _value_0 in pairs(parts) do
4597 if _idx_0 == _key_0 then
4598 _tab_0[#_tab_0 + 1] = _value_0
4599 _idx_0 = _idx_0 + 1
4600 else
4601 _tab_0[_key_0] = _value_0
4602 end
4603 end
4604 _tab_0[#_tab_0 + 1] = "and"
4605 _tab_0[#_tab_0 + 1] = "toes"
4606 lyrics = _tab_0
4607end
4608local copy
4609do
4610 local _tab_0 = { }
4611 local _idx_0 = 1
4612 for _key_0, _value_0 in pairs(other) do
4613 if _idx_0 == _key_0 then
4614 _tab_0[#_tab_0 + 1] = _value_0
4615 _idx_0 = _idx_0 + 1
4616 else
4617 _tab_0[_key_0] = _value_0
4618 end
4619 end
4620 copy = _tab_0
4621end
4622local a = {
4623 1,
4624 2,
4625 3,
4626 x = 1
4627}
4628local b = {
4629 4,
4630 5,
4631 y = 1
4632}
4633local merge
4634local _tab_0 = { }
4635local _idx_0 = 1
4636for _key_0, _value_0 in pairs(a) do
4637 if _idx_0 == _key_0 then
4638 _tab_0[#_tab_0 + 1] = _value_0
4639 _idx_0 = _idx_0 + 1
4640 else
4641 _tab_0[_key_0] = _value_0
4642 end
4643end
4644local _idx_1 = 1
4645for _key_0, _value_0 in pairs(b) do
4646 if _idx_1 == _key_0 then
4647 _tab_0[#_tab_0 + 1] = _value_0
4648 _idx_1 = _idx_1 + 1
4649 else
4650 _tab_0[_key_0] = _value_0
4651 end
4652end
4653merge = _tab_0
4654local last
4655do
4656 local _item_0 = data.items
4657 last = _item_0[#_item_0]
4658end
4659local second_last
4660do
4661 local _item_0 = data.items
4662 second_last = _item_0[#_item_0 - 1]
4663end
4664local _obj_0 = data.items
4665_obj_0[#_obj_0] = 1
4666local mt = { }
4667local add
4668add = function(self, right)
4669 return setmetatable({
4670 value = self.value + right.value
4671 }, mt)
4672end
4673mt.__add = add
4674local a = setmetatable({
4675 value = 1
4676}, mt)
4677local b = setmetatable({
4678 value = 2
4679}, {
4680 __add = add
4681})
4682local c = setmetatable({
4683 value = 3
4684}, {
4685 __add = mt.__add
4686})
4687local d = a + b + c
4688print(d.value)
4689local _ <close> = setmetatable({ }, {
4690 __close = function()
4691 return print("out of scope")
4692 end
4693})
4694local tb = setmetatable({ }, {
4695 ["value"] = 123
4696})
4697getmetatable(tb).__index = getmetatable(tb)
4698print(tb.value)
4699setmetatable(tb, {
4700 __index = {
4701 item = "hello"
4702 }
4703})
4704print(tb.item)
4705local item, new, close, getter
4706do
4707 local _obj_0 = tb
4708 item, new = _obj_0[1], _obj_0.new
4709 do
4710 local _obj_1 = getmetatable(_obj_0)
4711 close, getter = _obj_1.__close, _obj_1.__index
4712 end
4713end
4714print(item, new, close, getter)
4715do
4716 local _obj_0 = func
4717 if _obj_0 ~= nil then
4718 _obj_0()
4719 end
4720end
4721print((function()
4722 local _obj_0 = abc
4723 if _obj_0 ~= nil then
4724 local _obj_1 = _obj_0["hello world"]
4725 if _obj_1 ~= nil then
4726 return _obj_1.xyz
4727 end
4728 return nil
4729 end
4730 return nil
4731end)())
4732local x
4733do
4734 local _obj_0 = tab
4735 if _obj_0 ~= nil then
4736 x = _obj_0.value
4737 end
4738end
4739local len = (function()
4740 local _obj_0 = utf8
4741 if _obj_0 ~= nil then
4742 return _obj_0.len
4743 end
4744 return nil
4745end)() or (function()
4746 local _obj_0 = string
4747 if _obj_0 ~= nil then
4748 return _obj_0.len
4749 end
4750 return nil
4751end)() or function(o)
4752 return #o
4753end
4754if print and (x ~= nil) then
4755 print(x)
4756end
4757local _with_0 = io.open("test.txt", "w")
4758if _with_0 ~= nil then
4759 _with_0:write("hello")
4760 _with_0:close()
4761end
4762print("hello")
4763print(1, 2)
4764print(1, 2, 3)
4765print(render(emit(parse(extract(readFile("example.txt"), language, { }), language))))
4766local a, b, c, d
4767if b ~= nil then
4768 a = b
4769else
4770 if c ~= nil then
4771 a = c
4772 else
4773 a = d
4774 end
4775end
4776func((function()
4777 if a ~= nil then
4778 return a
4779 else
4780 return { }
4781 end
4782end)())
4783if a == nil then
4784 a = false
4785end
4786local list = {
4787 1,
4788 2,
4789 3
4790}
4791func({
4792 1,
4793 2,
4794 3
4795})
4796local f
4797f = function()
4798 return {
4799 1,
4800 2,
4801 3
4802 }
4803end
4804local tb = {
4805 name = "abc",
4806 values = {
4807 "a",
4808 "b",
4809 "c"
4810 },
4811 objects = {
4812 {
4813 name = "a",
4814 value = 1,
4815 func = function(self)
4816 return self.value + 1
4817 end,
4818 tb = {
4819 fieldA = 1
4820 }
4821 },
4822 {
4823 name = "b",
4824 value = 2,
4825 func = function(self)
4826 return self.value + 2
4827 end,
4828 tb = { }
4829 }
4830 }
4831}
4832if tb ~= nil then
4833 tb:func()
4834end
4835if tb ~= nil then
4836 tb:func()
4837end
4838print(1 < 2 and 2 <= 2 and 2 < 3 and 3 == 3 and 3 > 2 and 2 >= 1 and 1 == 1 and 1 < 3 and 3 ~= 5)
4839local a = 5
4840print(1 <= a and a <= 10)
4841local v
4842v = function(x)
4843 print(x)
4844 return x
4845end
4846print((function()
4847 local _cond_0 = v(2)
4848 if not (v(1) < _cond_0) then
4849 return false
4850 else
4851 return _cond_0 <= v(3)
4852 end
4853end)())
4854print((function()
4855 local _cond_0 = v(2)
4856 if not (v(1) > _cond_0) then
4857 return false
4858 else
4859 return _cond_0 <= v(3)
4860 end
4861end)())
4862local tab = { }
4863tab[#tab + 1] = "Value"
4864local tbA = {
4865 1,
4866 2,
4867 3
4868}
4869local tbB = {
4870 4,
4871 5,
4872 6
4873}
4874local _len_0 = #tbA + 1
4875for _index_0 = 1, #tbB do
4876 local _elm_0 = tbB[_index_0]
4877 tbA[_len_0], _len_0 = _elm_0, _len_0 + 1
4878end
4879local parts = {
4880 "shoulders",
4881 "knees"
4882}
4883local lyrics
4884do
4885 local _tab_0 = {
4886 "head"
4887 }
4888 local _idx_0 = 1
4889 for _key_0, _value_0 in pairs(parts) do
4890 if _idx_0 == _key_0 then
4891 _tab_0[#_tab_0 + 1] = _value_0
4892 _idx_0 = _idx_0 + 1
4893 else
4894 _tab_0[_key_0] = _value_0
4895 end
4896 end
4897 _tab_0[#_tab_0 + 1] = "and"
4898 _tab_0[#_tab_0 + 1] = "toes"
4899 lyrics = _tab_0
4900end
4901local copy
4902do
4903 local _tab_0 = { }
4904 local _idx_0 = 1
4905 for _key_0, _value_0 in pairs(other) do
4906 if _idx_0 == _key_0 then
4907 _tab_0[#_tab_0 + 1] = _value_0
4908 _idx_0 = _idx_0 + 1
4909 else
4910 _tab_0[_key_0] = _value_0
4911 end
4912 end
4913 copy = _tab_0
4914end
4915local a = {
4916 1,
4917 2,
4918 3,
4919 x = 1
4920}
4921local b = {
4922 4,
4923 5,
4924 y = 1
4925}
4926local merge
4927local _tab_0 = { }
4928local _idx_0 = 1
4929for _key_0, _value_0 in pairs(a) do
4930 if _idx_0 == _key_0 then
4931 _tab_0[#_tab_0 + 1] = _value_0
4932 _idx_0 = _idx_0 + 1
4933 else
4934 _tab_0[_key_0] = _value_0
4935 end
4936end
4937local _idx_1 = 1
4938for _key_0, _value_0 in pairs(b) do
4939 if _idx_1 == _key_0 then
4940 _tab_0[#_tab_0 + 1] = _value_0
4941 _idx_1 = _idx_1 + 1
4942 else
4943 _tab_0[_key_0] = _value_0
4944 end
4945end
4946merge = _tab_0
4947local last
4948do
4949 local _item_0 = data.items
4950 last = _item_0[#_item_0]
4951end
4952local second_last
4953do
4954 local _item_0 = data.items
4955 second_last = _item_0[#_item_0 - 1]
4956end
4957local _obj_0 = data.items
4958_obj_0[#_obj_0] = 1
4959local mt = { }
4960local add
4961add = function(self, right)
4962 return setmetatable({
4963 value = self.value + right.value
4964 }, mt)
4965end
4966mt.__add = add
4967local a = setmetatable({
4968 value = 1
4969}, mt)
4970local b = setmetatable({
4971 value = 2
4972}, {
4973 __add = add
4974})
4975local c = setmetatable({
4976 value = 3
4977}, {
4978 __add = mt.__add
4979})
4980local d = a + b + c
4981print(d.value)
4982local _ <close> = setmetatable({ }, {
4983 __close = function()
4984 return print("out of scope")
4985 end
4986})
4987local tb = setmetatable({ }, {
4988 ["value"] = 123
4989})
4990getmetatable(tb).__index = getmetatable(tb)
4991print(tb.value)
4992setmetatable(tb, {
4993 __index = {
4994 item = "hello"
4995 }
4996})
4997print(tb.item)
4998local item, new, close, getter
4999do
5000 local _obj_0 = tb
5001 item, new = _obj_0[1], _obj_0.new
5002 do
5003 local _obj_1 = getmetatable(_obj_0)
5004 close, getter = _obj_1.__close, _obj_1.__index
5005 end
5006end
5007print(item, new, close, getter)
5008do
5009 local _obj_0 = func
5010 if _obj_0 ~= nil then
5011 _obj_0()
5012 end
5013end
5014print((function()
5015 local _obj_0 = abc
5016 if _obj_0 ~= nil then
5017 local _obj_1 = _obj_0["hello world"]
5018 if _obj_1 ~= nil then
5019 return _obj_1.xyz
5020 end
5021 return nil
5022 end
5023 return nil
5024end)())
5025local x
5026do
5027 local _obj_0 = tab
5028 if _obj_0 ~= nil then
5029 x = _obj_0.value
5030 end
5031end
5032local len = (function()
5033 local _obj_0 = utf8
5034 if _obj_0 ~= nil then
5035 return _obj_0.len
5036 end
5037 return nil
5038end)() or (function()
5039 local _obj_0 = string
5040 if _obj_0 ~= nil then
5041 return _obj_0.len
5042 end
5043 return nil
5044end)() or function(o)
5045 return #o
5046end
5047if print and (x ~= nil) then
5048 print(x)
5049end
5050local _with_0 = io.open("test.txt", "w")
5051if _with_0 ~= nil then
5052 _with_0:write("hello")
5053 _with_0:close()
5054end
5055print("hello")
5056print(1, 2)
5057print(1, 2, 3)
5058print(render(emit(parse(extract(readFile("example.txt"), language, { }), language))))
5059local a, b, c, d
5060if b ~= nil then
5061 a = b
5062else
5063 if c ~= nil then
5064 a = c
5065 else
5066 a = d
5067 end
5068end
5069func((function()
5070 if a ~= nil then
5071 return a
5072 else
5073 return { }
5074 end
5075end)())
5076if a == nil then
5077 a = false
5078end
5079local list = {
5080 1,
5081 2,
5082 3
5083}
5084func({
5085 1,
5086 2,
5087 3
5088})
5089local f
5090f = function()
5091 return {
5092 1,
5093 2,
5094 3
5095 }
5096end
5097local tb = {
5098 name = "abc",
5099 values = {
5100 "a",
5101 "b",
5102 "c"
5103 },
5104 objects = {
5105 {
5106 name = "a",
5107 value = 1,
5108 func = function(self)
5109 return self.value + 1
5110 end,
5111 tb = {
5112 fieldA = 1
5113 }
5114 },
5115 {
5116 name = "b",
5117 value = 2,
5118 func = function(self)
5119 return self.value + 2
5120 end,
5121 tb = { }
5122 }
5123 }
5124}
5125local some_string = "Here is a string\n that has a line break in it."
5126print("I am " .. tostring(math.random() * 100) .. "% sure.")
5127local integer = 1000000
5128local hex = 0xEFBBBF
5129local binary = 19
5130local str = "key: value\nlist:\n - item1\n - " .. tostring(expr)
5131local fn
5132fn = function()
5133 local str = "foo:\n bar: baz"
5134 return str
5135end
5136local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'"
5137local some_string = "Here is a string\n that has a line break in it."
5138print("I am " .. tostring(math.random() * 100) .. "% sure.")
5139local integer = 1000000
5140local hex = 0xEFBBBF
5141local binary = 19
5142local str = "key: value\nlist:\n - item1\n - " .. tostring(expr)
5143local fn
5144fn = function()
5145 local str = "foo:\n bar: baz"
5146 return str
5147end
5148local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'"
diff --git a/spec/outputs/codes_from_doc_pt-br.lua b/spec/outputs/codes_from_doc_pt-br.lua
new file mode 100644
index 0000000..0b3670c
--- /dev/null
+++ b/spec/outputs/codes_from_doc_pt-br.lua
@@ -0,0 +1,5148 @@
1do
2 local var = "hello"
3 print(var)
4end
5print(var)
6local counter
7do
8 local i = 0
9 counter = function()
10 i = i + 1
11 return i
12 end
13end
14print(counter())
15print(counter())
16local tbl = {
17 key = (function()
18 print("assigning key!")
19 return 1234
20 end)()
21}
22do
23 local var = "hello"
24 print(var)
25end
26print(var)
27local counter
28do
29 local i = 0
30 counter = function()
31 i = i + 1
32 return i
33 end
34end
35print(counter())
36print(counter())
37local tbl = {
38 key = (function()
39 print("assigning key!")
40 return 1234
41 end)()
42}
43if name == "Rob" then
44 print("hello world")
45end
46local _list_0 = items
47for _index_0 = 1, #_list_0 do
48 local item = _list_0[_index_0]
49 print("item: ", item)
50end
51while game:isRunning() do
52 game:update()
53end
54while not reader:eof() do
55 reader:parse_line()
56end
57if name == "Rob" then
58 print("hello world")
59end
60local _list_0 = items
61for _index_0 = 1, #_list_0 do
62 local item = _list_0[_index_0]
63 print("item: ", item)
64end
65while game:isRunning() do
66 game:update()
67end
68while not reader:eof() do
69 reader:parse_line()
70end
71local area = 6.2831853071796 * 5
72print('hello world')
73do
74 assert(item ~= nil)
75end
76local value = item
77if (f1() and f2() and f3()) then
78 print("OK")
79end
80do
81 local funcA
82 funcA = function() end
83end
84local funcA
85funcA = function()
86 return "fail to assign to the Yue macro defined variable"
87end
88do
89local function funcB() end
90end
91local funcB
92funcB = function()
93 return "fail to assign to the Lua macro defined variable"
94end
95do
96-- raw Lua codes insertion
97if cond then
98 print("output")
99end
100end
101print("yuescript")
102print(2)
103print("Valid enum type:", "Static")
104do
105 print(123, "hello")
106end
107do
108 print(123, "hello")
109end
110local area = 6.2831853071796 * 5
111print('hello world')
112do
113 assert(item ~= nil)
114end
115local value = item
116if (f1() and f2() and f3()) then
117 print("OK")
118end
119do
120 local funcA
121 funcA = function() end
122end
123local funcA
124funcA = function()
125 return "fail to assign to the Yue macro defined variable"
126end
127do
128local function funcB() end
129end
130local funcB
131funcB = function()
132 return "fail to assign to the Lua macro defined variable"
133end
134do
135-- raw Lua codes insertion
136if cond then
137 print("output")
138end
139end
140print("yuescript")
141print(2)
142print("Valid enum type:", "Static")
143do
144 print(123, "hello")
145end
146do
147 print(123, "hello")
148end
149do
150 local insert, concat = table.insert, table.concat
151 local C, Ct, Cmt
152 do
153 local _obj_0 = require("lpeg")
154 C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt
155 end
156 local x, y, z
157 do
158 local _obj_0 = require('mymodule')
159 x, y, z = _obj_0.x, _obj_0.y, _obj_0.z
160 end
161 local a, b, c
162 local _obj_0 = require('module')
163 a, b, c = _obj_0.a, _obj_0.b, _obj_0.c
164end
165do
166 local module = require('module')
167 local module_x = require('module_x')
168 local d_a_s_h_e_s = require("d-a-s-h-e-s")
169 local part = require("module.part")
170end
171do
172 local PlayerModule = require("player")
173 local C, Ct, Cmt
174 do
175 local _obj_0 = require("lpeg")
176 C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt
177 end
178 local one, two, ch
179 local _obj_0 = require("export")
180 one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1]
181end
182do
183 local tostring <const> = tostring
184 local concat <const> = table.concat
185 print(concat({
186 "a",
187 tostring(1)
188 }))
189end
190do
191 local print <const> = print
192 local math <const> = math
193 print("hello")
194 math.random(3)
195end
196do
197 local print <const> = print
198 print(FLAG)
199 FLAG = 123
200end
201local _module_0 = { }
202local a, b, c = 1, 2, 3
203_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c
204local cool = "cat"
205_module_0["cool"] = cool
206local What
207if this then
208 What = "abc"
209else
210 What = "def"
211end
212_module_0["What"] = What
213local y
214y = function()
215 local hallo = 3434
216end
217_module_0["y"] = y
218local Something
219local _class_0
220local _base_0 = {
221 umm = "cool"
222}
223if _base_0.__index == nil then
224 _base_0.__index = _base_0
225end
226_class_0 = setmetatable({
227 __init = function() end,
228 __base = _base_0,
229 __name = "Something"
230}, {
231 __index = _base_0,
232 __call = function(cls, ...)
233 local _self_0 = setmetatable({ }, _base_0)
234 cls.__init(_self_0, ...)
235 return _self_0
236 end
237})
238_base_0.__class = _class_0
239Something = _class_0
240_module_0["Something"] = Something
241return _module_0
242local _module_0 = { }
243local loadstring, tolua
244do
245 local _obj_0 = yue
246 loadstring, tolua = _obj_0.loadstring, _obj_0.to_lua
247end
248_module_0["loadstring"], _module_0["tolua"] = loadstring, tolua
249local fieldA = tb.itemA.fieldA
250if fieldA == nil then
251 fieldA = 'default'
252end
253_module_0["fieldA"] = fieldA
254return _module_0
255local _module_0 = setmetatable({ }, { })
256_module_0.itemA = tb
257getmetatable(_module_0).__index = items
258_module_0["a-b-c"] = 123
259return _module_0
260local _module_0 = { }
261local d, e, f = 3, 2, 1
262_module_0[#_module_0 + 1] = d
263_module_0[#_module_0 + 1] = e
264_module_0[#_module_0 + 1] = f
265if this then
266 _module_0[#_module_0 + 1] = 123
267else
268 _module_0[#_module_0 + 1] = 456
269end
270local _with_0 = tmp
271local j = 2000
272_module_0[#_module_0 + 1] = _with_0
273return _module_0
274local _module_0 = nil
275_module_0 = function()
276 print("hello")
277 return 123
278end
279return _module_0
280do
281 local insert, concat = table.insert, table.concat
282 local C, Ct, Cmt
283 do
284 local _obj_0 = require("lpeg")
285 C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt
286 end
287 local x, y, z
288 do
289 local _obj_0 = require('mymodule')
290 x, y, z = _obj_0.x, _obj_0.y, _obj_0.z
291 end
292 local a, b, c
293 local _obj_0 = require('module')
294 a, b, c = _obj_0.a, _obj_0.b, _obj_0.c
295end
296do
297 local module = require('module')
298 local module_x = require('module_x')
299 local d_a_s_h_e_s = require("d-a-s-h-e-s")
300 local part = require("module.part")
301end
302do
303 local PlayerModule = require("player")
304 local C, Ct, Cmt
305 do
306 local _obj_0 = require("lpeg")
307 C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt
308 end
309 local one, two, ch
310 local _obj_0 = require("export")
311 one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1]
312end
313do
314 local tostring <const> = tostring
315 local concat <const> = table.concat
316 print(concat({
317 "a",
318 tostring(1)
319 }))
320end
321do
322 local print <const> = print
323 local math <const> = math
324 print("hello")
325 math.random(3)
326end
327do
328 local print <const> = print
329 print(FLAG)
330 FLAG = 123
331end
332local _module_0 = { }
333local a, b, c = 1, 2, 3
334_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c
335local cool = "cat"
336_module_0["cool"] = cool
337local What
338if this then
339 What = "abc"
340else
341 What = "def"
342end
343_module_0["What"] = What
344local y
345y = function()
346 local hallo = 3434
347end
348_module_0["y"] = y
349local Something
350local _class_0
351local _base_0 = {
352 umm = "cool"
353}
354if _base_0.__index == nil then
355 _base_0.__index = _base_0
356end
357_class_0 = setmetatable({
358 __init = function() end,
359 __base = _base_0,
360 __name = "Something"
361}, {
362 __index = _base_0,
363 __call = function(cls, ...)
364 local _self_0 = setmetatable({ }, _base_0)
365 cls.__init(_self_0, ...)
366 return _self_0
367 end
368})
369_base_0.__class = _class_0
370Something = _class_0
371_module_0["Something"] = Something
372return _module_0
373local _module_0 = { }
374local loadstring, tolua
375do
376 local _obj_0 = yue
377 loadstring, tolua = _obj_0.loadstring, _obj_0.to_lua
378end
379_module_0["loadstring"], _module_0["tolua"] = loadstring, tolua
380local fieldA = tb.itemA.fieldA
381if fieldA == nil then
382 fieldA = 'default'
383end
384_module_0["fieldA"] = fieldA
385return _module_0
386local _module_0 = setmetatable({ }, { })
387_module_0.itemA = tb
388getmetatable(_module_0).__index = items
389_module_0["a-b-c"] = 123
390return _module_0
391local _module_0 = { }
392local d, e, f = 3, 2, 1
393_module_0[#_module_0 + 1] = d
394_module_0[#_module_0 + 1] = e
395_module_0[#_module_0 + 1] = f
396if this then
397 _module_0[#_module_0 + 1] = 123
398else
399 _module_0[#_module_0 + 1] = 456
400end
401local _with_0 = tmp
402local j = 2000
403_module_0[#_module_0 + 1] = _with_0
404return _module_0
405local _module_0 = nil
406_module_0 = function()
407 print("hello")
408 return 123
409end
410return _module_0
411xpcall(function()
412 return func(1, 2, 3)
413end, function(err)
414 return print(yue.traceback(err))
415end)
416local success, result = xpcall(function()
417 return func(1, 2, 3)
418end, function(err)
419 return yue.traceback(err)
420end)
421xpcall(function()
422 return func(1, 2, 3)
423end, function(err)
424 return print(yue.traceback(err))
425end)
426success, result = pcall(function()
427 return func(1, 2, 3)
428end)
429pcall(function()
430 print("trying")
431 return func(1, 2, 3)
432end)
433success, result = xpcall(function()
434 return func(1, 2, 3)
435end, function(err)
436 return print(yue.traceback(err))
437end)
438if success then
439 print(result)
440end
441local a, b, c
442do
443 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function()
444 return func()
445 end)
446 if _ok_0 then
447 a, b, c = _ret_0, _ret_1, _ret_2
448 end
449end
450do
451 local _exp_0 = ((function()
452 return (function(_arg_0, ...)
453 local _ok_0 = _arg_0
454 if _ok_0 then
455 return ...
456 end
457 end)(pcall(function()
458 return func()
459 end))
460 end)())
461 if _exp_0 ~= nil then
462 a = _exp_0
463 else
464 a = "default"
465 end
466end
467f((function()
468 return (function(_arg_0, ...)
469 local _ok_0 = _arg_0
470 if _ok_0 then
471 return ...
472 end
473 end)(pcall(function()
474 return func()
475 end))
476end)())
477f((function()
478 return (function(_arg_0, ...)
479 local _ok_0 = _arg_0
480 if _ok_0 then
481 return ...
482 end
483 end)(xpcall(function()
484 print(123)
485 return func()
486 end, function(e)
487 print(e)
488 return e
489 end))
490end)())
491xpcall(function()
492 return func(1, 2, 3)
493end, function(err)
494 return print(yue.traceback(err))
495end)
496local success, result = xpcall(function()
497 return func(1, 2, 3)
498end, function(err)
499 return yue.traceback(err)
500end)
501xpcall(function()
502 return func(1, 2, 3)
503end, function(err)
504 return print(yue.traceback(err))
505end)
506success, result = pcall(function()
507 return func(1, 2, 3)
508end)
509pcall(function()
510 print("trying")
511 return func(1, 2, 3)
512end)
513success, result = xpcall(function()
514 return func(1, 2, 3)
515end, function(err)
516 return print(yue.traceback(err))
517end)
518if success then
519 print(result)
520end
521local a, b, c
522do
523 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function()
524 return func()
525 end)
526 if _ok_0 then
527 a, b, c = _ret_0, _ret_1, _ret_2
528 end
529end
530do
531 local _exp_0 = ((function()
532 return (function(_arg_0, ...)
533 local _ok_0 = _arg_0
534 if _ok_0 then
535 return ...
536 end
537 end)(pcall(function()
538 return func()
539 end))
540 end)())
541 if _exp_0 ~= nil then
542 a = _exp_0
543 else
544 a = "default"
545 end
546end
547f((function()
548 return (function(_arg_0, ...)
549 local _ok_0 = _arg_0
550 if _ok_0 then
551 return ...
552 end
553 end)(pcall(function()
554 return func()
555 end))
556end)())
557f((function()
558 return (function(_arg_0, ...)
559 local _ok_0 = _arg_0
560 if _ok_0 then
561 return ...
562 end
563 end)(xpcall(function()
564 print(123)
565 return func()
566 end, function(e)
567 print(e)
568 return e
569 end))
570end)())
571local some_values = {
572 1,
573 2,
574 3,
575 4
576}
577local some_values = {
578 name = "Bill",
579 age = 200,
580 ["favorite food"] = "rice"
581}
582local profile = {
583 height = "4 feet",
584 shoe_size = 13,
585 favorite_foods = {
586 "ice cream",
587 "donuts"
588 }
589}
590local values = {
591 1,
592 2,
593 3,
594 4,
595 5,
596 6,
597 7,
598 8,
599 name = "superman",
600 occupation = "crime fighting"
601}
602my_function({
603 dance = "Tango",
604 partner = "none"
605})
606local y = {
607 type = "dog",
608 legs = 4,
609 tails = 1
610}
611local tbl = {
612 ["do"] = "something",
613 ["end"] = "hunger"
614}
615local hair = "golden"
616local height = 200
617local person = {
618 hair = hair,
619 height = height,
620 shoe_size = 40
621}
622print_table({
623 hair = hair,
624 height = height
625})
626local t = {
627 [1 + 2] = "hello",
628 ["hello world"] = true
629}
630local some_values = {
631 1,
632 2,
633 3,
634 4
635}
636local list_with_one_element = {
637 1
638}
639local some_values = {
640 1,
641 2,
642 3,
643 4
644}
645local some_values = {
646 name = "Bill",
647 age = 200,
648 ["favorite food"] = "rice"
649}
650local profile = {
651 height = "4 feet",
652 shoe_size = 13,
653 favorite_foods = {
654 "ice cream",
655 "donuts"
656 }
657}
658local values = {
659 1,
660 2,
661 3,
662 4,
663 5,
664 6,
665 7,
666 8,
667 name = "superman",
668 occupation = "crime fighting"
669}
670my_function({
671 dance = "Tango",
672 partner = "none"
673})
674local y = {
675 type = "dog",
676 legs = 4,
677 tails = 1
678}
679local tbl = {
680 ["do"] = "something",
681 ["end"] = "hunger"
682}
683local hair = "golden"
684local height = 200
685local person = {
686 hair = hair,
687 height = height,
688 shoe_size = 40
689}
690print_table({
691 hair = hair,
692 height = height
693})
694local t = {
695 [1 + 2] = "hello",
696 ["hello world"] = true
697}
698local some_values = {
699 1,
700 2,
701 3,
702 4
703}
704local list_with_one_element = {
705 1
706}
707local items = {
708 1,
709 2,
710 3,
711 4
712}
713local doubled
714local _accum_0 = { }
715local _len_0 = 1
716for i, item in ipairs(items) do
717 _accum_0[_len_0] = item * 2
718 _len_0 = _len_0 + 1
719end
720doubled = _accum_0
721local slice
722local _accum_0 = { }
723local _len_0 = 1
724for i, item in ipairs(items) do
725 if i > 1 and i < 3 then
726 _accum_0[_len_0] = item
727 _len_0 = _len_0 + 1
728 end
729end
730slice = _accum_0
731local doubled
732local _accum_0 = { }
733local _len_0 = 1
734local _list_0 = items
735for _index_0 = 1, #_list_0 do
736 local item = _list_0[_index_0]
737 _accum_0[_len_0] = item * 2
738 _len_0 = _len_0 + 1
739end
740doubled = _accum_0
741local data = {
742 a = {
743 1,
744 2,
745 3
746 },
747 b = {
748 4,
749 5,
750 6
751 }
752}
753local flat
754local _accum_0 = { }
755for k, v in pairs(data) do
756 local _len_0 = #_accum_0 + 1
757 for _index_0 = 1, #v do
758 local _elm_0 = v[_index_0]
759 _accum_0[_len_0], _len_0 = _elm_0, _len_0 + 1
760 end
761end
762flat = _accum_0
763local x_coords = {
764 4,
765 5,
766 6,
767 7
768}
769local y_coords = {
770 9,
771 2,
772 3
773}
774local points
775local _accum_0 = { }
776local _len_0 = 1
777for _index_0 = 1, #x_coords do
778 local x = x_coords[_index_0]
779 for _index_1 = 1, #y_coords do
780 local y = y_coords[_index_1]
781 _accum_0[_len_0] = {
782 x,
783 y
784 }
785 _len_0 = _len_0 + 1
786 end
787end
788points = _accum_0
789local evens
790local _accum_0 = { }
791local _len_0 = 1
792for i = 1, 100 do
793 if i % 2 == 0 then
794 _accum_0[_len_0] = i
795 _len_0 = _len_0 + 1
796 end
797end
798evens = _accum_0
799local thing = {
800 color = "red",
801 name = "fast",
802 width = 123
803}
804local thing_copy
805local _tbl_0 = { }
806for k, v in pairs(thing) do
807 _tbl_0[k] = v
808end
809thing_copy = _tbl_0
810local no_color
811local _tbl_0 = { }
812for k, v in pairs(thing) do
813 if k ~= "color" then
814 _tbl_0[k] = v
815 end
816end
817no_color = _tbl_0
818local numbers = {
819 1,
820 2,
821 3,
822 4
823}
824local sqrts
825local _tbl_0 = { }
826for _index_0 = 1, #numbers do
827 local i = numbers[_index_0]
828 _tbl_0[i] = math.sqrt(i)
829end
830sqrts = _tbl_0
831local tuples = {
832 {
833 "hello",
834 "world"
835 },
836 {
837 "foo",
838 "bar"
839 }
840}
841local tbl
842local _tbl_0 = { }
843for _index_0 = 1, #tuples do
844 local tuple = tuples[_index_0]
845 local _key_0, _val_0 = unpack(tuple)
846 _tbl_0[_key_0] = _val_0
847end
848tbl = _tbl_0
849local slice
850local _accum_0 = { }
851local _len_0 = 1
852local _list_0 = items
853for _index_0 = 1, 5 do
854 local item = _list_0[_index_0]
855 _accum_0[_len_0] = item
856 _len_0 = _len_0 + 1
857end
858slice = _accum_0
859local slice
860local _accum_0 = { }
861local _len_0 = 1
862local _list_0 = items
863local _max_0 = #_list_0
864for _index_0 = 2, _max_0 do
865 local item = _list_0[_index_0]
866 _accum_0[_len_0] = item
867 _len_0 = _len_0 + 1
868end
869slice = _accum_0
870local slice
871local _accum_0 = { }
872local _len_0 = 1
873local _list_0 = items
874local _max_0 = #_list_0
875for _index_0 = 1, _max_0, 2 do
876 local item = _list_0[_index_0]
877 _accum_0[_len_0] = item
878 _len_0 = _len_0 + 1
879end
880slice = _accum_0
881local slice
882local _accum_0 = { }
883local _len_0 = 1
884local _list_0 = items
885local _min_0 = #_list_0 + -4 + 1
886local _max_0 = #_list_0 + -1 + 1
887for _index_0 = _min_0, _max_0 do
888 local item = _list_0[_index_0]
889 _accum_0[_len_0] = item
890 _len_0 = _len_0 + 1
891end
892slice = _accum_0
893local reverse_slice
894local _accum_0 = { }
895local _len_0 = 1
896local _list_0 = items
897local _min_0 = #_list_0 + -1 + 1
898for _index_0 = _min_0, 1, -1 do
899 local item = _list_0[_index_0]
900 _accum_0[_len_0] = item
901 _len_0 = _len_0 + 1
902end
903reverse_slice = _accum_0
904local sub_list
905do
906 local _accum_0 = { }
907 local _len_0 = 1
908 local _list_0 = items
909 for _index_0 = 2, 4 do
910 local _item_0 = _list_0[_index_0]
911 _accum_0[_len_0] = _item_0
912 _len_0 = _len_0 + 1
913 end
914 sub_list = _accum_0
915end
916local last_four_items
917local _accum_0 = { }
918local _len_0 = 1
919local _list_0 = items
920local _min_0 = #_list_0 + -4 + 1
921local _max_0 = #_list_0 + -1 + 1
922for _index_0 = _min_0, _max_0 do
923 local _item_0 = _list_0[_index_0]
924 _accum_0[_len_0] = _item_0
925 _len_0 = _len_0 + 1
926end
927last_four_items = _accum_0
928local items = {
929 1,
930 2,
931 3,
932 4
933}
934local doubled
935local _accum_0 = { }
936local _len_0 = 1
937for i, item in ipairs(items) do
938 _accum_0[_len_0] = item * 2
939 _len_0 = _len_0 + 1
940end
941doubled = _accum_0
942local slice
943local _accum_0 = { }
944local _len_0 = 1
945for i, item in ipairs(items) do
946 if i > 1 and i < 3 then
947 _accum_0[_len_0] = item
948 _len_0 = _len_0 + 1
949 end
950end
951slice = _accum_0
952local doubled
953local _accum_0 = { }
954local _len_0 = 1
955local _list_0 = items
956for _index_0 = 1, #_list_0 do
957 local item = _list_0[_index_0]
958 _accum_0[_len_0] = item * 2
959 _len_0 = _len_0 + 1
960end
961doubled = _accum_0
962local data = {
963 a = {
964 1,
965 2,
966 3
967 },
968 b = {
969 4,
970 5,
971 6
972 }
973}
974local flat
975local _accum_0 = { }
976for k, v in pairs(data) do
977 local _len_0 = #_accum_0 + 1
978 for _index_0 = 1, #v do
979 local _elm_0 = v[_index_0]
980 _accum_0[_len_0], _len_0 = _elm_0, _len_0 + 1
981 end
982end
983flat = _accum_0
984local x_coords = {
985 4,
986 5,
987 6,
988 7
989}
990local y_coords = {
991 9,
992 2,
993 3
994}
995local points
996local _accum_0 = { }
997local _len_0 = 1
998for _index_0 = 1, #x_coords do
999 local x = x_coords[_index_0]
1000 for _index_1 = 1, #y_coords do
1001 local y = y_coords[_index_1]
1002 _accum_0[_len_0] = {
1003 x,
1004 y
1005 }
1006 _len_0 = _len_0 + 1
1007 end
1008end
1009points = _accum_0
1010local evens
1011local _accum_0 = { }
1012local _len_0 = 1
1013for i = 1, 100 do
1014 if i % 2 == 0 then
1015 _accum_0[_len_0] = i
1016 _len_0 = _len_0 + 1
1017 end
1018end
1019evens = _accum_0
1020local thing = {
1021 color = "red",
1022 name = "fast",
1023 width = 123
1024}
1025local thing_copy
1026local _tbl_0 = { }
1027for k, v in pairs(thing) do
1028 _tbl_0[k] = v
1029end
1030thing_copy = _tbl_0
1031local no_color
1032local _tbl_0 = { }
1033for k, v in pairs(thing) do
1034 if k ~= "color" then
1035 _tbl_0[k] = v
1036 end
1037end
1038no_color = _tbl_0
1039local numbers = {
1040 1,
1041 2,
1042 3,
1043 4
1044}
1045local sqrts
1046local _tbl_0 = { }
1047for _index_0 = 1, #numbers do
1048 local i = numbers[_index_0]
1049 _tbl_0[i] = math.sqrt(i)
1050end
1051sqrts = _tbl_0
1052local tuples = {
1053 {
1054 "hello",
1055 "world"
1056 },
1057 {
1058 "foo",
1059 "bar"
1060 }
1061}
1062local tbl
1063local _tbl_0 = { }
1064for _index_0 = 1, #tuples do
1065 local tuple = tuples[_index_0]
1066 local _key_0, _val_0 = unpack(tuple)
1067 _tbl_0[_key_0] = _val_0
1068end
1069tbl = _tbl_0
1070local slice
1071local _accum_0 = { }
1072local _len_0 = 1
1073local _list_0 = items
1074for _index_0 = 1, 5 do
1075 local item = _list_0[_index_0]
1076 _accum_0[_len_0] = item
1077 _len_0 = _len_0 + 1
1078end
1079slice = _accum_0
1080local slice
1081local _accum_0 = { }
1082local _len_0 = 1
1083local _list_0 = items
1084local _max_0 = #_list_0
1085for _index_0 = 2, _max_0 do
1086 local item = _list_0[_index_0]
1087 _accum_0[_len_0] = item
1088 _len_0 = _len_0 + 1
1089end
1090slice = _accum_0
1091local slice
1092local _accum_0 = { }
1093local _len_0 = 1
1094local _list_0 = items
1095local _max_0 = #_list_0
1096for _index_0 = 1, _max_0, 2 do
1097 local item = _list_0[_index_0]
1098 _accum_0[_len_0] = item
1099 _len_0 = _len_0 + 1
1100end
1101slice = _accum_0
1102local slice
1103local _accum_0 = { }
1104local _len_0 = 1
1105local _list_0 = items
1106local _min_0 = #_list_0 + -4 + 1
1107local _max_0 = #_list_0 + -1 + 1
1108for _index_0 = _min_0, _max_0 do
1109 local item = _list_0[_index_0]
1110 _accum_0[_len_0] = item
1111 _len_0 = _len_0 + 1
1112end
1113slice = _accum_0
1114local reverse_slice
1115local _accum_0 = { }
1116local _len_0 = 1
1117local _list_0 = items
1118local _min_0 = #_list_0 + -1 + 1
1119for _index_0 = _min_0, 1, -1 do
1120 local item = _list_0[_index_0]
1121 _accum_0[_len_0] = item
1122 _len_0 = _len_0 + 1
1123end
1124reverse_slice = _accum_0
1125local sub_list
1126do
1127 local _accum_0 = { }
1128 local _len_0 = 1
1129 local _list_0 = items
1130 for _index_0 = 2, 4 do
1131 local _item_0 = _list_0[_index_0]
1132 _accum_0[_len_0] = _item_0
1133 _len_0 = _len_0 + 1
1134 end
1135 sub_list = _accum_0
1136end
1137local last_four_items
1138local _accum_0 = { }
1139local _len_0 = 1
1140local _list_0 = items
1141local _min_0 = #_list_0 + -4 + 1
1142local _max_0 = #_list_0 + -1 + 1
1143for _index_0 = _min_0, _max_0 do
1144 local _item_0 = _list_0[_index_0]
1145 _accum_0[_len_0] = _item_0
1146 _len_0 = _len_0 + 1
1147end
1148last_four_items = _accum_0
1149local Inventory
1150local _class_0
1151local _base_0 = {
1152 add_item = function(self, name)
1153 if self.items[name] then
1154 local _obj_0 = self.items
1155 _obj_0[name] = _obj_0[name] + 1
1156 else
1157 self.items[name] = 1
1158 end
1159 end
1160}
1161if _base_0.__index == nil then
1162 _base_0.__index = _base_0
1163end
1164_class_0 = setmetatable({
1165 __init = function(self)
1166 self.items = { }
1167 end,
1168 __base = _base_0,
1169 __name = "Inventory"
1170}, {
1171 __index = _base_0,
1172 __call = function(cls, ...)
1173 local _self_0 = setmetatable({ }, _base_0)
1174 cls.__init(_self_0, ...)
1175 return _self_0
1176 end
1177})
1178_base_0.__class = _class_0
1179Inventory = _class_0
1180local inv = Inventory()
1181inv:add_item("t-shirt")
1182inv:add_item("pants")
1183local Person
1184do
1185 local _class_0
1186 local _base_0 = {
1187 clothes = { },
1188 give_item = function(self, name)
1189 return table.insert(self.clothes, name)
1190 end
1191 }
1192 if _base_0.__index == nil then
1193 _base_0.__index = _base_0
1194 end
1195 _class_0 = setmetatable({
1196 __init = function() end,
1197 __base = _base_0,
1198 __name = "Person"
1199 }, {
1200 __index = _base_0,
1201 __call = function(cls, ...)
1202 local _self_0 = setmetatable({ }, _base_0)
1203 cls.__init(_self_0, ...)
1204 return _self_0
1205 end
1206 })
1207 _base_0.__class = _class_0
1208 Person = _class_0
1209end
1210local a = Person()
1211local b = Person()
1212a:give_item("pants")
1213b:give_item("shirt")
1214local _list_0 = a.clothes
1215for _index_0 = 1, #_list_0 do
1216 local item = _list_0[_index_0]
1217 print(item)
1218end
1219local Person
1220local _class_0
1221local _base_0 = { }
1222if _base_0.__index == nil then
1223 _base_0.__index = _base_0
1224end
1225_class_0 = setmetatable({
1226 __init = function(self)
1227 self.clothes = { }
1228 end,
1229 __base = _base_0,
1230 __name = "Person"
1231}, {
1232 __index = _base_0,
1233 __call = function(cls, ...)
1234 local _self_0 = setmetatable({ }, _base_0)
1235 cls.__init(_self_0, ...)
1236 return _self_0
1237 end
1238})
1239_base_0.__class = _class_0
1240Person = _class_0
1241local BackPack
1242local _class_0
1243local _parent_0 = Inventory
1244local _base_0 = {
1245 size = 10,
1246 add_item = function(self, name)
1247 if #self.items > size then
1248 error("backpack is full")
1249 end
1250 return _class_0.__parent.__base.add_item(self, name)
1251 end
1252}
1253for _key_0, _val_0 in pairs(_parent_0.__base) do
1254 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
1255 _base_0[_key_0] = _val_0
1256 end
1257end
1258if _base_0.__index == nil then
1259 _base_0.__index = _base_0
1260end
1261setmetatable(_base_0, _parent_0.__base)
1262_class_0 = setmetatable({
1263 __init = function(self, ...)
1264 return _class_0.__parent.__init(self, ...)
1265 end,
1266 __base = _base_0,
1267 __name = "BackPack",
1268 __parent = _parent_0
1269}, {
1270 __index = function(cls, name)
1271 local val = rawget(_base_0, name)
1272 if val == nil then
1273 local parent = rawget(cls, "__parent")
1274 if parent then
1275 return parent[name]
1276 end
1277 else
1278 return val
1279 end
1280 end,
1281 __call = function(cls, ...)
1282 local _self_0 = setmetatable({ }, _base_0)
1283 cls.__init(_self_0, ...)
1284 return _self_0
1285 end
1286})
1287_base_0.__class = _class_0
1288if _parent_0.__inherited then
1289 _parent_0.__inherited(_parent_0, _class_0)
1290end
1291BackPack = _class_0
1292local Shelf
1293do
1294 local _class_0
1295 local _base_0 = { }
1296 if _base_0.__index == nil then
1297 _base_0.__index = _base_0
1298 end
1299 _class_0 = setmetatable({
1300 __init = function() end,
1301 __base = _base_0,
1302 __name = "Shelf"
1303 }, {
1304 __index = _base_0,
1305 __call = function(cls, ...)
1306 local _self_0 = setmetatable({ }, _base_0)
1307 cls.__init(_self_0, ...)
1308 return _self_0
1309 end
1310 })
1311 _base_0.__class = _class_0
1312 local self = _class_0;
1313 self.__inherited = function(self, child)
1314 return print(self.__name, "was inherited by", child.__name)
1315 end
1316 Shelf = _class_0
1317end
1318local Cupboard
1319local _class_0
1320local _parent_0 = Shelf
1321local _base_0 = { }
1322for _key_0, _val_0 in pairs(_parent_0.__base) do
1323 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
1324 _base_0[_key_0] = _val_0
1325 end
1326end
1327if _base_0.__index == nil then
1328 _base_0.__index = _base_0
1329end
1330setmetatable(_base_0, _parent_0.__base)
1331_class_0 = setmetatable({
1332 __init = function(self, ...)
1333 return _class_0.__parent.__init(self, ...)
1334 end,
1335 __base = _base_0,
1336 __name = "Cupboard",
1337 __parent = _parent_0
1338}, {
1339 __index = function(cls, name)
1340 local val = rawget(_base_0, name)
1341 if val == nil then
1342 local parent = rawget(cls, "__parent")
1343 if parent then
1344 return parent[name]
1345 end
1346 else
1347 return val
1348 end
1349 end,
1350 __call = function(cls, ...)
1351 local _self_0 = setmetatable({ }, _base_0)
1352 cls.__init(_self_0, ...)
1353 return _self_0
1354 end
1355})
1356_base_0.__class = _class_0
1357if _parent_0.__inherited then
1358 _parent_0.__inherited(_parent_0, _class_0)
1359end
1360Cupboard = _class_0
1361local MyClass
1362local _class_0
1363local _parent_0 = ParentClass
1364local _base_0 = {
1365 a_method = function(self)
1366 _class_0.__parent.__base.a_method(self, "hello", "world")
1367 _class_0.__parent.a_method(self, "hello", "world")
1368 _class_0.__parent.a_method(self, "hello", "world")
1369 return assert(_class_0.__parent == ParentClass)
1370 end
1371}
1372for _key_0, _val_0 in pairs(_parent_0.__base) do
1373 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
1374 _base_0[_key_0] = _val_0
1375 end
1376end
1377if _base_0.__index == nil then
1378 _base_0.__index = _base_0
1379end
1380setmetatable(_base_0, _parent_0.__base)
1381_class_0 = setmetatable({
1382 __init = function(self, ...)
1383 return _class_0.__parent.__init(self, ...)
1384 end,
1385 __base = _base_0,
1386 __name = "MyClass",
1387 __parent = _parent_0
1388}, {
1389 __index = function(cls, name)
1390 local val = rawget(_base_0, name)
1391 if val == nil then
1392 local parent = rawget(cls, "__parent")
1393 if parent then
1394 return parent[name]
1395 end
1396 else
1397 return val
1398 end
1399 end,
1400 __call = function(cls, ...)
1401 local _self_0 = setmetatable({ }, _base_0)
1402 cls.__init(_self_0, ...)
1403 return _self_0
1404 end
1405})
1406_base_0.__class = _class_0
1407if _parent_0.__inherited then
1408 _parent_0.__inherited(_parent_0, _class_0)
1409end
1410MyClass = _class_0
1411local b = BackPack()
1412assert(b.__class == BackPack)
1413print(BackPack.size)
1414print(BackPack.__name)
1415local Things
1416do
1417 local _class_0
1418 local _base_0 = { }
1419 if _base_0.__index == nil then
1420 _base_0.__index = _base_0
1421 end
1422 _class_0 = setmetatable({
1423 __init = function() end,
1424 __base = _base_0,
1425 __name = "Things"
1426 }, {
1427 __index = _base_0,
1428 __call = function(cls, ...)
1429 local _self_0 = setmetatable({ }, _base_0)
1430 cls.__init(_self_0, ...)
1431 return _self_0
1432 end
1433 })
1434 _base_0.__class = _class_0
1435 local self = _class_0;
1436 self.some_func = function(self)
1437 return print("Hello from", self.__name)
1438 end
1439 Things = _class_0
1440end
1441Things:some_func()
1442assert(Things().some_func == nil)
1443local Counter
1444do
1445 local _class_0
1446 local _base_0 = { }
1447 if _base_0.__index == nil then
1448 _base_0.__index = _base_0
1449 end
1450 _class_0 = setmetatable({
1451 __init = function(self)
1452 self.__class.count = self.__class.count + 1
1453 end,
1454 __base = _base_0,
1455 __name = "Counter"
1456 }, {
1457 __index = _base_0,
1458 __call = function(cls, ...)
1459 local _self_0 = setmetatable({ }, _base_0)
1460 cls.__init(_self_0, ...)
1461 return _self_0
1462 end
1463 })
1464 _base_0.__class = _class_0
1465 local self = _class_0;
1466 self.count = 0
1467 Counter = _class_0
1468end
1469Counter()
1470Counter()
1471print(Counter.count)
1472self.__class:hello(1, 2, 3, 4)
1473local Things
1474local _class_0
1475local _base_0 = { }
1476if _base_0.__index == nil then
1477 _base_0.__index = _base_0
1478end
1479_class_0 = setmetatable({
1480 __init = function() end,
1481 __base = _base_0,
1482 __name = "Things"
1483}, {
1484 __index = _base_0,
1485 __call = function(cls, ...)
1486 local _self_0 = setmetatable({ }, _base_0)
1487 cls.__init(_self_0, ...)
1488 return _self_0
1489 end
1490})
1491_base_0.__class = _class_0
1492local self = _class_0;
1493self.class_var = "hello world"
1494Things = _class_0
1495local MoreThings
1496local _class_0
1497local secret, log
1498local _base_0 = {
1499 some_method = function(self)
1500 return log("hello world: " .. secret)
1501 end
1502}
1503if _base_0.__index == nil then
1504 _base_0.__index = _base_0
1505end
1506_class_0 = setmetatable({
1507 __init = function() end,
1508 __base = _base_0,
1509 __name = "MoreThings"
1510}, {
1511 __index = _base_0,
1512 __call = function(cls, ...)
1513 local _self_0 = setmetatable({ }, _base_0)
1514 cls.__init(_self_0, ...)
1515 return _self_0
1516 end
1517})
1518_base_0.__class = _class_0
1519local self = _class_0;
1520secret = 123
1521log = function(msg)
1522 return print("LOG:", msg)
1523end
1524MoreThings = _class_0
1525assert(self == self)
1526assert(self.__class == self.__class)
1527local some_instance_method
1528some_instance_method = function(self, ...)
1529 return self.__class(...)
1530end
1531local Something
1532do
1533 local _class_0
1534 local _base_0 = { }
1535 if _base_0.__index == nil then
1536 _base_0.__index = _base_0
1537 end
1538 _class_0 = setmetatable({
1539 __init = function(self, foo, bar, biz, baz)
1540 self.foo = foo
1541 self.bar = bar
1542 self.__class.biz = biz
1543 self.__class.baz = baz
1544 end,
1545 __base = _base_0,
1546 __name = "Something"
1547 }, {
1548 __index = _base_0,
1549 __call = function(cls, ...)
1550 local _self_0 = setmetatable({ }, _base_0)
1551 cls.__init(_self_0, ...)
1552 return _self_0
1553 end
1554 })
1555 _base_0.__class = _class_0
1556 Something = _class_0
1557end
1558local _class_0
1559local _base_0 = { }
1560if _base_0.__index == nil then
1561 _base_0.__index = _base_0
1562end
1563_class_0 = setmetatable({
1564 __init = function(self, foo, bar, biz, baz)
1565 self.foo = foo
1566 self.bar = bar
1567 self.__class.biz = biz
1568 self.__class.baz = baz
1569 end,
1570 __base = _base_0,
1571 __name = "Something"
1572}, {
1573 __index = _base_0,
1574 __call = function(cls, ...)
1575 local _self_0 = setmetatable({ }, _base_0)
1576 cls.__init(_self_0, ...)
1577 return _self_0
1578 end
1579})
1580_base_0.__class = _class_0
1581Something = _class_0
1582local new
1583new = function(self, fieldA, fieldB)
1584 self.fieldA = fieldA
1585 self.fieldB = fieldB
1586 return self
1587end
1588local obj = new({ }, 123, "abc")
1589print(obj)
1590local x
1591local Bucket
1592local _class_0
1593local _base_0 = {
1594 drops = 0,
1595 add_drop = function(self)
1596 self.drops = self.drops + 1
1597 end
1598}
1599if _base_0.__index == nil then
1600 _base_0.__index = _base_0
1601end
1602_class_0 = setmetatable({
1603 __init = function() end,
1604 __base = _base_0,
1605 __name = "Bucket"
1606}, {
1607 __index = _base_0,
1608 __call = function(cls, ...)
1609 local _self_0 = setmetatable({ }, _base_0)
1610 cls.__init(_self_0, ...)
1611 return _self_0
1612 end
1613})
1614_base_0.__class = _class_0
1615Bucket = _class_0
1616x = _class_0
1617local BigBucket
1618do
1619 local _class_0
1620 local _parent_0 = Bucket
1621 local _base_0 = {
1622 add_drop = function(self)
1623 self.drops = self.drops + 10
1624 end
1625 }
1626 for _key_0, _val_0 in pairs(_parent_0.__base) do
1627 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
1628 _base_0[_key_0] = _val_0
1629 end
1630 end
1631 if _base_0.__index == nil then
1632 _base_0.__index = _base_0
1633 end
1634 setmetatable(_base_0, _parent_0.__base)
1635 _class_0 = setmetatable({
1636 __init = function(self, ...)
1637 return _class_0.__parent.__init(self, ...)
1638 end,
1639 __base = _base_0,
1640 __name = "BigBucket",
1641 __parent = _parent_0
1642 }, {
1643 __index = function(cls, name)
1644 local val = rawget(_base_0, name)
1645 if val == nil then
1646 local parent = rawget(cls, "__parent")
1647 if parent then
1648 return parent[name]
1649 end
1650 else
1651 return val
1652 end
1653 end,
1654 __call = function(cls, ...)
1655 local _self_0 = setmetatable({ }, _base_0)
1656 cls.__init(_self_0, ...)
1657 return _self_0
1658 end
1659 })
1660 _base_0.__class = _class_0
1661 if _parent_0.__inherited then
1662 _parent_0.__inherited(_parent_0, _class_0)
1663 end
1664 BigBucket = _class_0
1665end
1666assert(Bucket.__name == "BigBucket")
1667local x
1668local _class_0
1669local _base_0 = { }
1670if _base_0.__index == nil then
1671 _base_0.__index = _base_0
1672end
1673_class_0 = setmetatable({
1674 __init = function() end,
1675 __base = _base_0,
1676 __name = "x"
1677}, {
1678 __index = _base_0,
1679 __call = function(cls, ...)
1680 local _self_0 = setmetatable({ }, _base_0)
1681 cls.__init(_self_0, ...)
1682 return _self_0
1683 end
1684})
1685_base_0.__class = _class_0
1686x = _class_0
1687local MyIndex = {
1688 __index = {
1689 var = 1
1690 }
1691}
1692local X
1693do
1694 local _class_0
1695 local _base_0 = {
1696 func = function(self)
1697 return print(123)
1698 end
1699 }
1700 local _list_0 = {
1701 MyIndex
1702 }
1703 for _index_0 = 1, #_list_0 do
1704 local _item_0 = _list_0[_index_0]
1705 local _cls_0, _mixin_0 = (_item_0.__base ~= nil), _item_0.__base or _item_0
1706 for _key_0, _val_0 in pairs(_mixin_0) do
1707 if _base_0[_key_0] == nil and (not _cls_0 or not _key_0:match("^__")) then
1708 _base_0[_key_0] = _val_0
1709 end
1710 end
1711 end
1712 if _base_0.__index == nil then
1713 _base_0.__index = _base_0
1714 end
1715 _class_0 = setmetatable({
1716 __init = function() end,
1717 __base = _base_0,
1718 __name = "X"
1719 }, {
1720 __index = _base_0,
1721 __call = function(cls, ...)
1722 local _self_0 = setmetatable({ }, _base_0)
1723 cls.__init(_self_0, ...)
1724 return _self_0
1725 end
1726 })
1727 _base_0.__class = _class_0
1728 X = _class_0
1729end
1730local x = X()
1731print(x.var)
1732local Y
1733do
1734 local _class_0
1735 local _base_0 = { }
1736 local _list_0 = {
1737 X
1738 }
1739 for _index_0 = 1, #_list_0 do
1740 local _item_0 = _list_0[_index_0]
1741 local _cls_0, _mixin_0 = (_item_0.__base ~= nil), _item_0.__base or _item_0
1742 for _key_0, _val_0 in pairs(_mixin_0) do
1743 if _base_0[_key_0] == nil and (not _cls_0 or not _key_0:match("^__")) then
1744 _base_0[_key_0] = _val_0
1745 end
1746 end
1747 end
1748 if _base_0.__index == nil then
1749 _base_0.__index = _base_0
1750 end
1751 _class_0 = setmetatable({
1752 __init = function() end,
1753 __base = _base_0,
1754 __name = "Y"
1755 }, {
1756 __index = _base_0,
1757 __call = function(cls, ...)
1758 local _self_0 = setmetatable({ }, _base_0)
1759 cls.__init(_self_0, ...)
1760 return _self_0
1761 end
1762 })
1763 _base_0.__class = _class_0
1764 Y = _class_0
1765end
1766local y = Y()
1767y:func()
1768assert(y.__class.__parent ~= X)
1769local Inventory
1770local _class_0
1771local _base_0 = {
1772 add_item = function(self, name)
1773 if self.items[name] then
1774 local _obj_0 = self.items
1775 _obj_0[name] = _obj_0[name] + 1
1776 else
1777 self.items[name] = 1
1778 end
1779 end
1780}
1781if _base_0.__index == nil then
1782 _base_0.__index = _base_0
1783end
1784_class_0 = setmetatable({
1785 __init = function(self)
1786 self.items = { }
1787 end,
1788 __base = _base_0,
1789 __name = "Inventory"
1790}, {
1791 __index = _base_0,
1792 __call = function(cls, ...)
1793 local _self_0 = setmetatable({ }, _base_0)
1794 cls.__init(_self_0, ...)
1795 return _self_0
1796 end
1797})
1798_base_0.__class = _class_0
1799Inventory = _class_0
1800local inv = Inventory()
1801inv:add_item("t-shirt")
1802inv:add_item("pants")
1803local Person
1804do
1805 local _class_0
1806 local _base_0 = {
1807 clothes = { },
1808 give_item = function(self, name)
1809 return table.insert(self.clothes, name)
1810 end
1811 }
1812 if _base_0.__index == nil then
1813 _base_0.__index = _base_0
1814 end
1815 _class_0 = setmetatable({
1816 __init = function() end,
1817 __base = _base_0,
1818 __name = "Person"
1819 }, {
1820 __index = _base_0,
1821 __call = function(cls, ...)
1822 local _self_0 = setmetatable({ }, _base_0)
1823 cls.__init(_self_0, ...)
1824 return _self_0
1825 end
1826 })
1827 _base_0.__class = _class_0
1828 Person = _class_0
1829end
1830local a = Person()
1831local b = Person()
1832a:give_item("pants")
1833b:give_item("shirt")
1834local _list_0 = a.clothes
1835for _index_0 = 1, #_list_0 do
1836 local item = _list_0[_index_0]
1837 print(item)
1838end
1839local Person
1840local _class_0
1841local _base_0 = { }
1842if _base_0.__index == nil then
1843 _base_0.__index = _base_0
1844end
1845_class_0 = setmetatable({
1846 __init = function(self)
1847 self.clothes = { }
1848 end,
1849 __base = _base_0,
1850 __name = "Person"
1851}, {
1852 __index = _base_0,
1853 __call = function(cls, ...)
1854 local _self_0 = setmetatable({ }, _base_0)
1855 cls.__init(_self_0, ...)
1856 return _self_0
1857 end
1858})
1859_base_0.__class = _class_0
1860Person = _class_0
1861local BackPack
1862local _class_0
1863local _parent_0 = Inventory
1864local _base_0 = {
1865 size = 10,
1866 add_item = function(self, name)
1867 if #self.items > size then
1868 error("backpack is full")
1869 end
1870 return _class_0.__parent.__base.add_item(self, name)
1871 end
1872}
1873for _key_0, _val_0 in pairs(_parent_0.__base) do
1874 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
1875 _base_0[_key_0] = _val_0
1876 end
1877end
1878if _base_0.__index == nil then
1879 _base_0.__index = _base_0
1880end
1881setmetatable(_base_0, _parent_0.__base)
1882_class_0 = setmetatable({
1883 __init = function(self, ...)
1884 return _class_0.__parent.__init(self, ...)
1885 end,
1886 __base = _base_0,
1887 __name = "BackPack",
1888 __parent = _parent_0
1889}, {
1890 __index = function(cls, name)
1891 local val = rawget(_base_0, name)
1892 if val == nil then
1893 local parent = rawget(cls, "__parent")
1894 if parent then
1895 return parent[name]
1896 end
1897 else
1898 return val
1899 end
1900 end,
1901 __call = function(cls, ...)
1902 local _self_0 = setmetatable({ }, _base_0)
1903 cls.__init(_self_0, ...)
1904 return _self_0
1905 end
1906})
1907_base_0.__class = _class_0
1908if _parent_0.__inherited then
1909 _parent_0.__inherited(_parent_0, _class_0)
1910end
1911BackPack = _class_0
1912local Shelf
1913do
1914 local _class_0
1915 local _base_0 = { }
1916 if _base_0.__index == nil then
1917 _base_0.__index = _base_0
1918 end
1919 _class_0 = setmetatable({
1920 __init = function() end,
1921 __base = _base_0,
1922 __name = "Shelf"
1923 }, {
1924 __index = _base_0,
1925 __call = function(cls, ...)
1926 local _self_0 = setmetatable({ }, _base_0)
1927 cls.__init(_self_0, ...)
1928 return _self_0
1929 end
1930 })
1931 _base_0.__class = _class_0
1932 local self = _class_0;
1933 self.__inherited = function(self, child)
1934 return print(self.__name, "was inherited by", child.__name)
1935 end
1936 Shelf = _class_0
1937end
1938local Cupboard
1939local _class_0
1940local _parent_0 = Shelf
1941local _base_0 = { }
1942for _key_0, _val_0 in pairs(_parent_0.__base) do
1943 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
1944 _base_0[_key_0] = _val_0
1945 end
1946end
1947if _base_0.__index == nil then
1948 _base_0.__index = _base_0
1949end
1950setmetatable(_base_0, _parent_0.__base)
1951_class_0 = setmetatable({
1952 __init = function(self, ...)
1953 return _class_0.__parent.__init(self, ...)
1954 end,
1955 __base = _base_0,
1956 __name = "Cupboard",
1957 __parent = _parent_0
1958}, {
1959 __index = function(cls, name)
1960 local val = rawget(_base_0, name)
1961 if val == nil then
1962 local parent = rawget(cls, "__parent")
1963 if parent then
1964 return parent[name]
1965 end
1966 else
1967 return val
1968 end
1969 end,
1970 __call = function(cls, ...)
1971 local _self_0 = setmetatable({ }, _base_0)
1972 cls.__init(_self_0, ...)
1973 return _self_0
1974 end
1975})
1976_base_0.__class = _class_0
1977if _parent_0.__inherited then
1978 _parent_0.__inherited(_parent_0, _class_0)
1979end
1980Cupboard = _class_0
1981local MyClass
1982local _class_0
1983local _parent_0 = ParentClass
1984local _base_0 = {
1985 a_method = function(self)
1986 _class_0.__parent.__base.a_method(self, "hello", "world")
1987 _class_0.__parent.a_method(self, "hello", "world")
1988 _class_0.__parent.a_method(self, "hello", "world")
1989 return assert(_class_0.__parent == ParentClass)
1990 end
1991}
1992for _key_0, _val_0 in pairs(_parent_0.__base) do
1993 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
1994 _base_0[_key_0] = _val_0
1995 end
1996end
1997if _base_0.__index == nil then
1998 _base_0.__index = _base_0
1999end
2000setmetatable(_base_0, _parent_0.__base)
2001_class_0 = setmetatable({
2002 __init = function(self, ...)
2003 return _class_0.__parent.__init(self, ...)
2004 end,
2005 __base = _base_0,
2006 __name = "MyClass",
2007 __parent = _parent_0
2008}, {
2009 __index = function(cls, name)
2010 local val = rawget(_base_0, name)
2011 if val == nil then
2012 local parent = rawget(cls, "__parent")
2013 if parent then
2014 return parent[name]
2015 end
2016 else
2017 return val
2018 end
2019 end,
2020 __call = function(cls, ...)
2021 local _self_0 = setmetatable({ }, _base_0)
2022 cls.__init(_self_0, ...)
2023 return _self_0
2024 end
2025})
2026_base_0.__class = _class_0
2027if _parent_0.__inherited then
2028 _parent_0.__inherited(_parent_0, _class_0)
2029end
2030MyClass = _class_0
2031local b = BackPack()
2032assert(b.__class == BackPack)
2033print(BackPack.size)
2034print(BackPack.__name)
2035local Things
2036do
2037 local _class_0
2038 local _base_0 = { }
2039 if _base_0.__index == nil then
2040 _base_0.__index = _base_0
2041 end
2042 _class_0 = setmetatable({
2043 __init = function() end,
2044 __base = _base_0,
2045 __name = "Things"
2046 }, {
2047 __index = _base_0,
2048 __call = function(cls, ...)
2049 local _self_0 = setmetatable({ }, _base_0)
2050 cls.__init(_self_0, ...)
2051 return _self_0
2052 end
2053 })
2054 _base_0.__class = _class_0
2055 local self = _class_0;
2056 self.some_func = function(self)
2057 return print("Hello from", self.__name)
2058 end
2059 Things = _class_0
2060end
2061Things:some_func()
2062assert(Things().some_func == nil)
2063local Counter
2064do
2065 local _class_0
2066 local _base_0 = { }
2067 if _base_0.__index == nil then
2068 _base_0.__index = _base_0
2069 end
2070 _class_0 = setmetatable({
2071 __init = function(self)
2072 self.__class.count = self.__class.count + 1
2073 end,
2074 __base = _base_0,
2075 __name = "Counter"
2076 }, {
2077 __index = _base_0,
2078 __call = function(cls, ...)
2079 local _self_0 = setmetatable({ }, _base_0)
2080 cls.__init(_self_0, ...)
2081 return _self_0
2082 end
2083 })
2084 _base_0.__class = _class_0
2085 local self = _class_0;
2086 self.count = 0
2087 Counter = _class_0
2088end
2089Counter()
2090Counter()
2091print(Counter.count)
2092self.__class:hello(1, 2, 3, 4)
2093local Things
2094local _class_0
2095local _base_0 = { }
2096if _base_0.__index == nil then
2097 _base_0.__index = _base_0
2098end
2099_class_0 = setmetatable({
2100 __init = function() end,
2101 __base = _base_0,
2102 __name = "Things"
2103}, {
2104 __index = _base_0,
2105 __call = function(cls, ...)
2106 local _self_0 = setmetatable({ }, _base_0)
2107 cls.__init(_self_0, ...)
2108 return _self_0
2109 end
2110})
2111_base_0.__class = _class_0
2112local self = _class_0;
2113self.class_var = "hello world"
2114Things = _class_0
2115local MoreThings
2116local _class_0
2117local secret, log
2118local _base_0 = {
2119 some_method = function(self)
2120 return log("hello world: " .. secret)
2121 end
2122}
2123if _base_0.__index == nil then
2124 _base_0.__index = _base_0
2125end
2126_class_0 = setmetatable({
2127 __init = function() end,
2128 __base = _base_0,
2129 __name = "MoreThings"
2130}, {
2131 __index = _base_0,
2132 __call = function(cls, ...)
2133 local _self_0 = setmetatable({ }, _base_0)
2134 cls.__init(_self_0, ...)
2135 return _self_0
2136 end
2137})
2138_base_0.__class = _class_0
2139local self = _class_0;
2140secret = 123
2141log = function(msg)
2142 return print("LOG:", msg)
2143end
2144MoreThings = _class_0
2145assert(self == self)
2146assert(self.__class == self.__class)
2147local some_instance_method
2148some_instance_method = function(self, ...)
2149 return self.__class(...)
2150end
2151local Something
2152do
2153 local _class_0
2154 local _base_0 = { }
2155 if _base_0.__index == nil then
2156 _base_0.__index = _base_0
2157 end
2158 _class_0 = setmetatable({
2159 __init = function(self, foo, bar, biz, baz)
2160 self.foo = foo
2161 self.bar = bar
2162 self.__class.biz = biz
2163 self.__class.baz = baz
2164 end,
2165 __base = _base_0,
2166 __name = "Something"
2167 }, {
2168 __index = _base_0,
2169 __call = function(cls, ...)
2170 local _self_0 = setmetatable({ }, _base_0)
2171 cls.__init(_self_0, ...)
2172 return _self_0
2173 end
2174 })
2175 _base_0.__class = _class_0
2176 Something = _class_0
2177end
2178local _class_0
2179local _base_0 = { }
2180if _base_0.__index == nil then
2181 _base_0.__index = _base_0
2182end
2183_class_0 = setmetatable({
2184 __init = function(self, foo, bar, biz, baz)
2185 self.foo = foo
2186 self.bar = bar
2187 self.__class.biz = biz
2188 self.__class.baz = baz
2189 end,
2190 __base = _base_0,
2191 __name = "Something"
2192}, {
2193 __index = _base_0,
2194 __call = function(cls, ...)
2195 local _self_0 = setmetatable({ }, _base_0)
2196 cls.__init(_self_0, ...)
2197 return _self_0
2198 end
2199})
2200_base_0.__class = _class_0
2201Something = _class_0
2202local new
2203new = function(self, fieldA, fieldB)
2204 self.fieldA = fieldA
2205 self.fieldB = fieldB
2206 return self
2207end
2208local obj = new({ }, 123, "abc")
2209print(obj)
2210local x
2211local Bucket
2212local _class_0
2213local _base_0 = {
2214 drops = 0,
2215 add_drop = function(self)
2216 self.drops = self.drops + 1
2217 end
2218}
2219if _base_0.__index == nil then
2220 _base_0.__index = _base_0
2221end
2222_class_0 = setmetatable({
2223 __init = function() end,
2224 __base = _base_0,
2225 __name = "Bucket"
2226}, {
2227 __index = _base_0,
2228 __call = function(cls, ...)
2229 local _self_0 = setmetatable({ }, _base_0)
2230 cls.__init(_self_0, ...)
2231 return _self_0
2232 end
2233})
2234_base_0.__class = _class_0
2235Bucket = _class_0
2236x = _class_0
2237local BigBucket
2238do
2239 local _class_0
2240 local _parent_0 = Bucket
2241 local _base_0 = {
2242 add_drop = function(self)
2243 self.drops = self.drops + 10
2244 end
2245 }
2246 for _key_0, _val_0 in pairs(_parent_0.__base) do
2247 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
2248 _base_0[_key_0] = _val_0
2249 end
2250 end
2251 if _base_0.__index == nil then
2252 _base_0.__index = _base_0
2253 end
2254 setmetatable(_base_0, _parent_0.__base)
2255 _class_0 = setmetatable({
2256 __init = function(self, ...)
2257 return _class_0.__parent.__init(self, ...)
2258 end,
2259 __base = _base_0,
2260 __name = "BigBucket",
2261 __parent = _parent_0
2262 }, {
2263 __index = function(cls, name)
2264 local val = rawget(_base_0, name)
2265 if val == nil then
2266 local parent = rawget(cls, "__parent")
2267 if parent then
2268 return parent[name]
2269 end
2270 else
2271 return val
2272 end
2273 end,
2274 __call = function(cls, ...)
2275 local _self_0 = setmetatable({ }, _base_0)
2276 cls.__init(_self_0, ...)
2277 return _self_0
2278 end
2279 })
2280 _base_0.__class = _class_0
2281 if _parent_0.__inherited then
2282 _parent_0.__inherited(_parent_0, _class_0)
2283 end
2284 BigBucket = _class_0
2285end
2286assert(Bucket.__name == "BigBucket")
2287local x
2288local _class_0
2289local _base_0 = { }
2290if _base_0.__index == nil then
2291 _base_0.__index = _base_0
2292end
2293_class_0 = setmetatable({
2294 __init = function() end,
2295 __base = _base_0,
2296 __name = "x"
2297}, {
2298 __index = _base_0,
2299 __call = function(cls, ...)
2300 local _self_0 = setmetatable({ }, _base_0)
2301 cls.__init(_self_0, ...)
2302 return _self_0
2303 end
2304})
2305_base_0.__class = _class_0
2306x = _class_0
2307local MyIndex = {
2308 __index = {
2309 var = 1
2310 }
2311}
2312local X
2313do
2314 local _class_0
2315 local _base_0 = {
2316 func = function(self)
2317 return print(123)
2318 end
2319 }
2320 local _list_0 = {
2321 MyIndex
2322 }
2323 for _index_0 = 1, #_list_0 do
2324 local _item_0 = _list_0[_index_0]
2325 local _cls_0, _mixin_0 = (_item_0.__base ~= nil), _item_0.__base or _item_0
2326 for _key_0, _val_0 in pairs(_mixin_0) do
2327 if _base_0[_key_0] == nil and (not _cls_0 or not _key_0:match("^__")) then
2328 _base_0[_key_0] = _val_0
2329 end
2330 end
2331 end
2332 if _base_0.__index == nil then
2333 _base_0.__index = _base_0
2334 end
2335 _class_0 = setmetatable({
2336 __init = function() end,
2337 __base = _base_0,
2338 __name = "X"
2339 }, {
2340 __index = _base_0,
2341 __call = function(cls, ...)
2342 local _self_0 = setmetatable({ }, _base_0)
2343 cls.__init(_self_0, ...)
2344 return _self_0
2345 end
2346 })
2347 _base_0.__class = _class_0
2348 X = _class_0
2349end
2350local x = X()
2351print(x.var)
2352local Y
2353do
2354 local _class_0
2355 local _base_0 = { }
2356 local _list_0 = {
2357 X
2358 }
2359 for _index_0 = 1, #_list_0 do
2360 local _item_0 = _list_0[_index_0]
2361 local _cls_0, _mixin_0 = (_item_0.__base ~= nil), _item_0.__base or _item_0
2362 for _key_0, _val_0 in pairs(_mixin_0) do
2363 if _base_0[_key_0] == nil and (not _cls_0 or not _key_0:match("^__")) then
2364 _base_0[_key_0] = _val_0
2365 end
2366 end
2367 end
2368 if _base_0.__index == nil then
2369 _base_0.__index = _base_0
2370 end
2371 _class_0 = setmetatable({
2372 __init = function() end,
2373 __base = _base_0,
2374 __name = "Y"
2375 }, {
2376 __index = _base_0,
2377 __call = function(cls, ...)
2378 local _self_0 = setmetatable({ }, _base_0)
2379 cls.__init(_self_0, ...)
2380 return _self_0
2381 end
2382 })
2383 _base_0.__class = _class_0
2384 Y = _class_0
2385end
2386local y = Y()
2387y:func()
2388assert(y.__class.__parent ~= X)
2389local _with_0 = Person()
2390_with_0.name = "Oswald"
2391_with_0:add_relative(my_dad)
2392_with_0:save()
2393print(_with_0.name)
2394local file
2395local _with_0 = File("favorite_foods.txt")
2396_with_0:set_encoding("utf8")
2397file = _with_0
2398local create_person
2399create_person = function(name, relatives)
2400 local _with_0 = Person()
2401 _with_0.name = name
2402 for _index_0 = 1, #relatives do
2403 local relative = relatives[_index_0]
2404 _with_0:add_relative(relative)
2405 end
2406 return _with_0
2407end
2408local me = create_person("Leaf", {
2409 dad,
2410 mother,
2411 sister
2412})
2413local str = "Hello"
2414print("original:", str)
2415print("upper:", str:upper())
2416local _with_0 = tb
2417_with_0[1] = 1
2418print(_with_0[2])
2419do
2420 local _with_1 = _with_0[abc]
2421 _with_1[3] = _with_1[2]:func()
2422 _with_1["key-name"] = value
2423end
2424_with_0[#_with_0 + 1] = "abc"
2425local _with_0 = obj
2426if _with_0 ~= nil then
2427 print(obj.name)
2428end
2429local _with_0 = Person()
2430_with_0.name = "Oswald"
2431_with_0:add_relative(my_dad)
2432_with_0:save()
2433print(_with_0.name)
2434local file
2435local _with_0 = File("favorite_foods.txt")
2436_with_0:set_encoding("utf8")
2437file = _with_0
2438local create_person
2439create_person = function(name, relatives)
2440 local _with_0 = Person()
2441 _with_0.name = name
2442 for _index_0 = 1, #relatives do
2443 local relative = relatives[_index_0]
2444 _with_0:add_relative(relative)
2445 end
2446 return _with_0
2447end
2448local me = create_person("Leaf", {
2449 dad,
2450 mother,
2451 sister
2452})
2453local str = "Hello"
2454print("original:", str)
2455print("upper:", str:upper())
2456local _with_0 = tb
2457_with_0[1] = 1
2458print(_with_0[2])
2459do
2460 local _with_1 = _with_0[abc]
2461 _with_1[3] = _with_1[2]:func()
2462 _with_1["key-name"] = value
2463end
2464_with_0[#_with_0 + 1] = "abc"
2465local _with_0 = obj
2466if _with_0 ~= nil then
2467 print(obj.name)
2468end
2469local hello = "world"
2470local a, b, c = 1, 2, 3
2471hello = 123
2472local x = 1
2473x = x + 1
2474x = x - 1
2475x = x * 10
2476x = x / 10
2477x = x % 10
2478local s = s .. "world"
2479local arg = arg or "default value"
2480local a = 0
2481local b = 0
2482local c = 0
2483local d = 0
2484local e = 0
2485local x = f()
2486local y = x
2487local z = x
2488do
2489 local a = 1
2490 local x, y, z
2491 print("forward declare all variables as locals")
2492 x = function()
2493 return 1 + y + z
2494 end
2495 y, z = 2, 3
2496 instance = Item:new()
2497end
2498do
2499 local X = 1
2500 local B
2501 print("only forward declare upper case variables")
2502 local a = 1
2503 B = 2
2504end
2505do
2506 a = 1
2507 print("declare all variables as globals")
2508 x = function()
2509 return 1 + y + z
2510 end
2511 y, z = 2, 3
2512end
2513do
2514 X = 1
2515 print("only declare upper case variables as globals")
2516 local a = 1
2517 B = 2
2518 local Temp = "a local value"
2519end
2520local hello = "world"
2521local a, b, c = 1, 2, 3
2522hello = 123
2523local x = 1
2524x = x + 1
2525x = x - 1
2526x = x * 10
2527x = x / 10
2528x = x % 10
2529local s = s .. "world"
2530local arg = arg or "default value"
2531local a = 0
2532local b = 0
2533local c = 0
2534local d = 0
2535local e = 0
2536local x = f()
2537local y = x
2538local z = x
2539do
2540 local a = 1
2541 local x, y, z
2542 print("forward declare all variables as locals")
2543 x = function()
2544 return 1 + y + z
2545 end
2546 y, z = 2, 3
2547 instance = Item:new()
2548end
2549do
2550 local X = 1
2551 local B
2552 print("only forward declare upper case variables")
2553 local a = 1
2554 B = 2
2555end
2556do
2557 a = 1
2558 print("declare all variables as globals")
2559 x = function()
2560 return 1 + y + z
2561 end
2562 y, z = 2, 3
2563end
2564do
2565 X = 1
2566 print("only declare upper case variables as globals")
2567 local a = 1
2568 B = 2
2569 local Temp = "a local value"
2570end
2571local list = {
2572 1,
2573 2,
2574 3,
2575 4,
2576 5
2577}
2578local fn
2579fn = function(ok)
2580 return ok, table.unpack(list)
2581end
2582(function(_arg_0, ...)
2583 local ok = _arg_0
2584 local count = select('#', ...)
2585 local first = select(1, ...)
2586 return print(ok, count, first)
2587end)(fn(true))
2588local list = {
2589 1,
2590 2,
2591 3,
2592 4,
2593 5
2594}
2595local fn
2596fn = function(ok)
2597 return ok, table.unpack(list)
2598end
2599(function(_arg_0, ...)
2600 local ok = _arg_0
2601 local count = select('#', ...)
2602 local first = select(1, ...)
2603 return print(ok, count, first)
2604end)(fn(true))
2605local user = database.find_user("moon")
2606if user then
2607 print(user.name)
2608end
2609local hello = os.getenv("hello")
2610if hello then
2611 print("You have hello", hello)
2612else
2613 local world = os.getenv("world")
2614 if world then
2615 print("you have world", world)
2616 else
2617 print("nothing :(")
2618 end
2619end
2620do
2621 local success, result = pcall(function()
2622 return "get result without problems"
2623 end)
2624 if success then
2625 print(result)
2626 end
2627end
2628print("OK")
2629repeat
2630 local byte = stream:read_one()
2631 if byte then
2632 print(byte)
2633 else
2634 break
2635 end
2636until false
2637local user = database.find_user("moon")
2638if user then
2639 print(user.name)
2640end
2641local hello = os.getenv("hello")
2642if hello then
2643 print("You have hello", hello)
2644else
2645 local world = os.getenv("world")
2646 if world then
2647 print("you have world", world)
2648 else
2649 print("nothing :(")
2650 end
2651end
2652do
2653 local success, result = pcall(function()
2654 return "get result without problems"
2655 end)
2656 if success then
2657 print(result)
2658 end
2659end
2660print("OK")
2661repeat
2662 local byte = stream:read_one()
2663 if byte then
2664 print(byte)
2665 else
2666 break
2667 end
2668until false
2669local thing = {
2670 1,
2671 2
2672}
2673local a, b = thing[1], thing[2]
2674print(a, b)
2675local obj = {
2676 hello = "world",
2677 day = "tuesday",
2678 length = 20
2679}
2680local hello, the_day = obj.hello, obj.day
2681print(hello, the_day)
2682local day = obj.day
2683local obj2 = {
2684 numbers = {
2685 1,
2686 2,
2687 3,
2688 4
2689 },
2690 properties = {
2691 color = "green",
2692 height = 13.5
2693 }
2694}
2695local first, second, color = obj2.numbers[1], obj2.numbers[2], obj2.properties.color
2696print(first, second, color)
2697local first, second, color
2698local _obj_0 = obj2
2699first, second, color = _obj_0.numbers[1], _obj_0.numbers[2], _obj_0.properties.color
2700local concat, insert
2701local _obj_0 = table
2702concat, insert = _obj_0.concat, _obj_0.insert
2703local mix, max, rand
2704local _obj_0 = math
2705mix, max, rand = _obj_0.mix, _obj_0.max, _obj_0.random
2706local name, job
2707local _obj_0 = person
2708name, job = _obj_0.name, _obj_0.job
2709if name == nil then
2710 name = "nameless"
2711end
2712if job == nil then
2713 job = "jobless"
2714end
2715local two, four
2716local _obj_0 = items
2717two, four = _obj_0[2], _obj_0[4]
2718local orders = {
2719 "first",
2720 "second",
2721 "third",
2722 "fourth",
2723 "last"
2724}
2725local first, bulk, last = orders[1], (function()
2726 local _accum_0 = { }
2727 local _len_0 = 1
2728 local _max_0 = #orders + -2 + 1
2729 for _index_0 = 2, _max_0 do
2730 local _item_0 = orders[_index_0]
2731 _accum_0[_len_0] = _item_0
2732 _len_0 = _len_0 + 1
2733 end
2734 return _accum_0
2735end)(), orders[#orders]
2736print(first)
2737print(bulk)
2738print(last)
2739local first, rest
2740do
2741 local _obj_0 = orders
2742 first, rest = _obj_0[1], (function()
2743 local _accum_0 = { }
2744 local _len_0 = 1
2745 local _max_0 = #_obj_0
2746 for _index_0 = 2, _max_0 do
2747 local _item_0 = _obj_0[_index_0]
2748 _accum_0[_len_0] = _item_0
2749 _len_0 = _len_0 + 1
2750 end
2751 return _accum_0
2752 end)()
2753end
2754local start, last
2755do
2756 local _obj_0 = orders
2757 start, last = (function()
2758 local _accum_0 = { }
2759 local _len_0 = 1
2760 local _max_0 = #_obj_0 + -2 + 1
2761 for _index_0 = 1, _max_0 do
2762 local _item_0 = _obj_0[_index_0]
2763 _accum_0[_len_0] = _item_0
2764 _len_0 = _len_0 + 1
2765 end
2766 return _accum_0
2767 end)(), _obj_0[#_obj_0]
2768end
2769local _obj_0 = orders
2770first, last = _obj_0[1], _obj_0[#_obj_0]
2771local tuples = {
2772 {
2773 "hello",
2774 "world"
2775 },
2776 {
2777 "egg",
2778 "head"
2779 }
2780}
2781for _index_0 = 1, #tuples do
2782 local _des_0 = tuples[_index_0]
2783 local left, right = _des_0[1], _des_0[2]
2784 print(left, right)
2785end
2786local thing = {
2787 1,
2788 2
2789}
2790local a, b = thing[1], thing[2]
2791print(a, b)
2792local obj = {
2793 hello = "world",
2794 day = "tuesday",
2795 length = 20
2796}
2797local hello, the_day = obj.hello, obj.day
2798print(hello, the_day)
2799local day = obj.day
2800local obj2 = {
2801 numbers = {
2802 1,
2803 2,
2804 3,
2805 4
2806 },
2807 properties = {
2808 color = "green",
2809 height = 13.5
2810 }
2811}
2812local first, second, color = obj2.numbers[1], obj2.numbers[2], obj2.properties.color
2813print(first, second, color)
2814local first, second, color
2815local _obj_0 = obj2
2816first, second, color = _obj_0.numbers[1], _obj_0.numbers[2], _obj_0.properties.color
2817local concat, insert
2818local _obj_0 = table
2819concat, insert = _obj_0.concat, _obj_0.insert
2820local mix, max, rand
2821local _obj_0 = math
2822mix, max, rand = _obj_0.mix, _obj_0.max, _obj_0.random
2823local name, job
2824local _obj_0 = person
2825name, job = _obj_0.name, _obj_0.job
2826if name == nil then
2827 name = "nameless"
2828end
2829if job == nil then
2830 job = "jobless"
2831end
2832local two, four
2833local _obj_0 = items
2834two, four = _obj_0[2], _obj_0[4]
2835local orders = {
2836 "first",
2837 "second",
2838 "third",
2839 "fourth",
2840 "last"
2841}
2842local first, bulk, last = orders[1], (function()
2843 local _accum_0 = { }
2844 local _len_0 = 1
2845 local _max_0 = #orders + -2 + 1
2846 for _index_0 = 2, _max_0 do
2847 local _item_0 = orders[_index_0]
2848 _accum_0[_len_0] = _item_0
2849 _len_0 = _len_0 + 1
2850 end
2851 return _accum_0
2852end)(), orders[#orders]
2853print(first)
2854print(bulk)
2855print(last)
2856local first, rest
2857do
2858 local _obj_0 = orders
2859 first, rest = _obj_0[1], (function()
2860 local _accum_0 = { }
2861 local _len_0 = 1
2862 local _max_0 = #_obj_0
2863 for _index_0 = 2, _max_0 do
2864 local _item_0 = _obj_0[_index_0]
2865 _accum_0[_len_0] = _item_0
2866 _len_0 = _len_0 + 1
2867 end
2868 return _accum_0
2869 end)()
2870end
2871local start, last
2872do
2873 local _obj_0 = orders
2874 start, last = (function()
2875 local _accum_0 = { }
2876 local _len_0 = 1
2877 local _max_0 = #_obj_0 + -2 + 1
2878 for _index_0 = 1, _max_0 do
2879 local _item_0 = _obj_0[_index_0]
2880 _accum_0[_len_0] = _item_0
2881 _len_0 = _len_0 + 1
2882 end
2883 return _accum_0
2884 end)(), _obj_0[#_obj_0]
2885end
2886local _obj_0 = orders
2887first, last = _obj_0[1], _obj_0[#_obj_0]
2888local tuples = {
2889 {
2890 "hello",
2891 "world"
2892 },
2893 {
2894 "egg",
2895 "head"
2896 }
2897}
2898for _index_0 = 1, #tuples do
2899 local _des_0 = tuples[_index_0]
2900 local left, right = _des_0[1], _des_0[2]
2901 print(left, right)
2902end
2903local i = 100
2904local my_func
2905my_func = function()
2906 i = 10
2907 while i > 0 do
2908 print(i)
2909 i = i - 1
2910 end
2911end
2912my_func()
2913print(i)
2914local i = 100
2915local my_func
2916my_func = function()
2917 local i = "hello"
2918end
2919my_func()
2920print(i)
2921local tmp = 1213
2922local i, k = 100, 50
2923local my_func
2924my_func = function(add)
2925 local tmp = tmp + add
2926 i = i + tmp
2927 k = k + tmp
2928end
2929my_func(22)
2930print(i, k)
2931local i = 100
2932local my_func
2933my_func = function()
2934 i = 10
2935 while i > 0 do
2936 print(i)
2937 i = i - 1
2938 end
2939end
2940my_func()
2941print(i)
2942local i = 100
2943local my_func
2944my_func = function()
2945 local i = "hello"
2946end
2947my_func()
2948print(i)
2949local tmp = 1213
2950local i, k = 100, 50
2951local my_func
2952my_func = function(add)
2953 local tmp = tmp + add
2954 i = i + tmp
2955 k = k + tmp
2956end
2957my_func(22)
2958print(i, k)
2959local _module_0 = { }
2960local p, to_lua
2961do
2962 local _obj_0 = require("yue")
2963 p, to_lua = _obj_0.p, _obj_0.to_lua
2964end
2965local inventory = {
2966 equipment = {
2967 "sword",
2968 "shield"
2969 },
2970 items = {
2971 {
2972 name = "potion",
2973 count = 10
2974 },
2975 {
2976 name = "bread",
2977 count = 3
2978 }
2979 }
2980}
2981local map
2982map = function(arr, action)
2983 local _accum_0 = { }
2984 local _len_0 = 1
2985 for _index_0 = 1, #arr do
2986 local item = arr[_index_0]
2987 _accum_0[_len_0] = action(item)
2988 _len_0 = _len_0 + 1
2989 end
2990 return _accum_0
2991end
2992local filter
2993filter = function(arr, cond)
2994 local _accum_0 = { }
2995 local _len_0 = 1
2996 for _index_0 = 1, #arr do
2997 local item = arr[_index_0]
2998 if cond(item) then
2999 _accum_0[_len_0] = item
3000 _len_0 = _len_0 + 1
3001 end
3002 end
3003 return _accum_0
3004end
3005local reduce
3006reduce = function(arr, init, action)
3007 for _index_0 = 1, #arr do
3008 local item = arr[_index_0]
3009 init = action(init, item)
3010 end
3011 return init
3012end
3013print(reduce(filter(map({
3014 1,
3015 2,
3016 3
3017}, function(x)
3018 return x * 2
3019end), function(x)
3020 return x > 4
3021end), 0, function(a, b)
3022 return a + b
3023end))
3024local apple = setmetatable({
3025 size = 15,
3026}, {
3027 __index = {
3028 color = 0x00ffff
3029 }
3030})
3031if (getmetatable(apple) ~= nil) then
3032 p(apple.size, apple.color, getmetatable(apple).__index)
3033end
3034local _u1f31b = "月之脚本"
3035_module_0["🌛"] = _u1f31b
3036return _module_0
3037local _module_0 = { }
3038local p, to_lua
3039do
3040 local _obj_0 = require("yue")
3041 p, to_lua = _obj_0.p, _obj_0.to_lua
3042end
3043local inventory = {
3044 equipment = {
3045 "sword",
3046 "shield"
3047 },
3048 items = {
3049 {
3050 name = "potion",
3051 count = 10
3052 },
3053 {
3054 name = "bread",
3055 count = 3
3056 }
3057 }
3058}
3059local map
3060map = function(arr, action)
3061 local _accum_0 = { }
3062 local _len_0 = 1
3063 for _index_0 = 1, #arr do
3064 local item = arr[_index_0]
3065 _accum_0[_len_0] = action(item)
3066 _len_0 = _len_0 + 1
3067 end
3068 return _accum_0
3069end
3070local filter
3071filter = function(arr, cond)
3072 local _accum_0 = { }
3073 local _len_0 = 1
3074 for _index_0 = 1, #arr do
3075 local item = arr[_index_0]
3076 if cond(item) then
3077 _accum_0[_len_0] = item
3078 _len_0 = _len_0 + 1
3079 end
3080 end
3081 return _accum_0
3082end
3083local reduce
3084reduce = function(arr, init, action)
3085 for _index_0 = 1, #arr do
3086 local item = arr[_index_0]
3087 init = action(init, item)
3088 end
3089 return init
3090end
3091print(reduce(filter(map({
3092 1,
3093 2,
3094 3
3095}, function(x)
3096 return x * 2
3097end), function(x)
3098 return x > 4
3099end), 0, function(a, b)
3100 return a + b
3101end))
3102local apple = setmetatable({
3103 size = 15,
3104}, {
3105 __index = {
3106 color = 0x00ffff
3107 }
3108})
3109if (getmetatable(apple) ~= nil) then
3110 p(apple.size, apple.color, getmetatable(apple).__index)
3111end
3112local _u1f31b = "月之脚本"
3113_module_0["🌛"] = _u1f31b
3114return _module_0
3115local have_coins = false
3116if have_coins then
3117 print("Got coins")
3118else
3119 print("No coins")
3120end
3121local have_coins = false
3122if have_coins then
3123 print("Got coins")
3124else
3125 print("No coins")
3126end
3127local have_coins = false
3128print((function()
3129 if have_coins then
3130 return "Got coins"
3131 else
3132 return "No coins"
3133 end
3134end)())
3135local is_tall
3136is_tall = function(name)
3137 if name == "Rob" then
3138 return true
3139 else
3140 return false
3141 end
3142end
3143local message
3144if is_tall("Rob") then
3145 message = "I am very tall"
3146else
3147 message = "I am not so tall"
3148end
3149print(message)
3150if not (os.date("%A") == "Monday") then
3151 print("it is not Monday!")
3152end
3153if not (math.random() > 0.1) then
3154 print("You're lucky!")
3155end
3156local a = 5
3157if (1 == a or 3 == a or 5 == a or 7 == a) then
3158 print("checking equality with discrete values")
3159end
3160if (function()
3161 local _check_0 = list
3162 for _index_0 = 1, #_check_0 do
3163 if _check_0[_index_0] == a then
3164 return true
3165 end
3166 end
3167 return false
3168end)() then
3169 print("checking if `a` is in a list")
3170end
3171if not (math.random() > 0.1) then
3172 print("You're lucky!")
3173end
3174local have_coins = false
3175if have_coins then
3176 print("Got coins")
3177else
3178 print("No coins")
3179end
3180local have_coins = false
3181if have_coins then
3182 print("Got coins")
3183else
3184 print("No coins")
3185end
3186local have_coins = false
3187print((function()
3188 if have_coins then
3189 return "Got coins"
3190 else
3191 return "No coins"
3192 end
3193end)())
3194local is_tall
3195is_tall = function(name)
3196 if name == "Rob" then
3197 return true
3198 else
3199 return false
3200 end
3201end
3202local message
3203if is_tall("Rob") then
3204 message = "I am very tall"
3205else
3206 message = "I am not so tall"
3207end
3208print(message)
3209if not (os.date("%A") == "Monday") then
3210 print("it is not Monday!")
3211end
3212if not (math.random() > 0.1) then
3213 print("You're lucky!")
3214end
3215local a = 5
3216if (1 == a or 3 == a or 5 == a or 7 == a) then
3217 print("checking equality with discrete values")
3218end
3219if (function()
3220 local _check_0 = list
3221 for _index_0 = 1, #_check_0 do
3222 if _check_0[_index_0] == a then
3223 return true
3224 end
3225 end
3226 return false
3227end)() then
3228 print("checking if `a` is in a list")
3229end
3230if not (math.random() > 0.1) then
3231 print("You're lucky!")
3232end
3233for i = 10, 20 do
3234 print(i)
3235end
3236for k = 1, 15, 2 do
3237 print(k)
3238end
3239for key, value in pairs(object) do
3240 print(key, value)
3241end
3242local _list_0 = items
3243for _index_0 = 2, 4 do
3244 local item = _list_0[_index_0]
3245 print(item)
3246end
3247local _list_0 = items
3248for _index_0 = 1, #_list_0 do
3249 local item = _list_0[_index_0]
3250 print(item)
3251end
3252for j = 1, 10, 3 do
3253 print(j)
3254end
3255local doubled_evens
3256local _accum_0 = { }
3257local _len_0 = 1
3258for i = 1, 20 do
3259 if i % 2 == 0 then
3260 _accum_0[_len_0] = i * 2
3261 _len_0 = _len_0 + 1
3262 else
3263 _accum_0[_len_0] = i
3264 _len_0 = _len_0 + 1
3265 end
3266end
3267doubled_evens = _accum_0
3268local first_large
3269local _accum_0
3270local _list_0 = numbers
3271for _index_0 = 1, #_list_0 do
3272 local n = _list_0[_index_0]
3273 if n > 10 then
3274 _accum_0 = n
3275 break
3276 end
3277end
3278first_large = _accum_0
3279local func_a
3280func_a = function()
3281 for i = 1, 10 do
3282 print(i)
3283 end
3284end
3285local func_b
3286func_b = function()
3287 local _accum_0 = { }
3288 local _len_0 = 1
3289 for i = 1, 10 do
3290 _accum_0[_len_0] = i
3291 _len_0 = _len_0 + 1
3292 end
3293 return _accum_0
3294end
3295print(func_a())
3296print(func_b())
3297for i = 10, 20 do
3298 print(i)
3299end
3300for k = 1, 15, 2 do
3301 print(k)
3302end
3303for key, value in pairs(object) do
3304 print(key, value)
3305end
3306local _list_0 = items
3307for _index_0 = 2, 4 do
3308 local item = _list_0[_index_0]
3309 print(item)
3310end
3311local _list_0 = items
3312for _index_0 = 1, #_list_0 do
3313 local item = _list_0[_index_0]
3314 print(item)
3315end
3316for j = 1, 10, 3 do
3317 print(j)
3318end
3319local doubled_evens
3320local _accum_0 = { }
3321local _len_0 = 1
3322for i = 1, 20 do
3323 if i % 2 == 0 then
3324 _accum_0[_len_0] = i * 2
3325 _len_0 = _len_0 + 1
3326 else
3327 _accum_0[_len_0] = i
3328 _len_0 = _len_0 + 1
3329 end
3330end
3331doubled_evens = _accum_0
3332local first_large
3333local _accum_0
3334local _list_0 = numbers
3335for _index_0 = 1, #_list_0 do
3336 local n = _list_0[_index_0]
3337 if n > 10 then
3338 _accum_0 = n
3339 break
3340 end
3341end
3342first_large = _accum_0
3343local func_a
3344func_a = function()
3345 for i = 1, 10 do
3346 print(i)
3347 end
3348end
3349local func_b
3350func_b = function()
3351 local _accum_0 = { }
3352 local _len_0 = 1
3353 for i = 1, 10 do
3354 _accum_0[_len_0] = i
3355 _len_0 = _len_0 + 1
3356 end
3357 return _accum_0
3358end
3359print(func_a())
3360print(func_b())
3361local i = 0
3362while i < 10 do
3363 i = i + 1
3364 if i % 2 == 0 then
3365 goto _continue_0
3366 end
3367 print(i)
3368 ::_continue_0::
3369end
3370local my_numbers = {
3371 1,
3372 2,
3373 3,
3374 4,
3375 5,
3376 6
3377}
3378local odds
3379local _accum_0 = { }
3380local _len_0 = 1
3381for _index_0 = 1, #my_numbers do
3382 local x = my_numbers[_index_0]
3383 if x % 2 == 1 then
3384 goto _continue_0
3385 end
3386 _accum_0[_len_0] = x
3387 _len_0 = _len_0 + 1
3388 ::_continue_0::
3389end
3390odds = _accum_0
3391local i = 0
3392while i < 10 do
3393 i = i + 1
3394 if i % 2 == 0 then
3395 goto _continue_0
3396 end
3397 print(i)
3398 ::_continue_0::
3399end
3400local my_numbers = {
3401 1,
3402 2,
3403 3,
3404 4,
3405 5,
3406 6
3407}
3408local odds
3409local _accum_0 = { }
3410local _len_0 = 1
3411for _index_0 = 1, #my_numbers do
3412 local x = my_numbers[_index_0]
3413 if x % 2 == 1 then
3414 goto _continue_0
3415 end
3416 _accum_0[_len_0] = x
3417 _len_0 = _len_0 + 1
3418 ::_continue_0::
3419end
3420odds = _accum_0
3421local name = "Dan"
3422if "Robert" == name then
3423 print("You are Robert")
3424elseif "Dan" == name or "Daniel" == name then
3425 print("Your name, it's Dan")
3426else
3427 print("I don't know about you with name " .. tostring(name))
3428end
3429local b = 1
3430local next_number
3431if 1 == b then
3432 next_number = 2
3433elseif 2 == b then
3434 next_number = 3
3435else
3436 next_number = error("can't count that high!")
3437end
3438local msg
3439local _exp_0 = math.random(1, 5)
3440if 1 == _exp_0 then
3441 msg = "you are lucky"
3442elseif 2 == _exp_0 then
3443 msg = "you are almost lucky"
3444else
3445 msg = "not so lucky"
3446end
3447do
3448 local _exp_0 = math.random(1, 5)
3449 if 1 == _exp_0 then
3450 print("you are lucky")
3451 else
3452 print("not so lucky")
3453 end
3454end
3455local _exp_0 = math.random(1, 5)
3456if 1 == _exp_0 then
3457 print("you are lucky")
3458else
3459 print("not so lucky")
3460end
3461local items = {
3462 {
3463 x = 100,
3464 y = 200
3465 },
3466 {
3467 width = 300,
3468 height = 400
3469 }
3470}
3471for _index_0 = 1, #items do
3472 local item = items[_index_0]
3473 local _type_0 = type(item)
3474 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3475 local _match_0 = false
3476 if _tab_0 then
3477 local x = item.x
3478 local y = item.y
3479 if x ~= nil and y ~= nil then
3480 _match_0 = true
3481 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3482 end
3483 end
3484 if not _match_0 then
3485 if _tab_0 then
3486 local width = item.width
3487 local height = item.height
3488 if width ~= nil and height ~= nil then
3489 print("size " .. tostring(width) .. ", " .. tostring(height))
3490 end
3491 end
3492 end
3493end
3494local item = { }
3495local x, y = item.pos.x, item.pos.y
3496if x == nil then
3497 x = 50
3498end
3499if y == nil then
3500 y = 200
3501end
3502local _type_0 = type(item)
3503local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3504if _tab_0 then
3505 do
3506 local _obj_0 = item.pos
3507 local _type_1 = type(_obj_0)
3508 if "table" == _type_1 or "userdata" == _type_1 then
3509 x = _obj_0.x
3510 end
3511 end
3512 do
3513 local _obj_0 = item.pos
3514 local _type_1 = type(_obj_0)
3515 if "table" == _type_1 or "userdata" == _type_1 then
3516 y = _obj_0.y
3517 end
3518 end
3519 if x == nil then
3520 x = 50
3521 end
3522 if y == nil then
3523 y = 200
3524 end
3525 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3526end
3527local _exp_0 = tb
3528local _type_0 = type(_exp_0)
3529local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3530local _match_0 = false
3531if _tab_0 then
3532 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
3533 _match_0 = true
3534 print("1, 2, 3")
3535 end
3536end
3537if not _match_0 then
3538 local _match_1 = false
3539 if _tab_0 then
3540 local b = _exp_0[2]
3541 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
3542 _match_1 = true
3543 print("1, " .. tostring(b) .. ", 3")
3544 end
3545 end
3546 if not _match_1 then
3547 if _tab_0 then
3548 local b = _exp_0[3]
3549 if b == nil then
3550 b = 3
3551 end
3552 if 1 == _exp_0[1] and 2 == _exp_0[2] then
3553 print("1, 2, " .. tostring(b))
3554 end
3555 end
3556 end
3557end
3558local _exp_0 = tb
3559local _type_0 = type(_exp_0)
3560local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3561local _match_0 = false
3562if _tab_0 then
3563 local result = _exp_0.result
3564 if true == _exp_0.success and result ~= nil then
3565 _match_0 = true
3566 print("success", result)
3567 end
3568end
3569if not _match_0 then
3570 local _match_1 = false
3571 if _tab_0 then
3572 if false == _exp_0.success then
3573 _match_1 = true
3574 print("failed", result)
3575 end
3576 end
3577 if not _match_1 then
3578 print("invalid")
3579 end
3580end
3581local _exp_0 = tb
3582local _type_0 = type(_exp_0)
3583local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3584local _match_0 = false
3585if _tab_0 then
3586 local content
3587 do
3588 local _obj_0 = _exp_0.data
3589 local _type_1 = type(_obj_0)
3590 if "table" == _type_1 or "userdata" == _type_1 then
3591 content = _obj_0.content
3592 end
3593 end
3594 local _val_0
3595 do
3596 local _obj_0 = _exp_0.data
3597 if _obj_0 ~= nil then
3598 _val_0 = _obj_0.type
3599 end
3600 end
3601 if "success" == _val_0 and content ~= nil then
3602 _match_0 = true
3603 print("success", content)
3604 end
3605end
3606if not _match_0 then
3607 local _match_1 = false
3608 if _tab_0 then
3609 local content
3610 do
3611 local _obj_0 = _exp_0.data
3612 local _type_1 = type(_obj_0)
3613 if "table" == _type_1 or "userdata" == _type_1 then
3614 content = _obj_0.content
3615 end
3616 end
3617 local _val_0
3618 do
3619 local _obj_0 = _exp_0.data
3620 if _obj_0 ~= nil then
3621 _val_0 = _obj_0.type
3622 end
3623 end
3624 if "error" == _val_0 and content ~= nil then
3625 _match_1 = true
3626 print("failed", content)
3627 end
3628 end
3629 if not _match_1 then
3630 print("invalid")
3631 end
3632end
3633local _exp_0 = tb
3634local _type_0 = type(_exp_0)
3635local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3636if _tab_0 then
3637 local fourth = _exp_0[4]
3638 local _val_0
3639 do
3640 local _obj_0 = _exp_0[1]
3641 if _obj_0 ~= nil then
3642 _val_0 = _obj_0.a
3643 end
3644 end
3645 local _val_1
3646 do
3647 local _obj_0 = _exp_0[1]
3648 if _obj_0 ~= nil then
3649 _val_1 = _obj_0.b
3650 end
3651 end
3652 local _val_2
3653 do
3654 local _obj_0 = _exp_0[2]
3655 if _obj_0 ~= nil then
3656 _val_2 = _obj_0.a
3657 end
3658 end
3659 local _val_3
3660 do
3661 local _obj_0 = _exp_0[2]
3662 if _obj_0 ~= nil then
3663 _val_3 = _obj_0.b
3664 end
3665 end
3666 local _val_4
3667 do
3668 local _obj_0 = _exp_0[3]
3669 if _obj_0 ~= nil then
3670 _val_4 = _obj_0.a
3671 end
3672 end
3673 local _val_5
3674 do
3675 local _obj_0 = _exp_0[3]
3676 if _obj_0 ~= nil then
3677 _val_5 = _obj_0.b
3678 end
3679 end
3680 if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and fourth ~= nil then
3681 print("matched", fourth)
3682 end
3683end
3684local segments = {
3685 "admin",
3686 "users",
3687 "logs",
3688 "view"
3689}
3690local _type_0 = type(segments)
3691local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3692if _tab_0 then
3693 local groups
3694 do
3695 local _accum_0 = { }
3696 local _len_0 = 1
3697 local _max_0 = #segments + -3 + 1
3698 for _index_0 = 1, _max_0 do
3699 local _item_0 = segments[_index_0]
3700 _accum_0[_len_0] = _item_0
3701 _len_0 = _len_0 + 1
3702 end
3703 groups = _accum_0
3704 end
3705 local resource = segments[#segments - 1]
3706 local action = segments[#segments]
3707 if resource ~= nil and action ~= nil then
3708 print("Group:", groups)
3709 print("Resource:", resource)
3710 print("Action:", action)
3711 end
3712end
3713local name = "Dan"
3714if "Robert" == name then
3715 print("You are Robert")
3716elseif "Dan" == name or "Daniel" == name then
3717 print("Your name, it's Dan")
3718else
3719 print("I don't know about you with name " .. tostring(name))
3720end
3721local b = 1
3722local next_number
3723if 1 == b then
3724 next_number = 2
3725elseif 2 == b then
3726 next_number = 3
3727else
3728 next_number = error("can't count that high!")
3729end
3730local msg
3731local _exp_0 = math.random(1, 5)
3732if 1 == _exp_0 then
3733 msg = "you are lucky"
3734elseif 2 == _exp_0 then
3735 msg = "you are almost lucky"
3736else
3737 msg = "not so lucky"
3738end
3739do
3740 local _exp_0 = math.random(1, 5)
3741 if 1 == _exp_0 then
3742 print("you are lucky")
3743 else
3744 print("not so lucky")
3745 end
3746end
3747local _exp_0 = math.random(1, 5)
3748if 1 == _exp_0 then
3749 print("you are lucky")
3750else
3751 print("not so lucky")
3752end
3753local items = {
3754 {
3755 x = 100,
3756 y = 200
3757 },
3758 {
3759 width = 300,
3760 height = 400
3761 }
3762}
3763for _index_0 = 1, #items do
3764 local item = items[_index_0]
3765 local _type_0 = type(item)
3766 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3767 local _match_0 = false
3768 if _tab_0 then
3769 local x = item.x
3770 local y = item.y
3771 if x ~= nil and y ~= nil then
3772 _match_0 = true
3773 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3774 end
3775 end
3776 if not _match_0 then
3777 if _tab_0 then
3778 local width = item.width
3779 local height = item.height
3780 if width ~= nil and height ~= nil then
3781 print("size " .. tostring(width) .. ", " .. tostring(height))
3782 end
3783 end
3784 end
3785end
3786local item = { }
3787local x, y = item.pos.x, item.pos.y
3788if x == nil then
3789 x = 50
3790end
3791if y == nil then
3792 y = 200
3793end
3794local _type_0 = type(item)
3795local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3796if _tab_0 then
3797 do
3798 local _obj_0 = item.pos
3799 local _type_1 = type(_obj_0)
3800 if "table" == _type_1 or "userdata" == _type_1 then
3801 x = _obj_0.x
3802 end
3803 end
3804 do
3805 local _obj_0 = item.pos
3806 local _type_1 = type(_obj_0)
3807 if "table" == _type_1 or "userdata" == _type_1 then
3808 y = _obj_0.y
3809 end
3810 end
3811 if x == nil then
3812 x = 50
3813 end
3814 if y == nil then
3815 y = 200
3816 end
3817 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3818end
3819local _exp_0 = tb
3820local _type_0 = type(_exp_0)
3821local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3822local _match_0 = false
3823if _tab_0 then
3824 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
3825 _match_0 = true
3826 print("1, 2, 3")
3827 end
3828end
3829if not _match_0 then
3830 local _match_1 = false
3831 if _tab_0 then
3832 local b = _exp_0[2]
3833 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
3834 _match_1 = true
3835 print("1, " .. tostring(b) .. ", 3")
3836 end
3837 end
3838 if not _match_1 then
3839 if _tab_0 then
3840 local b = _exp_0[3]
3841 if b == nil then
3842 b = 3
3843 end
3844 if 1 == _exp_0[1] and 2 == _exp_0[2] then
3845 print("1, 2, " .. tostring(b))
3846 end
3847 end
3848 end
3849end
3850local _exp_0 = tb
3851local _type_0 = type(_exp_0)
3852local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3853local _match_0 = false
3854if _tab_0 then
3855 local result = _exp_0.result
3856 if true == _exp_0.success and result ~= nil then
3857 _match_0 = true
3858 print("success", result)
3859 end
3860end
3861if not _match_0 then
3862 local _match_1 = false
3863 if _tab_0 then
3864 if false == _exp_0.success then
3865 _match_1 = true
3866 print("failed", result)
3867 end
3868 end
3869 if not _match_1 then
3870 print("invalid")
3871 end
3872end
3873local _exp_0 = tb
3874local _type_0 = type(_exp_0)
3875local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3876local _match_0 = false
3877if _tab_0 then
3878 local content
3879 do
3880 local _obj_0 = _exp_0.data
3881 local _type_1 = type(_obj_0)
3882 if "table" == _type_1 or "userdata" == _type_1 then
3883 content = _obj_0.content
3884 end
3885 end
3886 local _val_0
3887 do
3888 local _obj_0 = _exp_0.data
3889 if _obj_0 ~= nil then
3890 _val_0 = _obj_0.type
3891 end
3892 end
3893 if "success" == _val_0 and content ~= nil then
3894 _match_0 = true
3895 print("success", content)
3896 end
3897end
3898if not _match_0 then
3899 local _match_1 = false
3900 if _tab_0 then
3901 local content
3902 do
3903 local _obj_0 = _exp_0.data
3904 local _type_1 = type(_obj_0)
3905 if "table" == _type_1 or "userdata" == _type_1 then
3906 content = _obj_0.content
3907 end
3908 end
3909 local _val_0
3910 do
3911 local _obj_0 = _exp_0.data
3912 if _obj_0 ~= nil then
3913 _val_0 = _obj_0.type
3914 end
3915 end
3916 if "error" == _val_0 and content ~= nil then
3917 _match_1 = true
3918 print("failed", content)
3919 end
3920 end
3921 if not _match_1 then
3922 print("invalid")
3923 end
3924end
3925local _exp_0 = tb
3926local _type_0 = type(_exp_0)
3927local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3928if _tab_0 then
3929 local fourth = _exp_0[4]
3930 local _val_0
3931 do
3932 local _obj_0 = _exp_0[1]
3933 if _obj_0 ~= nil then
3934 _val_0 = _obj_0.a
3935 end
3936 end
3937 local _val_1
3938 do
3939 local _obj_0 = _exp_0[1]
3940 if _obj_0 ~= nil then
3941 _val_1 = _obj_0.b
3942 end
3943 end
3944 local _val_2
3945 do
3946 local _obj_0 = _exp_0[2]
3947 if _obj_0 ~= nil then
3948 _val_2 = _obj_0.a
3949 end
3950 end
3951 local _val_3
3952 do
3953 local _obj_0 = _exp_0[2]
3954 if _obj_0 ~= nil then
3955 _val_3 = _obj_0.b
3956 end
3957 end
3958 local _val_4
3959 do
3960 local _obj_0 = _exp_0[3]
3961 if _obj_0 ~= nil then
3962 _val_4 = _obj_0.a
3963 end
3964 end
3965 local _val_5
3966 do
3967 local _obj_0 = _exp_0[3]
3968 if _obj_0 ~= nil then
3969 _val_5 = _obj_0.b
3970 end
3971 end
3972 if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and fourth ~= nil then
3973 print("matched", fourth)
3974 end
3975end
3976local segments = {
3977 "admin",
3978 "users",
3979 "logs",
3980 "view"
3981}
3982local _type_0 = type(segments)
3983local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3984if _tab_0 then
3985 local groups
3986 do
3987 local _accum_0 = { }
3988 local _len_0 = 1
3989 local _max_0 = #segments + -3 + 1
3990 for _index_0 = 1, _max_0 do
3991 local _item_0 = segments[_index_0]
3992 _accum_0[_len_0] = _item_0
3993 _len_0 = _len_0 + 1
3994 end
3995 groups = _accum_0
3996 end
3997 local resource = segments[#segments - 1]
3998 local action = segments[#segments]
3999 if resource ~= nil and action ~= nil then
4000 print("Group:", groups)
4001 print("Resource:", resource)
4002 print("Action:", action)
4003 end
4004end
4005local i = 10
4006while i > 0 do
4007 print(i)
4008 i = i - 1
4009end
4010while running == true do
4011 my_function()
4012end
4013local i = 10
4014while not (i == 0) do
4015 print(i)
4016 i = i - 1
4017end
4018while not (running == false) do
4019 my_function()
4020end
4021local i = 10
4022repeat
4023 print(i)
4024 i = i - 1
4025until i == 0
4026local i = 10
4027while i > 0 do
4028 print(i)
4029 i = i - 1
4030end
4031while running == true do
4032 my_function()
4033end
4034local i = 10
4035while not (i == 0) do
4036 print(i)
4037 i = i - 1
4038end
4039while not (running == false) do
4040 my_function()
4041end
4042local i = 10
4043repeat
4044 print(i)
4045 i = i - 1
4046until i == 0
4047local my_object = {
4048 value = 1000,
4049 write = function(self)
4050 return print("the value:", self.value)
4051 end
4052}
4053local run_callback
4054run_callback = function(func)
4055 print("running callback...")
4056 return func()
4057end
4058run_callback(my_object.write)
4059run_callback((function()
4060 local _base_0 = my_object
4061 local _fn_0 = _base_0.write
4062 return _fn_0 and function(...)
4063 return _fn_0(_base_0, ...)
4064 end
4065end)())
4066local my_object = {
4067 value = 1000,
4068 write = function(self)
4069 return print("the value:", self.value)
4070 end
4071}
4072local run_callback
4073run_callback = function(func)
4074 print("running callback...")
4075 return func()
4076end
4077run_callback(my_object.write)
4078run_callback((function()
4079 local _base_0 = my_object
4080 local _fn_0 = _base_0.write
4081 return _fn_0 and function(...)
4082 return _fn_0(_base_0, ...)
4083 end
4084end)())
4085f(function(x)
4086 return print("hello" .. x)
4087end)
4088f(function(self)
4089 return print(self.value)
4090end)
4091map(function(x)
4092 return x * 2
4093end, {
4094 1,
4095 2,
4096 3
4097})
4098local result, msg
4099do
4100 result, msg = readAsync("filename.txt", function(data)
4101 print(data)
4102 return processAsync(data, function(info)
4103 return check(info)
4104 end)
4105 end)
4106end
4107print(result, msg)
4108f(function(x)
4109 return print("hello" .. x)
4110end)
4111f(function(self)
4112 return print(self.value)
4113end)
4114map(function(x)
4115 return x * 2
4116end, {
4117 1,
4118 2,
4119 3
4120})
4121local result, msg
4122do
4123 result, msg = readAsync("filename.txt", function(data)
4124 print(data)
4125 return processAsync(data, function(info)
4126 return check(info)
4127 end)
4128 end)
4129end
4130print(result, msg)
4131local my_function
4132my_function = function() end
4133my_function()
4134local func_a
4135func_a = function()
4136 return print("hello world")
4137end
4138local func_b
4139func_b = function()
4140 local value = 100
4141 return print("The value:", value)
4142end
4143func_a()
4144func_b()
4145local sum
4146sum = function(x, y)
4147 return print("sum", x + y)
4148end
4149sum(10, 20)
4150print(sum(10, 20))
4151a(b(c("a", "b", "c")))
4152print("x:", sum(10, 20), "y:", sum(30, 40))
4153local sum
4154sum = function(x, y)
4155 return x + y
4156end
4157print("The sum is ", sum(10, 20))
4158local sum
4159sum = function(x, y)
4160 return x + y
4161end
4162local mystery
4163mystery = function(x, y)
4164 return x + y, x - y
4165end
4166local a, b = mystery(10, 20)
4167local func
4168func = function(self, num)
4169 return self.value + num
4170end
4171local my_function
4172my_function = function(name, height)
4173 if name == nil then
4174 name = "something"
4175 end
4176 if height == nil then
4177 height = 100
4178 end
4179 print("Hello I am", name)
4180 return print("My height is", height)
4181end
4182local some_args
4183some_args = function(x, y)
4184 if x == nil then
4185 x = 100
4186 end
4187 if y == nil then
4188 y = x + 1000
4189 end
4190 return print(x + y)
4191end
4192local a = x - 10
4193local b = x - 10
4194local c = x(-y)
4195local d = x - z
4196local x = func("hello") + 100
4197local y = func("hello" + 100)
4198my_func(5, 4, 3, 8, 9, 10)
4199cool_func(1, 2, 3, 4, 5, 6, 7, 8)
4200my_func(5, 6, 7, 6, another_func(6, 7, 8, 9, 1, 2), 5, 4)
4201local x = {
4202 1,
4203 2,
4204 3,
4205 4,
4206 a_func(4, 5, 5, 6),
4207 8,
4208 9,
4209 10
4210}
4211local y = {
4212 my_func(1, 2, 3, 4, 5),
4213 5,
4214 6,
4215 7
4216}
4217if func(1, 2, 3, "hello", "world") then
4218 print("hello")
4219 print("I am inside if")
4220end
4221if func(1, 2, 3, "hello", "world") then
4222 print("hello")
4223 print("I am inside if")
4224end
4225local f1
4226f1 = function(_arg_0)
4227 local a, b, c
4228 a, b, c = _arg_0.a, _arg_0.b, _arg_0.c
4229 return print(a, b, c)
4230end
4231f1({
4232 a = 1,
4233 b = "2",
4234 c = { }
4235})
4236local f2
4237f2 = function(_arg_0, c)
4238 local a1, b
4239 a1, b = _arg_0.a, _arg_0.b
4240 if a1 == nil then
4241 a1 = 123
4242 end
4243 if b == nil then
4244 b = 'abc'
4245 end
4246 if c == nil then
4247 c = { }
4248 end
4249 return print(a1, b, c)
4250end
4251local arg1 = {
4252 a = 0
4253}
4254f2(arg1, arg2)
4255local findFirstEven
4256findFirstEven = function(list)
4257 for _index_0 = 1, #list do
4258 local item = list[_index_0]
4259 if type(item) == "table" then
4260 for _index_1 = 1, #item do
4261 local sub = item[_index_1]
4262 if sub % 2 == 0 then
4263 return sub
4264 end
4265 end
4266 end
4267 end
4268 return nil
4269end
4270local findFirstEven
4271findFirstEven = function(list)
4272 for _index_0 = 1, #list do
4273 local item = list[_index_0]
4274 if type(item) == "table" then
4275 for _index_1 = 1, #item do
4276 local sub = item[_index_1]
4277 if sub % 2 == 0 then
4278 return sub
4279 end
4280 end
4281 end
4282 end
4283 return nil
4284end
4285local f
4286f = function(...)
4287 local t = {
4288 n = select("#", ...),
4289 ...
4290 }
4291 print("argument count:", t.n)
4292 print("table length:", #t)
4293 for i = 1, t.n do
4294 print(t[i])
4295 end
4296end
4297f(1, 2, 3)
4298f("a", "b", "c", "d")
4299f()
4300local process
4301process = function(...)
4302 local args = {
4303 n = select("#", ...),
4304 ...
4305 }
4306 local sum = 0
4307 for i = 1, args.n do
4308 if args[i] ~= nil and type(args[i]) == "number" then
4309 sum = sum + args[i]
4310 end
4311 end
4312 return sum
4313end
4314process(1, nil, 3, nil, 5)
4315local my_function
4316my_function = function() end
4317my_function()
4318local func_a
4319func_a = function()
4320 return print("hello world")
4321end
4322local func_b
4323func_b = function()
4324 local value = 100
4325 return print("The value:", value)
4326end
4327func_a()
4328func_b()
4329local sum
4330sum = function(x, y)
4331 return print("sum", x + y)
4332end
4333sum(10, 20)
4334print(sum(10, 20))
4335a(b(c("a", "b", "c")))
4336print("x:", sum(10, 20), "y:", sum(30, 40))
4337local sum
4338sum = function(x, y)
4339 return x + y
4340end
4341print("The sum is ", sum(10, 20))
4342local sum
4343sum = function(x, y)
4344 return x + y
4345end
4346local mystery
4347mystery = function(x, y)
4348 return x + y, x - y
4349end
4350local a, b = mystery(10, 20)
4351local func
4352func = function(self, num)
4353 return self.value + num
4354end
4355local my_function
4356my_function = function(name, height)
4357 if name == nil then
4358 name = "something"
4359 end
4360 if height == nil then
4361 height = 100
4362 end
4363 print("Hello I am", name)
4364 return print("My height is", height)
4365end
4366local some_args
4367some_args = function(x, y)
4368 if x == nil then
4369 x = 100
4370 end
4371 if y == nil then
4372 y = x + 1000
4373 end
4374 return print(x + y)
4375end
4376local a = x - 10
4377local b = x - 10
4378local c = x(-y)
4379local d = x - z
4380local x = func("hello") + 100
4381local y = func("hello" + 100)
4382my_func(5, 4, 3, 8, 9, 10)
4383cool_func(1, 2, 3, 4, 5, 6, 7, 8)
4384my_func(5, 6, 7, 6, another_func(6, 7, 8, 9, 1, 2), 5, 4)
4385local x = {
4386 1,
4387 2,
4388 3,
4389 4,
4390 a_func(4, 5, 5, 6),
4391 8,
4392 9,
4393 10
4394}
4395local y = {
4396 my_func(1, 2, 3, 4, 5),
4397 5,
4398 6,
4399 7
4400}
4401if func(1, 2, 3, "hello", "world") then
4402 print("hello")
4403 print("I am inside if")
4404end
4405if func(1, 2, 3, "hello", "world") then
4406 print("hello")
4407 print("I am inside if")
4408end
4409local f1
4410f1 = function(_arg_0)
4411 local a, b, c
4412 a, b, c = _arg_0.a, _arg_0.b, _arg_0.c
4413 return print(a, b, c)
4414end
4415f1({
4416 a = 1,
4417 b = "2",
4418 c = { }
4419})
4420local f2
4421f2 = function(_arg_0, c)
4422 local a1, b
4423 a1, b = _arg_0.a, _arg_0.b
4424 if a1 == nil then
4425 a1 = 123
4426 end
4427 if b == nil then
4428 b = 'abc'
4429 end
4430 if c == nil then
4431 c = { }
4432 end
4433end
4434print(a1, b, c)
4435local arg1 = {
4436 a = 0
4437}
4438f2(arg1, arg2)
4439local findFirstEven
4440findFirstEven = function(list)
4441 for _index_0 = 1, #list do
4442 local item = list[_index_0]
4443 if type(item) == "table" then
4444 for _index_1 = 1, #item do
4445 local sub = item[_index_1]
4446 if sub % 2 == 0 then
4447 return sub
4448 end
4449 end
4450 end
4451 end
4452 return nil
4453end
4454local findFirstEven
4455findFirstEven = function(list)
4456 for _index_0 = 1, #list do
4457 local item = list[_index_0]
4458 if type(item) == "table" then
4459 for _index_1 = 1, #item do
4460 local sub = item[_index_1]
4461 if sub % 2 == 0 then
4462 return sub
4463 end
4464 end
4465 end
4466 end
4467 return nil
4468end
4469local f
4470f = function(...)
4471 local t = {
4472 n = select("#", ...),
4473 ...
4474 }
4475 print("argument count:", t.n)
4476 print("table length:", #t)
4477 for i = 1, t.n do
4478 print(t[i])
4479 end
4480end
4481f(1, 2, 3)
4482f("a", "b", "c", "d")
4483f()
4484local process
4485process = function(...)
4486 local args = {
4487 n = select("#", ...),
4488 ...
4489 }
4490 local sum = 0
4491 for i = 1, args.n do
4492 if args[i] ~= nil and type(args[i]) == "number" then
4493 sum = sum + args[i]
4494 end
4495 end
4496 return sum
4497end
4498process(1, nil, 3, nil, 5)
4499local a = 1
4500local b = 2
4501print(a + b)
4502Rx.Observable.fromRange(1, 8):filter(function(x)
4503 return x % 2 == 0
4504end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
4505 return value .. '!'
4506end):subscribe(print)
4507local a = 1
4508local b = 2
4509print(a + b)
4510Rx.Observable.fromRange(1, 8):filter(function(x)
4511 return x % 2 == 0
4512end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
4513 return value .. '!'
4514end):subscribe(print)
4515local str = strA .. strB .. strC
4516func(3000, "192.168.1.1")
4517local str = strA .. strB .. strC
4518func(3000, "192.168.1.1")
4519local a <const> = 123
4520local _ <close> = setmetatable({ }, {
4521 __close = function()
4522 return print("Out of scope.")
4523 end
4524})
4525local a, b, c, d
4526local _obj_0 = tb
4527a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
4528Constant = 123
4529local a <const> = 123
4530local _ <close> = setmetatable({ }, {
4531 __close = function()
4532 return print("Out of scope.")
4533 end
4534})
4535local a, b, c, d
4536local _obj_0 = tb
4537a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
4538Constant = 123
4539if tb ~= nil then
4540 tb:func()
4541end
4542if tb ~= nil then
4543 tb:func()
4544end
4545print(1 < 2 and 2 <= 2 and 2 < 3 and 3 == 3 and 3 > 2 and 2 >= 1 and 1 == 1 and 1 < 3 and 3 ~= 5)
4546local a = 5
4547print(1 <= a and a <= 10)
4548local v
4549v = function(x)
4550 print(x)
4551 return x
4552end
4553print((function()
4554 local _cond_0 = v(2)
4555 if not (v(1) < _cond_0) then
4556 return false
4557 else
4558 return _cond_0 <= v(3)
4559 end
4560end)())
4561print((function()
4562 local _cond_0 = v(2)
4563 if not (v(1) > _cond_0) then
4564 return false
4565 else
4566 return _cond_0 <= v(3)
4567 end
4568end)())
4569local tab = { }
4570tab[#tab + 1] = "Value"
4571local tbA = {
4572 1,
4573 2,
4574 3
4575}
4576local tbB = {
4577 4,
4578 5,
4579 6
4580}
4581local _len_0 = #tbA + 1
4582for _index_0 = 1, #tbB do
4583 local _elm_0 = tbB[_index_0]
4584 tbA[_len_0], _len_0 = _elm_0, _len_0 + 1
4585end
4586local parts = {
4587 "shoulders",
4588 "knees"
4589}
4590local lyrics
4591do
4592 local _tab_0 = {
4593 "head"
4594 }
4595 local _idx_0 = 1
4596 for _key_0, _value_0 in pairs(parts) do
4597 if _idx_0 == _key_0 then
4598 _tab_0[#_tab_0 + 1] = _value_0
4599 _idx_0 = _idx_0 + 1
4600 else
4601 _tab_0[_key_0] = _value_0
4602 end
4603 end
4604 _tab_0[#_tab_0 + 1] = "and"
4605 _tab_0[#_tab_0 + 1] = "toes"
4606 lyrics = _tab_0
4607end
4608local copy
4609do
4610 local _tab_0 = { }
4611 local _idx_0 = 1
4612 for _key_0, _value_0 in pairs(other) do
4613 if _idx_0 == _key_0 then
4614 _tab_0[#_tab_0 + 1] = _value_0
4615 _idx_0 = _idx_0 + 1
4616 else
4617 _tab_0[_key_0] = _value_0
4618 end
4619 end
4620 copy = _tab_0
4621end
4622local a = {
4623 1,
4624 2,
4625 3,
4626 x = 1
4627}
4628local b = {
4629 4,
4630 5,
4631 y = 1
4632}
4633local merge
4634local _tab_0 = { }
4635local _idx_0 = 1
4636for _key_0, _value_0 in pairs(a) do
4637 if _idx_0 == _key_0 then
4638 _tab_0[#_tab_0 + 1] = _value_0
4639 _idx_0 = _idx_0 + 1
4640 else
4641 _tab_0[_key_0] = _value_0
4642 end
4643end
4644local _idx_1 = 1
4645for _key_0, _value_0 in pairs(b) do
4646 if _idx_1 == _key_0 then
4647 _tab_0[#_tab_0 + 1] = _value_0
4648 _idx_1 = _idx_1 + 1
4649 else
4650 _tab_0[_key_0] = _value_0
4651 end
4652end
4653merge = _tab_0
4654local last
4655do
4656 local _item_0 = data.items
4657 last = _item_0[#_item_0]
4658end
4659local second_last
4660do
4661 local _item_0 = data.items
4662 second_last = _item_0[#_item_0 - 1]
4663end
4664local _obj_0 = data.items
4665_obj_0[#_obj_0] = 1
4666local mt = { }
4667local add
4668add = function(self, right)
4669 return setmetatable({
4670 value = self.value + right.value
4671 }, mt)
4672end
4673mt.__add = add
4674local a = setmetatable({
4675 value = 1
4676}, mt)
4677local b = setmetatable({
4678 value = 2
4679}, {
4680 __add = add
4681})
4682local c = setmetatable({
4683 value = 3
4684}, {
4685 __add = mt.__add
4686})
4687local d = a + b + c
4688print(d.value)
4689local _ <close> = setmetatable({ }, {
4690 __close = function()
4691 return print("out of scope")
4692 end
4693})
4694local tb = setmetatable({ }, {
4695 ["value"] = 123
4696})
4697getmetatable(tb).__index = getmetatable(tb)
4698print(tb.value)
4699setmetatable(tb, {
4700 __index = {
4701 item = "hello"
4702 }
4703})
4704print(tb.item)
4705local item, new, close, getter
4706do
4707 local _obj_0 = tb
4708 item, new = _obj_0[1], _obj_0.new
4709 do
4710 local _obj_1 = getmetatable(_obj_0)
4711 close, getter = _obj_1.__close, _obj_1.__index
4712 end
4713end
4714print(item, new, close, getter)
4715do
4716 local _obj_0 = func
4717 if _obj_0 ~= nil then
4718 _obj_0()
4719 end
4720end
4721print((function()
4722 local _obj_0 = abc
4723 if _obj_0 ~= nil then
4724 local _obj_1 = _obj_0["hello world"]
4725 if _obj_1 ~= nil then
4726 return _obj_1.xyz
4727 end
4728 return nil
4729 end
4730 return nil
4731end)())
4732local x
4733do
4734 local _obj_0 = tab
4735 if _obj_0 ~= nil then
4736 x = _obj_0.value
4737 end
4738end
4739local len = (function()
4740 local _obj_0 = utf8
4741 if _obj_0 ~= nil then
4742 return _obj_0.len
4743 end
4744 return nil
4745end)() or (function()
4746 local _obj_0 = string
4747 if _obj_0 ~= nil then
4748 return _obj_0.len
4749 end
4750 return nil
4751end)() or function(o)
4752 return #o
4753end
4754if print and (x ~= nil) then
4755 print(x)
4756end
4757local _with_0 = io.open("test.txt", "w")
4758if _with_0 ~= nil then
4759 _with_0:write("hello")
4760 _with_0:close()
4761end
4762print("hello")
4763print(1, 2)
4764print(1, 2, 3)
4765print(render(emit(parse(extract(readFile("example.txt"), language, { }), language))))
4766local a, b, c, d
4767if b ~= nil then
4768 a = b
4769else
4770 if c ~= nil then
4771 a = c
4772 else
4773 a = d
4774 end
4775end
4776func((function()
4777 if a ~= nil then
4778 return a
4779 else
4780 return { }
4781 end
4782end)())
4783if a == nil then
4784 a = false
4785end
4786local list = {
4787 1,
4788 2,
4789 3
4790}
4791func({
4792 1,
4793 2,
4794 3
4795})
4796local f
4797f = function()
4798 return {
4799 1,
4800 2,
4801 3
4802 }
4803end
4804local tb = {
4805 name = "abc",
4806 values = {
4807 "a",
4808 "b",
4809 "c"
4810 },
4811 objects = {
4812 {
4813 name = "a",
4814 value = 1,
4815 func = function(self)
4816 return self.value + 1
4817 end,
4818 tb = {
4819 fieldA = 1
4820 }
4821 },
4822 {
4823 name = "b",
4824 value = 2,
4825 func = function(self)
4826 return self.value + 2
4827 end,
4828 tb = { }
4829 }
4830 }
4831}
4832if tb ~= nil then
4833 tb:func()
4834end
4835if tb ~= nil then
4836 tb:func()
4837end
4838print(1 < 2 and 2 <= 2 and 2 < 3 and 3 == 3 and 3 > 2 and 2 >= 1 and 1 == 1 and 1 < 3 and 3 ~= 5)
4839local a = 5
4840print(1 <= a and a <= 10)
4841local v
4842v = function(x)
4843 print(x)
4844 return x
4845end
4846print((function()
4847 local _cond_0 = v(2)
4848 if not (v(1) < _cond_0) then
4849 return false
4850 else
4851 return _cond_0 <= v(3)
4852 end
4853end)())
4854print((function()
4855 local _cond_0 = v(2)
4856 if not (v(1) > _cond_0) then
4857 return false
4858 else
4859 return _cond_0 <= v(3)
4860 end
4861end)())
4862local tab = { }
4863tab[#tab + 1] = "Value"
4864local tbA = {
4865 1,
4866 2,
4867 3
4868}
4869local tbB = {
4870 4,
4871 5,
4872 6
4873}
4874local _len_0 = #tbA + 1
4875for _index_0 = 1, #tbB do
4876 local _elm_0 = tbB[_index_0]
4877 tbA[_len_0], _len_0 = _elm_0, _len_0 + 1
4878end
4879local parts = {
4880 "shoulders",
4881 "knees"
4882}
4883local lyrics
4884do
4885 local _tab_0 = {
4886 "head"
4887 }
4888 local _idx_0 = 1
4889 for _key_0, _value_0 in pairs(parts) do
4890 if _idx_0 == _key_0 then
4891 _tab_0[#_tab_0 + 1] = _value_0
4892 _idx_0 = _idx_0 + 1
4893 else
4894 _tab_0[_key_0] = _value_0
4895 end
4896 end
4897 _tab_0[#_tab_0 + 1] = "and"
4898 _tab_0[#_tab_0 + 1] = "toes"
4899 lyrics = _tab_0
4900end
4901local copy
4902do
4903 local _tab_0 = { }
4904 local _idx_0 = 1
4905 for _key_0, _value_0 in pairs(other) do
4906 if _idx_0 == _key_0 then
4907 _tab_0[#_tab_0 + 1] = _value_0
4908 _idx_0 = _idx_0 + 1
4909 else
4910 _tab_0[_key_0] = _value_0
4911 end
4912 end
4913 copy = _tab_0
4914end
4915local a = {
4916 1,
4917 2,
4918 3,
4919 x = 1
4920}
4921local b = {
4922 4,
4923 5,
4924 y = 1
4925}
4926local merge
4927local _tab_0 = { }
4928local _idx_0 = 1
4929for _key_0, _value_0 in pairs(a) do
4930 if _idx_0 == _key_0 then
4931 _tab_0[#_tab_0 + 1] = _value_0
4932 _idx_0 = _idx_0 + 1
4933 else
4934 _tab_0[_key_0] = _value_0
4935 end
4936end
4937local _idx_1 = 1
4938for _key_0, _value_0 in pairs(b) do
4939 if _idx_1 == _key_0 then
4940 _tab_0[#_tab_0 + 1] = _value_0
4941 _idx_1 = _idx_1 + 1
4942 else
4943 _tab_0[_key_0] = _value_0
4944 end
4945end
4946merge = _tab_0
4947local last
4948do
4949 local _item_0 = data.items
4950 last = _item_0[#_item_0]
4951end
4952local second_last
4953do
4954 local _item_0 = data.items
4955 second_last = _item_0[#_item_0 - 1]
4956end
4957local _obj_0 = data.items
4958_obj_0[#_obj_0] = 1
4959local mt = { }
4960local add
4961add = function(self, right)
4962 return setmetatable({
4963 value = self.value + right.value
4964 }, mt)
4965end
4966mt.__add = add
4967local a = setmetatable({
4968 value = 1
4969}, mt)
4970local b = setmetatable({
4971 value = 2
4972}, {
4973 __add = add
4974})
4975local c = setmetatable({
4976 value = 3
4977}, {
4978 __add = mt.__add
4979})
4980local d = a + b + c
4981print(d.value)
4982local _ <close> = setmetatable({ }, {
4983 __close = function()
4984 return print("out of scope")
4985 end
4986})
4987local tb = setmetatable({ }, {
4988 ["value"] = 123
4989})
4990getmetatable(tb).__index = getmetatable(tb)
4991print(tb.value)
4992setmetatable(tb, {
4993 __index = {
4994 item = "hello"
4995 }
4996})
4997print(tb.item)
4998local item, new, close, getter
4999do
5000 local _obj_0 = tb
5001 item, new = _obj_0[1], _obj_0.new
5002 do
5003 local _obj_1 = getmetatable(_obj_0)
5004 close, getter = _obj_1.__close, _obj_1.__index
5005 end
5006end
5007print(item, new, close, getter)
5008do
5009 local _obj_0 = func
5010 if _obj_0 ~= nil then
5011 _obj_0()
5012 end
5013end
5014print((function()
5015 local _obj_0 = abc
5016 if _obj_0 ~= nil then
5017 local _obj_1 = _obj_0["hello world"]
5018 if _obj_1 ~= nil then
5019 return _obj_1.xyz
5020 end
5021 return nil
5022 end
5023 return nil
5024end)())
5025local x
5026do
5027 local _obj_0 = tab
5028 if _obj_0 ~= nil then
5029 x = _obj_0.value
5030 end
5031end
5032local len = (function()
5033 local _obj_0 = utf8
5034 if _obj_0 ~= nil then
5035 return _obj_0.len
5036 end
5037 return nil
5038end)() or (function()
5039 local _obj_0 = string
5040 if _obj_0 ~= nil then
5041 return _obj_0.len
5042 end
5043 return nil
5044end)() or function(o)
5045 return #o
5046end
5047if print and (x ~= nil) then
5048 print(x)
5049end
5050local _with_0 = io.open("test.txt", "w")
5051if _with_0 ~= nil then
5052 _with_0:write("hello")
5053 _with_0:close()
5054end
5055print("hello")
5056print(1, 2)
5057print(1, 2, 3)
5058print(render(emit(parse(extract(readFile("example.txt"), language, { }), language))))
5059local a, b, c, d
5060if b ~= nil then
5061 a = b
5062else
5063 if c ~= nil then
5064 a = c
5065 else
5066 a = d
5067 end
5068end
5069func((function()
5070 if a ~= nil then
5071 return a
5072 else
5073 return { }
5074 end
5075end)())
5076if a == nil then
5077 a = false
5078end
5079local list = {
5080 1,
5081 2,
5082 3
5083}
5084func({
5085 1,
5086 2,
5087 3
5088})
5089local f
5090f = function()
5091 return {
5092 1,
5093 2,
5094 3
5095 }
5096end
5097local tb = {
5098 name = "abc",
5099 values = {
5100 "a",
5101 "b",
5102 "c"
5103 },
5104 objects = {
5105 {
5106 name = "a",
5107 value = 1,
5108 func = function(self)
5109 return self.value + 1
5110 end,
5111 tb = {
5112 fieldA = 1
5113 }
5114 },
5115 {
5116 name = "b",
5117 value = 2,
5118 func = function(self)
5119 return self.value + 2
5120 end,
5121 tb = { }
5122 }
5123 }
5124}
5125local some_string = "Here is a string\n that has a line break in it."
5126print("I am " .. tostring(math.random() * 100) .. "% sure.")
5127local integer = 1000000
5128local hex = 0xEFBBBF
5129local binary = 19
5130local str = "key: value\nlist:\n - item1\n - " .. tostring(expr)
5131local fn
5132fn = function()
5133 local str = "foo:\n bar: baz"
5134 return str
5135end
5136local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'"
5137local some_string = "Here is a string\n that has a line break in it."
5138print("I am " .. tostring(math.random() * 100) .. "% sure.")
5139local integer = 1000000
5140local hex = 0xEFBBBF
5141local binary = 19
5142local str = "key: value\nlist:\n - item1\n - " .. tostring(expr)
5143local fn
5144fn = function()
5145 local str = "foo:\n bar: baz"
5146 return str
5147end
5148local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'"
diff --git a/spec/outputs/codes_from_doc_zh.lua b/spec/outputs/codes_from_doc_zh.lua
index 650d923..e0d364d 100644
--- a/spec/outputs/codes_from_doc_zh.lua
+++ b/spec/outputs/codes_from_doc_zh.lua
@@ -1,159 +1,73 @@
1local _module_0 = { }
2local p, to_lua
3do 1do
4 local _obj_0 = require("yue") 2 local var = "hello"
5 p, to_lua = _obj_0.p, _obj_0.to_lua 3 print(var)
6end 4end
7local inventory = { 5print(var)
8 equipment = { 6local counter
9 "sword", 7do
10 "shield" 8 local i = 0
11 }, 9 counter = function()
12 items = { 10 i = i + 1
13 { 11 return i
14 name = "potion",
15 count = 10
16 },
17 {
18 name = "bread",
19 count = 3
20 }
21 }
22}
23local map
24map = function(arr, action)
25 local _accum_0 = { }
26 local _len_0 = 1
27 for _index_0 = 1, #arr do
28 local item = arr[_index_0]
29 _accum_0[_len_0] = action(item)
30 _len_0 = _len_0 + 1
31 end 12 end
32 return _accum_0
33end 13end
34local filter 14print(counter())
35filter = function(arr, cond) 15print(counter())
36 local _accum_0 = { } 16local tbl = {
37 local _len_0 = 1 17 key = (function()
38 for _index_0 = 1, #arr do 18 print("分配键值!")
39 local item = arr[_index_0] 19 return 1234
40 if cond(item) then 20 end)()
41 _accum_0[_len_0] = item 21}
42 _len_0 = _len_0 + 1 22do
43 end 23 local var = "hello"
44 end 24 print(var)
45 return _accum_0
46end 25end
47local reduce 26print(var)
48reduce = function(arr, init, action) 27local counter
49 for _index_0 = 1, #arr do 28do
50 local item = arr[_index_0] 29 local i = 0
51 init = action(init, item) 30 counter = function()
31 i = i + 1
32 return i
52 end 33 end
53 return init
54end 34end
55print(reduce(filter(map({ 35print(counter())
56 1, 36print(counter())
57 2, 37local tbl = {
58 3 38 key = (function()
59}, function(x) 39 print("分配键值!")
60 return x * 2 40 return 1234
61end), function(x) 41 end)()
62 return x > 4 42}
63end), 0, function(a, b) 43if name == "Rob" then
64 return a + b 44 print("你好,世界")
65end))
66local apple = setmetatable({
67 size = 15,
68}, {
69 __index = {
70 color = 0x00ffff
71 }
72})
73if (getmetatable(apple) ~= nil) then
74 p(apple.size, apple.color, getmetatable(apple).__index)
75end 45end
76local _u1f31b = "月之脚本" 46local _list_0 = items
77_module_0["🌛"] = _u1f31b 47for _index_0 = 1, #_list_0 do
78return _module_0 48 local item = _list_0[_index_0]
79local _module_0 = { } 49 print("项目: ", item)
80local p, to_lua
81do
82 local _obj_0 = require("yue")
83 p, to_lua = _obj_0.p, _obj_0.to_lua
84end 50end
85local inventory = { 51while game:isRunning() do
86 equipment = { 52 game:update()
87 "sword",
88 "shield"
89 },
90 items = {
91 {
92 name = "potion",
93 count = 10
94 },
95 {
96 name = "bread",
97 count = 3
98 }
99 }
100}
101local map
102map = function(arr, action)
103 local _accum_0 = { }
104 local _len_0 = 1
105 for _index_0 = 1, #arr do
106 local item = arr[_index_0]
107 _accum_0[_len_0] = action(item)
108 _len_0 = _len_0 + 1
109 end
110 return _accum_0
111end 53end
112local filter 54while not reader:eof() do
113filter = function(arr, cond) 55 reader:parse_line()
114 local _accum_0 = { }
115 local _len_0 = 1
116 for _index_0 = 1, #arr do
117 local item = arr[_index_0]
118 if cond(item) then
119 _accum_0[_len_0] = item
120 _len_0 = _len_0 + 1
121 end
122 end
123 return _accum_0
124end 56end
125local reduce 57if name == "Rob" then
126reduce = function(arr, init, action) 58 print("你好,世界")
127 for _index_0 = 1, #arr do
128 local item = arr[_index_0]
129 init = action(init, item)
130 end
131 return init
132end 59end
133print(reduce(filter(map({ 60local _list_0 = items
134 1, 61for _index_0 = 1, #_list_0 do
135 2, 62 local item = _list_0[_index_0]
136 3 63 print("项目: ", item)
137}, function(x) 64end
138 return x * 2 65while game:isRunning() do
139end), function(x) 66 game:update()
140 return x > 4 67end
141end), 0, function(a, b) 68while not reader:eof() do
142 return a + b 69 reader:parse_line()
143end))
144local apple = setmetatable({
145 size = 15,
146}, {
147 __index = {
148 color = 0x00ffff
149 }
150})
151if (getmetatable(apple) ~= nil) then
152 p(apple.size, apple.color, getmetatable(apple).__index)
153end 70end
154local _u1f31b = "月之脚本"
155_module_0["🌛"] = _u1f31b
156return _module_0
157local area = 6.2831853071796 * 5 71local area = 6.2831853071796 * 5
158print('你好 世界') 72print('你好 世界')
159do 73do
@@ -232,592 +146,6 @@ end
232do 146do
233 print(123, "hello") 147 print(123, "hello")
234end 148end
235if tb ~= nil then
236 tb:func()
237end
238if tb ~= nil then
239 tb:func()
240end
241print(1 < 2 and 2 <= 2 and 2 < 3 and 3 == 3 and 3 > 2 and 2 >= 1 and 1 == 1 and 1 < 3 and 3 ~= 5)
242local a = 5
243print(1 <= a and a <= 10)
244local v
245v = function(x)
246 print(x)
247 return x
248end
249print((function()
250 local _cond_0 = v(2)
251 if not (v(1) < _cond_0) then
252 return false
253 else
254 return _cond_0 <= v(3)
255 end
256end)())
257print((function()
258 local _cond_0 = v(2)
259 if not (v(1) > _cond_0) then
260 return false
261 else
262 return _cond_0 <= v(3)
263 end
264end)())
265local tab = { }
266tab[#tab + 1] = "Value"
267local tbA = {
268 1,
269 2,
270 3
271}
272local tbB = {
273 4,
274 5,
275 6
276}
277local _len_0 = #tbA + 1
278for _index_0 = 1, #tbB do
279 local _elm_0 = tbB[_index_0]
280 tbA[_len_0], _len_0 = _elm_0, _len_0 + 1
281end
282local parts = {
283 "shoulders",
284 "knees"
285}
286local lyrics
287do
288 local _tab_0 = {
289 "head"
290 }
291 local _idx_0 = 1
292 for _key_0, _value_0 in pairs(parts) do
293 if _idx_0 == _key_0 then
294 _tab_0[#_tab_0 + 1] = _value_0
295 _idx_0 = _idx_0 + 1
296 else
297 _tab_0[_key_0] = _value_0
298 end
299 end
300 _tab_0[#_tab_0 + 1] = "and"
301 _tab_0[#_tab_0 + 1] = "toes"
302 lyrics = _tab_0
303end
304local copy
305do
306 local _tab_0 = { }
307 local _idx_0 = 1
308 for _key_0, _value_0 in pairs(other) do
309 if _idx_0 == _key_0 then
310 _tab_0[#_tab_0 + 1] = _value_0
311 _idx_0 = _idx_0 + 1
312 else
313 _tab_0[_key_0] = _value_0
314 end
315 end
316 copy = _tab_0
317end
318local a = {
319 1,
320 2,
321 3,
322 x = 1
323}
324local b = {
325 4,
326 5,
327 y = 1
328}
329local merge
330local _tab_0 = { }
331local _idx_0 = 1
332for _key_0, _value_0 in pairs(a) do
333 if _idx_0 == _key_0 then
334 _tab_0[#_tab_0 + 1] = _value_0
335 _idx_0 = _idx_0 + 1
336 else
337 _tab_0[_key_0] = _value_0
338 end
339end
340local _idx_1 = 1
341for _key_0, _value_0 in pairs(b) do
342 if _idx_1 == _key_0 then
343 _tab_0[#_tab_0 + 1] = _value_0
344 _idx_1 = _idx_1 + 1
345 else
346 _tab_0[_key_0] = _value_0
347 end
348end
349merge = _tab_0
350local last
351do
352 local _item_0 = data.items
353 last = _item_0[#_item_0]
354end
355local second_last
356do
357 local _item_0 = data.items
358 second_last = _item_0[#_item_0 - 1]
359end
360local _obj_0 = data.items
361_obj_0[#_obj_0] = 1
362local mt = { }
363local add
364add = function(self, right)
365 return setmetatable({
366 value = self.value + right.value
367 }, mt)
368end
369mt.__add = add
370local a = setmetatable({
371 value = 1
372}, mt)
373local b = setmetatable({
374 value = 2
375}, {
376 __add = add
377})
378local c = setmetatable({
379 value = 3
380}, {
381 __add = mt.__add
382})
383local d = a + b + c
384print(d.value)
385local _ <close> = setmetatable({ }, {
386 __close = function()
387 return print("超出范围")
388 end
389})
390local tb = setmetatable({ }, {
391 ["value"] = 123
392})
393getmetatable(tb).__index = getmetatable(tb)
394print(tb.value)
395setmetatable(tb, {
396 __index = {
397 item = "hello"
398 }
399})
400print(tb.item)
401local item, new, close, getter
402do
403 local _obj_0 = tb
404 item, new = _obj_0[1], _obj_0.new
405 do
406 local _obj_1 = getmetatable(_obj_0)
407 close, getter = _obj_1.__close, _obj_1.__index
408 end
409end
410print(item, new, close, getter)
411do
412 local _obj_0 = func
413 if _obj_0 ~= nil then
414 _obj_0()
415 end
416end
417print((function()
418 local _obj_0 = abc
419 if _obj_0 ~= nil then
420 local _obj_1 = _obj_0["你好 世界"]
421 if _obj_1 ~= nil then
422 return _obj_1.xyz
423 end
424 return nil
425 end
426 return nil
427end)())
428local x
429do
430 local _obj_0 = tab
431 if _obj_0 ~= nil then
432 x = _obj_0.value
433 end
434end
435local len = (function()
436 local _obj_0 = utf8
437 if _obj_0 ~= nil then
438 return _obj_0.len
439 end
440 return nil
441end)() or (function()
442 local _obj_0 = string
443 if _obj_0 ~= nil then
444 return _obj_0.len
445 end
446 return nil
447end)() or function(o)
448 return #o
449end
450if print and (x ~= nil) then
451 print(x)
452end
453local _with_0 = io.open("test.txt", "w")
454if _with_0 ~= nil then
455 _with_0:write("你好")
456 _with_0:close()
457end
458print("你好")
459print(1, 2)
460print(1, 2, 3)
461print(render(emit(parse(extract(readFile("example.txt"), language, { }), language))))
462local a, b, c, d
463if b ~= nil then
464 a = b
465else
466 if c ~= nil then
467 a = c
468 else
469 a = d
470 end
471end
472func((function()
473 if a ~= nil then
474 return a
475 else
476 return { }
477 end
478end)())
479if a == nil then
480 a = false
481end
482local list = {
483 1,
484 2,
485 3
486}
487func({
488 1,
489 2,
490 3
491})
492local f
493f = function()
494 return {
495 1,
496 2,
497 3
498 }
499end
500local tb = {
501 name = "abc",
502 values = {
503 "a",
504 "b",
505 "c"
506 },
507 objects = {
508 {
509 name = "a",
510 value = 1,
511 func = function(self)
512 return self.value + 1
513 end,
514 tb = {
515 fieldA = 1
516 }
517 },
518 {
519 name = "b",
520 value = 2,
521 func = function(self)
522 return self.value + 2
523 end,
524 tb = { }
525 }
526 }
527}
528if tb ~= nil then
529 tb:func()
530end
531if tb ~= nil then
532 tb:func()
533end
534print(1 < 2 and 2 <= 2 and 2 < 3 and 3 == 3 and 3 > 2 and 2 >= 1 and 1 == 1 and 1 < 3 and 3 ~= 5)
535local a = 5
536print(1 <= a and a <= 10)
537local v
538v = function(x)
539 print(x)
540 return x
541end
542print((function()
543 local _cond_0 = v(2)
544 if not (v(1) < _cond_0) then
545 return false
546 else
547 return _cond_0 <= v(3)
548 end
549end)())
550print((function()
551 local _cond_0 = v(2)
552 if not (v(1) > _cond_0) then
553 return false
554 else
555 return _cond_0 <= v(3)
556 end
557end)())
558local tab = { }
559tab[#tab + 1] = "Value"
560local tbA = {
561 1,
562 2,
563 3
564}
565local tbB = {
566 4,
567 5,
568 6
569}
570local _len_0 = #tbA + 1
571for _index_0 = 1, #tbB do
572 local _elm_0 = tbB[_index_0]
573 tbA[_len_0], _len_0 = _elm_0, _len_0 + 1
574end
575local parts = {
576 "shoulders",
577 "knees"
578}
579local lyrics
580do
581 local _tab_0 = {
582 "head"
583 }
584 local _idx_0 = 1
585 for _key_0, _value_0 in pairs(parts) do
586 if _idx_0 == _key_0 then
587 _tab_0[#_tab_0 + 1] = _value_0
588 _idx_0 = _idx_0 + 1
589 else
590 _tab_0[_key_0] = _value_0
591 end
592 end
593 _tab_0[#_tab_0 + 1] = "and"
594 _tab_0[#_tab_0 + 1] = "toes"
595 lyrics = _tab_0
596end
597local copy
598do
599 local _tab_0 = { }
600 local _idx_0 = 1
601 for _key_0, _value_0 in pairs(other) do
602 if _idx_0 == _key_0 then
603 _tab_0[#_tab_0 + 1] = _value_0
604 _idx_0 = _idx_0 + 1
605 else
606 _tab_0[_key_0] = _value_0
607 end
608 end
609 copy = _tab_0
610end
611local a = {
612 1,
613 2,
614 3,
615 x = 1
616}
617local b = {
618 4,
619 5,
620 y = 1
621}
622local merge
623local _tab_0 = { }
624local _idx_0 = 1
625for _key_0, _value_0 in pairs(a) do
626 if _idx_0 == _key_0 then
627 _tab_0[#_tab_0 + 1] = _value_0
628 _idx_0 = _idx_0 + 1
629 else
630 _tab_0[_key_0] = _value_0
631 end
632end
633local _idx_1 = 1
634for _key_0, _value_0 in pairs(b) do
635 if _idx_1 == _key_0 then
636 _tab_0[#_tab_0 + 1] = _value_0
637 _idx_1 = _idx_1 + 1
638 else
639 _tab_0[_key_0] = _value_0
640 end
641end
642merge = _tab_0
643local last
644do
645 local _item_0 = data.items
646 last = _item_0[#_item_0]
647end
648local second_last
649do
650 local _item_0 = data.items
651 second_last = _item_0[#_item_0 - 1]
652end
653local _obj_0 = data.items
654_obj_0[#_obj_0] = 1
655local mt = { }
656local add
657add = function(self, right)
658 return setmetatable({
659 value = self.value + right.value
660 }, mt)
661end
662mt.__add = add
663local a = setmetatable({
664 value = 1
665}, mt)
666local b = setmetatable({
667 value = 2
668}, {
669 __add = add
670})
671local c = setmetatable({
672 value = 3
673}, {
674 __add = mt.__add
675})
676local d = a + b + c
677print(d.value)
678local _ <close> = setmetatable({ }, {
679 __close = function()
680 return print("超出范围")
681 end
682})
683local tb = setmetatable({ }, {
684 ["value"] = 123
685})
686getmetatable(tb).__index = getmetatable(tb)
687print(tb.value)
688setmetatable(tb, {
689 __index = {
690 item = "hello"
691 }
692})
693print(tb.item)
694local item, new, close, getter
695do
696 local _obj_0 = tb
697 item, new = _obj_0[1], _obj_0.new
698 do
699 local _obj_1 = getmetatable(_obj_0)
700 close, getter = _obj_1.__close, _obj_1.__index
701 end
702end
703print(item, new, close, getter)
704do
705 local _obj_0 = func
706 if _obj_0 ~= nil then
707 _obj_0()
708 end
709end
710print((function()
711 local _obj_0 = abc
712 if _obj_0 ~= nil then
713 local _obj_1 = _obj_0["你好 世界"]
714 if _obj_1 ~= nil then
715 return _obj_1.xyz
716 end
717 return nil
718 end
719 return nil
720end)())
721local x
722do
723 local _obj_0 = tab
724 if _obj_0 ~= nil then
725 x = _obj_0.value
726 end
727end
728local len = (function()
729 local _obj_0 = utf8
730 if _obj_0 ~= nil then
731 return _obj_0.len
732 end
733 return nil
734end)() or (function()
735 local _obj_0 = string
736 if _obj_0 ~= nil then
737 return _obj_0.len
738 end
739 return nil
740end)() or function(o)
741 return #o
742end
743if print and (x ~= nil) then
744 print(x)
745end
746local _with_0 = io.open("test.txt", "w")
747if _with_0 ~= nil then
748 _with_0:write("你好")
749 _with_0:close()
750end
751print("你好")
752print(1, 2)
753print(1, 2, 3)
754print(render(emit(parse(extract(readFile("example.txt"), language, { }), language))))
755local a, b, c, d
756if b ~= nil then
757 a = b
758else
759 if c ~= nil then
760 a = c
761 else
762 a = d
763 end
764end
765func((function()
766 if a ~= nil then
767 return a
768 else
769 return { }
770 end
771end)())
772if a == nil then
773 a = false
774end
775local list = {
776 1,
777 2,
778 3
779}
780func({
781 1,
782 2,
783 3
784})
785local f
786f = function()
787 return {
788 1,
789 2,
790 3
791 }
792end
793local tb = {
794 name = "abc",
795 values = {
796 "a",
797 "b",
798 "c"
799 },
800 objects = {
801 {
802 name = "a",
803 value = 1,
804 func = function(self)
805 return self.value + 1
806 end,
807 tb = {
808 fieldA = 1
809 }
810 },
811 {
812 name = "b",
813 value = 2,
814 func = function(self)
815 return self.value + 2
816 end,
817 tb = { }
818 }
819 }
820}
821do 149do
822 local insert, concat = table.insert, table.concat 150 local insert, concat = table.insert, table.concat
823 local C, Ct, Cmt 151 local C, Ct, Cmt
@@ -1080,460 +408,6 @@ _module_0 = function()
1080 return 123 408 return 123
1081end 409end
1082return _module_0 410return _module_0
1083local hello = "world"
1084local a, b, c = 1, 2, 3
1085hello = 123
1086local x = 1
1087x = x + 1
1088x = x - 1
1089x = x * 10
1090x = x / 10
1091x = x % 10
1092local s = s .. "world"
1093local arg = arg or "默认值"
1094local a = 0
1095local b = 0
1096local c = 0
1097local d = 0
1098local e = 0
1099local x = f()
1100local y = x
1101local z = x
1102do
1103 local a = 1
1104 local x, y, z
1105 print("预先声明后续所有变量为局部变量")
1106 x = function()
1107 return 1 + y + z
1108 end
1109 y, z = 2, 3
1110 instance = Item:new()
1111end
1112do
1113 local X = 1
1114 local B
1115 print("只预先声明后续大写的变量为局部变量")
1116 local a = 1
1117 B = 2
1118end
1119do
1120 a = 1
1121 print("预先声明所有变量为全局变量")
1122 x = function()
1123 return 1 + y + z
1124 end
1125 y, z = 2, 3
1126end
1127do
1128 x = 1
1129 print("只预先声明大写的变量为全局变量")
1130 local a = 1
1131 B = 2
1132 local Temp = "一个局部值"
1133end
1134local hello = "world"
1135local a, b, c = 1, 2, 3
1136hello = 123
1137local x = 1
1138x = x + 1
1139x = x - 1
1140x = x * 10
1141x = x / 10
1142x = x % 10
1143local s = s .. "world"
1144local arg = arg or "默认值"
1145local a = 0
1146local b = 0
1147local c = 0
1148local d = 0
1149local e = 0
1150local x = f()
1151local y = x
1152local z = x
1153do
1154 local a = 1
1155 local x, y, z
1156 print("预先声明后续所有变量为局部变量")
1157 x = function()
1158 return 1 + y + z
1159 end
1160 y, z = 2, 3
1161 instance = Item:new()
1162end
1163do
1164 local X = 1
1165 local B
1166 print("只预先声明后续大写的变量为局部变量")
1167 local a = 1
1168 B = 2
1169end
1170do
1171 a = 1
1172 print("预先声明所有变量为全局变量")
1173 x = function()
1174 return 1 + y + z
1175 end
1176 y, z = 2, 3
1177end
1178do
1179 x = 1
1180 print("只预先声明大写的变量为全局变量")
1181 local a = 1
1182 B = 2
1183 local Temp = "一个局部值"
1184end
1185local thing = {
1186 1,
1187 2
1188}
1189local a, b = thing[1], thing[2]
1190print(a, b)
1191local obj = {
1192 hello = "world",
1193 day = "tuesday",
1194 length = 20
1195}
1196local hello, the_day = obj.hello, obj.day
1197print(hello, the_day)
1198local day = obj.day
1199local obj2 = {
1200 numbers = {
1201 1,
1202 2,
1203 3,
1204 4
1205 },
1206 properties = {
1207 color = "green",
1208 height = 13.5
1209 }
1210}
1211local first, second, color = obj2.numbers[1], obj2.numbers[2], obj2.properties.color
1212print(first, second, color)
1213local first, second, color
1214local _obj_0 = obj2
1215first, second, color = _obj_0.numbers[1], _obj_0.numbers[2], _obj_0.properties.color
1216local concat, insert
1217local _obj_0 = table
1218concat, insert = _obj_0.concat, _obj_0.insert
1219local mix, max, rand
1220local _obj_0 = math
1221mix, max, rand = _obj_0.mix, _obj_0.max, _obj_0.random
1222local name, job
1223local _obj_0 = person
1224name, job = _obj_0.name, _obj_0.job
1225if name == nil then
1226 name = "nameless"
1227end
1228if job == nil then
1229 job = "jobless"
1230end
1231local two, four
1232local _obj_0 = items
1233two, four = _obj_0[2], _obj_0[4]
1234local orders = {
1235 "first",
1236 "second",
1237 "third",
1238 "fourth",
1239 "last"
1240}
1241local first, bulk, last = orders[1], (function()
1242 local _accum_0 = { }
1243 local _len_0 = 1
1244 local _max_0 = #orders + -2 + 1
1245 for _index_0 = 2, _max_0 do
1246 local _item_0 = orders[_index_0]
1247 _accum_0[_len_0] = _item_0
1248 _len_0 = _len_0 + 1
1249 end
1250 return _accum_0
1251end)(), orders[#orders]
1252print(first)
1253print(bulk)
1254print(last)
1255local first, rest
1256do
1257 local _obj_0 = orders
1258 first, rest = _obj_0[1], (function()
1259 local _accum_0 = { }
1260 local _len_0 = 1
1261 local _max_0 = #_obj_0
1262 for _index_0 = 2, _max_0 do
1263 local _item_0 = _obj_0[_index_0]
1264 _accum_0[_len_0] = _item_0
1265 _len_0 = _len_0 + 1
1266 end
1267 return _accum_0
1268 end)()
1269end
1270local start, last
1271do
1272 local _obj_0 = orders
1273 start, last = (function()
1274 local _accum_0 = { }
1275 local _len_0 = 1
1276 local _max_0 = #_obj_0 + -2 + 1
1277 for _index_0 = 1, _max_0 do
1278 local _item_0 = _obj_0[_index_0]
1279 _accum_0[_len_0] = _item_0
1280 _len_0 = _len_0 + 1
1281 end
1282 return _accum_0
1283 end)(), _obj_0[#_obj_0]
1284end
1285local _obj_0 = orders
1286first, last = _obj_0[1], _obj_0[#_obj_0]
1287local tuples = {
1288 {
1289 "hello",
1290 "world"
1291 },
1292 {
1293 "egg",
1294 "head"
1295 }
1296}
1297for _index_0 = 1, #tuples do
1298 local _des_0 = tuples[_index_0]
1299 local left, right = _des_0[1], _des_0[2]
1300 print(left, right)
1301end
1302local thing = {
1303 1,
1304 2
1305}
1306local a, b = thing[1], thing[2]
1307print(a, b)
1308local obj = {
1309 hello = "world",
1310 day = "tuesday",
1311 length = 20
1312}
1313local hello, the_day = obj.hello, obj.day
1314print(hello, the_day)
1315local day = obj.day
1316local obj2 = {
1317 numbers = {
1318 1,
1319 2,
1320 3,
1321 4
1322 },
1323 properties = {
1324 color = "green",
1325 height = 13.5
1326 }
1327}
1328local first, second, color = obj2.numbers[1], obj2.numbers[2], obj2.properties.color
1329print(first, second, color)
1330local first, second, color
1331local _obj_0 = obj2
1332first, second, color = _obj_0.numbers[1], _obj_0.numbers[2], _obj_0.properties.color
1333local concat, insert
1334local _obj_0 = table
1335concat, insert = _obj_0.concat, _obj_0.insert
1336local mix, max, rand
1337local _obj_0 = math
1338mix, max, rand = _obj_0.mix, _obj_0.max, _obj_0.random
1339local name, job
1340local _obj_0 = person
1341name, job = _obj_0.name, _obj_0.job
1342if name == nil then
1343 name = "nameless"
1344end
1345if job == nil then
1346 job = "jobless"
1347end
1348local two, four
1349local _obj_0 = items
1350two, four = _obj_0[2], _obj_0[4]
1351local orders = {
1352 "first",
1353 "second",
1354 "third",
1355 "fourth",
1356 "last"
1357}
1358local first, bulk, last = orders[1], (function()
1359 local _accum_0 = { }
1360 local _len_0 = 1
1361 local _max_0 = #orders + -2 + 1
1362 for _index_0 = 2, _max_0 do
1363 local _item_0 = orders[_index_0]
1364 _accum_0[_len_0] = _item_0
1365 _len_0 = _len_0 + 1
1366 end
1367 return _accum_0
1368end)(), orders[#orders]
1369print(first)
1370print(bulk)
1371print(last)
1372local first, rest
1373do
1374 local _obj_0 = orders
1375 first, rest = _obj_0[1], (function()
1376 local _accum_0 = { }
1377 local _len_0 = 1
1378 local _max_0 = #_obj_0
1379 for _index_0 = 2, _max_0 do
1380 local _item_0 = _obj_0[_index_0]
1381 _accum_0[_len_0] = _item_0
1382 _len_0 = _len_0 + 1
1383 end
1384 return _accum_0
1385 end)()
1386end
1387local start, last
1388do
1389 local _obj_0 = orders
1390 start, last = (function()
1391 local _accum_0 = { }
1392 local _len_0 = 1
1393 local _max_0 = #_obj_0 + -2 + 1
1394 for _index_0 = 1, _max_0 do
1395 local _item_0 = _obj_0[_index_0]
1396 _accum_0[_len_0] = _item_0
1397 _len_0 = _len_0 + 1
1398 end
1399 return _accum_0
1400 end)(), _obj_0[#_obj_0]
1401end
1402local _obj_0 = orders
1403first, last = _obj_0[1], _obj_0[#_obj_0]
1404local tuples = {
1405 {
1406 "hello",
1407 "world"
1408 },
1409 {
1410 "egg",
1411 "head"
1412 }
1413}
1414for _index_0 = 1, #tuples do
1415 local _des_0 = tuples[_index_0]
1416 local left, right = _des_0[1], _des_0[2]
1417 print(left, right)
1418end
1419local user = database.find_user("moon")
1420if user then
1421 print(user.name)
1422end
1423local hello = os.getenv("hello")
1424if hello then
1425 print("你有 hello", hello)
1426else
1427 local world = os.getenv("world")
1428 if world then
1429 print("你有 world", world)
1430 else
1431 print("什么都没有 :(")
1432 end
1433end
1434do
1435 local success, result = pcall(function()
1436 return "无报错地获取结果"
1437 end)
1438 if success then
1439 print(result)
1440 end
1441end
1442print("好的")
1443repeat
1444 local byte = stream:read_one()
1445 if byte then
1446 print(byte)
1447 else
1448 break
1449 end
1450until false
1451local user = database.find_user("moon")
1452if user then
1453 print(user.name)
1454end
1455local hello = os.getenv("hello")
1456if hello then
1457 print("你有 hello", hello)
1458else
1459 local world = os.getenv("world")
1460 if world then
1461 print("你有 world", world)
1462 else
1463 print("什么都没有 :(")
1464 end
1465end
1466do
1467 local success, result = pcall(function()
1468 return "无报错地获取结果"
1469 end)
1470 if success then
1471 print(result)
1472 end
1473end
1474print("好的")
1475repeat
1476 local byte = stream:read_one()
1477 if byte then
1478 print(byte)
1479 else
1480 break
1481 end
1482until false
1483local list = {
1484 1,
1485 2,
1486 3,
1487 4,
1488 5
1489}
1490local fn
1491fn = function(ok)
1492 return ok, table.unpack(list)
1493end
1494(function(_arg_0, ...)
1495 local ok = _arg_0
1496 local count = select('#', ...)
1497 local first = select(1, ...)
1498 return print(ok, count, first)
1499end)(fn(true))
1500local list = {
1501 1,
1502 2,
1503 3,
1504 4,
1505 5
1506}
1507local fn
1508fn = function(ok)
1509 return ok, table.unpack(list)
1510end
1511(function(_arg_0, ...)
1512 local ok = _arg_0
1513 local count = select('#', ...)
1514 local first = select(1, ...)
1515 return print(ok, count, first)
1516end)(fn(true))
1517local a = 1
1518local b = 2
1519print(a + b)
1520Rx.Observable.fromRange(1, 8):filter(function(x)
1521 return x % 2 == 0
1522end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
1523 return value .. '!'
1524end):subscribe(print)
1525local a = 1
1526local b = 2
1527print(a + b)
1528Rx.Observable.fromRange(1, 8):filter(function(x)
1529 return x % 2 == 0
1530end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
1531 return value .. '!'
1532end):subscribe(print)
1533local str = strA .. strB .. strC
1534func(3000, "192.168.1.1")
1535local str = strA .. strB .. strC
1536func(3000, "192.168.1.1")
1537xpcall(function() 411xpcall(function()
1538 return func(1, 2, 3) 412 return func(1, 2, 3)
1539end, function(err) 413end, function(err)
@@ -1694,464 +568,6 @@ f((function()
1694 return e 568 return e
1695 end)) 569 end))
1696end)()) 570end)())
1697local a <const> = 123
1698local _ <close> = setmetatable({ }, {
1699 __close = function()
1700 return print("超出范围。")
1701 end
1702})
1703local a, b, c, d
1704local _obj_0 = tb
1705a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
1706Constant = 123
1707local a <const> = 123
1708local _ <close> = setmetatable({ }, {
1709 __close = function()
1710 return print("超出范围。")
1711 end
1712})
1713local a, b, c, d
1714local _obj_0 = tb
1715a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
1716Constant = 123
1717local some_string = "这是一个字符串\n 并包括一个换行。"
1718print("我有" .. tostring(math.random() * 100) .. "%的把握。")
1719local integer = 1000000
1720local hex = 0xEFBBBF
1721local binary = 19
1722local str = "key: value\nlist:\n - item1\n - " .. tostring(expr)
1723local fn
1724fn = function()
1725 local str = "foo:\n bar: baz"
1726 return str
1727end
1728local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'"
1729local some_string = "这是一个字符串\n 并包括一个换行。"
1730print("我有" .. tostring(math.random() * 100) .. "%的把握。")
1731local integer = 1000000
1732local hex = 0xEFBBBF
1733local binary = 19
1734local str = "key: value\nlist:\n - item1\n - " .. tostring(expr)
1735local fn
1736fn = function()
1737 local str = "foo:\n bar: baz"
1738 return str
1739end
1740local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'"
1741local my_function
1742my_function = function() end
1743my_function()
1744local func_a
1745func_a = function()
1746 return print("你好,世界")
1747end
1748local func_b
1749func_b = function()
1750 local value = 100
1751 return print("这个值是:", value)
1752end
1753func_a()
1754func_b()
1755local sum
1756sum = function(x, y)
1757 return print("数字的和", x + y)
1758end
1759sum(10, 20)
1760print(sum(10, 20))
1761a(b(c("a", "b", "c")))
1762print("x:", sum(10, 20), "y:", sum(30, 40))
1763local sum
1764sum = function(x, y)
1765 return x + y
1766end
1767print("数字的和是", sum(10, 20))
1768local sum
1769sum = function(x, y)
1770 return x + y
1771end
1772local mystery
1773mystery = function(x, y)
1774 return x + y, x - y
1775end
1776local a, b = mystery(10, 20)
1777local func
1778func = function(self, num)
1779 return self.value + num
1780end
1781local my_function
1782my_function = function(name, height)
1783 if name == nil then
1784 name = "某物"
1785 end
1786 if height == nil then
1787 height = 100
1788 end
1789 print("你好,我是", name)
1790 return print("我的高度是", height)
1791end
1792local some_args
1793some_args = function(x, y)
1794 if x == nil then
1795 x = 100
1796 end
1797 if y == nil then
1798 y = x + 1000
1799 end
1800 return print(x + y)
1801end
1802local a = x - 10
1803local b = x - 10
1804local c = x(-y)
1805local d = x - z
1806local x = func("hello") + 100
1807local y = func("hello" + 100)
1808my_func(5, 4, 3, 8, 9, 10)
1809cool_func(1, 2, 3, 4, 5, 6, 7, 8)
1810my_func(5, 6, 7, 6, another_func(6, 7, 8, 9, 1, 2), 5, 4)
1811local x = {
1812 1,
1813 2,
1814 3,
1815 4,
1816 a_func(4, 5, 5, 6),
1817 8,
1818 9,
1819 10
1820}
1821local y = {
1822 my_func(1, 2, 3, 4, 5),
1823 5,
1824 6,
1825 7
1826}
1827if func(1, 2, 3, "你好", "世界") then
1828 print("你好")
1829 print("我在if内部")
1830end
1831if func(1, 2, 3, "你好", "世界") then
1832 print("hello")
1833 print("我在if内部")
1834end
1835local f1
1836f1 = function(_arg_0)
1837 local a, b, c
1838 a, b, c = _arg_0.a, _arg_0.b, _arg_0.c
1839 return print(a, b, c)
1840end
1841f1({
1842 a = 1,
1843 b = "2",
1844 c = { }
1845})
1846local f2
1847f2 = function(_arg_0, c)
1848 local a1, b
1849 a1, b = _arg_0.a, _arg_0.b
1850 if a1 == nil then
1851 a1 = 123
1852 end
1853 if b == nil then
1854 b = 'abc'
1855 end
1856 if c == nil then
1857 c = { }
1858 end
1859 return print(a1, b, c)
1860end
1861local arg1 = {
1862 a = 0
1863}
1864f2(arg1, arg2)
1865local findFirstEven
1866findFirstEven = function(list)
1867 for _index_0 = 1, #list do
1868 local item = list[_index_0]
1869 if type(item) == "table" then
1870 for _index_1 = 1, #item do
1871 local sub = item[_index_1]
1872 if sub % 2 == 0 then
1873 return sub
1874 end
1875 end
1876 end
1877 end
1878 return nil
1879end
1880local findFirstEven
1881findFirstEven = function(list)
1882 for _index_0 = 1, #list do
1883 local item = list[_index_0]
1884 if type(item) == "table" then
1885 for _index_1 = 1, #item do
1886 local sub = item[_index_1]
1887 if sub % 2 == 0 then
1888 return sub
1889 end
1890 end
1891 end
1892 end
1893 return nil
1894end
1895local f
1896f = function(...)
1897 local t = {
1898 n = select("#", ...),
1899 ...
1900 }
1901 print("参数个数:", t.n)
1902 print("表长度:", #t)
1903 for i = 1, t.n do
1904 print(t[i])
1905 end
1906end
1907f(1, 2, 3)
1908f("a", "b", "c", "d")
1909f()
1910local process
1911process = function(...)
1912 local args = {
1913 n = select("#", ...),
1914 ...
1915 }
1916 local sum = 0
1917 for i = 1, args.n do
1918 if args[i] ~= nil and type(args[i]) == "number" then
1919 sum = sum + args[i]
1920 end
1921 end
1922 return sum
1923end
1924process(1, nil, 3, nil, 5)
1925local my_function
1926my_function = function() end
1927my_function()
1928local func_a
1929func_a = function()
1930 return print("你好,世界")
1931end
1932local func_b
1933func_b = function()
1934 local value = 100
1935 return print("这个值是:", value)
1936end
1937func_a()
1938func_b()
1939local sum
1940sum = function(x, y)
1941 return print("数字的和", x + y)
1942end
1943sum(10, 20)
1944print(sum(10, 20))
1945a(b(c("a", "b", "c")))
1946print("x:", sum(10, 20), "y:", sum(30, 40))
1947local sum
1948sum = function(x, y)
1949 return x + y
1950end
1951print("数字的和是", sum(10, 20))
1952local sum
1953sum = function(x, y)
1954 return x + y
1955end
1956local mystery
1957mystery = function(x, y)
1958 return x + y, x - y
1959end
1960local a, b = mystery(10, 20)
1961local func
1962func = function(self, num)
1963 return self.value + num
1964end
1965local my_function
1966my_function = function(name, height)
1967 if name == nil then
1968 name = "某物"
1969 end
1970 if height == nil then
1971 height = 100
1972 end
1973 print("你好,我是", name)
1974 return print("我的高度是", height)
1975end
1976local some_args
1977some_args = function(x, y)
1978 if x == nil then
1979 x = 100
1980 end
1981 if y == nil then
1982 y = x + 1000
1983 end
1984 return print(x + y)
1985end
1986local a = x - 10
1987local b = x - 10
1988local c = x(-y)
1989local d = x - z
1990local x = func("hello") + 100
1991local y = func("hello" + 100)
1992my_func(5, 4, 3, 8, 9, 10)
1993cool_func(1, 2, 3, 4, 5, 6, 7, 8)
1994my_func(5, 6, 7, 6, another_func(6, 7, 8, 9, 1, 2), 5, 4)
1995local x = {
1996 1,
1997 2,
1998 3,
1999 4,
2000 a_func(4, 5, 5, 6),
2001 8,
2002 9,
2003 10
2004}
2005local y = {
2006 my_func(1, 2, 3, 4, 5),
2007 5,
2008 6,
2009 7
2010}
2011if func(1, 2, 3, "你好", "世界") then
2012 print("你好")
2013 print("我在if内部")
2014end
2015if func(1, 2, 3, "你好", "世界") then
2016 print("你好")
2017 print("我在if内部")
2018end
2019local f1
2020f1 = function(_arg_0)
2021 local a, b, c
2022 a, b, c = _arg_0.a, _arg_0.b, _arg_0.c
2023 return print(a, b, c)
2024end
2025f1({
2026 a = 1,
2027 b = "2",
2028 c = { }
2029})
2030local f2
2031f2 = function(_arg_0, c)
2032 local a1, b
2033 a1, b = _arg_0.a, _arg_0.b
2034 if a1 == nil then
2035 a1 = 123
2036 end
2037 if b == nil then
2038 b = 'abc'
2039 end
2040 if c == nil then
2041 c = { }
2042 end
2043 return print(a1, b, c)
2044end
2045local arg1 = {
2046 a = 0
2047}
2048f2(arg1, arg2)
2049local findFirstEven
2050findFirstEven = function(list)
2051 for _index_0 = 1, #list do
2052 local item = list[_index_0]
2053 if type(item) == "table" then
2054 for _index_1 = 1, #item do
2055 local sub = item[_index_1]
2056 if sub % 2 == 0 then
2057 return sub
2058 end
2059 end
2060 end
2061 end
2062 return nil
2063end
2064local findFirstEven
2065findFirstEven = function(list)
2066 for _index_0 = 1, #list do
2067 local item = list[_index_0]
2068 if type(item) == "table" then
2069 for _index_1 = 1, #item do
2070 local sub = item[_index_1]
2071 if sub % 2 == 0 then
2072 return sub
2073 end
2074 end
2075 end
2076 end
2077 return nil
2078end
2079local f
2080f = function(...)
2081 local t = {
2082 n = select("#", ...),
2083 ...
2084 }
2085 print("参数个数:", t.n)
2086 print("表长度:", #t)
2087 for i = 1, t.n do
2088 print(t[i])
2089 end
2090end
2091f(1, 2, 3)
2092f("a", "b", "c", "d")
2093f()
2094local process
2095process = function(...)
2096 local args = {
2097 n = select("#", ...),
2098 ...
2099 }
2100 local sum = 0
2101 for i = 1, args.n do
2102 if args[i] ~= nil and type(args[i]) == "number" then
2103 sum = sum + args[i]
2104 end
2105 end
2106 return sum
2107end
2108process(1, nil, 3, nil, 5)
2109f(function(x)
2110 return print("hello" .. x)
2111end)
2112f(function(self)
2113 return print(self.value)
2114end)
2115map(function(x)
2116 return x * 2
2117end, {
2118 1,
2119 2,
2120 3
2121})
2122local result, msg
2123do
2124 result, msg = readAsync("文件名.txt", function(data)
2125 print(data)
2126 return processAsync(data, function(info)
2127 return check(info)
2128 end)
2129 end)
2130end
2131print(result, msg)
2132f(function(x)
2133 return print("hello" .. x)
2134end)
2135f(function(self)
2136 return print(self.value)
2137end)
2138map(function(x)
2139 return x * 2
2140end, {
2141 1,
2142 2,
2143 3
2144})
2145local result, msg
2146do
2147 result, msg = readAsync("文件名.txt", function(data)
2148 print(data)
2149 return processAsync(data, function(info)
2150 return check(info)
2151 end)
2152 end)
2153end
2154print(result, msg)
2155local some_values = { 571local some_values = {
2156 1, 572 1,
2157 2, 573 2,
@@ -2730,966 +1146,6 @@ for _index_0 = _min_0, _max_0 do
2730 _len_0 = _len_0 + 1 1146 _len_0 = _len_0 + 1
2731end 1147end
2732last_four_items = _accum_0 1148last_four_items = _accum_0
2733for i = 10, 20 do
2734 print(i)
2735end
2736for k = 1, 15, 2 do
2737 print(k)
2738end
2739for key, value in pairs(object) do
2740 print(key, value)
2741end
2742local _list_0 = items
2743for _index_0 = 2, 4 do
2744 local item = _list_0[_index_0]
2745 print(item)
2746end
2747local _list_0 = items
2748for _index_0 = 1, #_list_0 do
2749 local item = _list_0[_index_0]
2750 print(item)
2751end
2752for j = 1, 10, 3 do
2753 print(j)
2754end
2755local doubled_evens
2756local _accum_0 = { }
2757local _len_0 = 1
2758for i = 1, 20 do
2759 if i % 2 == 0 then
2760 _accum_0[_len_0] = i * 2
2761 _len_0 = _len_0 + 1
2762 else
2763 _accum_0[_len_0] = i
2764 _len_0 = _len_0 + 1
2765 end
2766end
2767doubled_evens = _accum_0
2768local first_large
2769local _accum_0
2770local _list_0 = numbers
2771for _index_0 = 1, #_list_0 do
2772 local n = _list_0[_index_0]
2773 if n > 10 then
2774 _accum_0 = n
2775 break
2776 end
2777end
2778first_large = _accum_0
2779local func_a
2780func_a = function()
2781 for i = 1, 10 do
2782 print(i)
2783 end
2784end
2785local func_b
2786func_b = function()
2787 local _accum_0 = { }
2788 local _len_0 = 1
2789 for i = 1, 10 do
2790 _accum_0[_len_0] = i
2791 _len_0 = _len_0 + 1
2792 end
2793 return _accum_0
2794end
2795print(func_a())
2796print(func_b())
2797for i = 10, 20 do
2798 print(i)
2799end
2800for k = 1, 15, 2 do
2801 print(k)
2802end
2803for key, value in pairs(object) do
2804 print(key, value)
2805end
2806local _list_0 = items
2807for _index_0 = 2, 4 do
2808 local item = _list_0[_index_0]
2809 print(item)
2810end
2811local _list_0 = items
2812for _index_0 = 1, #_list_0 do
2813 local item = _list_0[_index_0]
2814 print(item)
2815end
2816for j = 1, 10, 3 do
2817 print(j)
2818end
2819local doubled_evens
2820local _accum_0 = { }
2821local _len_0 = 1
2822for i = 1, 20 do
2823 if i % 2 == 0 then
2824 _accum_0[_len_0] = i * 2
2825 _len_0 = _len_0 + 1
2826 else
2827 _accum_0[_len_0] = i
2828 _len_0 = _len_0 + 1
2829 end
2830end
2831doubled_evens = _accum_0
2832local first_large
2833local _accum_0
2834local _list_0 = numbers
2835for _index_0 = 1, #_list_0 do
2836 local n = _list_0[_index_0]
2837 if n > 10 then
2838 _accum_0 = n
2839 break
2840 end
2841end
2842first_large = _accum_0
2843local func_a
2844func_a = function()
2845 for i = 1, 10 do
2846 print(i)
2847 end
2848end
2849local func_b
2850func_b = function()
2851 local _accum_0 = { }
2852 local _len_0 = 1
2853 for i = 1, 10 do
2854 _accum_0[_len_0] = i
2855 _len_0 = _len_0 + 1
2856 end
2857 return _accum_0
2858end
2859print(func_a())
2860print(func_b())
2861local i = 10
2862while i > 0 do
2863 print(i)
2864 i = i - 1
2865end
2866while running == true do
2867 my_function()
2868end
2869local i = 10
2870while not (i == 0) do
2871 print(i)
2872 i = i - 1
2873end
2874while not (running == false) do
2875 my_function()
2876end
2877local i = 10
2878repeat
2879 print(i)
2880 i = i - 1
2881until i == 0
2882local i = 10
2883while i > 0 do
2884 print(i)
2885 i = i - 1
2886end
2887while running == true do
2888 my_function()
2889end
2890local i = 10
2891while not (i == 0) do
2892 print(i)
2893 i = i - 1
2894end
2895while not (running == false) do
2896 my_function()
2897end
2898local i = 10
2899repeat
2900 print(i)
2901 i = i - 1
2902until i == 0
2903local i = 0
2904while i < 10 do
2905 i = i + 1
2906 if i % 2 == 0 then
2907 goto _continue_0
2908 end
2909 print(i)
2910 ::_continue_0::
2911end
2912local my_numbers = {
2913 1,
2914 2,
2915 3,
2916 4,
2917 5,
2918 6
2919}
2920local odds
2921local _accum_0 = { }
2922local _len_0 = 1
2923for _index_0 = 1, #my_numbers do
2924 local x = my_numbers[_index_0]
2925 if x % 2 == 1 then
2926 goto _continue_0
2927 end
2928 _accum_0[_len_0] = x
2929 _len_0 = _len_0 + 1
2930 ::_continue_0::
2931end
2932odds = _accum_0
2933local i = 0
2934while i < 10 do
2935 i = i + 1
2936 if i % 2 == 0 then
2937 goto _continue_0
2938 end
2939 print(i)
2940 ::_continue_0::
2941end
2942local my_numbers = {
2943 1,
2944 2,
2945 3,
2946 4,
2947 5,
2948 6
2949}
2950local odds
2951local _accum_0 = { }
2952local _len_0 = 1
2953for _index_0 = 1, #my_numbers do
2954 local x = my_numbers[_index_0]
2955 if x % 2 == 1 then
2956 goto _continue_0
2957 end
2958 _accum_0[_len_0] = x
2959 _len_0 = _len_0 + 1
2960 ::_continue_0::
2961end
2962odds = _accum_0
2963local have_coins = false
2964if have_coins then
2965 print("有硬币")
2966else
2967 print("没有硬币")
2968end
2969local have_coins = false
2970if have_coins then
2971 print("有硬币")
2972else
2973 print("没有硬币")
2974end
2975local have_coins = false
2976print((function()
2977 if have_coins then
2978 return "有硬币"
2979 else
2980 return "没有硬币"
2981 end
2982end)())
2983local is_tall
2984is_tall = function(name)
2985 if name == "Rob" then
2986 return true
2987 else
2988 return false
2989 end
2990end
2991local message
2992if is_tall("Rob") then
2993 message = "我很高"
2994else
2995 message = "我不是很高"
2996end
2997print(message)
2998if not (os.date("%A") == "Monday") then
2999 print("今天不是星期一!")
3000end
3001if not (math.random() > 0.1) then
3002 print("你真幸运!")
3003end
3004local a = 5
3005if (1 == a or 3 == a or 5 == a or 7 == a) then
3006 print("检查离散值的相等性")
3007end
3008if (function()
3009 local _check_0 = list
3010 for _index_0 = 1, #_check_0 do
3011 if _check_0[_index_0] == a then
3012 return true
3013 end
3014 end
3015 return false
3016end)() then
3017 print("检查`a`是否在列表中")
3018end
3019if not (math.random() > 0.1) then
3020 print("你很幸运!")
3021end
3022local have_coins = false
3023if have_coins then
3024 print("有硬币")
3025else
3026 print("没有硬币")
3027end
3028local have_coins = false
3029if have_coins then
3030 print("有硬币")
3031else
3032 print("没有硬币")
3033end
3034local have_coins = false
3035print((function()
3036 if have_coins then
3037 return "有硬币"
3038 else
3039 return "没有硬币"
3040 end
3041end)())
3042local is_tall
3043is_tall = function(name)
3044 if name == "Rob" then
3045 return true
3046 else
3047 return false
3048 end
3049end
3050local message
3051if is_tall("Rob") then
3052 message = "我很高"
3053else
3054 message = "我不是很高"
3055end
3056print(message)
3057if not (os.date("%A") == "Monday") then
3058 print("今天不是星期一!")
3059end
3060if not (math.random() > 0.1) then
3061 print("你真幸运!")
3062end
3063local a = 5
3064if (1 == a or 3 == a or 5 == a or 7 == a) then
3065 print("检查离散值的相等性")
3066end
3067if (function()
3068 local _check_0 = list
3069 for _index_0 = 1, #_check_0 do
3070 if _check_0[_index_0] == a then
3071 return true
3072 end
3073 end
3074 return false
3075end)() then
3076 print("检查`a`是否在列表中")
3077end
3078if not (math.random() > 0.1) then
3079 print("你很幸运!")
3080end
3081if name == "Rob" then
3082 print("你好,世界")
3083end
3084local _list_0 = items
3085for _index_0 = 1, #_list_0 do
3086 local item = _list_0[_index_0]
3087 print("项目: ", item)
3088end
3089while game:isRunning() do
3090 game:update()
3091end
3092while not reader:eof() do
3093 reader:parse_line()
3094end
3095if name == "Rob" then
3096 print("你好,世界")
3097end
3098local _list_0 = items
3099for _index_0 = 1, #_list_0 do
3100 local item = _list_0[_index_0]
3101 print("项目: ", item)
3102end
3103while game:isRunning() do
3104 game:update()
3105end
3106while not reader:eof() do
3107 reader:parse_line()
3108end
3109local name = "Dan"
3110if "Robert" == name then
3111 print("你是Robert")
3112elseif "Dan" == name or "Daniel" == name then
3113 print("你的名字是Dan")
3114else
3115 print("我不认识你,你的名字是" .. tostring(name))
3116end
3117local b = 1
3118local next_number
3119if 1 == b then
3120 next_number = 2
3121elseif 2 == b then
3122 next_number = 3
3123else
3124 next_number = error("数字数得太大了!")
3125end
3126local msg
3127local _exp_0 = math.random(1, 5)
3128if 1 == _exp_0 then
3129 msg = "你很幸运"
3130elseif 2 == _exp_0 then
3131 msg = "你差点很幸运"
3132else
3133 msg = "不太幸运"
3134end
3135do
3136 local _exp_0 = math.random(1, 5)
3137 if 1 == _exp_0 then
3138 print("你很幸运")
3139 else
3140 print("不太幸运")
3141 end
3142end
3143local _exp_0 = math.random(1, 5)
3144if 1 == _exp_0 then
3145 print("你很幸运")
3146else
3147 print("不太幸运")
3148end
3149local items = {
3150 {
3151 x = 100,
3152 y = 200
3153 },
3154 {
3155 width = 300,
3156 height = 400
3157 }
3158}
3159for _index_0 = 1, #items do
3160 local item = items[_index_0]
3161 local _type_0 = type(item)
3162 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3163 local _match_0 = false
3164 if _tab_0 then
3165 local x = item.x
3166 local y = item.y
3167 if x ~= nil and y ~= nil then
3168 _match_0 = true
3169 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3170 end
3171 end
3172 if not _match_0 then
3173 if _tab_0 then
3174 local width = item.width
3175 local height = item.height
3176 if width ~= nil and height ~= nil then
3177 print("尺寸 " .. tostring(width) .. ", " .. tostring(height))
3178 end
3179 end
3180 end
3181end
3182local item = { }
3183local x, y = item.pos.x, item.pos.y
3184if x == nil then
3185 x = 50
3186end
3187if y == nil then
3188 y = 200
3189end
3190local _type_0 = type(item)
3191local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3192if _tab_0 then
3193 do
3194 local _obj_0 = item.pos
3195 local _type_1 = type(_obj_0)
3196 if "table" == _type_1 or "userdata" == _type_1 then
3197 x = _obj_0.x
3198 end
3199 end
3200 do
3201 local _obj_0 = item.pos
3202 local _type_1 = type(_obj_0)
3203 if "table" == _type_1 or "userdata" == _type_1 then
3204 y = _obj_0.y
3205 end
3206 end
3207 if x == nil then
3208 x = 50
3209 end
3210 if y == nil then
3211 y = 200
3212 end
3213 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3214end
3215local _exp_0 = tb
3216local _type_0 = type(_exp_0)
3217local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3218local _match_0 = false
3219if _tab_0 then
3220 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
3221 _match_0 = true
3222 print("1, 2, 3")
3223 end
3224end
3225if not _match_0 then
3226 local _match_1 = false
3227 if _tab_0 then
3228 local b = _exp_0[2]
3229 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
3230 _match_1 = true
3231 print("1, " .. tostring(b) .. ", 3")
3232 end
3233 end
3234 if not _match_1 then
3235 if _tab_0 then
3236 local b = _exp_0[3]
3237 if b == nil then
3238 b = 3
3239 end
3240 if 1 == _exp_0[1] and 2 == _exp_0[2] then
3241 print("1, 2, " .. tostring(b))
3242 end
3243 end
3244 end
3245end
3246local _exp_0 = tb
3247local _type_0 = type(_exp_0)
3248local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3249local _match_0 = false
3250if _tab_0 then
3251 local result = _exp_0.result
3252 if true == _exp_0.success and result ~= nil then
3253 _match_0 = true
3254 print("成功", result)
3255 end
3256end
3257if not _match_0 then
3258 local _match_1 = false
3259 if _tab_0 then
3260 if false == _exp_0.success then
3261 _match_1 = true
3262 print("失败", result)
3263 end
3264 end
3265 if not _match_1 then
3266 print("无效值")
3267 end
3268end
3269local _exp_0 = tb
3270local _type_0 = type(_exp_0)
3271local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3272local _match_0 = false
3273if _tab_0 then
3274 local content
3275 do
3276 local _obj_0 = _exp_0.data
3277 local _type_1 = type(_obj_0)
3278 if "table" == _type_1 or "userdata" == _type_1 then
3279 content = _obj_0.content
3280 end
3281 end
3282 local _val_0
3283 do
3284 local _obj_0 = _exp_0.data
3285 if _obj_0 ~= nil then
3286 _val_0 = _obj_0.type
3287 end
3288 end
3289 if "success" == _val_0 and content ~= nil then
3290 _match_0 = true
3291 print("成功", content)
3292 end
3293end
3294if not _match_0 then
3295 local _match_1 = false
3296 if _tab_0 then
3297 local content
3298 do
3299 local _obj_0 = _exp_0.data
3300 local _type_1 = type(_obj_0)
3301 if "table" == _type_1 or "userdata" == _type_1 then
3302 content = _obj_0.content
3303 end
3304 end
3305 local _val_0
3306 do
3307 local _obj_0 = _exp_0.data
3308 if _obj_0 ~= nil then
3309 _val_0 = _obj_0.type
3310 end
3311 end
3312 if "error" == _val_0 and content ~= nil then
3313 _match_1 = true
3314 print("失败", content)
3315 end
3316 end
3317 if not _match_1 then
3318 print("无效值")
3319 end
3320end
3321local _exp_0 = tb
3322local _type_0 = type(_exp_0)
3323local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3324if _tab_0 then
3325 local fourth = _exp_0[4]
3326 local _val_0
3327 do
3328 local _obj_0 = _exp_0[1]
3329 if _obj_0 ~= nil then
3330 _val_0 = _obj_0.a
3331 end
3332 end
3333 local _val_1
3334 do
3335 local _obj_0 = _exp_0[1]
3336 if _obj_0 ~= nil then
3337 _val_1 = _obj_0.b
3338 end
3339 end
3340 local _val_2
3341 do
3342 local _obj_0 = _exp_0[2]
3343 if _obj_0 ~= nil then
3344 _val_2 = _obj_0.a
3345 end
3346 end
3347 local _val_3
3348 do
3349 local _obj_0 = _exp_0[2]
3350 if _obj_0 ~= nil then
3351 _val_3 = _obj_0.b
3352 end
3353 end
3354 local _val_4
3355 do
3356 local _obj_0 = _exp_0[3]
3357 if _obj_0 ~= nil then
3358 _val_4 = _obj_0.a
3359 end
3360 end
3361 local _val_5
3362 do
3363 local _obj_0 = _exp_0[3]
3364 if _obj_0 ~= nil then
3365 _val_5 = _obj_0.b
3366 end
3367 end
3368 if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and fourth ~= nil then
3369 print("匹配成功", fourth)
3370 end
3371end
3372local segments = {
3373 "admin",
3374 "users",
3375 "logs",
3376 "view"
3377}
3378local _type_0 = type(segments)
3379local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3380if _tab_0 then
3381 local groups
3382 do
3383 local _accum_0 = { }
3384 local _len_0 = 1
3385 local _max_0 = #segments + -3 + 1
3386 for _index_0 = 1, _max_0 do
3387 local _item_0 = segments[_index_0]
3388 _accum_0[_len_0] = _item_0
3389 _len_0 = _len_0 + 1
3390 end
3391 groups = _accum_0
3392 end
3393 local resource = segments[#segments - 1]
3394 local action = segments[#segments]
3395 if resource ~= nil and action ~= nil then
3396 print("Group:", groups)
3397 print("Resource:", resource)
3398 print("Action:", action)
3399 end
3400end
3401local name = "Dan"
3402if "Robert" == name then
3403 print("你是Robert")
3404elseif "Dan" == name or "Daniel" == name then
3405 print("你的名字是Dan")
3406else
3407 print("我不认识你,你的名字是" .. tostring(name))
3408end
3409local b = 1
3410local next_number
3411if 1 == b then
3412 next_number = 2
3413elseif 2 == b then
3414 next_number = 3
3415else
3416 next_number = error("数字数得太大了!")
3417end
3418local msg
3419local _exp_0 = math.random(1, 5)
3420if 1 == _exp_0 then
3421 msg = "你很幸运"
3422elseif 2 == _exp_0 then
3423 msg = "你差点很幸运"
3424else
3425 msg = "不太幸运"
3426end
3427do
3428 local _exp_0 = math.random(1, 5)
3429 if 1 == _exp_0 then
3430 print("你很幸运")
3431 else
3432 print("不太幸运")
3433 end
3434end
3435local _exp_0 = math.random(1, 5)
3436if 1 == _exp_0 then
3437 print("你很幸运")
3438else
3439 print("不太幸运")
3440end
3441local items = {
3442 {
3443 x = 100,
3444 y = 200
3445 },
3446 {
3447 width = 300,
3448 height = 400
3449 }
3450}
3451for _index_0 = 1, #items do
3452 local item = items[_index_0]
3453 local _type_0 = type(item)
3454 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3455 local _match_0 = false
3456 if _tab_0 then
3457 local x = item.x
3458 local y = item.y
3459 if x ~= nil and y ~= nil then
3460 _match_0 = true
3461 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3462 end
3463 end
3464 if not _match_0 then
3465 if _tab_0 then
3466 local width = item.width
3467 local height = item.height
3468 if width ~= nil and height ~= nil then
3469 print("尺寸 " .. tostring(width) .. ", " .. tostring(height))
3470 end
3471 end
3472 end
3473end
3474local item = { }
3475local x, y = item.pos.x, item.pos.y
3476if x == nil then
3477 x = 50
3478end
3479if y == nil then
3480 y = 200
3481end
3482local _type_0 = type(item)
3483local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3484if _tab_0 then
3485 do
3486 local _obj_0 = item.pos
3487 local _type_1 = type(_obj_0)
3488 if "table" == _type_1 or "userdata" == _type_1 then
3489 x = _obj_0.x
3490 end
3491 end
3492 do
3493 local _obj_0 = item.pos
3494 local _type_1 = type(_obj_0)
3495 if "table" == _type_1 or "userdata" == _type_1 then
3496 y = _obj_0.y
3497 end
3498 end
3499 if x == nil then
3500 x = 50
3501 end
3502 if y == nil then
3503 y = 200
3504 end
3505 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3506end
3507local _exp_0 = tb
3508local _type_0 = type(_exp_0)
3509local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3510local _match_0 = false
3511if _tab_0 then
3512 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
3513 _match_0 = true
3514 print("1, 2, 3")
3515 end
3516end
3517if not _match_0 then
3518 local _match_1 = false
3519 if _tab_0 then
3520 local b = _exp_0[2]
3521 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
3522 _match_1 = true
3523 print("1, " .. tostring(b) .. ", 3")
3524 end
3525 end
3526 if not _match_1 then
3527 if _tab_0 then
3528 local b = _exp_0[3]
3529 if b == nil then
3530 b = 3
3531 end
3532 if 1 == _exp_0[1] and 2 == _exp_0[2] then
3533 print("1, 2, " .. tostring(b))
3534 end
3535 end
3536 end
3537end
3538local _exp_0 = tb
3539local _type_0 = type(_exp_0)
3540local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3541local _match_0 = false
3542if _tab_0 then
3543 local result = _exp_0.result
3544 if true == _exp_0.success and result ~= nil then
3545 _match_0 = true
3546 print("成功", result)
3547 end
3548end
3549if not _match_0 then
3550 local _match_1 = false
3551 if _tab_0 then
3552 if false == _exp_0.success then
3553 _match_1 = true
3554 print("失败", result)
3555 end
3556 end
3557 if not _match_1 then
3558 print("无效值")
3559 end
3560end
3561local _exp_0 = tb
3562local _type_0 = type(_exp_0)
3563local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3564local _match_0 = false
3565if _tab_0 then
3566 local content
3567 do
3568 local _obj_0 = _exp_0.data
3569 local _type_1 = type(_obj_0)
3570 if "table" == _type_1 or "userdata" == _type_1 then
3571 content = _obj_0.content
3572 end
3573 end
3574 local _val_0
3575 do
3576 local _obj_0 = _exp_0.data
3577 if _obj_0 ~= nil then
3578 _val_0 = _obj_0.type
3579 end
3580 end
3581 if "success" == _val_0 and content ~= nil then
3582 _match_0 = true
3583 print("成功", content)
3584 end
3585end
3586if not _match_0 then
3587 local _match_1 = false
3588 if _tab_0 then
3589 local content
3590 do
3591 local _obj_0 = _exp_0.data
3592 local _type_1 = type(_obj_0)
3593 if "table" == _type_1 or "userdata" == _type_1 then
3594 content = _obj_0.content
3595 end
3596 end
3597 local _val_0
3598 do
3599 local _obj_0 = _exp_0.data
3600 if _obj_0 ~= nil then
3601 _val_0 = _obj_0.type
3602 end
3603 end
3604 if "error" == _val_0 and content ~= nil then
3605 _match_1 = true
3606 print("失败", content)
3607 end
3608 end
3609 if not _match_1 then
3610 print("无效值")
3611 end
3612end
3613local _exp_0 = tb
3614local _type_0 = type(_exp_0)
3615local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3616if _tab_0 then
3617 local fourth = _exp_0[4]
3618 local _val_0
3619 do
3620 local _obj_0 = _exp_0[1]
3621 if _obj_0 ~= nil then
3622 _val_0 = _obj_0.a
3623 end
3624 end
3625 local _val_1
3626 do
3627 local _obj_0 = _exp_0[1]
3628 if _obj_0 ~= nil then
3629 _val_1 = _obj_0.b
3630 end
3631 end
3632 local _val_2
3633 do
3634 local _obj_0 = _exp_0[2]
3635 if _obj_0 ~= nil then
3636 _val_2 = _obj_0.a
3637 end
3638 end
3639 local _val_3
3640 do
3641 local _obj_0 = _exp_0[2]
3642 if _obj_0 ~= nil then
3643 _val_3 = _obj_0.b
3644 end
3645 end
3646 local _val_4
3647 do
3648 local _obj_0 = _exp_0[3]
3649 if _obj_0 ~= nil then
3650 _val_4 = _obj_0.a
3651 end
3652 end
3653 local _val_5
3654 do
3655 local _obj_0 = _exp_0[3]
3656 if _obj_0 ~= nil then
3657 _val_5 = _obj_0.b
3658 end
3659 end
3660 if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and fourth ~= nil then
3661 print("匹配成功", fourth)
3662 end
3663end
3664local segments = {
3665 "admin",
3666 "users",
3667 "logs",
3668 "view"
3669}
3670local _type_0 = type(segments)
3671local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3672if _tab_0 then
3673 local groups
3674 do
3675 local _accum_0 = { }
3676 local _len_0 = 1
3677 local _max_0 = #segments + -3 + 1
3678 for _index_0 = 1, _max_0 do
3679 local _item_0 = segments[_index_0]
3680 _accum_0[_len_0] = _item_0
3681 _len_0 = _len_0 + 1
3682 end
3683 groups = _accum_0
3684 end
3685 local resource = segments[#segments - 1]
3686 local action = segments[#segments]
3687 if resource ~= nil and action ~= nil then
3688 print("Group:", groups)
3689 print("Resource:", resource)
3690 print("Action:", action)
3691 end
3692end
3693local Inventory 1149local Inventory
3694local _class_0 1150local _class_0
3695local _base_0 = { 1151local _base_0 = {
@@ -5010,86 +2466,440 @@ local _with_0 = obj
5010if _with_0 ~= nil then 2466if _with_0 ~= nil then
5011 print(obj.name) 2467 print(obj.name)
5012end 2468end
2469local hello = "world"
2470local a, b, c = 1, 2, 3
2471hello = 123
2472local x = 1
2473x = x + 1
2474x = x - 1
2475x = x * 10
2476x = x / 10
2477x = x % 10
2478local s = s .. "world"
2479local arg = arg or "默认值"
2480local a = 0
2481local b = 0
2482local c = 0
2483local d = 0
2484local e = 0
2485local x = f()
2486local y = x
2487local z = x
2488do
2489 local a = 1
2490 local x, y, z
2491 print("预先声明后续所有变量为局部变量")
2492 x = function()
2493 return 1 + y + z
2494 end
2495 y, z = 2, 3
2496 instance = Item:new()
2497end
5013do 2498do
5014 local var = "hello" 2499 local X = 1
5015 print(var) 2500 local B
2501 print("只预先声明后续大写的变量为局部变量")
2502 local a = 1
2503 B = 2
5016end 2504end
5017print(var)
5018local counter
5019do 2505do
5020 local i = 0 2506 a = 1
5021 counter = function() 2507 print("预先声明所有变量为全局变量")
5022 i = i + 1 2508 x = function()
5023 return i 2509 return 1 + y + z
5024 end 2510 end
2511 y, z = 2, 3
5025end 2512end
5026print(counter())
5027print(counter())
5028local tbl = {
5029 key = (function()
5030 print("分配键值!")
5031 return 1234
5032 end)()
5033}
5034do 2513do
5035 local var = "hello" 2514 x = 1
5036 print(var) 2515 print("只预先声明大写的变量为全局变量")
2516 local a = 1
2517 B = 2
2518 local Temp = "一个局部值"
5037end 2519end
5038print(var) 2520local hello = "world"
5039local counter 2521local a, b, c = 1, 2, 3
2522hello = 123
2523local x = 1
2524x = x + 1
2525x = x - 1
2526x = x * 10
2527x = x / 10
2528x = x % 10
2529local s = s .. "world"
2530local arg = arg or "默认值"
2531local a = 0
2532local b = 0
2533local c = 0
2534local d = 0
2535local e = 0
2536local x = f()
2537local y = x
2538local z = x
5040do 2539do
5041 local i = 0 2540 local a = 1
5042 counter = function() 2541 local x, y, z
5043 i = i + 1 2542 print("预先声明后续所有变量为局部变量")
5044 return i 2543 x = function()
2544 return 1 + y + z
5045 end 2545 end
2546 y, z = 2, 3
2547 instance = Item:new()
5046end 2548end
5047print(counter()) 2549do
5048print(counter()) 2550 local X = 1
5049local tbl = { 2551 local B
5050 key = (function() 2552 print("只预先声明后续大写的变量为局部变量")
5051 print("分配键值!") 2553 local a = 1
5052 return 1234 2554 B = 2
5053 end)() 2555end
5054} 2556do
5055local my_object = { 2557 a = 1
5056 value = 1000, 2558 print("预先声明所有变量为全局变量")
5057 write = function(self) 2559 x = function()
5058 return print("值为:", self.value) 2560 return 1 + y + z
5059 end 2561 end
2562 y, z = 2, 3
2563end
2564do
2565 x = 1
2566 print("只预先声明大写的变量为全局变量")
2567 local a = 1
2568 B = 2
2569 local Temp = "一个局部值"
2570end
2571local list = {
2572 1,
2573 2,
2574 3,
2575 4,
2576 5
5060} 2577}
5061local run_callback 2578local fn
5062run_callback = function(func) 2579fn = function(ok)
5063 print("运行回调...") 2580 return ok, table.unpack(list)
5064 return func()
5065end 2581end
5066run_callback(my_object.write) 2582(function(_arg_0, ...)
5067run_callback((function() 2583 local ok = _arg_0
5068 local _base_0 = my_object 2584 local count = select('#', ...)
5069 local _fn_0 = _base_0.write 2585 local first = select(1, ...)
5070 return _fn_0 and function(...) 2586 return print(ok, count, first)
5071 return _fn_0(_base_0, ...) 2587end)(fn(true))
2588local list = {
2589 1,
2590 2,
2591 3,
2592 4,
2593 5
2594}
2595local fn
2596fn = function(ok)
2597 return ok, table.unpack(list)
2598end
2599(function(_arg_0, ...)
2600 local ok = _arg_0
2601 local count = select('#', ...)
2602 local first = select(1, ...)
2603 return print(ok, count, first)
2604end)(fn(true))
2605local user = database.find_user("moon")
2606if user then
2607 print(user.name)
2608end
2609local hello = os.getenv("hello")
2610if hello then
2611 print("你有 hello", hello)
2612else
2613 local world = os.getenv("world")
2614 if world then
2615 print("你有 world", world)
2616 else
2617 print("什么都没有 :(")
5072 end 2618 end
5073end)()) 2619end
5074local my_object = { 2620do
5075 value = 1000, 2621 local success, result = pcall(function()
5076 write = function(self) 2622 return "无报错地获取结果"
5077 return print("值为:", self.value) 2623 end)
2624 if success then
2625 print(result)
5078 end 2626 end
2627end
2628print("好的")
2629repeat
2630 local byte = stream:read_one()
2631 if byte then
2632 print(byte)
2633 else
2634 break
2635 end
2636until false
2637local user = database.find_user("moon")
2638if user then
2639 print(user.name)
2640end
2641local hello = os.getenv("hello")
2642if hello then
2643 print("你有 hello", hello)
2644else
2645 local world = os.getenv("world")
2646 if world then
2647 print("你有 world", world)
2648 else
2649 print("什么都没有 :(")
2650 end
2651end
2652do
2653 local success, result = pcall(function()
2654 return "无报错地获取结果"
2655 end)
2656 if success then
2657 print(result)
2658 end
2659end
2660print("好的")
2661repeat
2662 local byte = stream:read_one()
2663 if byte then
2664 print(byte)
2665 else
2666 break
2667 end
2668until false
2669local thing = {
2670 1,
2671 2
5079} 2672}
5080local run_callback 2673local a, b = thing[1], thing[2]
5081run_callback = function(func) 2674print(a, b)
5082 print("运行回调...") 2675local obj = {
5083 return func() 2676 hello = "world",
2677 day = "tuesday",
2678 length = 20
2679}
2680local hello, the_day = obj.hello, obj.day
2681print(hello, the_day)
2682local day = obj.day
2683local obj2 = {
2684 numbers = {
2685 1,
2686 2,
2687 3,
2688 4
2689 },
2690 properties = {
2691 color = "green",
2692 height = 13.5
2693 }
2694}
2695local first, second, color = obj2.numbers[1], obj2.numbers[2], obj2.properties.color
2696print(first, second, color)
2697local first, second, color
2698local _obj_0 = obj2
2699first, second, color = _obj_0.numbers[1], _obj_0.numbers[2], _obj_0.properties.color
2700local concat, insert
2701local _obj_0 = table
2702concat, insert = _obj_0.concat, _obj_0.insert
2703local mix, max, rand
2704local _obj_0 = math
2705mix, max, rand = _obj_0.mix, _obj_0.max, _obj_0.random
2706local name, job
2707local _obj_0 = person
2708name, job = _obj_0.name, _obj_0.job
2709if name == nil then
2710 name = "nameless"
5084end 2711end
5085run_callback(my_object.write) 2712if job == nil then
5086run_callback((function() 2713 job = "jobless"
5087 local _base_0 = my_object 2714end
5088 local _fn_0 = _base_0.write 2715local two, four
5089 return _fn_0 and function(...) 2716local _obj_0 = items
5090 return _fn_0(_base_0, ...) 2717two, four = _obj_0[2], _obj_0[4]
2718local orders = {
2719 "first",
2720 "second",
2721 "third",
2722 "fourth",
2723 "last"
2724}
2725local first, bulk, last = orders[1], (function()
2726 local _accum_0 = { }
2727 local _len_0 = 1
2728 local _max_0 = #orders + -2 + 1
2729 for _index_0 = 2, _max_0 do
2730 local _item_0 = orders[_index_0]
2731 _accum_0[_len_0] = _item_0
2732 _len_0 = _len_0 + 1
5091 end 2733 end
5092end)()) 2734 return _accum_0
2735end)(), orders[#orders]
2736print(first)
2737print(bulk)
2738print(last)
2739local first, rest
2740do
2741 local _obj_0 = orders
2742 first, rest = _obj_0[1], (function()
2743 local _accum_0 = { }
2744 local _len_0 = 1
2745 local _max_0 = #_obj_0
2746 for _index_0 = 2, _max_0 do
2747 local _item_0 = _obj_0[_index_0]
2748 _accum_0[_len_0] = _item_0
2749 _len_0 = _len_0 + 1
2750 end
2751 return _accum_0
2752 end)()
2753end
2754local start, last
2755do
2756 local _obj_0 = orders
2757 start, last = (function()
2758 local _accum_0 = { }
2759 local _len_0 = 1
2760 local _max_0 = #_obj_0 + -2 + 1
2761 for _index_0 = 1, _max_0 do
2762 local _item_0 = _obj_0[_index_0]
2763 _accum_0[_len_0] = _item_0
2764 _len_0 = _len_0 + 1
2765 end
2766 return _accum_0
2767 end)(), _obj_0[#_obj_0]
2768end
2769local _obj_0 = orders
2770first, last = _obj_0[1], _obj_0[#_obj_0]
2771local tuples = {
2772 {
2773 "hello",
2774 "world"
2775 },
2776 {
2777 "egg",
2778 "head"
2779 }
2780}
2781for _index_0 = 1, #tuples do
2782 local _des_0 = tuples[_index_0]
2783 local left, right = _des_0[1], _des_0[2]
2784 print(left, right)
2785end
2786local thing = {
2787 1,
2788 2
2789}
2790local a, b = thing[1], thing[2]
2791print(a, b)
2792local obj = {
2793 hello = "world",
2794 day = "tuesday",
2795 length = 20
2796}
2797local hello, the_day = obj.hello, obj.day
2798print(hello, the_day)
2799local day = obj.day
2800local obj2 = {
2801 numbers = {
2802 1,
2803 2,
2804 3,
2805 4
2806 },
2807 properties = {
2808 color = "green",
2809 height = 13.5
2810 }
2811}
2812local first, second, color = obj2.numbers[1], obj2.numbers[2], obj2.properties.color
2813print(first, second, color)
2814local first, second, color
2815local _obj_0 = obj2
2816first, second, color = _obj_0.numbers[1], _obj_0.numbers[2], _obj_0.properties.color
2817local concat, insert
2818local _obj_0 = table
2819concat, insert = _obj_0.concat, _obj_0.insert
2820local mix, max, rand
2821local _obj_0 = math
2822mix, max, rand = _obj_0.mix, _obj_0.max, _obj_0.random
2823local name, job
2824local _obj_0 = person
2825name, job = _obj_0.name, _obj_0.job
2826if name == nil then
2827 name = "nameless"
2828end
2829if job == nil then
2830 job = "jobless"
2831end
2832local two, four
2833local _obj_0 = items
2834two, four = _obj_0[2], _obj_0[4]
2835local orders = {
2836 "first",
2837 "second",
2838 "third",
2839 "fourth",
2840 "last"
2841}
2842local first, bulk, last = orders[1], (function()
2843 local _accum_0 = { }
2844 local _len_0 = 1
2845 local _max_0 = #orders + -2 + 1
2846 for _index_0 = 2, _max_0 do
2847 local _item_0 = orders[_index_0]
2848 _accum_0[_len_0] = _item_0
2849 _len_0 = _len_0 + 1
2850 end
2851 return _accum_0
2852end)(), orders[#orders]
2853print(first)
2854print(bulk)
2855print(last)
2856local first, rest
2857do
2858 local _obj_0 = orders
2859 first, rest = _obj_0[1], (function()
2860 local _accum_0 = { }
2861 local _len_0 = 1
2862 local _max_0 = #_obj_0
2863 for _index_0 = 2, _max_0 do
2864 local _item_0 = _obj_0[_index_0]
2865 _accum_0[_len_0] = _item_0
2866 _len_0 = _len_0 + 1
2867 end
2868 return _accum_0
2869 end)()
2870end
2871local start, last
2872do
2873 local _obj_0 = orders
2874 start, last = (function()
2875 local _accum_0 = { }
2876 local _len_0 = 1
2877 local _max_0 = #_obj_0 + -2 + 1
2878 for _index_0 = 1, _max_0 do
2879 local _item_0 = _obj_0[_index_0]
2880 _accum_0[_len_0] = _item_0
2881 _len_0 = _len_0 + 1
2882 end
2883 return _accum_0
2884 end)(), _obj_0[#_obj_0]
2885end
2886local _obj_0 = orders
2887first, last = _obj_0[1], _obj_0[#_obj_0]
2888local tuples = {
2889 {
2890 "hello",
2891 "world"
2892 },
2893 {
2894 "egg",
2895 "head"
2896 }
2897}
2898for _index_0 = 1, #tuples do
2899 local _des_0 = tuples[_index_0]
2900 local left, right = _des_0[1], _des_0[2]
2901 print(left, right)
2902end
5093local i = 100 2903local i = 100
5094local my_func 2904local my_func
5095my_func = function() 2905my_func = function()
@@ -5146,3 +2956,2193 @@ my_func = function(add)
5146end 2956end
5147my_func(22) 2957my_func(22)
5148print(i, k) 2958print(i, k)
2959local _module_0 = { }
2960local p, to_lua
2961do
2962 local _obj_0 = require("yue")
2963 p, to_lua = _obj_0.p, _obj_0.to_lua
2964end
2965local inventory = {
2966 equipment = {
2967 "sword",
2968 "shield"
2969 },
2970 items = {
2971 {
2972 name = "potion",
2973 count = 10
2974 },
2975 {
2976 name = "bread",
2977 count = 3
2978 }
2979 }
2980}
2981local map
2982map = function(arr, action)
2983 local _accum_0 = { }
2984 local _len_0 = 1
2985 for _index_0 = 1, #arr do
2986 local item = arr[_index_0]
2987 _accum_0[_len_0] = action(item)
2988 _len_0 = _len_0 + 1
2989 end
2990 return _accum_0
2991end
2992local filter
2993filter = function(arr, cond)
2994 local _accum_0 = { }
2995 local _len_0 = 1
2996 for _index_0 = 1, #arr do
2997 local item = arr[_index_0]
2998 if cond(item) then
2999 _accum_0[_len_0] = item
3000 _len_0 = _len_0 + 1
3001 end
3002 end
3003 return _accum_0
3004end
3005local reduce
3006reduce = function(arr, init, action)
3007 for _index_0 = 1, #arr do
3008 local item = arr[_index_0]
3009 init = action(init, item)
3010 end
3011 return init
3012end
3013print(reduce(filter(map({
3014 1,
3015 2,
3016 3
3017}, function(x)
3018 return x * 2
3019end), function(x)
3020 return x > 4
3021end), 0, function(a, b)
3022 return a + b
3023end))
3024local apple = setmetatable({
3025 size = 15,
3026}, {
3027 __index = {
3028 color = 0x00ffff
3029 }
3030})
3031if (getmetatable(apple) ~= nil) then
3032 p(apple.size, apple.color, getmetatable(apple).__index)
3033end
3034local _u1f31b = "月之脚本"
3035_module_0["🌛"] = _u1f31b
3036return _module_0
3037local _module_0 = { }
3038local p, to_lua
3039do
3040 local _obj_0 = require("yue")
3041 p, to_lua = _obj_0.p, _obj_0.to_lua
3042end
3043local inventory = {
3044 equipment = {
3045 "sword",
3046 "shield"
3047 },
3048 items = {
3049 {
3050 name = "potion",
3051 count = 10
3052 },
3053 {
3054 name = "bread",
3055 count = 3
3056 }
3057 }
3058}
3059local map
3060map = function(arr, action)
3061 local _accum_0 = { }
3062 local _len_0 = 1
3063 for _index_0 = 1, #arr do
3064 local item = arr[_index_0]
3065 _accum_0[_len_0] = action(item)
3066 _len_0 = _len_0 + 1
3067 end
3068 return _accum_0
3069end
3070local filter
3071filter = function(arr, cond)
3072 local _accum_0 = { }
3073 local _len_0 = 1
3074 for _index_0 = 1, #arr do
3075 local item = arr[_index_0]
3076 if cond(item) then
3077 _accum_0[_len_0] = item
3078 _len_0 = _len_0 + 1
3079 end
3080 end
3081 return _accum_0
3082end
3083local reduce
3084reduce = function(arr, init, action)
3085 for _index_0 = 1, #arr do
3086 local item = arr[_index_0]
3087 init = action(init, item)
3088 end
3089 return init
3090end
3091print(reduce(filter(map({
3092 1,
3093 2,
3094 3
3095}, function(x)
3096 return x * 2
3097end), function(x)
3098 return x > 4
3099end), 0, function(a, b)
3100 return a + b
3101end))
3102local apple = setmetatable({
3103 size = 15,
3104}, {
3105 __index = {
3106 color = 0x00ffff
3107 }
3108})
3109if (getmetatable(apple) ~= nil) then
3110 p(apple.size, apple.color, getmetatable(apple).__index)
3111end
3112local _u1f31b = "月之脚本"
3113_module_0["🌛"] = _u1f31b
3114return _module_0
3115local have_coins = false
3116if have_coins then
3117 print("有硬币")
3118else
3119 print("没有硬币")
3120end
3121local have_coins = false
3122if have_coins then
3123 print("有硬币")
3124else
3125 print("没有硬币")
3126end
3127local have_coins = false
3128print((function()
3129 if have_coins then
3130 return "有硬币"
3131 else
3132 return "没有硬币"
3133 end
3134end)())
3135local is_tall
3136is_tall = function(name)
3137 if name == "Rob" then
3138 return true
3139 else
3140 return false
3141 end
3142end
3143local message
3144if is_tall("Rob") then
3145 message = "我很高"
3146else
3147 message = "我不是很高"
3148end
3149print(message)
3150if not (os.date("%A") == "Monday") then
3151 print("今天不是星期一!")
3152end
3153if not (math.random() > 0.1) then
3154 print("你真幸运!")
3155end
3156local a = 5
3157if (1 == a or 3 == a or 5 == a or 7 == a) then
3158 print("检查离散值的相等性")
3159end
3160if (function()
3161 local _check_0 = list
3162 for _index_0 = 1, #_check_0 do
3163 if _check_0[_index_0] == a then
3164 return true
3165 end
3166 end
3167 return false
3168end)() then
3169 print("检查`a`是否在列表中")
3170end
3171if not (math.random() > 0.1) then
3172 print("你很幸运!")
3173end
3174local have_coins = false
3175if have_coins then
3176 print("有硬币")
3177else
3178 print("没有硬币")
3179end
3180local have_coins = false
3181if have_coins then
3182 print("有硬币")
3183else
3184 print("没有硬币")
3185end
3186local have_coins = false
3187print((function()
3188 if have_coins then
3189 return "有硬币"
3190 else
3191 return "没有硬币"
3192 end
3193end)())
3194local is_tall
3195is_tall = function(name)
3196 if name == "Rob" then
3197 return true
3198 else
3199 return false
3200 end
3201end
3202local message
3203if is_tall("Rob") then
3204 message = "我很高"
3205else
3206 message = "我不是很高"
3207end
3208print(message)
3209if not (os.date("%A") == "Monday") then
3210 print("今天不是星期一!")
3211end
3212if not (math.random() > 0.1) then
3213 print("你真幸运!")
3214end
3215local a = 5
3216if (1 == a or 3 == a or 5 == a or 7 == a) then
3217 print("检查离散值的相等性")
3218end
3219if (function()
3220 local _check_0 = list
3221 for _index_0 = 1, #_check_0 do
3222 if _check_0[_index_0] == a then
3223 return true
3224 end
3225 end
3226 return false
3227end)() then
3228 print("检查`a`是否在列表中")
3229end
3230if not (math.random() > 0.1) then
3231 print("你很幸运!")
3232end
3233for i = 10, 20 do
3234 print(i)
3235end
3236for k = 1, 15, 2 do
3237 print(k)
3238end
3239for key, value in pairs(object) do
3240 print(key, value)
3241end
3242local _list_0 = items
3243for _index_0 = 2, 4 do
3244 local item = _list_0[_index_0]
3245 print(item)
3246end
3247local _list_0 = items
3248for _index_0 = 1, #_list_0 do
3249 local item = _list_0[_index_0]
3250 print(item)
3251end
3252for j = 1, 10, 3 do
3253 print(j)
3254end
3255local doubled_evens
3256local _accum_0 = { }
3257local _len_0 = 1
3258for i = 1, 20 do
3259 if i % 2 == 0 then
3260 _accum_0[_len_0] = i * 2
3261 _len_0 = _len_0 + 1
3262 else
3263 _accum_0[_len_0] = i
3264 _len_0 = _len_0 + 1
3265 end
3266end
3267doubled_evens = _accum_0
3268local first_large
3269local _accum_0
3270local _list_0 = numbers
3271for _index_0 = 1, #_list_0 do
3272 local n = _list_0[_index_0]
3273 if n > 10 then
3274 _accum_0 = n
3275 break
3276 end
3277end
3278first_large = _accum_0
3279local func_a
3280func_a = function()
3281 for i = 1, 10 do
3282 print(i)
3283 end
3284end
3285local func_b
3286func_b = function()
3287 local _accum_0 = { }
3288 local _len_0 = 1
3289 for i = 1, 10 do
3290 _accum_0[_len_0] = i
3291 _len_0 = _len_0 + 1
3292 end
3293 return _accum_0
3294end
3295print(func_a())
3296print(func_b())
3297for i = 10, 20 do
3298 print(i)
3299end
3300for k = 1, 15, 2 do
3301 print(k)
3302end
3303for key, value in pairs(object) do
3304 print(key, value)
3305end
3306local _list_0 = items
3307for _index_0 = 2, 4 do
3308 local item = _list_0[_index_0]
3309 print(item)
3310end
3311local _list_0 = items
3312for _index_0 = 1, #_list_0 do
3313 local item = _list_0[_index_0]
3314 print(item)
3315end
3316for j = 1, 10, 3 do
3317 print(j)
3318end
3319local doubled_evens
3320local _accum_0 = { }
3321local _len_0 = 1
3322for i = 1, 20 do
3323 if i % 2 == 0 then
3324 _accum_0[_len_0] = i * 2
3325 _len_0 = _len_0 + 1
3326 else
3327 _accum_0[_len_0] = i
3328 _len_0 = _len_0 + 1
3329 end
3330end
3331doubled_evens = _accum_0
3332local first_large
3333local _accum_0
3334local _list_0 = numbers
3335for _index_0 = 1, #_list_0 do
3336 local n = _list_0[_index_0]
3337 if n > 10 then
3338 _accum_0 = n
3339 break
3340 end
3341end
3342first_large = _accum_0
3343local func_a
3344func_a = function()
3345 for i = 1, 10 do
3346 print(i)
3347 end
3348end
3349local func_b
3350func_b = function()
3351 local _accum_0 = { }
3352 local _len_0 = 1
3353 for i = 1, 10 do
3354 _accum_0[_len_0] = i
3355 _len_0 = _len_0 + 1
3356 end
3357 return _accum_0
3358end
3359print(func_a())
3360print(func_b())
3361local i = 0
3362while i < 10 do
3363 i = i + 1
3364 if i % 2 == 0 then
3365 goto _continue_0
3366 end
3367 print(i)
3368 ::_continue_0::
3369end
3370local my_numbers = {
3371 1,
3372 2,
3373 3,
3374 4,
3375 5,
3376 6
3377}
3378local odds
3379local _accum_0 = { }
3380local _len_0 = 1
3381for _index_0 = 1, #my_numbers do
3382 local x = my_numbers[_index_0]
3383 if x % 2 == 1 then
3384 goto _continue_0
3385 end
3386 _accum_0[_len_0] = x
3387 _len_0 = _len_0 + 1
3388 ::_continue_0::
3389end
3390odds = _accum_0
3391local i = 0
3392while i < 10 do
3393 i = i + 1
3394 if i % 2 == 0 then
3395 goto _continue_0
3396 end
3397 print(i)
3398 ::_continue_0::
3399end
3400local my_numbers = {
3401 1,
3402 2,
3403 3,
3404 4,
3405 5,
3406 6
3407}
3408local odds
3409local _accum_0 = { }
3410local _len_0 = 1
3411for _index_0 = 1, #my_numbers do
3412 local x = my_numbers[_index_0]
3413 if x % 2 == 1 then
3414 goto _continue_0
3415 end
3416 _accum_0[_len_0] = x
3417 _len_0 = _len_0 + 1
3418 ::_continue_0::
3419end
3420odds = _accum_0
3421local name = "Dan"
3422if "Robert" == name then
3423 print("你是Robert")
3424elseif "Dan" == name or "Daniel" == name then
3425 print("你的名字是Dan")
3426else
3427 print("我不认识你,你的名字是" .. tostring(name))
3428end
3429local b = 1
3430local next_number
3431if 1 == b then
3432 next_number = 2
3433elseif 2 == b then
3434 next_number = 3
3435else
3436 next_number = error("数字数得太大了!")
3437end
3438local msg
3439local _exp_0 = math.random(1, 5)
3440if 1 == _exp_0 then
3441 msg = "你很幸运"
3442elseif 2 == _exp_0 then
3443 msg = "你差点很幸运"
3444else
3445 msg = "不太幸运"
3446end
3447do
3448 local _exp_0 = math.random(1, 5)
3449 if 1 == _exp_0 then
3450 print("你很幸运")
3451 else
3452 print("不太幸运")
3453 end
3454end
3455local _exp_0 = math.random(1, 5)
3456if 1 == _exp_0 then
3457 print("你很幸运")
3458else
3459 print("不太幸运")
3460end
3461local items = {
3462 {
3463 x = 100,
3464 y = 200
3465 },
3466 {
3467 width = 300,
3468 height = 400
3469 }
3470}
3471for _index_0 = 1, #items do
3472 local item = items[_index_0]
3473 local _type_0 = type(item)
3474 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3475 local _match_0 = false
3476 if _tab_0 then
3477 local x = item.x
3478 local y = item.y
3479 if x ~= nil and y ~= nil then
3480 _match_0 = true
3481 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3482 end
3483 end
3484 if not _match_0 then
3485 if _tab_0 then
3486 local width = item.width
3487 local height = item.height
3488 if width ~= nil and height ~= nil then
3489 print("尺寸 " .. tostring(width) .. ", " .. tostring(height))
3490 end
3491 end
3492 end
3493end
3494local item = { }
3495local x, y = item.pos.x, item.pos.y
3496if x == nil then
3497 x = 50
3498end
3499if y == nil then
3500 y = 200
3501end
3502local _type_0 = type(item)
3503local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3504if _tab_0 then
3505 do
3506 local _obj_0 = item.pos
3507 local _type_1 = type(_obj_0)
3508 if "table" == _type_1 or "userdata" == _type_1 then
3509 x = _obj_0.x
3510 end
3511 end
3512 do
3513 local _obj_0 = item.pos
3514 local _type_1 = type(_obj_0)
3515 if "table" == _type_1 or "userdata" == _type_1 then
3516 y = _obj_0.y
3517 end
3518 end
3519 if x == nil then
3520 x = 50
3521 end
3522 if y == nil then
3523 y = 200
3524 end
3525 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3526end
3527local _exp_0 = tb
3528local _type_0 = type(_exp_0)
3529local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3530local _match_0 = false
3531if _tab_0 then
3532 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
3533 _match_0 = true
3534 print("1, 2, 3")
3535 end
3536end
3537if not _match_0 then
3538 local _match_1 = false
3539 if _tab_0 then
3540 local b = _exp_0[2]
3541 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
3542 _match_1 = true
3543 print("1, " .. tostring(b) .. ", 3")
3544 end
3545 end
3546 if not _match_1 then
3547 if _tab_0 then
3548 local b = _exp_0[3]
3549 if b == nil then
3550 b = 3
3551 end
3552 if 1 == _exp_0[1] and 2 == _exp_0[2] then
3553 print("1, 2, " .. tostring(b))
3554 end
3555 end
3556 end
3557end
3558local _exp_0 = tb
3559local _type_0 = type(_exp_0)
3560local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3561local _match_0 = false
3562if _tab_0 then
3563 local result = _exp_0.result
3564 if true == _exp_0.success and result ~= nil then
3565 _match_0 = true
3566 print("成功", result)
3567 end
3568end
3569if not _match_0 then
3570 local _match_1 = false
3571 if _tab_0 then
3572 if false == _exp_0.success then
3573 _match_1 = true
3574 print("失败", result)
3575 end
3576 end
3577 if not _match_1 then
3578 print("无效值")
3579 end
3580end
3581local _exp_0 = tb
3582local _type_0 = type(_exp_0)
3583local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3584local _match_0 = false
3585if _tab_0 then
3586 local content
3587 do
3588 local _obj_0 = _exp_0.data
3589 local _type_1 = type(_obj_0)
3590 if "table" == _type_1 or "userdata" == _type_1 then
3591 content = _obj_0.content
3592 end
3593 end
3594 local _val_0
3595 do
3596 local _obj_0 = _exp_0.data
3597 if _obj_0 ~= nil then
3598 _val_0 = _obj_0.type
3599 end
3600 end
3601 if "success" == _val_0 and content ~= nil then
3602 _match_0 = true
3603 print("成功", content)
3604 end
3605end
3606if not _match_0 then
3607 local _match_1 = false
3608 if _tab_0 then
3609 local content
3610 do
3611 local _obj_0 = _exp_0.data
3612 local _type_1 = type(_obj_0)
3613 if "table" == _type_1 or "userdata" == _type_1 then
3614 content = _obj_0.content
3615 end
3616 end
3617 local _val_0
3618 do
3619 local _obj_0 = _exp_0.data
3620 if _obj_0 ~= nil then
3621 _val_0 = _obj_0.type
3622 end
3623 end
3624 if "error" == _val_0 and content ~= nil then
3625 _match_1 = true
3626 print("失败", content)
3627 end
3628 end
3629 if not _match_1 then
3630 print("无效值")
3631 end
3632end
3633local _exp_0 = tb
3634local _type_0 = type(_exp_0)
3635local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3636if _tab_0 then
3637 local fourth = _exp_0[4]
3638 local _val_0
3639 do
3640 local _obj_0 = _exp_0[1]
3641 if _obj_0 ~= nil then
3642 _val_0 = _obj_0.a
3643 end
3644 end
3645 local _val_1
3646 do
3647 local _obj_0 = _exp_0[1]
3648 if _obj_0 ~= nil then
3649 _val_1 = _obj_0.b
3650 end
3651 end
3652 local _val_2
3653 do
3654 local _obj_0 = _exp_0[2]
3655 if _obj_0 ~= nil then
3656 _val_2 = _obj_0.a
3657 end
3658 end
3659 local _val_3
3660 do
3661 local _obj_0 = _exp_0[2]
3662 if _obj_0 ~= nil then
3663 _val_3 = _obj_0.b
3664 end
3665 end
3666 local _val_4
3667 do
3668 local _obj_0 = _exp_0[3]
3669 if _obj_0 ~= nil then
3670 _val_4 = _obj_0.a
3671 end
3672 end
3673 local _val_5
3674 do
3675 local _obj_0 = _exp_0[3]
3676 if _obj_0 ~= nil then
3677 _val_5 = _obj_0.b
3678 end
3679 end
3680 if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and fourth ~= nil then
3681 print("匹配成功", fourth)
3682 end
3683end
3684local segments = {
3685 "admin",
3686 "users",
3687 "logs",
3688 "view"
3689}
3690local _type_0 = type(segments)
3691local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3692if _tab_0 then
3693 local groups
3694 do
3695 local _accum_0 = { }
3696 local _len_0 = 1
3697 local _max_0 = #segments + -3 + 1
3698 for _index_0 = 1, _max_0 do
3699 local _item_0 = segments[_index_0]
3700 _accum_0[_len_0] = _item_0
3701 _len_0 = _len_0 + 1
3702 end
3703 groups = _accum_0
3704 end
3705 local resource = segments[#segments - 1]
3706 local action = segments[#segments]
3707 if resource ~= nil and action ~= nil then
3708 print("Group:", groups)
3709 print("Resource:", resource)
3710 print("Action:", action)
3711 end
3712end
3713local name = "Dan"
3714if "Robert" == name then
3715 print("你是Robert")
3716elseif "Dan" == name or "Daniel" == name then
3717 print("你的名字是Dan")
3718else
3719 print("我不认识你,你的名字是" .. tostring(name))
3720end
3721local b = 1
3722local next_number
3723if 1 == b then
3724 next_number = 2
3725elseif 2 == b then
3726 next_number = 3
3727else
3728 next_number = error("数字数得太大了!")
3729end
3730local msg
3731local _exp_0 = math.random(1, 5)
3732if 1 == _exp_0 then
3733 msg = "你很幸运"
3734elseif 2 == _exp_0 then
3735 msg = "你差点很幸运"
3736else
3737 msg = "不太幸运"
3738end
3739do
3740 local _exp_0 = math.random(1, 5)
3741 if 1 == _exp_0 then
3742 print("你很幸运")
3743 else
3744 print("不太幸运")
3745 end
3746end
3747local _exp_0 = math.random(1, 5)
3748if 1 == _exp_0 then
3749 print("你很幸运")
3750else
3751 print("不太幸运")
3752end
3753local items = {
3754 {
3755 x = 100,
3756 y = 200
3757 },
3758 {
3759 width = 300,
3760 height = 400
3761 }
3762}
3763for _index_0 = 1, #items do
3764 local item = items[_index_0]
3765 local _type_0 = type(item)
3766 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3767 local _match_0 = false
3768 if _tab_0 then
3769 local x = item.x
3770 local y = item.y
3771 if x ~= nil and y ~= nil then
3772 _match_0 = true
3773 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3774 end
3775 end
3776 if not _match_0 then
3777 if _tab_0 then
3778 local width = item.width
3779 local height = item.height
3780 if width ~= nil and height ~= nil then
3781 print("尺寸 " .. tostring(width) .. ", " .. tostring(height))
3782 end
3783 end
3784 end
3785end
3786local item = { }
3787local x, y = item.pos.x, item.pos.y
3788if x == nil then
3789 x = 50
3790end
3791if y == nil then
3792 y = 200
3793end
3794local _type_0 = type(item)
3795local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3796if _tab_0 then
3797 do
3798 local _obj_0 = item.pos
3799 local _type_1 = type(_obj_0)
3800 if "table" == _type_1 or "userdata" == _type_1 then
3801 x = _obj_0.x
3802 end
3803 end
3804 do
3805 local _obj_0 = item.pos
3806 local _type_1 = type(_obj_0)
3807 if "table" == _type_1 or "userdata" == _type_1 then
3808 y = _obj_0.y
3809 end
3810 end
3811 if x == nil then
3812 x = 50
3813 end
3814 if y == nil then
3815 y = 200
3816 end
3817 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3818end
3819local _exp_0 = tb
3820local _type_0 = type(_exp_0)
3821local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3822local _match_0 = false
3823if _tab_0 then
3824 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
3825 _match_0 = true
3826 print("1, 2, 3")
3827 end
3828end
3829if not _match_0 then
3830 local _match_1 = false
3831 if _tab_0 then
3832 local b = _exp_0[2]
3833 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
3834 _match_1 = true
3835 print("1, " .. tostring(b) .. ", 3")
3836 end
3837 end
3838 if not _match_1 then
3839 if _tab_0 then
3840 local b = _exp_0[3]
3841 if b == nil then
3842 b = 3
3843 end
3844 if 1 == _exp_0[1] and 2 == _exp_0[2] then
3845 print("1, 2, " .. tostring(b))
3846 end
3847 end
3848 end
3849end
3850local _exp_0 = tb
3851local _type_0 = type(_exp_0)
3852local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3853local _match_0 = false
3854if _tab_0 then
3855 local result = _exp_0.result
3856 if true == _exp_0.success and result ~= nil then
3857 _match_0 = true
3858 print("成功", result)
3859 end
3860end
3861if not _match_0 then
3862 local _match_1 = false
3863 if _tab_0 then
3864 if false == _exp_0.success then
3865 _match_1 = true
3866 print("失败", result)
3867 end
3868 end
3869 if not _match_1 then
3870 print("无效值")
3871 end
3872end
3873local _exp_0 = tb
3874local _type_0 = type(_exp_0)
3875local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3876local _match_0 = false
3877if _tab_0 then
3878 local content
3879 do
3880 local _obj_0 = _exp_0.data
3881 local _type_1 = type(_obj_0)
3882 if "table" == _type_1 or "userdata" == _type_1 then
3883 content = _obj_0.content
3884 end
3885 end
3886 local _val_0
3887 do
3888 local _obj_0 = _exp_0.data
3889 if _obj_0 ~= nil then
3890 _val_0 = _obj_0.type
3891 end
3892 end
3893 if "success" == _val_0 and content ~= nil then
3894 _match_0 = true
3895 print("成功", content)
3896 end
3897end
3898if not _match_0 then
3899 local _match_1 = false
3900 if _tab_0 then
3901 local content
3902 do
3903 local _obj_0 = _exp_0.data
3904 local _type_1 = type(_obj_0)
3905 if "table" == _type_1 or "userdata" == _type_1 then
3906 content = _obj_0.content
3907 end
3908 end
3909 local _val_0
3910 do
3911 local _obj_0 = _exp_0.data
3912 if _obj_0 ~= nil then
3913 _val_0 = _obj_0.type
3914 end
3915 end
3916 if "error" == _val_0 and content ~= nil then
3917 _match_1 = true
3918 print("失败", content)
3919 end
3920 end
3921 if not _match_1 then
3922 print("无效值")
3923 end
3924end
3925local _exp_0 = tb
3926local _type_0 = type(_exp_0)
3927local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3928if _tab_0 then
3929 local fourth = _exp_0[4]
3930 local _val_0
3931 do
3932 local _obj_0 = _exp_0[1]
3933 if _obj_0 ~= nil then
3934 _val_0 = _obj_0.a
3935 end
3936 end
3937 local _val_1
3938 do
3939 local _obj_0 = _exp_0[1]
3940 if _obj_0 ~= nil then
3941 _val_1 = _obj_0.b
3942 end
3943 end
3944 local _val_2
3945 do
3946 local _obj_0 = _exp_0[2]
3947 if _obj_0 ~= nil then
3948 _val_2 = _obj_0.a
3949 end
3950 end
3951 local _val_3
3952 do
3953 local _obj_0 = _exp_0[2]
3954 if _obj_0 ~= nil then
3955 _val_3 = _obj_0.b
3956 end
3957 end
3958 local _val_4
3959 do
3960 local _obj_0 = _exp_0[3]
3961 if _obj_0 ~= nil then
3962 _val_4 = _obj_0.a
3963 end
3964 end
3965 local _val_5
3966 do
3967 local _obj_0 = _exp_0[3]
3968 if _obj_0 ~= nil then
3969 _val_5 = _obj_0.b
3970 end
3971 end
3972 if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and fourth ~= nil then
3973 print("匹配成功", fourth)
3974 end
3975end
3976local segments = {
3977 "admin",
3978 "users",
3979 "logs",
3980 "view"
3981}
3982local _type_0 = type(segments)
3983local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3984if _tab_0 then
3985 local groups
3986 do
3987 local _accum_0 = { }
3988 local _len_0 = 1
3989 local _max_0 = #segments + -3 + 1
3990 for _index_0 = 1, _max_0 do
3991 local _item_0 = segments[_index_0]
3992 _accum_0[_len_0] = _item_0
3993 _len_0 = _len_0 + 1
3994 end
3995 groups = _accum_0
3996 end
3997 local resource = segments[#segments - 1]
3998 local action = segments[#segments]
3999 if resource ~= nil and action ~= nil then
4000 print("Group:", groups)
4001 print("Resource:", resource)
4002 print("Action:", action)
4003 end
4004end
4005local i = 10
4006while i > 0 do
4007 print(i)
4008 i = i - 1
4009end
4010while running == true do
4011 my_function()
4012end
4013local i = 10
4014while not (i == 0) do
4015 print(i)
4016 i = i - 1
4017end
4018while not (running == false) do
4019 my_function()
4020end
4021local i = 10
4022repeat
4023 print(i)
4024 i = i - 1
4025until i == 0
4026local i = 10
4027while i > 0 do
4028 print(i)
4029 i = i - 1
4030end
4031while running == true do
4032 my_function()
4033end
4034local i = 10
4035while not (i == 0) do
4036 print(i)
4037 i = i - 1
4038end
4039while not (running == false) do
4040 my_function()
4041end
4042local i = 10
4043repeat
4044 print(i)
4045 i = i - 1
4046until i == 0
4047local my_object = {
4048 value = 1000,
4049 write = function(self)
4050 return print("值为:", self.value)
4051 end
4052}
4053local run_callback
4054run_callback = function(func)
4055 print("运行回调...")
4056 return func()
4057end
4058run_callback(my_object.write)
4059run_callback((function()
4060 local _base_0 = my_object
4061 local _fn_0 = _base_0.write
4062 return _fn_0 and function(...)
4063 return _fn_0(_base_0, ...)
4064 end
4065end)())
4066local my_object = {
4067 value = 1000,
4068 write = function(self)
4069 return print("值为:", self.value)
4070 end
4071}
4072local run_callback
4073run_callback = function(func)
4074 print("运行回调...")
4075 return func()
4076end
4077run_callback(my_object.write)
4078run_callback((function()
4079 local _base_0 = my_object
4080 local _fn_0 = _base_0.write
4081 return _fn_0 and function(...)
4082 return _fn_0(_base_0, ...)
4083 end
4084end)())
4085f(function(x)
4086 return print("hello" .. x)
4087end)
4088f(function(self)
4089 return print(self.value)
4090end)
4091map(function(x)
4092 return x * 2
4093end, {
4094 1,
4095 2,
4096 3
4097})
4098local result, msg
4099do
4100 result, msg = readAsync("文件名.txt", function(data)
4101 print(data)
4102 return processAsync(data, function(info)
4103 return check(info)
4104 end)
4105 end)
4106end
4107print(result, msg)
4108f(function(x)
4109 return print("hello" .. x)
4110end)
4111f(function(self)
4112 return print(self.value)
4113end)
4114map(function(x)
4115 return x * 2
4116end, {
4117 1,
4118 2,
4119 3
4120})
4121local result, msg
4122do
4123 result, msg = readAsync("文件名.txt", function(data)
4124 print(data)
4125 return processAsync(data, function(info)
4126 return check(info)
4127 end)
4128 end)
4129end
4130print(result, msg)
4131local my_function
4132my_function = function() end
4133my_function()
4134local func_a
4135func_a = function()
4136 return print("你好,世界")
4137end
4138local func_b
4139func_b = function()
4140 local value = 100
4141 return print("这个值是:", value)
4142end
4143func_a()
4144func_b()
4145local sum
4146sum = function(x, y)
4147 return print("数字的和", x + y)
4148end
4149sum(10, 20)
4150print(sum(10, 20))
4151a(b(c("a", "b", "c")))
4152print("x:", sum(10, 20), "y:", sum(30, 40))
4153local sum
4154sum = function(x, y)
4155 return x + y
4156end
4157print("数字的和是", sum(10, 20))
4158local sum
4159sum = function(x, y)
4160 return x + y
4161end
4162local mystery
4163mystery = function(x, y)
4164 return x + y, x - y
4165end
4166local a, b = mystery(10, 20)
4167local func
4168func = function(self, num)
4169 return self.value + num
4170end
4171local my_function
4172my_function = function(name, height)
4173 if name == nil then
4174 name = "某物"
4175 end
4176 if height == nil then
4177 height = 100
4178 end
4179 print("你好,我是", name)
4180 return print("我的高度是", height)
4181end
4182local some_args
4183some_args = function(x, y)
4184 if x == nil then
4185 x = 100
4186 end
4187 if y == nil then
4188 y = x + 1000
4189 end
4190 return print(x + y)
4191end
4192local a = x - 10
4193local b = x - 10
4194local c = x(-y)
4195local d = x - z
4196local x = func("hello") + 100
4197local y = func("hello" + 100)
4198my_func(5, 4, 3, 8, 9, 10)
4199cool_func(1, 2, 3, 4, 5, 6, 7, 8)
4200my_func(5, 6, 7, 6, another_func(6, 7, 8, 9, 1, 2), 5, 4)
4201local x = {
4202 1,
4203 2,
4204 3,
4205 4,
4206 a_func(4, 5, 5, 6),
4207 8,
4208 9,
4209 10
4210}
4211local y = {
4212 my_func(1, 2, 3, 4, 5),
4213 5,
4214 6,
4215 7
4216}
4217if func(1, 2, 3, "你好", "世界") then
4218 print("你好")
4219 print("我在if内部")
4220end
4221if func(1, 2, 3, "你好", "世界") then
4222 print("hello")
4223 print("我在if内部")
4224end
4225local f1
4226f1 = function(_arg_0)
4227 local a, b, c
4228 a, b, c = _arg_0.a, _arg_0.b, _arg_0.c
4229 return print(a, b, c)
4230end
4231f1({
4232 a = 1,
4233 b = "2",
4234 c = { }
4235})
4236local f2
4237f2 = function(_arg_0, c)
4238 local a1, b
4239 a1, b = _arg_0.a, _arg_0.b
4240 if a1 == nil then
4241 a1 = 123
4242 end
4243 if b == nil then
4244 b = 'abc'
4245 end
4246 if c == nil then
4247 c = { }
4248 end
4249 return print(a1, b, c)
4250end
4251local arg1 = {
4252 a = 0
4253}
4254f2(arg1, arg2)
4255local findFirstEven
4256findFirstEven = function(list)
4257 for _index_0 = 1, #list do
4258 local item = list[_index_0]
4259 if type(item) == "table" then
4260 for _index_1 = 1, #item do
4261 local sub = item[_index_1]
4262 if sub % 2 == 0 then
4263 return sub
4264 end
4265 end
4266 end
4267 end
4268 return nil
4269end
4270local findFirstEven
4271findFirstEven = function(list)
4272 for _index_0 = 1, #list do
4273 local item = list[_index_0]
4274 if type(item) == "table" then
4275 for _index_1 = 1, #item do
4276 local sub = item[_index_1]
4277 if sub % 2 == 0 then
4278 return sub
4279 end
4280 end
4281 end
4282 end
4283 return nil
4284end
4285local f
4286f = function(...)
4287 local t = {
4288 n = select("#", ...),
4289 ...
4290 }
4291 print("参数个数:", t.n)
4292 print("表长度:", #t)
4293 for i = 1, t.n do
4294 print(t[i])
4295 end
4296end
4297f(1, 2, 3)
4298f("a", "b", "c", "d")
4299f()
4300local process
4301process = function(...)
4302 local args = {
4303 n = select("#", ...),
4304 ...
4305 }
4306 local sum = 0
4307 for i = 1, args.n do
4308 if args[i] ~= nil and type(args[i]) == "number" then
4309 sum = sum + args[i]
4310 end
4311 end
4312 return sum
4313end
4314process(1, nil, 3, nil, 5)
4315local my_function
4316my_function = function() end
4317my_function()
4318local func_a
4319func_a = function()
4320 return print("你好,世界")
4321end
4322local func_b
4323func_b = function()
4324 local value = 100
4325 return print("这个值是:", value)
4326end
4327func_a()
4328func_b()
4329local sum
4330sum = function(x, y)
4331 return print("数字的和", x + y)
4332end
4333sum(10, 20)
4334print(sum(10, 20))
4335a(b(c("a", "b", "c")))
4336print("x:", sum(10, 20), "y:", sum(30, 40))
4337local sum
4338sum = function(x, y)
4339 return x + y
4340end
4341print("数字的和是", sum(10, 20))
4342local sum
4343sum = function(x, y)
4344 return x + y
4345end
4346local mystery
4347mystery = function(x, y)
4348 return x + y, x - y
4349end
4350local a, b = mystery(10, 20)
4351local func
4352func = function(self, num)
4353 return self.value + num
4354end
4355local my_function
4356my_function = function(name, height)
4357 if name == nil then
4358 name = "某物"
4359 end
4360 if height == nil then
4361 height = 100
4362 end
4363 print("你好,我是", name)
4364 return print("我的高度是", height)
4365end
4366local some_args
4367some_args = function(x, y)
4368 if x == nil then
4369 x = 100
4370 end
4371 if y == nil then
4372 y = x + 1000
4373 end
4374 return print(x + y)
4375end
4376local a = x - 10
4377local b = x - 10
4378local c = x(-y)
4379local d = x - z
4380local x = func("hello") + 100
4381local y = func("hello" + 100)
4382my_func(5, 4, 3, 8, 9, 10)
4383cool_func(1, 2, 3, 4, 5, 6, 7, 8)
4384my_func(5, 6, 7, 6, another_func(6, 7, 8, 9, 1, 2), 5, 4)
4385local x = {
4386 1,
4387 2,
4388 3,
4389 4,
4390 a_func(4, 5, 5, 6),
4391 8,
4392 9,
4393 10
4394}
4395local y = {
4396 my_func(1, 2, 3, 4, 5),
4397 5,
4398 6,
4399 7
4400}
4401if func(1, 2, 3, "你好", "世界") then
4402 print("你好")
4403 print("我在if内部")
4404end
4405if func(1, 2, 3, "你好", "世界") then
4406 print("你好")
4407 print("我在if内部")
4408end
4409local f1
4410f1 = function(_arg_0)
4411 local a, b, c
4412 a, b, c = _arg_0.a, _arg_0.b, _arg_0.c
4413 return print(a, b, c)
4414end
4415f1({
4416 a = 1,
4417 b = "2",
4418 c = { }
4419})
4420local f2
4421f2 = function(_arg_0, c)
4422 local a1, b
4423 a1, b = _arg_0.a, _arg_0.b
4424 if a1 == nil then
4425 a1 = 123
4426 end
4427 if b == nil then
4428 b = 'abc'
4429 end
4430 if c == nil then
4431 c = { }
4432 end
4433 return print(a1, b, c)
4434end
4435local arg1 = {
4436 a = 0
4437}
4438f2(arg1, arg2)
4439local findFirstEven
4440findFirstEven = function(list)
4441 for _index_0 = 1, #list do
4442 local item = list[_index_0]
4443 if type(item) == "table" then
4444 for _index_1 = 1, #item do
4445 local sub = item[_index_1]
4446 if sub % 2 == 0 then
4447 return sub
4448 end
4449 end
4450 end
4451 end
4452 return nil
4453end
4454local findFirstEven
4455findFirstEven = function(list)
4456 for _index_0 = 1, #list do
4457 local item = list[_index_0]
4458 if type(item) == "table" then
4459 for _index_1 = 1, #item do
4460 local sub = item[_index_1]
4461 if sub % 2 == 0 then
4462 return sub
4463 end
4464 end
4465 end
4466 end
4467 return nil
4468end
4469local f
4470f = function(...)
4471 local t = {
4472 n = select("#", ...),
4473 ...
4474 }
4475 print("参数个数:", t.n)
4476 print("表长度:", #t)
4477 for i = 1, t.n do
4478 print(t[i])
4479 end
4480end
4481f(1, 2, 3)
4482f("a", "b", "c", "d")
4483f()
4484local process
4485process = function(...)
4486 local args = {
4487 n = select("#", ...),
4488 ...
4489 }
4490 local sum = 0
4491 for i = 1, args.n do
4492 if args[i] ~= nil and type(args[i]) == "number" then
4493 sum = sum + args[i]
4494 end
4495 end
4496 return sum
4497end
4498process(1, nil, 3, nil, 5)
4499local a = 1
4500local b = 2
4501print(a + b)
4502Rx.Observable.fromRange(1, 8):filter(function(x)
4503 return x % 2 == 0
4504end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
4505 return value .. '!'
4506end):subscribe(print)
4507local a = 1
4508local b = 2
4509print(a + b)
4510Rx.Observable.fromRange(1, 8):filter(function(x)
4511 return x % 2 == 0
4512end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
4513 return value .. '!'
4514end):subscribe(print)
4515local str = strA .. strB .. strC
4516func(3000, "192.168.1.1")
4517local str = strA .. strB .. strC
4518func(3000, "192.168.1.1")
4519local a <const> = 123
4520local _ <close> = setmetatable({ }, {
4521 __close = function()
4522 return print("超出范围。")
4523 end
4524})
4525local a, b, c, d
4526local _obj_0 = tb
4527a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
4528Constant = 123
4529local a <const> = 123
4530local _ <close> = setmetatable({ }, {
4531 __close = function()
4532 return print("超出范围。")
4533 end
4534})
4535local a, b, c, d
4536local _obj_0 = tb
4537a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
4538Constant = 123
4539if tb ~= nil then
4540 tb:func()
4541end
4542if tb ~= nil then
4543 tb:func()
4544end
4545print(1 < 2 and 2 <= 2 and 2 < 3 and 3 == 3 and 3 > 2 and 2 >= 1 and 1 == 1 and 1 < 3 and 3 ~= 5)
4546local a = 5
4547print(1 <= a and a <= 10)
4548local v
4549v = function(x)
4550 print(x)
4551 return x
4552end
4553print((function()
4554 local _cond_0 = v(2)
4555 if not (v(1) < _cond_0) then
4556 return false
4557 else
4558 return _cond_0 <= v(3)
4559 end
4560end)())
4561print((function()
4562 local _cond_0 = v(2)
4563 if not (v(1) > _cond_0) then
4564 return false
4565 else
4566 return _cond_0 <= v(3)
4567 end
4568end)())
4569local tab = { }
4570tab[#tab + 1] = "Value"
4571local tbA = {
4572 1,
4573 2,
4574 3
4575}
4576local tbB = {
4577 4,
4578 5,
4579 6
4580}
4581local _len_0 = #tbA + 1
4582for _index_0 = 1, #tbB do
4583 local _elm_0 = tbB[_index_0]
4584 tbA[_len_0], _len_0 = _elm_0, _len_0 + 1
4585end
4586local parts = {
4587 "shoulders",
4588 "knees"
4589}
4590local lyrics
4591do
4592 local _tab_0 = {
4593 "head"
4594 }
4595 local _idx_0 = 1
4596 for _key_0, _value_0 in pairs(parts) do
4597 if _idx_0 == _key_0 then
4598 _tab_0[#_tab_0 + 1] = _value_0
4599 _idx_0 = _idx_0 + 1
4600 else
4601 _tab_0[_key_0] = _value_0
4602 end
4603 end
4604 _tab_0[#_tab_0 + 1] = "and"
4605 _tab_0[#_tab_0 + 1] = "toes"
4606 lyrics = _tab_0
4607end
4608local copy
4609do
4610 local _tab_0 = { }
4611 local _idx_0 = 1
4612 for _key_0, _value_0 in pairs(other) do
4613 if _idx_0 == _key_0 then
4614 _tab_0[#_tab_0 + 1] = _value_0
4615 _idx_0 = _idx_0 + 1
4616 else
4617 _tab_0[_key_0] = _value_0
4618 end
4619 end
4620 copy = _tab_0
4621end
4622local a = {
4623 1,
4624 2,
4625 3,
4626 x = 1
4627}
4628local b = {
4629 4,
4630 5,
4631 y = 1
4632}
4633local merge
4634local _tab_0 = { }
4635local _idx_0 = 1
4636for _key_0, _value_0 in pairs(a) do
4637 if _idx_0 == _key_0 then
4638 _tab_0[#_tab_0 + 1] = _value_0
4639 _idx_0 = _idx_0 + 1
4640 else
4641 _tab_0[_key_0] = _value_0
4642 end
4643end
4644local _idx_1 = 1
4645for _key_0, _value_0 in pairs(b) do
4646 if _idx_1 == _key_0 then
4647 _tab_0[#_tab_0 + 1] = _value_0
4648 _idx_1 = _idx_1 + 1
4649 else
4650 _tab_0[_key_0] = _value_0
4651 end
4652end
4653merge = _tab_0
4654local last
4655do
4656 local _item_0 = data.items
4657 last = _item_0[#_item_0]
4658end
4659local second_last
4660do
4661 local _item_0 = data.items
4662 second_last = _item_0[#_item_0 - 1]
4663end
4664local _obj_0 = data.items
4665_obj_0[#_obj_0] = 1
4666local mt = { }
4667local add
4668add = function(self, right)
4669 return setmetatable({
4670 value = self.value + right.value
4671 }, mt)
4672end
4673mt.__add = add
4674local a = setmetatable({
4675 value = 1
4676}, mt)
4677local b = setmetatable({
4678 value = 2
4679}, {
4680 __add = add
4681})
4682local c = setmetatable({
4683 value = 3
4684}, {
4685 __add = mt.__add
4686})
4687local d = a + b + c
4688print(d.value)
4689local _ <close> = setmetatable({ }, {
4690 __close = function()
4691 return print("超出范围")
4692 end
4693})
4694local tb = setmetatable({ }, {
4695 ["value"] = 123
4696})
4697getmetatable(tb).__index = getmetatable(tb)
4698print(tb.value)
4699setmetatable(tb, {
4700 __index = {
4701 item = "hello"
4702 }
4703})
4704print(tb.item)
4705local item, new, close, getter
4706do
4707 local _obj_0 = tb
4708 item, new = _obj_0[1], _obj_0.new
4709 do
4710 local _obj_1 = getmetatable(_obj_0)
4711 close, getter = _obj_1.__close, _obj_1.__index
4712 end
4713end
4714print(item, new, close, getter)
4715do
4716 local _obj_0 = func
4717 if _obj_0 ~= nil then
4718 _obj_0()
4719 end
4720end
4721print((function()
4722 local _obj_0 = abc
4723 if _obj_0 ~= nil then
4724 local _obj_1 = _obj_0["你好 世界"]
4725 if _obj_1 ~= nil then
4726 return _obj_1.xyz
4727 end
4728 return nil
4729 end
4730 return nil
4731end)())
4732local x
4733do
4734 local _obj_0 = tab
4735 if _obj_0 ~= nil then
4736 x = _obj_0.value
4737 end
4738end
4739local len = (function()
4740 local _obj_0 = utf8
4741 if _obj_0 ~= nil then
4742 return _obj_0.len
4743 end
4744 return nil
4745end)() or (function()
4746 local _obj_0 = string
4747 if _obj_0 ~= nil then
4748 return _obj_0.len
4749 end
4750 return nil
4751end)() or function(o)
4752 return #o
4753end
4754if print and (x ~= nil) then
4755 print(x)
4756end
4757local _with_0 = io.open("test.txt", "w")
4758if _with_0 ~= nil then
4759 _with_0:write("你好")
4760 _with_0:close()
4761end
4762print("你好")
4763print(1, 2)
4764print(1, 2, 3)
4765print(render(emit(parse(extract(readFile("example.txt"), language, { }), language))))
4766local a, b, c, d
4767if b ~= nil then
4768 a = b
4769else
4770 if c ~= nil then
4771 a = c
4772 else
4773 a = d
4774 end
4775end
4776func((function()
4777 if a ~= nil then
4778 return a
4779 else
4780 return { }
4781 end
4782end)())
4783if a == nil then
4784 a = false
4785end
4786local list = {
4787 1,
4788 2,
4789 3
4790}
4791func({
4792 1,
4793 2,
4794 3
4795})
4796local f
4797f = function()
4798 return {
4799 1,
4800 2,
4801 3
4802 }
4803end
4804local tb = {
4805 name = "abc",
4806 values = {
4807 "a",
4808 "b",
4809 "c"
4810 },
4811 objects = {
4812 {
4813 name = "a",
4814 value = 1,
4815 func = function(self)
4816 return self.value + 1
4817 end,
4818 tb = {
4819 fieldA = 1
4820 }
4821 },
4822 {
4823 name = "b",
4824 value = 2,
4825 func = function(self)
4826 return self.value + 2
4827 end,
4828 tb = { }
4829 }
4830 }
4831}
4832if tb ~= nil then
4833 tb:func()
4834end
4835if tb ~= nil then
4836 tb:func()
4837end
4838print(1 < 2 and 2 <= 2 and 2 < 3 and 3 == 3 and 3 > 2 and 2 >= 1 and 1 == 1 and 1 < 3 and 3 ~= 5)
4839local a = 5
4840print(1 <= a and a <= 10)
4841local v
4842v = function(x)
4843 print(x)
4844 return x
4845end
4846print((function()
4847 local _cond_0 = v(2)
4848 if not (v(1) < _cond_0) then
4849 return false
4850 else
4851 return _cond_0 <= v(3)
4852 end
4853end)())
4854print((function()
4855 local _cond_0 = v(2)
4856 if not (v(1) > _cond_0) then
4857 return false
4858 else
4859 return _cond_0 <= v(3)
4860 end
4861end)())
4862local tab = { }
4863tab[#tab + 1] = "Value"
4864local tbA = {
4865 1,
4866 2,
4867 3
4868}
4869local tbB = {
4870 4,
4871 5,
4872 6
4873}
4874local _len_0 = #tbA + 1
4875for _index_0 = 1, #tbB do
4876 local _elm_0 = tbB[_index_0]
4877 tbA[_len_0], _len_0 = _elm_0, _len_0 + 1
4878end
4879local parts = {
4880 "shoulders",
4881 "knees"
4882}
4883local lyrics
4884do
4885 local _tab_0 = {
4886 "head"
4887 }
4888 local _idx_0 = 1
4889 for _key_0, _value_0 in pairs(parts) do
4890 if _idx_0 == _key_0 then
4891 _tab_0[#_tab_0 + 1] = _value_0
4892 _idx_0 = _idx_0 + 1
4893 else
4894 _tab_0[_key_0] = _value_0
4895 end
4896 end
4897 _tab_0[#_tab_0 + 1] = "and"
4898 _tab_0[#_tab_0 + 1] = "toes"
4899 lyrics = _tab_0
4900end
4901local copy
4902do
4903 local _tab_0 = { }
4904 local _idx_0 = 1
4905 for _key_0, _value_0 in pairs(other) do
4906 if _idx_0 == _key_0 then
4907 _tab_0[#_tab_0 + 1] = _value_0
4908 _idx_0 = _idx_0 + 1
4909 else
4910 _tab_0[_key_0] = _value_0
4911 end
4912 end
4913 copy = _tab_0
4914end
4915local a = {
4916 1,
4917 2,
4918 3,
4919 x = 1
4920}
4921local b = {
4922 4,
4923 5,
4924 y = 1
4925}
4926local merge
4927local _tab_0 = { }
4928local _idx_0 = 1
4929for _key_0, _value_0 in pairs(a) do
4930 if _idx_0 == _key_0 then
4931 _tab_0[#_tab_0 + 1] = _value_0
4932 _idx_0 = _idx_0 + 1
4933 else
4934 _tab_0[_key_0] = _value_0
4935 end
4936end
4937local _idx_1 = 1
4938for _key_0, _value_0 in pairs(b) do
4939 if _idx_1 == _key_0 then
4940 _tab_0[#_tab_0 + 1] = _value_0
4941 _idx_1 = _idx_1 + 1
4942 else
4943 _tab_0[_key_0] = _value_0
4944 end
4945end
4946merge = _tab_0
4947local last
4948do
4949 local _item_0 = data.items
4950 last = _item_0[#_item_0]
4951end
4952local second_last
4953do
4954 local _item_0 = data.items
4955 second_last = _item_0[#_item_0 - 1]
4956end
4957local _obj_0 = data.items
4958_obj_0[#_obj_0] = 1
4959local mt = { }
4960local add
4961add = function(self, right)
4962 return setmetatable({
4963 value = self.value + right.value
4964 }, mt)
4965end
4966mt.__add = add
4967local a = setmetatable({
4968 value = 1
4969}, mt)
4970local b = setmetatable({
4971 value = 2
4972}, {
4973 __add = add
4974})
4975local c = setmetatable({
4976 value = 3
4977}, {
4978 __add = mt.__add
4979})
4980local d = a + b + c
4981print(d.value)
4982local _ <close> = setmetatable({ }, {
4983 __close = function()
4984 return print("超出范围")
4985 end
4986})
4987local tb = setmetatable({ }, {
4988 ["value"] = 123
4989})
4990getmetatable(tb).__index = getmetatable(tb)
4991print(tb.value)
4992setmetatable(tb, {
4993 __index = {
4994 item = "hello"
4995 }
4996})
4997print(tb.item)
4998local item, new, close, getter
4999do
5000 local _obj_0 = tb
5001 item, new = _obj_0[1], _obj_0.new
5002 do
5003 local _obj_1 = getmetatable(_obj_0)
5004 close, getter = _obj_1.__close, _obj_1.__index
5005 end
5006end
5007print(item, new, close, getter)
5008do
5009 local _obj_0 = func
5010 if _obj_0 ~= nil then
5011 _obj_0()
5012 end
5013end
5014print((function()
5015 local _obj_0 = abc
5016 if _obj_0 ~= nil then
5017 local _obj_1 = _obj_0["你好 世界"]
5018 if _obj_1 ~= nil then
5019 return _obj_1.xyz
5020 end
5021 return nil
5022 end
5023 return nil
5024end)())
5025local x
5026do
5027 local _obj_0 = tab
5028 if _obj_0 ~= nil then
5029 x = _obj_0.value
5030 end
5031end
5032local len = (function()
5033 local _obj_0 = utf8
5034 if _obj_0 ~= nil then
5035 return _obj_0.len
5036 end
5037 return nil
5038end)() or (function()
5039 local _obj_0 = string
5040 if _obj_0 ~= nil then
5041 return _obj_0.len
5042 end
5043 return nil
5044end)() or function(o)
5045 return #o
5046end
5047if print and (x ~= nil) then
5048 print(x)
5049end
5050local _with_0 = io.open("test.txt", "w")
5051if _with_0 ~= nil then
5052 _with_0:write("你好")
5053 _with_0:close()
5054end
5055print("你好")
5056print(1, 2)
5057print(1, 2, 3)
5058print(render(emit(parse(extract(readFile("example.txt"), language, { }), language))))
5059local a, b, c, d
5060if b ~= nil then
5061 a = b
5062else
5063 if c ~= nil then
5064 a = c
5065 else
5066 a = d
5067 end
5068end
5069func((function()
5070 if a ~= nil then
5071 return a
5072 else
5073 return { }
5074 end
5075end)())
5076if a == nil then
5077 a = false
5078end
5079local list = {
5080 1,
5081 2,
5082 3
5083}
5084func({
5085 1,
5086 2,
5087 3
5088})
5089local f
5090f = function()
5091 return {
5092 1,
5093 2,
5094 3
5095 }
5096end
5097local tb = {
5098 name = "abc",
5099 values = {
5100 "a",
5101 "b",
5102 "c"
5103 },
5104 objects = {
5105 {
5106 name = "a",
5107 value = 1,
5108 func = function(self)
5109 return self.value + 1
5110 end,
5111 tb = {
5112 fieldA = 1
5113 }
5114 },
5115 {
5116 name = "b",
5117 value = 2,
5118 func = function(self)
5119 return self.value + 2
5120 end,
5121 tb = { }
5122 }
5123 }
5124}
5125local some_string = "这是一个字符串\n 并包括一个换行。"
5126print("我有" .. tostring(math.random() * 100) .. "%的把握。")
5127local integer = 1000000
5128local hex = 0xEFBBBF
5129local binary = 19
5130local str = "key: value\nlist:\n - item1\n - " .. tostring(expr)
5131local fn
5132fn = function()
5133 local str = "foo:\n bar: baz"
5134 return str
5135end
5136local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'"
5137local some_string = "这是一个字符串\n 并包括一个换行。"
5138print("我有" .. tostring(math.random() * 100) .. "%的把握。")
5139local integer = 1000000
5140local hex = 0xEFBBBF
5141local binary = 19
5142local str = "key: value\nlist:\n - item1\n - " .. tostring(expr)
5143local fn
5144fn = function()
5145 local str = "foo:\n bar: baz"
5146 return str
5147end
5148local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'"
diff --git a/spec/outputs/compile_doc.lua b/spec/outputs/compile_doc.lua
index cb359a1..6a5efd5 100644
--- a/spec/outputs/compile_doc.lua
+++ b/spec/outputs/compile_doc.lua
@@ -1,74 +1,70 @@
1local outputFolder = ... 1local outputFolder = ...
2local _list_0 = { 2local getFiles
3 { 3getFiles = function(locale)
4 "codes_from_doc.lua", 4 if locale == "en" then
5 { 5 locale = ""
6 "doc/docs/doc/introduction.md", 6 else
7 "doc/docs/doc/macro.md", 7 locale = tostring(locale) .. "/"
8 "doc/docs/doc/operator.md", 8 end
9 "doc/docs/doc/module.md", 9 return {
10 "doc/docs/doc/assignment.md", 10 "doc/docs/" .. tostring(locale) .. "doc/index.md",
11 "doc/docs/doc/destructuring-assignment.md", 11 "doc/docs/" .. tostring(locale) .. "doc/advanced/do.md",
12 "doc/docs/doc/if-assignment.md", 12 "doc/docs/" .. tostring(locale) .. "doc/advanced/line-decorators.md",
13 "doc/docs/doc/varargs-assignment.md", 13 "doc/docs/" .. tostring(locale) .. "doc/advanced/macro.md",
14 "doc/docs/doc/whitespace.md", 14 "doc/docs/" .. tostring(locale) .. "doc/advanced/module.md",
15 "doc/docs/doc/comment.md", 15 "doc/docs/" .. tostring(locale) .. "doc/advanced/try.md",
16 "doc/docs/doc/try.md", 16 "doc/docs/" .. tostring(locale) .. "doc/data-structures/table-literals.md",
17 "doc/docs/doc/attributes.md", 17 "doc/docs/" .. tostring(locale) .. "doc/data-structures/comprehensions.md",
18 "doc/docs/doc/literals.md", 18 "doc/docs/" .. tostring(locale) .. "doc/objects/object-oriented-programming.md",
19 "doc/docs/doc/function-literals.md", 19 "doc/docs/" .. tostring(locale) .. "doc/objects/with-statement.md",
20 "doc/docs/doc/backcalls.md", 20 "doc/docs/" .. tostring(locale) .. "doc/assignment/assignment.md",
21 "doc/docs/doc/table-literals.md", 21 "doc/docs/" .. tostring(locale) .. "doc/assignment/varargs-assignment.md",
22 "doc/docs/doc/comprehensions.md", 22 "doc/docs/" .. tostring(locale) .. "doc/assignment/if-assignment.md",
23 "doc/docs/doc/for-loop.md", 23 "doc/docs/" .. tostring(locale) .. "doc/assignment/destructuring-assignment.md",
24 "doc/docs/doc/while-loop.md", 24 "doc/docs/" .. tostring(locale) .. "doc/assignment/the-using-clause-controlling-destructive-assignment.md",
25 "doc/docs/doc/continue.md", 25 "doc/docs/" .. tostring(locale) .. "doc/getting-started/usage.md",
26 "doc/docs/doc/conditionals.md", 26 "doc/docs/" .. tostring(locale) .. "doc/getting-started/introduction.md",
27 "doc/docs/doc/line-decorators.md", 27 "doc/docs/" .. tostring(locale) .. "doc/getting-started/installation.md",
28 "doc/docs/doc/switch.md", 28 "doc/docs/" .. tostring(locale) .. "doc/control-flow/conditionals.md",
29 "doc/docs/doc/object-oriented-programming.md", 29 "doc/docs/" .. tostring(locale) .. "doc/control-flow/for-loop.md",
30 "doc/docs/doc/with-statement.md", 30 "doc/docs/" .. tostring(locale) .. "doc/control-flow/continue.md",
31 "doc/docs/doc/do.md", 31 "doc/docs/" .. tostring(locale) .. "doc/control-flow/switch.md",
32 "doc/docs/doc/function-stubs.md", 32 "doc/docs/" .. tostring(locale) .. "doc/control-flow/while-loop.md",
33 "doc/docs/doc/the-using-clause-controlling-destructive-assignment.md" 33 "doc/docs/" .. tostring(locale) .. "doc/functions/function-stubs.md",
34 } 34 "doc/docs/" .. tostring(locale) .. "doc/functions/backcalls.md",
35 }, 35 "doc/docs/" .. tostring(locale) .. "doc/functions/function-literals.md",
36 { 36 "doc/docs/" .. tostring(locale) .. "doc/language-basics/whitespace.md",
37 "codes_from_doc_zh.lua", 37 "doc/docs/" .. tostring(locale) .. "doc/language-basics/comment.md",
38 { 38 "doc/docs/" .. tostring(locale) .. "doc/language-basics/attributes.md",
39 "doc/docs/zh/doc/introduction.md", 39 "doc/docs/" .. tostring(locale) .. "doc/language-basics/operator.md",
40 "doc/docs/zh/doc/macro.md", 40 "doc/docs/" .. tostring(locale) .. "doc/language-basics/literals.md",
41 "doc/docs/zh/doc/operator.md", 41 "doc/docs/" .. tostring(locale) .. "doc/reference/license-mit.md",
42 "doc/docs/zh/doc/module.md", 42 "doc/docs/" .. tostring(locale) .. "doc/reference/the-yuescript-library.md"
43 "doc/docs/zh/doc/assignment.md", 43 }
44 "doc/docs/zh/doc/destructuring-assignment.md", 44end
45 "doc/docs/zh/doc/if-assignment.md", 45local docs
46 "doc/docs/zh/doc/varargs-assignment.md", 46do
47 "doc/docs/zh/doc/whitespace.md", 47 local _accum_0 = { }
48 "doc/docs/zh/doc/comment.md", 48 local _len_0 = 1
49 "doc/docs/zh/doc/try.md", 49 local _list_0 = {
50 "doc/docs/zh/doc/attributes.md", 50 "en",
51 "doc/docs/zh/doc/literals.md", 51 "zh",
52 "doc/docs/zh/doc/function-literals.md", 52 "pt-br",
53 "doc/docs/zh/doc/backcalls.md", 53 "de",
54 "doc/docs/zh/doc/table-literals.md", 54 "id-id"
55 "doc/docs/zh/doc/comprehensions.md",
56 "doc/docs/zh/doc/for-loop.md",
57 "doc/docs/zh/doc/while-loop.md",
58 "doc/docs/zh/doc/continue.md",
59 "doc/docs/zh/doc/conditionals.md",
60 "doc/docs/zh/doc/line-decorators.md",
61 "doc/docs/zh/doc/switch.md",
62 "doc/docs/zh/doc/object-oriented-programming.md",
63 "doc/docs/zh/doc/with-statement.md",
64 "doc/docs/zh/doc/do.md",
65 "doc/docs/zh/doc/function-stubs.md",
66 "doc/docs/zh/doc/the-using-clause-controlling-destructive-assignment.md"
67 }
68 } 55 }
69} 56 for _index_0 = 1, #_list_0 do
70for _index_0 = 1, #_list_0 do 57 local locale = _list_0[_index_0]
71 local _des_0 = _list_0[_index_0] 58 _accum_0[_len_0] = {
59 "codes_from_doc_" .. tostring(locale) .. ".lua",
60 getFiles(locale)
61 }
62 _len_0 = _len_0 + 1
63 end
64 docs = _accum_0
65end
66for _index_0 = 1, #docs do
67 local _des_0 = docs[_index_0]
72 local compiledFile, docFiles = _des_0[1], _des_0[2] 68 local compiledFile, docFiles = _des_0[1], _des_0[2]
73 local codes = { } 69 local codes = { }
74 for _index_1 = 1, #docFiles do 70 for _index_1 = 1, #docFiles do
diff --git a/spec/outputs/test/format_spec.lua b/spec/outputs/test/format_spec.lua
index bb31d50..3e98e4a 100644
--- a/spec/outputs/test/format_spec.lua
+++ b/spec/outputs/test/format_spec.lua
@@ -185,7 +185,7 @@ return describe("format", function()
185 local original_ast = yue.to_ast(code) 185 local original_ast = yue.to_ast(code)
186 assert.is_not_nil(original_ast) 186 assert.is_not_nil(original_ast)
187 rewriteLineCol(original_ast) 187 rewriteLineCol(original_ast)
188 local formated = yue.format(code, 0, false) 188 local formated = yue.format(code, 0, true)
189 local ast = yue.to_ast(formated) 189 local ast = yue.to_ast(formated)
190 assert.is_not_nil(ast) 190 assert.is_not_nil(ast)
191 rewriteLineCol(ast) 191 rewriteLineCol(ast)
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp
index bcc44d2..eb31ab5 100644
--- a/src/yuescript/yue_compiler.cpp
+++ b/src/yuescript/yue_compiler.cpp
@@ -78,7 +78,7 @@ static std::unordered_set<std::string> Metamethods = {
78 "close"s // Lua 5.4 78 "close"s // Lua 5.4
79}; 79};
80 80
81const std::string_view version = "0.32.8"sv; 81const std::string_view version = "0.32.9"sv;
82const std::string_view extension = "yue"sv; 82const std::string_view extension = "yue"sv;
83 83
84class CompileError : public std::logic_error { 84class CompileError : public std::logic_error {
diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp
index 194d04d..3d8e315 100644
--- a/src/yuescript/yue_parser.cpp
+++ b/src/yuescript/yue_parser.cpp
@@ -1149,7 +1149,7 @@ YueParser::YueParser() {
1149 check_indent >> comment_line >> and_(stop) | 1149 check_indent >> comment_line >> and_(stop) |
1150 advance >> ensure(comment_line, pop_indent) >> and_(stop); 1150 advance >> ensure(comment_line, pop_indent) >> and_(stop);
1151 1151
1152 EmptyLine = plain_space >> and_(stop); 1152 EmptyLine = +(*set(" \t") >> line_break);
1153 1153
1154 indentation_error = pl::user(not_(pipe_operator | eof()), [](const item_t& item) { 1154 indentation_error = pl::user(not_(pipe_operator | eof()), [](const item_t& item) {
1155 RaiseError("unexpected indent"sv, item); 1155 RaiseError("unexpected indent"sv, item);
@@ -1161,7 +1161,7 @@ YueParser::YueParser() {
1161 return st->lax; 1161 return st->lax;
1162 }); 1162 });
1163 1163
1164 line = *(EmptyLine >> line_break) >> ( 1164 line = -EmptyLine >> (
1165 check_indent_match >> space >> Statement >> *(';' >> space >> (Statement | not_(';'))) | 1165 check_indent_match >> space >> Statement >> *(';' >> space >> (Statement | not_(';'))) |
1166 YueComment | 1166 YueComment |
1167 advance_match >> ensure(space >> (indentation_error | Statement), pop_indent) 1167 advance_match >> ensure(space >> (indentation_error | Statement), pop_indent)