aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2023-10-31 17:06:43 +0800
committerLi Jin <dragon-fly@qq.com>2023-10-31 17:06:50 +0800
commit9908433cc0d493c6910d0aed5cdf263397cee87f (patch)
tree4a62db9fc0d49e9a05ce9cb1e35bb956c9b03b3b /spec
parentca6f13ea62e1fb566a604a00176beb6dda0dcb1a (diff)
downloadyuescript-9908433cc0d493c6910d0aed5cdf263397cee87f.tar.gz
yuescript-9908433cc0d493c6910d0aed5cdf263397cee87f.tar.bz2
yuescript-9908433cc0d493c6910d0aed5cdf263397cee87f.zip
add doc codes check.
Diffstat (limited to 'spec')
-rw-r--r--spec/inputs/compile_doc.yue24
-rw-r--r--spec/outputs/codes_from_doc.lua4156
-rw-r--r--spec/outputs/codes_from_doc_zh.lua4144
-rw-r--r--spec/outputs/compile_doc.lua57
4 files changed, 8381 insertions, 0 deletions
diff --git a/spec/inputs/compile_doc.yue b/spec/inputs/compile_doc.yue
new file mode 100644
index 0000000..4ce2b13
--- /dev/null
+++ b/spec/inputs/compile_doc.yue
@@ -0,0 +1,24 @@
1outputFolder = ...
2for [compiledFile, docFile] in *[
3 ["codes_from_doc.lua", "doc/docs/doc/README.md"]
4 ["codes_from_doc_zh.lua", "doc/docs/zh/doc/README.md"]
5 ]
6 close input = with? io.open docFile
7 import "yue" as :to_lua
8 text = \read "*a"
9 codes = []
10 for code in text\gmatch "```moonscript(.-)```"
11 if result, err = to_lua code, implicit_return_root: false, reserve_line_number: false
12 codes[] = result
13 elseif not err\match "macro exporting module only accepts macro definition"
14 print err
15 os.exit 1
16 for code in text\gmatch "<pre>(.-)</pre>"
17 if result, err = to_lua code\gsub("&lt;", "<")\gsub("&gt;", ">"), implicit_return_root: false, reserve_line_number: false
18 codes[] = result
19 else
20 print err
21 os.exit 1
22 close output = with io.open "#{outputFolder}/#{compiledFile}", "w+"
23 \write table.concat codes
24
diff --git a/spec/outputs/codes_from_doc.lua b/spec/outputs/codes_from_doc.lua
new file mode 100644
index 0000000..1bcc587
--- /dev/null
+++ b/spec/outputs/codes_from_doc.lua
@@ -0,0 +1,4156 @@
1local _module_0 = { }
2local p, to_lua
3do
4 local _obj_0 = require("yue")
5 p, to_lua = _obj_0.p, _obj_0.to_lua
6end
7local inventory = {
8 equipment = {
9 "sword",
10 "shield"
11 },
12 items = {
13 {
14 name = "potion",
15 count = 10
16 },
17 {
18 name = "bread",
19 count = 3
20 }
21 }
22}
23print(reduce(filter(map({
24 1,
25 2,
26 3
27}, function(x)
28 return x * 2
29end), function(x)
30 return x > 4
31end), 0, function(a, b)
32 return a + b
33end))
34local apple = setmetatable({
35 size = 15,
36}, {
37 __index = {
38 color = 0x00ffff
39 }
40})
41if (getmetatable(apple) ~= nil) then
42 p(apple.color, getmetatable(apple).__index)
43end
44local _ud83c_udf1b = "月之脚本"
45_module_0["🌛"] = _ud83c_udf1b
46return _module_0
47local area = 6.2831853071796 * 5
48print('hello world')
49assert(item ~= nil)
50local value = item
51if (f1() and f2() and f3()) then
52 print("OK")
53end
54local funcA
55funcA = function() end
56funcA = function()
57 return "assign the Yue defined variable"
58end
59local function funcB() end
60funcB = function()
61 return "assign the Lua defined variable"
62end
63-- raw Lua codes insertion
64if cond then
65 print("output")
66end
67print("yuescript")
68print(3)
69if tb ~= nil then
70 tb:func()
71end
72if tb ~= nil then
73 tb:func()
74end
75print(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)
76local a = 5
77print(1 <= a and a <= 10)
78local v
79v = function(x)
80 print(x)
81 return x
82end
83print((function()
84 local _cond_0 = v(2)
85 if not (v(1) < _cond_0) then
86 return false
87 else
88 return _cond_0 <= v(3)
89 end
90end)())
91print((function()
92 local _cond_0 = v(2)
93 if not (v(1) > _cond_0) then
94 return false
95 else
96 return _cond_0 <= v(3)
97 end
98end)())
99local tab = { }
100tab[#tab + 1] = "Value"
101local parts = {
102 "shoulders",
103 "knees"
104}
105local lyrics
106do
107 local _tab_0 = {
108 "head"
109 }
110 local _idx_0 = 1
111 for _key_0, _value_0 in pairs(parts) do
112 if _idx_0 == _key_0 then
113 _tab_0[#_tab_0 + 1] = _value_0
114 _idx_0 = _idx_0 + 1
115 else
116 _tab_0[_key_0] = _value_0
117 end
118 end
119 _tab_0[#_tab_0 + 1] = "and"
120 _tab_0[#_tab_0 + 1] = "toes"
121 lyrics = _tab_0
122end
123local copy
124do
125 local _tab_0 = { }
126 local _idx_0 = 1
127 for _key_0, _value_0 in pairs(other) do
128 if _idx_0 == _key_0 then
129 _tab_0[#_tab_0 + 1] = _value_0
130 _idx_0 = _idx_0 + 1
131 else
132 _tab_0[_key_0] = _value_0
133 end
134 end
135 copy = _tab_0
136end
137local a = {
138 1,
139 2,
140 3,
141 x = 1
142}
143local b = {
144 4,
145 5,
146 y = 1
147}
148local merge
149do
150 local _tab_0 = { }
151 local _idx_0 = 1
152 for _key_0, _value_0 in pairs(a) do
153 if _idx_0 == _key_0 then
154 _tab_0[#_tab_0 + 1] = _value_0
155 _idx_0 = _idx_0 + 1
156 else
157 _tab_0[_key_0] = _value_0
158 end
159 end
160 local _idx_1 = 1
161 for _key_0, _value_0 in pairs(b) do
162 if _idx_1 == _key_0 then
163 _tab_0[#_tab_0 + 1] = _value_0
164 _idx_1 = _idx_1 + 1
165 else
166 _tab_0[_key_0] = _value_0
167 end
168 end
169 merge = _tab_0
170end
171local mt = { }
172local add
173add = function(self, right)
174 return setmetatable({
175 value = self.value + right.value
176 }, mt)
177end
178mt.__add = add
179local a = setmetatable({
180 value = 1
181}, mt)
182local b = setmetatable({
183 value = 2
184}, {
185 __add = add
186})
187local c = setmetatable({
188 value = 3
189}, {
190 __add = mt.__add
191})
192local d = a + b + c
193print(d.value)
194local _ <close> = setmetatable({ }, {
195 __close = function()
196 return print("out of scope")
197 end
198})
199local tb = setmetatable({ }, {
200 ["value"] = 123
201})
202getmetatable(tb).__index = getmetatable(tb)
203print(tb.value)
204setmetatable(tb, {
205 __index = {
206 item = "hello"
207 }
208})
209print(tb.item)
210local item, new, close, getter
211do
212 local _obj_0 = tb
213 item, new = _obj_0[1], _obj_0.new
214 do
215 local _obj_1 = getmetatable(_obj_0)
216 close, getter = _obj_1.__close, _obj_1.__index
217 end
218end
219print(item, new, close, getter)
220do
221 local _obj_0 = func
222 if _obj_0 ~= nil then
223 _obj_0()
224 end
225end
226print((function()
227 local _obj_0 = abc
228 if _obj_0 ~= nil then
229 local _obj_1 = _obj_0["hello world"]
230 if _obj_1 ~= nil then
231 return _obj_1.xyz
232 end
233 return nil
234 end
235 return nil
236end)())
237local x
238do
239 local _obj_0 = tab
240 if _obj_0 ~= nil then
241 x = _obj_0.value
242 end
243end
244local len = (function()
245 local _obj_0 = utf8
246 if _obj_0 ~= nil then
247 return _obj_0.len
248 end
249 return nil
250end)() or (function()
251 local _obj_0 = string
252 if _obj_0 ~= nil then
253 return _obj_0.len
254 end
255 return nil
256end)() or function(o)
257 return #o
258end
259if print and (x ~= nil) then
260 print(x)
261end
262do
263 local _with_0 = io.open("test.txt", "w")
264 if _with_0 ~= nil then
265 _with_0:write("hello")
266 _with_0:close()
267 end
268end
269print("hello")
270print(1, 2)
271print(1, 2, 3)
272print(render(emit(parse(extract(readFile("example.txt"), language, { }), language))))
273local a, b, c, d
274if b ~= nil then
275 a = b
276else
277 if c ~= nil then
278 a = c
279 else
280 a = d
281 end
282end
283func((function()
284 if a ~= nil then
285 return a
286 else
287 return { }
288 end
289end)())
290if a == nil then
291 a = false
292end
293local list = {
294 1,
295 2,
296 3
297}
298func({
299 1,
300 2,
301 3
302})
303local tb = {
304 name = "abc",
305 values = {
306 "a",
307 "b",
308 "c"
309 },
310 objects = {
311 {
312 name = "a",
313 value = 1,
314 func = function(self)
315 return self.value + 1
316 end,
317 tb = {
318 fieldA = 1
319 }
320 },
321 {
322 name = "b",
323 value = 2,
324 func = function(self)
325 return self.value + 2
326 end,
327 tb = { }
328 }
329 }
330}
331do
332 local insert, concat = table.insert, table.concat
333 local C, Ct, Cmt
334 do
335 local _obj_0 = require("lpeg")
336 C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt
337 end
338 local x, y, z
339 do
340 local _obj_0 = require('mymodule')
341 x, y, z = _obj_0.x, _obj_0.y, _obj_0.z
342 end
343 local a, b, c
344 do
345 local _obj_0 = require('module')
346 a, b, c = _obj_0.a, _obj_0.b, _obj_0.c
347 end
348end
349do
350 local module = require('module')
351 local module_x = require('module_x')
352 local d_a_s_h_e_s = require("d-a-s-h-e-s")
353 local part = require("module.part")
354end
355do
356 local PlayerModule = require("player")
357 local C, Ct, Cmt
358 do
359 local _obj_0 = require("lpeg")
360 C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt
361 end
362 local one, two, ch
363 do
364 local _obj_0 = require("export")
365 one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1]
366 end
367end
368local _module_0 = { }
369local a, b, c = 1, 2, 3
370_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c
371local cool = "cat"
372_module_0["cool"] = cool
373local What
374if this then
375 What = "abc"
376else
377 What = "def"
378end
379_module_0["What"] = What
380local y
381y = function()
382 local hallo = 3434
383end
384_module_0["y"] = y
385local Something
386do
387 local _class_0
388 local _base_0 = {
389 umm = "cool"
390 }
391 if _base_0.__index == nil then
392 _base_0.__index = _base_0
393 end
394 _class_0 = setmetatable({
395 __init = function() end,
396 __base = _base_0,
397 __name = "Something"
398 }, {
399 __index = _base_0,
400 __call = function(cls, ...)
401 local _self_0 = setmetatable({ }, _base_0)
402 cls.__init(_self_0, ...)
403 return _self_0
404 end
405 })
406 _base_0.__class = _class_0
407 Something = _class_0
408end
409_module_0["Something"] = Something
410return _module_0
411local _module_0 = { }
412local loadstring, tolua
413do
414 local _obj_0 = yue
415 loadstring, tolua = _obj_0.loadstring, _obj_0.to_lua
416end
417_module_0["loadstring"], _module_0["tolua"] = loadstring, tolua
418local fieldA = tb.itemA.fieldA
419if fieldA == nil then
420 fieldA = 'default'
421end
422_module_0["fieldA"] = fieldA
423return _module_0
424local _module_0 = setmetatable({ }, { })
425_module_0.itemA = tb
426getmetatable(_module_0).__index = items
427_module_0["a-b-c"] = 123
428return _module_0
429local _module_0 = { }
430local d, e, f = 3, 2, 1
431_module_0[#_module_0 + 1] = d
432_module_0[#_module_0 + 1] = e
433_module_0[#_module_0 + 1] = f
434if this then
435 _module_0[#_module_0 + 1] = 123
436else
437 _module_0[#_module_0 + 1] = 456
438end
439do
440 local _with_0 = tmp
441 local j = 2000
442 _module_0[#_module_0 + 1] = _with_0
443end
444return _module_0
445local _module_0 = nil
446_module_0 = function()
447 print("hello")
448 return 123
449end
450return _module_0
451local hello = "world"
452local a, b, c = 1, 2, 3
453hello = 123
454local x = 1
455x = x + 1
456x = x - 1
457x = x * 10
458x = x / 10
459x = x % 10
460local s = s .. "world"
461local arg = arg or "default value"
462local a = 0
463local b = 0
464local c = 0
465local d = 0
466local e = 0
467local x = f()
468local y = x
469local z = x
470do
471 local a
472 a = 1
473 local x, y, z
474 print("forward declare all variables as locals")
475 x = function()
476 return 1 + y + z
477 end
478 y, z = 2, 3
479 instance = Item:new()
480end
481do
482 local X
483 X = 1
484 local B
485 print("only forward declare upper case variables")
486 local a = 1
487 B = 2
488end
489do
490 a = 1
491 print("declare all variables as globals")
492 local x
493 x = function()
494 return 1 + y + z
495 end
496 local y, z = 2, 3
497end
498do
499 X = 1
500 print("only declare upper case variables as globals")
501 local a = 1
502 local B = 2
503 local Temp
504 Temp = "a local value"
505end
506local thing = {
507 1,
508 2
509}
510local a, b = thing[1], thing[2]
511print(a, b)
512local obj = {
513 hello = "world",
514 day = "tuesday",
515 length = 20
516}
517local hello, the_day = obj.hello, obj.day
518print(hello, the_day)
519local day = obj.day
520local obj2 = {
521 numbers = {
522 1,
523 2,
524 3,
525 4
526 },
527 properties = {
528 color = "green",
529 height = 13.5
530 }
531}
532local first, second = obj2.numbers[1], obj2.numbers[2]
533print(first, second, color)
534local first, second, color
535do
536 local _obj_0 = obj2
537 first, second, color = _obj_0.numbers[1], _obj_0.numbers[2], _obj_0.properties.color
538end
539local concat, insert
540do
541 local _obj_0 = table
542 concat, insert = _obj_0.concat, _obj_0.insert
543end
544local mix, max, rand
545do
546 local _obj_0 = math
547 mix, max, rand = _obj_0.mix, _obj_0.max, _obj_0.random
548end
549local name, job
550do
551 local _obj_0 = person
552 name, job = _obj_0.name, _obj_0.job
553 if name == nil then
554 name = "nameless"
555 end
556 if job == nil then
557 job = "jobless"
558 end
559end
560local two, four
561do
562 local _obj_0 = items
563 two, four = _obj_0[2], _obj_0[4]
564end
565local tuples = {
566 {
567 "hello",
568 "world"
569 },
570 {
571 "egg",
572 "head"
573 }
574}
575for _index_0 = 1, #tuples do
576 local _des_0 = tuples[_index_0]
577 local left, right = _des_0[1], _des_0[2]
578 print(left, right)
579end
580do
581 local user = database.find_user("moon")
582 if user then
583 print(user.name)
584 end
585end
586do
587 local hello = os.getenv("hello")
588 if hello then
589 print("You have hello", hello)
590 else
591 do
592 local world = os.getenv("world")
593 if world then
594 print("you have world", world)
595 else
596 print("nothing :(")
597 end
598 end
599 end
600end
601do
602 local success, result = pcall(function()
603 return "get result without problems"
604 end)
605 if success then
606 print(result)
607 end
608end
609print("OK")
610local list = {
611 1,
612 2,
613 3,
614 4,
615 5
616}
617local fn
618fn = function(ok)
619 return ok, table.unpack(list)
620end
621(function(_arg_0, ...)
622 local ok = _arg_0
623 local count = select('#', ...)
624 local first = select(1, ...)
625 return print(ok, count, first)
626end)(fn(true))
627Rx.Observable.fromRange(1, 8):filter(function(x)
628 return x % 2 == 0
629end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
630 return value .. '!'
631end):subscribe(print)
632local str = strA .. strB .. strC
633func(3000, "192.168.1.1")
634xpcall(func, function(err)
635 return print(yue.traceback(err))
636end, 1, 2, 3)
637local success, result = xpcall(func, function(err)
638 return yue.traceback(err)
639end, 1, 2, 3)
640xpcall(func, function(err)
641 return print(yue.traceback(err))
642end, 1, 2, 3)
643success, result = pcall(func, 1, 2, 3)
644pcall(function()
645 print("trying")
646 return func(1, 2, 3)
647end)
648success, result = xpcall(func, function(err)
649 return print(yue.traceback(err))
650end, 1, 2, 3)
651if success then
652 print(result)
653end
654local a <const> = 123
655local _ <close> = setmetatable({ }, {
656 __close = function()
657 return print("Out of scope.")
658 end
659})
660local a, b, c, d
661do
662 local _obj_0 = tb
663 a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
664end
665local some_string = "Here is a string\n that has a line break in it."
666print("I am " .. tostring(math.random() * 100) .. "% sure.")
667local integer = 1000000
668local hex = 0xEFBBBF
669local my_function
670my_function = function() end
671my_function()
672local func_a
673func_a = function()
674 return print("hello world")
675end
676local func_b
677func_b = function()
678 local value = 100
679 return print("The value:", value)
680end
681func_a()
682func_b()
683local sum
684sum = function(x, y)
685 return print("sum", x + y)
686end
687sum(10, 20)
688print(sum(10, 20))
689a(b(c("a", "b", "c")))
690print("x:", sum(10, 20), "y:", sum(30, 40))
691local sum
692sum = function(x, y)
693 return x + y
694end
695print("The sum is ", sum(10, 20))
696local sum
697sum = function(x, y)
698 return x + y
699end
700local mystery
701mystery = function(x, y)
702 return x + y, x - y
703end
704local a, b = mystery(10, 20)
705local func
706func = function(self, num)
707 return self.value + num
708end
709local my_function
710my_function = function(name, height)
711 if name == nil then
712 name = "something"
713 end
714 if height == nil then
715 height = 100
716 end
717 print("Hello I am", name)
718 return print("My height is", height)
719end
720local some_args
721some_args = function(x, y)
722 if x == nil then
723 x = 100
724 end
725 if y == nil then
726 y = x + 1000
727 end
728 return print(x + y)
729end
730local a = x - 10
731local b = x - 10
732local c = x(-y)
733local d = x - z
734local x = func("hello") + 100
735local y = func("hello" + 100)
736my_func(5, 4, 3, 8, 9, 10)
737cool_func(1, 2, 3, 4, 5, 6, 7, 8)
738my_func(5, 6, 7, 6, another_func(6, 7, 8, 9, 1, 2), 5, 4)
739local x = {
740 1,
741 2,
742 3,
743 4,
744 a_func(4, 5, 5, 6),
745 8,
746 9,
747 10
748}
749local y = {
750 my_func(1, 2, 3, 4, 5),
751 5,
752 6,
753 7
754}
755if func(1, 2, 3, "hello", "world") then
756 print("hello")
757 print("I am inside if")
758end
759if func(1, 2, 3, "hello", "world") then
760 print("hello")
761 print("I am inside if")
762end
763f(function()
764 return print("hello")
765end)
766f(function(self)
767 return print(self.value)
768end)
769map(function(x)
770 return x * 2
771end, {
772 1,
773 2,
774 3
775})
776local result, msg
777do
778 result, msg = readAsync("filename.txt", function(data)
779 print(data)
780 return processAsync(data, function(info)
781 return check(info)
782 end)
783 end)
784end
785print(result, msg)
786local some_values = {
787 1,
788 2,
789 3,
790 4
791}
792local some_values = {
793 name = "Bill",
794 age = 200,
795 ["favorite food"] = "rice"
796}
797local profile = {
798 height = "4 feet",
799 shoe_size = 13,
800 favorite_foods = {
801 "ice cream",
802 "donuts"
803 }
804}
805local values = {
806 1,
807 2,
808 3,
809 4,
810 5,
811 6,
812 7,
813 8,
814 name = "superman",
815 occupation = "crime fighting"
816}
817my_function({
818 dance = "Tango",
819 partner = "none"
820})
821local y = {
822 type = "dog",
823 legs = 4,
824 tails = 1
825}
826local tbl = {
827 ["do"] = "something",
828 ["end"] = "hunger"
829}
830local hair = "golden"
831local height = 200
832local person = {
833 hair = hair,
834 height = height,
835 shoe_size = 40
836}
837print_table({
838 hair = hair,
839 height = height
840})
841local t = {
842 [1 + 2] = "hello",
843 ["hello world"] = true
844}
845local some_values = {
846 1,
847 2,
848 3,
849 4
850}
851local list_with_one_element = {
852 1
853}
854local items = {
855 1,
856 2,
857 3,
858 4
859}
860local doubled
861do
862 local _accum_0 = { }
863 local _len_0 = 1
864 for i, item in ipairs(items) do
865 _accum_0[_len_0] = item * 2
866 _len_0 = _len_0 + 1
867 end
868 doubled = _accum_0
869end
870local iter = ipairs(items)
871local slice
872do
873 local _accum_0 = { }
874 local _len_0 = 1
875 for i, item in iter do
876 if i > 1 and i < 3 then
877 _accum_0[_len_0] = item
878 _len_0 = _len_0 + 1
879 end
880 end
881 slice = _accum_0
882end
883local doubled
884do
885 local _accum_0 = { }
886 local _len_0 = 1
887 local _list_0 = items
888 for _index_0 = 1, #_list_0 do
889 local item = _list_0[_index_0]
890 _accum_0[_len_0] = item * 2
891 _len_0 = _len_0 + 1
892 end
893 doubled = _accum_0
894end
895local x_coords = {
896 4,
897 5,
898 6,
899 7
900}
901local y_coords = {
902 9,
903 2,
904 3
905}
906local points
907do
908 local _accum_0 = { }
909 local _len_0 = 1
910 for _index_0 = 1, #x_coords do
911 local x = x_coords[_index_0]
912 for _index_1 = 1, #y_coords do
913 local y = y_coords[_index_1]
914 _accum_0[_len_0] = {
915 x,
916 y
917 }
918 _len_0 = _len_0 + 1
919 end
920 end
921 points = _accum_0
922end
923local evens
924do
925 local _accum_0 = { }
926 local _len_0 = 1
927 for i = 1, 100 do
928 if i % 2 == 0 then
929 _accum_0[_len_0] = i
930 _len_0 = _len_0 + 1
931 end
932 end
933 evens = _accum_0
934end
935local thing = {
936 color = "red",
937 name = "fast",
938 width = 123
939}
940local thing_copy
941do
942 local _tbl_0 = { }
943 for k, v in pairs(thing) do
944 _tbl_0[k] = v
945 end
946 thing_copy = _tbl_0
947end
948local no_color
949do
950 local _tbl_0 = { }
951 for k, v in pairs(thing) do
952 if k ~= "color" then
953 _tbl_0[k] = v
954 end
955 end
956 no_color = _tbl_0
957end
958local numbers = {
959 1,
960 2,
961 3,
962 4
963}
964local sqrts
965do
966 local _tbl_0 = { }
967 for _index_0 = 1, #numbers do
968 local i = numbers[_index_0]
969 _tbl_0[i] = math.sqrt(i)
970 end
971 sqrts = _tbl_0
972end
973local tuples = {
974 {
975 "hello",
976 "world"
977 },
978 {
979 "foo",
980 "bar"
981 }
982}
983local tbl
984do
985 local _tbl_0 = { }
986 for _index_0 = 1, #tuples do
987 local tuple = tuples[_index_0]
988 local _key_0, _val_0 = unpack(tuple)
989 _tbl_0[_key_0] = _val_0
990 end
991 tbl = _tbl_0
992end
993local slice
994do
995 local _accum_0 = { }
996 local _len_0 = 1
997 local _list_0 = items
998 local _max_0 = 5
999 for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
1000 local item = _list_0[_index_0]
1001 _accum_0[_len_0] = item
1002 _len_0 = _len_0 + 1
1003 end
1004 slice = _accum_0
1005end
1006local slice
1007do
1008 local _accum_0 = { }
1009 local _len_0 = 1
1010 local _list_0 = items
1011 for _index_0 = 2, #_list_0 do
1012 local item = _list_0[_index_0]
1013 _accum_0[_len_0] = item
1014 _len_0 = _len_0 + 1
1015 end
1016 slice = _accum_0
1017end
1018local slice
1019do
1020 local _accum_0 = { }
1021 local _len_0 = 1
1022 local _list_0 = items
1023 for _index_0 = 1, #_list_0, 2 do
1024 local item = _list_0[_index_0]
1025 _accum_0[_len_0] = item
1026 _len_0 = _len_0 + 1
1027 end
1028 slice = _accum_0
1029end
1030for i = 10, 20 do
1031 print(i)
1032end
1033for k = 1, 15, 2 do
1034 print(k)
1035end
1036for key, value in pairs(object) do
1037 print(key, value)
1038end
1039do
1040 local _list_0 = items
1041 local _max_0 = 4
1042 for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
1043 local item = _list_0[_index_0]
1044 print(item)
1045 end
1046end
1047local _list_0 = items
1048for _index_0 = 1, #_list_0 do
1049 local item = _list_0[_index_0]
1050 print(item)
1051end
1052for j = 1, 10, 3 do
1053 print(j)
1054end
1055local doubled_evens
1056do
1057 local _accum_0 = { }
1058 local _len_0 = 1
1059 for i = 1, 20 do
1060 if i % 2 == 0 then
1061 _accum_0[_len_0] = i * 2
1062 else
1063 _accum_0[_len_0] = i
1064 end
1065 _len_0 = _len_0 + 1
1066 end
1067 doubled_evens = _accum_0
1068end
1069local func_a
1070func_a = function()
1071 for i = 1, 10 do
1072 print(i)
1073 end
1074end
1075local func_b
1076func_b = function()
1077 local _accum_0 = { }
1078 local _len_0 = 1
1079 for i = 1, 10 do
1080 _accum_0[_len_0] = i
1081 _len_0 = _len_0 + 1
1082 end
1083 return _accum_0
1084end
1085print(func_a())
1086print(func_b())
1087local i = 10
1088repeat
1089 print(i)
1090 i = i - 1
1091until i == 0
1092local i = 10
1093while i > 0 do
1094 print(i)
1095 i = i - 1
1096end
1097while running == true do
1098 my_function()
1099end
1100local i = 10
1101while not (i == 0) do
1102 print(i)
1103 i = i - 1
1104end
1105while not (running == false) do
1106 my_function()
1107end
1108local i = 0
1109while i < 10 do
1110 i = i + 1
1111 if i % 2 == 0 then
1112 goto _continue_0
1113 end
1114 print(i)
1115 ::_continue_0::
1116end
1117local my_numbers = {
1118 1,
1119 2,
1120 3,
1121 4,
1122 5,
1123 6
1124}
1125local odds
1126do
1127 local _accum_0 = { }
1128 local _len_0 = 1
1129 for _index_0 = 1, #my_numbers do
1130 local x = my_numbers[_index_0]
1131 if x % 2 == 1 then
1132 goto _continue_0
1133 end
1134 _accum_0[_len_0] = x
1135 _len_0 = _len_0 + 1
1136 ::_continue_0::
1137 end
1138 odds = _accum_0
1139end
1140local have_coins = false
1141if have_coins then
1142 print("Got coins")
1143else
1144 print("No coins")
1145end
1146local have_coins = false
1147if have_coins then
1148 print("Got coins")
1149else
1150 print("No coins")
1151end
1152local have_coins = false
1153print((function()
1154 if have_coins then
1155 return "Got coins"
1156 else
1157 return "No coins"
1158 end
1159end)())
1160local is_tall
1161is_tall = function(name)
1162 if name == "Rob" then
1163 return true
1164 else
1165 return false
1166 end
1167end
1168local message
1169if is_tall("Rob") then
1170 message = "I am very tall"
1171else
1172 message = "I am not so tall"
1173end
1174print(message)
1175if not (os.date("%A") == "Monday") then
1176 print("it is not Monday!")
1177end
1178if not (math.random() > 0.1) then
1179 print("You're lucky!")
1180end
1181local a = 5
1182if (1 == a or 3 == a or 5 == a or 7 == a) then
1183 print("checking equality with discrete values")
1184end
1185if (function()
1186 local _check_0 = list
1187 for _index_0 = 1, #_check_0 do
1188 if _check_0[_index_0] == a then
1189 return true
1190 end
1191 end
1192 return false
1193end)() then
1194 print("checking if `a` is in a list")
1195end
1196if not (math.random() > 0.1) then
1197 print("You're lucky!")
1198end
1199if name == "Rob" then
1200 print("hello world")
1201end
1202local _list_0 = items
1203for _index_0 = 1, #_list_0 do
1204 local item = _list_0[_index_0]
1205 print("item: ", item)
1206end
1207while game:isRunning() do
1208 game:update()
1209end
1210while not reader:eof() do
1211 reader:parse_line()
1212end
1213local name = "Dan"
1214if "Robert" == name then
1215 print("You are Robert")
1216elseif "Dan" == name or "Daniel" == name then
1217 print("Your name, it's Dan")
1218else
1219 print("I don't know about your name")
1220end
1221local b = 1
1222local next_number
1223if 1 == b then
1224 next_number = 2
1225elseif 2 == b then
1226 next_number = 3
1227else
1228 next_number = error("can't count that high!")
1229end
1230local msg
1231do
1232 local _exp_0 = math.random(1, 5)
1233 if 1 == _exp_0 then
1234 msg = "you are lucky"
1235 elseif 2 == _exp_0 then
1236 msg = "you are almost lucky"
1237 else
1238 msg = "not so lucky"
1239 end
1240end
1241do
1242 local _exp_0 = math.random(1, 5)
1243 if 1 == _exp_0 then
1244 print("you are lucky")
1245 else
1246 print("not so lucky")
1247 end
1248end
1249do
1250 local _exp_0 = math.random(1, 5)
1251 if 1 == _exp_0 then
1252 print("you are lucky")
1253 else
1254 print("not so lucky")
1255 end
1256end
1257local items = {
1258 {
1259 x = 100,
1260 y = 200
1261 },
1262 {
1263 width = 300,
1264 height = 400
1265 }
1266}
1267for _index_0 = 1, #items do
1268 local item = items[_index_0]
1269 do
1270 local _type_0 = type(item)
1271 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1272 local _match_0 = false
1273 if _tab_0 then
1274 local x = item.x
1275 local y = item.y
1276 if x ~= nil and y ~= nil then
1277 _match_0 = true
1278 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
1279 end
1280 end
1281 if not _match_0 then
1282 if _tab_0 then
1283 local width = item.width
1284 local height = item.height
1285 if width ~= nil and height ~= nil then
1286 print("size " .. tostring(width) .. ", " .. tostring(height))
1287 end
1288 end
1289 end
1290 end
1291end
1292local item = { }
1293local x, y = item.pos.x, item.pos.y
1294if x == nil then
1295 x = 50
1296end
1297if y == nil then
1298 y = 200
1299end
1300do
1301 local _type_0 = type(item)
1302 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1303 if _tab_0 then
1304 do
1305 local _obj_0 = item.pos
1306 local _type_1 = type(_obj_0)
1307 if "table" == _type_1 or "userdata" == _type_1 then
1308 x = _obj_0.x
1309 end
1310 end
1311 do
1312 local _obj_0 = item.pos
1313 local _type_1 = type(_obj_0)
1314 if "table" == _type_1 or "userdata" == _type_1 then
1315 y = _obj_0.y
1316 end
1317 end
1318 if x == nil then
1319 x = 50
1320 end
1321 if y == nil then
1322 y = 200
1323 end
1324 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
1325 end
1326end
1327local Inventory
1328do
1329 local _class_0
1330 local _base_0 = {
1331 add_item = function(self, name)
1332 if self.items[name] then
1333 local _obj_0 = self.items
1334 _obj_0[name] = _obj_0[name] + 1
1335 else
1336 self.items[name] = 1
1337 end
1338 end
1339 }
1340 if _base_0.__index == nil then
1341 _base_0.__index = _base_0
1342 end
1343 _class_0 = setmetatable({
1344 __init = function(self)
1345 self.items = { }
1346 end,
1347 __base = _base_0,
1348 __name = "Inventory"
1349 }, {
1350 __index = _base_0,
1351 __call = function(cls, ...)
1352 local _self_0 = setmetatable({ }, _base_0)
1353 cls.__init(_self_0, ...)
1354 return _self_0
1355 end
1356 })
1357 _base_0.__class = _class_0
1358 Inventory = _class_0
1359end
1360local inv = Inventory()
1361inv:add_item("t-shirt")
1362inv:add_item("pants")
1363local Person
1364do
1365 local _class_0
1366 local _base_0 = {
1367 clothes = { },
1368 give_item = function(self, name)
1369 return table.insert(self.clothes, name)
1370 end
1371 }
1372 if _base_0.__index == nil then
1373 _base_0.__index = _base_0
1374 end
1375 _class_0 = setmetatable({
1376 __init = function() end,
1377 __base = _base_0,
1378 __name = "Person"
1379 }, {
1380 __index = _base_0,
1381 __call = function(cls, ...)
1382 local _self_0 = setmetatable({ }, _base_0)
1383 cls.__init(_self_0, ...)
1384 return _self_0
1385 end
1386 })
1387 _base_0.__class = _class_0
1388 Person = _class_0
1389end
1390local a = Person()
1391local b = Person()
1392a:give_item("pants")
1393b:give_item("shirt")
1394local _list_0 = a.clothes
1395for _index_0 = 1, #_list_0 do
1396 local item = _list_0[_index_0]
1397 print(item)
1398end
1399local Person
1400do
1401 local _class_0
1402 local _base_0 = { }
1403 if _base_0.__index == nil then
1404 _base_0.__index = _base_0
1405 end
1406 _class_0 = setmetatable({
1407 __init = function(self)
1408 self.clothes = { }
1409 end,
1410 __base = _base_0,
1411 __name = "Person"
1412 }, {
1413 __index = _base_0,
1414 __call = function(cls, ...)
1415 local _self_0 = setmetatable({ }, _base_0)
1416 cls.__init(_self_0, ...)
1417 return _self_0
1418 end
1419 })
1420 _base_0.__class = _class_0
1421 Person = _class_0
1422end
1423local BackPack
1424do
1425 local _class_0
1426 local _parent_0 = Inventory
1427 local _base_0 = {
1428 size = 10,
1429 add_item = function(self, name)
1430 if #self.items > size then
1431 error("backpack is full")
1432 end
1433 return _class_0.__parent.__base.add_item(self, name)
1434 end
1435 }
1436 for _key_0, _val_0 in pairs(_parent_0.__base) do
1437 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
1438 _base_0[_key_0] = _val_0
1439 end
1440 end
1441 if _base_0.__index == nil then
1442 _base_0.__index = _base_0
1443 end
1444 setmetatable(_base_0, _parent_0.__base)
1445 _class_0 = setmetatable({
1446 __init = function(self, ...)
1447 return _class_0.__parent.__init(self, ...)
1448 end,
1449 __base = _base_0,
1450 __name = "BackPack",
1451 __parent = _parent_0
1452 }, {
1453 __index = function(cls, name)
1454 local val = rawget(_base_0, name)
1455 if val == nil then
1456 local parent = rawget(cls, "__parent")
1457 if parent then
1458 return parent[name]
1459 end
1460 else
1461 return val
1462 end
1463 end,
1464 __call = function(cls, ...)
1465 local _self_0 = setmetatable({ }, _base_0)
1466 cls.__init(_self_0, ...)
1467 return _self_0
1468 end
1469 })
1470 _base_0.__class = _class_0
1471 if _parent_0.__inherited then
1472 _parent_0.__inherited(_parent_0, _class_0)
1473 end
1474 BackPack = _class_0
1475end
1476local Shelf
1477do
1478 local _class_0
1479 local _base_0 = { }
1480 if _base_0.__index == nil then
1481 _base_0.__index = _base_0
1482 end
1483 _class_0 = setmetatable({
1484 __init = function() end,
1485 __base = _base_0,
1486 __name = "Shelf"
1487 }, {
1488 __index = _base_0,
1489 __call = function(cls, ...)
1490 local _self_0 = setmetatable({ }, _base_0)
1491 cls.__init(_self_0, ...)
1492 return _self_0
1493 end
1494 })
1495 _base_0.__class = _class_0
1496 local self = _class_0;
1497 self.__inherited = function(self, child)
1498 return print(self.__name, "was inherited by", child.__name)
1499 end
1500 Shelf = _class_0
1501end
1502local Cupboard
1503do
1504 local _class_0
1505 local _parent_0 = Shelf
1506 local _base_0 = { }
1507 for _key_0, _val_0 in pairs(_parent_0.__base) do
1508 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
1509 _base_0[_key_0] = _val_0
1510 end
1511 end
1512 if _base_0.__index == nil then
1513 _base_0.__index = _base_0
1514 end
1515 setmetatable(_base_0, _parent_0.__base)
1516 _class_0 = setmetatable({
1517 __init = function(self, ...)
1518 return _class_0.__parent.__init(self, ...)
1519 end,
1520 __base = _base_0,
1521 __name = "Cupboard",
1522 __parent = _parent_0
1523 }, {
1524 __index = function(cls, name)
1525 local val = rawget(_base_0, name)
1526 if val == nil then
1527 local parent = rawget(cls, "__parent")
1528 if parent then
1529 return parent[name]
1530 end
1531 else
1532 return val
1533 end
1534 end,
1535 __call = function(cls, ...)
1536 local _self_0 = setmetatable({ }, _base_0)
1537 cls.__init(_self_0, ...)
1538 return _self_0
1539 end
1540 })
1541 _base_0.__class = _class_0
1542 if _parent_0.__inherited then
1543 _parent_0.__inherited(_parent_0, _class_0)
1544 end
1545 Cupboard = _class_0
1546end
1547local MyClass
1548do
1549 local _class_0
1550 local _parent_0 = ParentClass
1551 local _base_0 = {
1552 a_method = function(self)
1553 _class_0.__parent.__base.a_method(self, "hello", "world")
1554 _class_0.__parent.a_method(self, "hello", "world")
1555 _class_0.__parent.a_method(self, "hello", "world")
1556 return assert(_class_0.__parent == ParentClass)
1557 end
1558 }
1559 for _key_0, _val_0 in pairs(_parent_0.__base) do
1560 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
1561 _base_0[_key_0] = _val_0
1562 end
1563 end
1564 if _base_0.__index == nil then
1565 _base_0.__index = _base_0
1566 end
1567 setmetatable(_base_0, _parent_0.__base)
1568 _class_0 = setmetatable({
1569 __init = function(self, ...)
1570 return _class_0.__parent.__init(self, ...)
1571 end,
1572 __base = _base_0,
1573 __name = "MyClass",
1574 __parent = _parent_0
1575 }, {
1576 __index = function(cls, name)
1577 local val = rawget(_base_0, name)
1578 if val == nil then
1579 local parent = rawget(cls, "__parent")
1580 if parent then
1581 return parent[name]
1582 end
1583 else
1584 return val
1585 end
1586 end,
1587 __call = function(cls, ...)
1588 local _self_0 = setmetatable({ }, _base_0)
1589 cls.__init(_self_0, ...)
1590 return _self_0
1591 end
1592 })
1593 _base_0.__class = _class_0
1594 if _parent_0.__inherited then
1595 _parent_0.__inherited(_parent_0, _class_0)
1596 end
1597 MyClass = _class_0
1598end
1599local b = BackPack()
1600assert(b.__class == BackPack)
1601print(BackPack.size)
1602print(BackPack.__name)
1603local Things
1604do
1605 local _class_0
1606 local _base_0 = { }
1607 if _base_0.__index == nil then
1608 _base_0.__index = _base_0
1609 end
1610 _class_0 = setmetatable({
1611 __init = function() end,
1612 __base = _base_0,
1613 __name = "Things"
1614 }, {
1615 __index = _base_0,
1616 __call = function(cls, ...)
1617 local _self_0 = setmetatable({ }, _base_0)
1618 cls.__init(_self_0, ...)
1619 return _self_0
1620 end
1621 })
1622 _base_0.__class = _class_0
1623 local self = _class_0;
1624 self.some_func = function(self)
1625 return print("Hello from", self.__name)
1626 end
1627 Things = _class_0
1628end
1629Things:some_func()
1630assert(Things().some_func == nil)
1631local Counter
1632do
1633 local _class_0
1634 local _base_0 = { }
1635 if _base_0.__index == nil then
1636 _base_0.__index = _base_0
1637 end
1638 _class_0 = setmetatable({
1639 __init = function(self)
1640 self.__class.count = self.__class.count + 1
1641 end,
1642 __base = _base_0,
1643 __name = "Counter"
1644 }, {
1645 __index = _base_0,
1646 __call = function(cls, ...)
1647 local _self_0 = setmetatable({ }, _base_0)
1648 cls.__init(_self_0, ...)
1649 return _self_0
1650 end
1651 })
1652 _base_0.__class = _class_0
1653 local self = _class_0;
1654 self.count = 0
1655 Counter = _class_0
1656end
1657Counter()
1658Counter()
1659print(Counter.count)
1660self.__class:hello(1, 2, 3, 4)
1661local Things
1662do
1663 local _class_0
1664 local _base_0 = { }
1665 if _base_0.__index == nil then
1666 _base_0.__index = _base_0
1667 end
1668 _class_0 = setmetatable({
1669 __init = function() end,
1670 __base = _base_0,
1671 __name = "Things"
1672 }, {
1673 __index = _base_0,
1674 __call = function(cls, ...)
1675 local _self_0 = setmetatable({ }, _base_0)
1676 cls.__init(_self_0, ...)
1677 return _self_0
1678 end
1679 })
1680 _base_0.__class = _class_0
1681 local self = _class_0;
1682 self.class_var = "hello world"
1683 Things = _class_0
1684end
1685local MoreThings
1686do
1687 local _class_0
1688 local secret, log
1689 local _base_0 = {
1690 some_method = function(self)
1691 return log("hello world: " .. secret)
1692 end
1693 }
1694 if _base_0.__index == nil then
1695 _base_0.__index = _base_0
1696 end
1697 _class_0 = setmetatable({
1698 __init = function() end,
1699 __base = _base_0,
1700 __name = "MoreThings"
1701 }, {
1702 __index = _base_0,
1703 __call = function(cls, ...)
1704 local _self_0 = setmetatable({ }, _base_0)
1705 cls.__init(_self_0, ...)
1706 return _self_0
1707 end
1708 })
1709 _base_0.__class = _class_0
1710 local self = _class_0;
1711 secret = 123
1712 log = function(msg)
1713 return print("LOG:", msg)
1714 end
1715 MoreThings = _class_0
1716end
1717assert(self == self)
1718assert(self.__class == self.__class)
1719local some_instance_method
1720some_instance_method = function(self, ...)
1721 return self.__class(...)
1722end
1723local Something
1724do
1725 local _class_0
1726 local _base_0 = { }
1727 if _base_0.__index == nil then
1728 _base_0.__index = _base_0
1729 end
1730 _class_0 = setmetatable({
1731 __init = function(self, foo, bar, biz, baz)
1732 self.foo = foo
1733 self.bar = bar
1734 self.__class.biz = biz
1735 self.__class.baz = baz
1736 end,
1737 __base = _base_0,
1738 __name = "Something"
1739 }, {
1740 __index = _base_0,
1741 __call = function(cls, ...)
1742 local _self_0 = setmetatable({ }, _base_0)
1743 cls.__init(_self_0, ...)
1744 return _self_0
1745 end
1746 })
1747 _base_0.__class = _class_0
1748 Something = _class_0
1749end
1750do
1751 local _class_0
1752 local _base_0 = { }
1753 if _base_0.__index == nil then
1754 _base_0.__index = _base_0
1755 end
1756 _class_0 = setmetatable({
1757 __init = function(self, foo, bar, biz, baz)
1758 self.foo = foo
1759 self.bar = bar
1760 self.__class.biz = biz
1761 self.__class.baz = baz
1762 end,
1763 __base = _base_0,
1764 __name = "Something"
1765 }, {
1766 __index = _base_0,
1767 __call = function(cls, ...)
1768 local _self_0 = setmetatable({ }, _base_0)
1769 cls.__init(_self_0, ...)
1770 return _self_0
1771 end
1772 })
1773 _base_0.__class = _class_0
1774 Something = _class_0
1775end
1776local new
1777new = function(self, fieldA, fieldB)
1778 self.fieldA = fieldA
1779 self.fieldB = fieldB
1780 return self
1781end
1782local obj = new({ }, 123, "abc")
1783print(obj)
1784local x
1785local Bucket
1786do
1787 local _class_0
1788 local _base_0 = {
1789 drops = 0,
1790 add_drop = function(self)
1791 self.drops = self.drops + 1
1792 end
1793 }
1794 if _base_0.__index == nil then
1795 _base_0.__index = _base_0
1796 end
1797 _class_0 = setmetatable({
1798 __init = function() end,
1799 __base = _base_0,
1800 __name = "Bucket"
1801 }, {
1802 __index = _base_0,
1803 __call = function(cls, ...)
1804 local _self_0 = setmetatable({ }, _base_0)
1805 cls.__init(_self_0, ...)
1806 return _self_0
1807 end
1808 })
1809 _base_0.__class = _class_0
1810 Bucket = _class_0
1811 x = _class_0
1812end
1813local BigBucket
1814do
1815 local _class_0
1816 local _parent_0 = Bucket
1817 local _base_0 = {
1818 add_drop = function(self)
1819 self.drops = self.drops + 10
1820 end
1821 }
1822 for _key_0, _val_0 in pairs(_parent_0.__base) do
1823 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
1824 _base_0[_key_0] = _val_0
1825 end
1826 end
1827 if _base_0.__index == nil then
1828 _base_0.__index = _base_0
1829 end
1830 setmetatable(_base_0, _parent_0.__base)
1831 _class_0 = setmetatable({
1832 __init = function(self, ...)
1833 return _class_0.__parent.__init(self, ...)
1834 end,
1835 __base = _base_0,
1836 __name = "BigBucket",
1837 __parent = _parent_0
1838 }, {
1839 __index = function(cls, name)
1840 local val = rawget(_base_0, name)
1841 if val == nil then
1842 local parent = rawget(cls, "__parent")
1843 if parent then
1844 return parent[name]
1845 end
1846 else
1847 return val
1848 end
1849 end,
1850 __call = function(cls, ...)
1851 local _self_0 = setmetatable({ }, _base_0)
1852 cls.__init(_self_0, ...)
1853 return _self_0
1854 end
1855 })
1856 _base_0.__class = _class_0
1857 if _parent_0.__inherited then
1858 _parent_0.__inherited(_parent_0, _class_0)
1859 end
1860 BigBucket = _class_0
1861end
1862assert(Bucket.__name == "BigBucket")
1863local x
1864do
1865 local _class_0
1866 local _base_0 = { }
1867 if _base_0.__index == nil then
1868 _base_0.__index = _base_0
1869 end
1870 _class_0 = setmetatable({
1871 __init = function() end,
1872 __base = _base_0,
1873 __name = "x"
1874 }, {
1875 __index = _base_0,
1876 __call = function(cls, ...)
1877 local _self_0 = setmetatable({ }, _base_0)
1878 cls.__init(_self_0, ...)
1879 return _self_0
1880 end
1881 })
1882 _base_0.__class = _class_0
1883 x = _class_0
1884end
1885local MyIndex = {
1886 __index = {
1887 var = 1
1888 }
1889}
1890local X
1891do
1892 local _class_0
1893 local _base_0 = {
1894 func = function(self)
1895 return print(123)
1896 end
1897 }
1898 local _list_0 = {
1899 MyIndex
1900 }
1901 for _index_0 = 1, #_list_0 do
1902 local _item_0 = _list_0[_index_0]
1903 local _cls_0, _mixin_0 = (_item_0.__base ~= nil), _item_0.__base or _item_0
1904 for _key_0, _val_0 in pairs(_mixin_0) do
1905 if _base_0[_key_0] == nil and (not _cls_0 or not _key_0:match("^__")) then
1906 _base_0[_key_0] = _val_0
1907 end
1908 end
1909 end
1910 if _base_0.__index == nil then
1911 _base_0.__index = _base_0
1912 end
1913 _class_0 = setmetatable({
1914 __init = function() end,
1915 __base = _base_0,
1916 __name = "X"
1917 }, {
1918 __index = _base_0,
1919 __call = function(cls, ...)
1920 local _self_0 = setmetatable({ }, _base_0)
1921 cls.__init(_self_0, ...)
1922 return _self_0
1923 end
1924 })
1925 _base_0.__class = _class_0
1926 X = _class_0
1927end
1928local x = X()
1929print(x.var)
1930local Y
1931do
1932 local _class_0
1933 local _base_0 = { }
1934 local _list_0 = {
1935 X
1936 }
1937 for _index_0 = 1, #_list_0 do
1938 local _item_0 = _list_0[_index_0]
1939 local _cls_0, _mixin_0 = (_item_0.__base ~= nil), _item_0.__base or _item_0
1940 for _key_0, _val_0 in pairs(_mixin_0) do
1941 if _base_0[_key_0] == nil and (not _cls_0 or not _key_0:match("^__")) then
1942 _base_0[_key_0] = _val_0
1943 end
1944 end
1945 end
1946 if _base_0.__index == nil then
1947 _base_0.__index = _base_0
1948 end
1949 _class_0 = setmetatable({
1950 __init = function() end,
1951 __base = _base_0,
1952 __name = "Y"
1953 }, {
1954 __index = _base_0,
1955 __call = function(cls, ...)
1956 local _self_0 = setmetatable({ }, _base_0)
1957 cls.__init(_self_0, ...)
1958 return _self_0
1959 end
1960 })
1961 _base_0.__class = _class_0
1962 Y = _class_0
1963end
1964local y = Y()
1965y:func()
1966assert(y.__class.__parent ~= X)
1967do
1968 local _with_0 = Person()
1969 _with_0.name = "Oswald"
1970 _with_0:add_relative(my_dad)
1971 _with_0:save()
1972 print(_with_0.name)
1973end
1974local file
1975do
1976 local _with_0 = File("favorite_foods.txt")
1977 _with_0:set_encoding("utf8")
1978 file = _with_0
1979end
1980local create_person
1981create_person = function(name, relatives)
1982 local _with_0 = Person()
1983 _with_0.name = name
1984 for _index_0 = 1, #relatives do
1985 local relative = relatives[_index_0]
1986 _with_0:add_relative(relative)
1987 end
1988 return _with_0
1989end
1990local me = create_person("Leaf", {
1991 dad,
1992 mother,
1993 sister
1994})
1995do
1996 local str = "Hello"
1997 print("original:", str)
1998 print("upper:", str:upper())
1999end
2000do
2001 local _with_0 = tb
2002 _with_0[1] = 1
2003 print(_with_0[2])
2004 do
2005 local _with_1 = _with_0[abc]
2006 _with_1[3] = _with_1[2]:func()
2007 _with_1["key-name"] = value
2008 end
2009 _with_0[#_with_0 + 1] = "abc"
2010end
2011do
2012 local var = "hello"
2013 print(var)
2014end
2015print(var)
2016local counter
2017do
2018 local i = 0
2019 counter = function()
2020 i = i + 1
2021 return i
2022 end
2023end
2024print(counter())
2025print(counter())
2026local tbl = {
2027 key = (function()
2028 print("assigning key!")
2029 return 1234
2030 end)()
2031}
2032local my_object = {
2033 value = 1000,
2034 write = function(self)
2035 return print("the value:", self.value)
2036 end
2037}
2038local run_callback
2039run_callback = function(func)
2040 print("running callback...")
2041 return func()
2042end
2043run_callback(my_object.write)
2044run_callback((function()
2045 local _base_0 = my_object
2046 local _fn_0 = _base_0.write
2047 return _fn_0 and function(...)
2048 return _fn_0(_base_0, ...)
2049 end
2050end)())
2051local i = 100
2052local my_func
2053my_func = function()
2054 i = 10
2055 while i > 0 do
2056 print(i)
2057 i = i - 1
2058 end
2059end
2060my_func()
2061print(i)
2062local i = 100
2063local my_func
2064my_func = function()
2065 local i = "hello"
2066end
2067my_func()
2068print(i)
2069local tmp = 1213
2070local i, k = 100, 50
2071local my_func
2072my_func = function(add)
2073 local tmp = tmp + add
2074 i = i + tmp
2075 k = k + tmp
2076end
2077my_func(22)
2078print(i, k)
2079local _module_0 = { }
2080local p, to_lua
2081do
2082 local _obj_0 = require("yue")
2083 p, to_lua = _obj_0.p, _obj_0.to_lua
2084end
2085local inventory = {
2086 equipment = {
2087 "sword",
2088 "shield"
2089 },
2090 items = {
2091 {
2092 name = "potion",
2093 count = 10
2094 },
2095 {
2096 name = "bread",
2097 count = 3
2098 }
2099 }
2100}
2101print(reduce(filter(map({
2102 1,
2103 2,
2104 3
2105}, function(x)
2106 return x * 2
2107end), function(x)
2108 return x > 4
2109end), 0, function(a, b)
2110 return a + b
2111end))
2112local apple = setmetatable({
2113 size = 15,
2114}, {
2115 __index = {
2116 color = 0x00ffff
2117 }
2118})
2119if (getmetatable(apple) ~= nil) then
2120 p(apple.color, getmetatable(apple).__index)
2121end
2122local _ud83c_udf1b = "月之脚本"
2123_module_0["🌛"] = _ud83c_udf1b
2124return _module_0
2125local area = 6.2831853071796 * 5
2126print('hello world')
2127assert(item ~= nil)
2128local value = item
2129if (f1() and f2() and f3()) then
2130 print("OK")
2131end
2132local funcA
2133funcA = function() end
2134funcA = function()
2135 return "assign the Yue defined variable"
2136end
2137local function funcB() end
2138funcB = function()
2139 return "assign the Lua defined variable"
2140end
2141-- raw Lua codes insertion
2142if cond then
2143 print("output")
2144end
2145print("yuescript")
2146print(3)
2147if tb ~= nil then
2148 tb:func()
2149end
2150if tb ~= nil then
2151 tb:func()
2152end
2153print(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)
2154local a = 5
2155print(1 <= a and a <= 10)
2156local v
2157v = function(x)
2158 print(x)
2159 return x
2160end
2161print((function()
2162 local _cond_0 = v(2)
2163 if not (v(1) < _cond_0) then
2164 return false
2165 else
2166 return _cond_0 <= v(3)
2167 end
2168end)())
2169print((function()
2170 local _cond_0 = v(2)
2171 if not (v(1) > _cond_0) then
2172 return false
2173 else
2174 return _cond_0 <= v(3)
2175 end
2176end)())
2177local tab = { }
2178tab[#tab + 1] = "Value"
2179local parts = {
2180 "shoulders",
2181 "knees"
2182}
2183local lyrics
2184do
2185 local _tab_0 = {
2186 "head"
2187 }
2188 local _idx_0 = 1
2189 for _key_0, _value_0 in pairs(parts) do
2190 if _idx_0 == _key_0 then
2191 _tab_0[#_tab_0 + 1] = _value_0
2192 _idx_0 = _idx_0 + 1
2193 else
2194 _tab_0[_key_0] = _value_0
2195 end
2196 end
2197 _tab_0[#_tab_0 + 1] = "and"
2198 _tab_0[#_tab_0 + 1] = "toes"
2199 lyrics = _tab_0
2200end
2201local copy
2202do
2203 local _tab_0 = { }
2204 local _idx_0 = 1
2205 for _key_0, _value_0 in pairs(other) do
2206 if _idx_0 == _key_0 then
2207 _tab_0[#_tab_0 + 1] = _value_0
2208 _idx_0 = _idx_0 + 1
2209 else
2210 _tab_0[_key_0] = _value_0
2211 end
2212 end
2213 copy = _tab_0
2214end
2215local a = {
2216 1,
2217 2,
2218 3,
2219 x = 1
2220}
2221local b = {
2222 4,
2223 5,
2224 y = 1
2225}
2226local merge
2227do
2228 local _tab_0 = { }
2229 local _idx_0 = 1
2230 for _key_0, _value_0 in pairs(a) do
2231 if _idx_0 == _key_0 then
2232 _tab_0[#_tab_0 + 1] = _value_0
2233 _idx_0 = _idx_0 + 1
2234 else
2235 _tab_0[_key_0] = _value_0
2236 end
2237 end
2238 local _idx_1 = 1
2239 for _key_0, _value_0 in pairs(b) do
2240 if _idx_1 == _key_0 then
2241 _tab_0[#_tab_0 + 1] = _value_0
2242 _idx_1 = _idx_1 + 1
2243 else
2244 _tab_0[_key_0] = _value_0
2245 end
2246 end
2247 merge = _tab_0
2248end
2249local mt = { }
2250local add
2251add = function(self, right)
2252 return setmetatable({
2253 value = self.value + right.value
2254 }, mt)
2255end
2256mt.__add = add
2257local a = setmetatable({
2258 value = 1
2259}, mt)
2260local b = setmetatable({
2261 value = 2
2262}, {
2263 __add = add
2264})
2265local c = setmetatable({
2266 value = 3
2267}, {
2268 __add = mt.__add
2269})
2270local d = a + b + c
2271print(d.value)
2272local _ <close> = setmetatable({ }, {
2273 __close = function()
2274 return print("out of scope")
2275 end
2276})
2277local tb = setmetatable({ }, {
2278 ["value"] = 123
2279})
2280getmetatable(tb).__index = getmetatable(tb)
2281print(tb.value)
2282setmetatable(tb, {
2283 __index = {
2284 item = "hello"
2285 }
2286})
2287print(tb.item)
2288local item, new, close, getter
2289do
2290 local _obj_0 = tb
2291 item, new = _obj_0[1], _obj_0.new
2292 do
2293 local _obj_1 = getmetatable(_obj_0)
2294 close, getter = _obj_1.__close, _obj_1.__index
2295 end
2296end
2297print(item, new, close, getter)
2298do
2299 local _obj_0 = func
2300 if _obj_0 ~= nil then
2301 _obj_0()
2302 end
2303end
2304print((function()
2305 local _obj_0 = abc
2306 if _obj_0 ~= nil then
2307 local _obj_1 = _obj_0["hello world"]
2308 if _obj_1 ~= nil then
2309 return _obj_1.xyz
2310 end
2311 return nil
2312 end
2313 return nil
2314end)())
2315local x
2316do
2317 local _obj_0 = tab
2318 if _obj_0 ~= nil then
2319 x = _obj_0.value
2320 end
2321end
2322local len = (function()
2323 local _obj_0 = utf8
2324 if _obj_0 ~= nil then
2325 return _obj_0.len
2326 end
2327 return nil
2328end)() or (function()
2329 local _obj_0 = string
2330 if _obj_0 ~= nil then
2331 return _obj_0.len
2332 end
2333 return nil
2334end)() or function(o)
2335 return #o
2336end
2337if print and (x ~= nil) then
2338 print(x)
2339end
2340do
2341 local _with_0 = io.open("test.txt", "w")
2342 if _with_0 ~= nil then
2343 _with_0:write("hello")
2344 _with_0:close()
2345 end
2346end
2347print("hello")
2348print(1, 2)
2349print(1, 2, 3)
2350print(render(emit(parse(extract(readFile("example.txt"), language, { }), language))))
2351local a, b, c, d
2352if b ~= nil then
2353 a = b
2354else
2355 if c ~= nil then
2356 a = c
2357 else
2358 a = d
2359 end
2360end
2361func((function()
2362 if a ~= nil then
2363 return a
2364 else
2365 return { }
2366 end
2367end)())
2368if a == nil then
2369 a = false
2370end
2371local list = {
2372 1,
2373 2,
2374 3
2375}
2376func({
2377 1,
2378 2,
2379 3
2380})
2381local tb = {
2382 name = "abc",
2383 values = {
2384 "a",
2385 "b",
2386 "c"
2387 },
2388 objects = {
2389 {
2390 name = "a",
2391 value = 1,
2392 func = function(self)
2393 return self.value + 1
2394 end,
2395 tb = {
2396 fieldA = 1
2397 }
2398 },
2399 {
2400 name = "b",
2401 value = 2,
2402 func = function(self)
2403 return self.value + 2
2404 end,
2405 tb = { }
2406 }
2407 }
2408}
2409do
2410 local insert, concat = table.insert, table.concat
2411 local C, Ct, Cmt
2412 do
2413 local _obj_0 = require("lpeg")
2414 C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt
2415 end
2416 local x, y, z
2417 do
2418 local _obj_0 = require('mymodule')
2419 x, y, z = _obj_0.x, _obj_0.y, _obj_0.z
2420 end
2421 local a, b, c
2422 do
2423 local _obj_0 = require('module')
2424 a, b, c = _obj_0.a, _obj_0.b, _obj_0.c
2425 end
2426end
2427do
2428 local module = require('module')
2429 local module_x = require('module_x')
2430 local d_a_s_h_e_s = require("d-a-s-h-e-s")
2431 local part = require("module.part")
2432end
2433do
2434 local PlayerModule = require("player")
2435 local C, Ct, Cmt
2436 do
2437 local _obj_0 = require("lpeg")
2438 C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt
2439 end
2440 local one, two, ch
2441 do
2442 local _obj_0 = require("export")
2443 one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1]
2444 end
2445end
2446local _module_0 = { }
2447local a, b, c = 1, 2, 3
2448_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c
2449local cool = "cat"
2450_module_0["cool"] = cool
2451local What
2452if this then
2453 What = "abc"
2454else
2455 What = "def"
2456end
2457_module_0["What"] = What
2458local y
2459y = function()
2460 local hallo = 3434
2461end
2462_module_0["y"] = y
2463local Something
2464do
2465 local _class_0
2466 local _base_0 = {
2467 umm = "cool"
2468 }
2469 if _base_0.__index == nil then
2470 _base_0.__index = _base_0
2471 end
2472 _class_0 = setmetatable({
2473 __init = function() end,
2474 __base = _base_0,
2475 __name = "Something"
2476 }, {
2477 __index = _base_0,
2478 __call = function(cls, ...)
2479 local _self_0 = setmetatable({ }, _base_0)
2480 cls.__init(_self_0, ...)
2481 return _self_0
2482 end
2483 })
2484 _base_0.__class = _class_0
2485 Something = _class_0
2486end
2487_module_0["Something"] = Something
2488return _module_0
2489local _module_0 = { }
2490local loadstring, tolua
2491do
2492 local _obj_0 = yue
2493 loadstring, tolua = _obj_0.loadstring, _obj_0.to_lua
2494end
2495_module_0["loadstring"], _module_0["tolua"] = loadstring, tolua
2496local fieldA = tb.itemA.fieldA
2497if fieldA == nil then
2498 fieldA = 'default'
2499end
2500_module_0["fieldA"] = fieldA
2501return _module_0
2502local _module_0 = setmetatable({ }, { })
2503_module_0.itemA = tb
2504getmetatable(_module_0).__index = items
2505_module_0["a-b-c"] = 123
2506return _module_0
2507local _module_0 = { }
2508local d, e, f = 3, 2, 1
2509_module_0[#_module_0 + 1] = d
2510_module_0[#_module_0 + 1] = e
2511_module_0[#_module_0 + 1] = f
2512if this then
2513 _module_0[#_module_0 + 1] = 123
2514else
2515 _module_0[#_module_0 + 1] = 456
2516end
2517do
2518 local _with_0 = tmp
2519 local j = 2000
2520 _module_0[#_module_0 + 1] = _with_0
2521end
2522return _module_0
2523local _module_0 = nil
2524_module_0 = function()
2525 print("hello")
2526 return 123
2527end
2528return _module_0
2529local hello = "world"
2530local a, b, c = 1, 2, 3
2531hello = 123
2532local x = 1
2533x = x + 1
2534x = x - 1
2535x = x * 10
2536x = x / 10
2537x = x % 10
2538local s = s .. "world"
2539local arg = arg or "default value"
2540local a = 0
2541local b = 0
2542local c = 0
2543local d = 0
2544local e = 0
2545local x = f()
2546local y = x
2547local z = x
2548do
2549 local a
2550 a = 1
2551 local x, y, z
2552 print("forward declare all variables as locals")
2553 x = function()
2554 return 1 + y + z
2555 end
2556 y, z = 2, 3
2557 instance = Item:new()
2558end
2559do
2560 local X
2561 X = 1
2562 local B
2563 print("only forward declare upper case variables")
2564 local a = 1
2565 B = 2
2566end
2567do
2568 a = 1
2569 print("declare all variables as globals")
2570 local x
2571 x = function()
2572 return 1 + y + z
2573 end
2574 local y, z = 2, 3
2575end
2576do
2577 X = 1
2578 print("only declare upper case variables as globals")
2579 local a = 1
2580 local B = 2
2581 local Temp
2582 Temp = "a local value"
2583end
2584local thing = {
2585 1,
2586 2
2587}
2588local a, b = thing[1], thing[2]
2589print(a, b)
2590local obj = {
2591 hello = "world",
2592 day = "tuesday",
2593 length = 20
2594}
2595local hello, the_day = obj.hello, obj.day
2596print(hello, the_day)
2597local day = obj.day
2598local obj2 = {
2599 numbers = {
2600 1,
2601 2,
2602 3,
2603 4
2604 },
2605 properties = {
2606 color = "green",
2607 height = 13.5
2608 }
2609}
2610local first, second = obj2.numbers[1], obj2.numbers[2]
2611print(first, second, color)
2612local first, second, color
2613do
2614 local _obj_0 = obj2
2615 first, second, color = _obj_0.numbers[1], _obj_0.numbers[2], _obj_0.properties.color
2616end
2617local concat, insert
2618do
2619 local _obj_0 = table
2620 concat, insert = _obj_0.concat, _obj_0.insert
2621end
2622local mix, max, rand
2623do
2624 local _obj_0 = math
2625 mix, max, rand = _obj_0.mix, _obj_0.max, _obj_0.random
2626end
2627local name, job
2628do
2629 local _obj_0 = person
2630 name, job = _obj_0.name, _obj_0.job
2631 if name == nil then
2632 name = "nameless"
2633 end
2634 if job == nil then
2635 job = "jobless"
2636 end
2637end
2638local two, four
2639do
2640 local _obj_0 = items
2641 two, four = _obj_0[2], _obj_0[4]
2642end
2643local tuples = {
2644 {
2645 "hello",
2646 "world"
2647 },
2648 {
2649 "egg",
2650 "head"
2651 }
2652}
2653for _index_0 = 1, #tuples do
2654 local _des_0 = tuples[_index_0]
2655 local left, right = _des_0[1], _des_0[2]
2656 print(left, right)
2657end
2658do
2659 local user = database.find_user("moon")
2660 if user then
2661 print(user.name)
2662 end
2663end
2664do
2665 local hello = os.getenv("hello")
2666 if hello then
2667 print("You have hello", hello)
2668 else
2669 do
2670 local world = os.getenv("world")
2671 if world then
2672 print("you have world", world)
2673 else
2674 print("nothing :(")
2675 end
2676 end
2677 end
2678end
2679do
2680 local success, result = pcall(function()
2681 return "get result without problems"
2682 end)
2683 if success then
2684 print(result)
2685 end
2686end
2687print("OK")
2688local list = {
2689 1,
2690 2,
2691 3,
2692 4,
2693 5
2694}
2695local fn
2696fn = function(ok)
2697 return ok, table.unpack(list)
2698end
2699(function(_arg_0, ...)
2700 local ok = _arg_0
2701 local count = select('#', ...)
2702 local first = select(1, ...)
2703 return print(ok, count, first)
2704end)(fn(true))
2705Rx.Observable.fromRange(1, 8):filter(function(x)
2706 return x % 2 == 0
2707end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
2708 return value .. '!'
2709end):subscribe(print)
2710local str = strA .. strB .. strC
2711func(3000, "192.168.1.1")
2712xpcall(func, function(err)
2713 return print(yue.traceback(err))
2714end, 1, 2, 3)
2715local success, result = xpcall(func, function(err)
2716 return yue.traceback(err)
2717end, 1, 2, 3)
2718xpcall(func, function(err)
2719 return print(yue.traceback(err))
2720end, 1, 2, 3)
2721success, result = pcall(func, 1, 2, 3)
2722pcall(function()
2723 print("trying")
2724 return func(1, 2, 3)
2725end)
2726success, result = xpcall(func, function(err)
2727 return print(yue.traceback(err))
2728end, 1, 2, 3)
2729if success then
2730 print(result)
2731end
2732local a <const> = 123
2733local _ <close> = setmetatable({ }, {
2734 __close = function()
2735 return print("Out of scope.")
2736 end
2737})
2738local a, b, c, d
2739do
2740 local _obj_0 = tb
2741 a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
2742end
2743local some_string = "Here is a string\n that has a line break in it."
2744print("I am " .. tostring(math.random() * 100) .. "% sure.")
2745local integer = 1000000
2746local hex = 0xEFBBBF
2747local my_function
2748my_function = function() end
2749my_function()
2750local func_a
2751func_a = function()
2752 return print("hello world")
2753end
2754local func_b
2755func_b = function()
2756 local value = 100
2757 return print("The value:", value)
2758end
2759func_a()
2760func_b()
2761local sum
2762sum = function(x, y)
2763 return print("sum", x + y)
2764end
2765sum(10, 20)
2766print(sum(10, 20))
2767a(b(c("a", "b", "c")))
2768print("x:", sum(10, 20), "y:", sum(30, 40))
2769local sum
2770sum = function(x, y)
2771 return x + y
2772end
2773print("The sum is ", sum(10, 20))
2774local sum
2775sum = function(x, y)
2776 return x + y
2777end
2778local mystery
2779mystery = function(x, y)
2780 return x + y, x - y
2781end
2782local a, b = mystery(10, 20)
2783local func
2784func = function(self, num)
2785 return self.value + num
2786end
2787local my_function
2788my_function = function(name, height)
2789 if name == nil then
2790 name = "something"
2791 end
2792 if height == nil then
2793 height = 100
2794 end
2795 print("Hello I am", name)
2796 return print("My height is", height)
2797end
2798local some_args
2799some_args = function(x, y)
2800 if x == nil then
2801 x = 100
2802 end
2803 if y == nil then
2804 y = x + 1000
2805 end
2806 return print(x + y)
2807end
2808local a = x - 10
2809local b = x - 10
2810local c = x(-y)
2811local d = x - z
2812local x = func("hello") + 100
2813local y = func("hello" + 100)
2814my_func(5, 4, 3, 8, 9, 10)
2815cool_func(1, 2, 3, 4, 5, 6, 7, 8)
2816my_func(5, 6, 7, 6, another_func(6, 7, 8, 9, 1, 2), 5, 4)
2817local x = {
2818 1,
2819 2,
2820 3,
2821 4,
2822 a_func(4, 5, 5, 6),
2823 8,
2824 9,
2825 10
2826}
2827local y = {
2828 my_func(1, 2, 3, 4, 5),
2829 5,
2830 6,
2831 7
2832}
2833if func(1, 2, 3, "hello", "world") then
2834 print("hello")
2835 print("I am inside if")
2836end
2837if func(1, 2, 3, "hello", "world") then
2838 print("hello")
2839 print("I am inside if")
2840end
2841f(function()
2842 return print("hello")
2843end)
2844f(function(self)
2845 return print(self.value)
2846end)
2847map(function(x)
2848 return x * 2
2849end, {
2850 1,
2851 2,
2852 3
2853})
2854local result, msg
2855do
2856 result, msg = readAsync("filename.txt", function(data)
2857 print(data)
2858 return processAsync(data, function(info)
2859 return check(info)
2860 end)
2861 end)
2862end
2863print(result, msg)
2864local some_values = {
2865 1,
2866 2,
2867 3,
2868 4
2869}
2870local some_values = {
2871 name = "Bill",
2872 age = 200,
2873 ["favorite food"] = "rice"
2874}
2875local profile = {
2876 height = "4 feet",
2877 shoe_size = 13,
2878 favorite_foods = {
2879 "ice cream",
2880 "donuts"
2881 }
2882}
2883local values = {
2884 1,
2885 2,
2886 3,
2887 4,
2888 5,
2889 6,
2890 7,
2891 8,
2892 name = "superman",
2893 occupation = "crime fighting"
2894}
2895my_function({
2896 dance = "Tango",
2897 partner = "none"
2898})
2899local y = {
2900 type = "dog",
2901 legs = 4,
2902 tails = 1
2903}
2904local tbl = {
2905 ["do"] = "something",
2906 ["end"] = "hunger"
2907}
2908local hair = "golden"
2909local height = 200
2910local person = {
2911 hair = hair,
2912 height = height,
2913 shoe_size = 40
2914}
2915print_table({
2916 hair = hair,
2917 height = height
2918})
2919local t = {
2920 [1 + 2] = "hello",
2921 ["hello world"] = true
2922}
2923local some_values = {
2924 1,
2925 2,
2926 3,
2927 4
2928}
2929local list_with_one_element = {
2930 1
2931}
2932local items = {
2933 1,
2934 2,
2935 3,
2936 4
2937}
2938local doubled
2939do
2940 local _accum_0 = { }
2941 local _len_0 = 1
2942 for i, item in ipairs(items) do
2943 _accum_0[_len_0] = item * 2
2944 _len_0 = _len_0 + 1
2945 end
2946 doubled = _accum_0
2947end
2948local iter = ipairs(items)
2949local slice
2950do
2951 local _accum_0 = { }
2952 local _len_0 = 1
2953 for i, item in iter do
2954 if i > 1 and i < 3 then
2955 _accum_0[_len_0] = item
2956 _len_0 = _len_0 + 1
2957 end
2958 end
2959 slice = _accum_0
2960end
2961local doubled
2962do
2963 local _accum_0 = { }
2964 local _len_0 = 1
2965 local _list_0 = items
2966 for _index_0 = 1, #_list_0 do
2967 local item = _list_0[_index_0]
2968 _accum_0[_len_0] = item * 2
2969 _len_0 = _len_0 + 1
2970 end
2971 doubled = _accum_0
2972end
2973local x_coords = {
2974 4,
2975 5,
2976 6,
2977 7
2978}
2979local y_coords = {
2980 9,
2981 2,
2982 3
2983}
2984local points
2985do
2986 local _accum_0 = { }
2987 local _len_0 = 1
2988 for _index_0 = 1, #x_coords do
2989 local x = x_coords[_index_0]
2990 for _index_1 = 1, #y_coords do
2991 local y = y_coords[_index_1]
2992 _accum_0[_len_0] = {
2993 x,
2994 y
2995 }
2996 _len_0 = _len_0 + 1
2997 end
2998 end
2999 points = _accum_0
3000end
3001local evens
3002do
3003 local _accum_0 = { }
3004 local _len_0 = 1
3005 for i = 1, 100 do
3006 if i % 2 == 0 then
3007 _accum_0[_len_0] = i
3008 _len_0 = _len_0 + 1
3009 end
3010 end
3011 evens = _accum_0
3012end
3013local thing = {
3014 color = "red",
3015 name = "fast",
3016 width = 123
3017}
3018local thing_copy
3019do
3020 local _tbl_0 = { }
3021 for k, v in pairs(thing) do
3022 _tbl_0[k] = v
3023 end
3024 thing_copy = _tbl_0
3025end
3026local no_color
3027do
3028 local _tbl_0 = { }
3029 for k, v in pairs(thing) do
3030 if k ~= "color" then
3031 _tbl_0[k] = v
3032 end
3033 end
3034 no_color = _tbl_0
3035end
3036local numbers = {
3037 1,
3038 2,
3039 3,
3040 4
3041}
3042local sqrts
3043do
3044 local _tbl_0 = { }
3045 for _index_0 = 1, #numbers do
3046 local i = numbers[_index_0]
3047 _tbl_0[i] = math.sqrt(i)
3048 end
3049 sqrts = _tbl_0
3050end
3051local tuples = {
3052 {
3053 "hello",
3054 "world"
3055 },
3056 {
3057 "foo",
3058 "bar"
3059 }
3060}
3061local tbl
3062do
3063 local _tbl_0 = { }
3064 for _index_0 = 1, #tuples do
3065 local tuple = tuples[_index_0]
3066 local _key_0, _val_0 = unpack(tuple)
3067 _tbl_0[_key_0] = _val_0
3068 end
3069 tbl = _tbl_0
3070end
3071local slice
3072do
3073 local _accum_0 = { }
3074 local _len_0 = 1
3075 local _list_0 = items
3076 local _max_0 = 5
3077 for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
3078 local item = _list_0[_index_0]
3079 _accum_0[_len_0] = item
3080 _len_0 = _len_0 + 1
3081 end
3082 slice = _accum_0
3083end
3084local slice
3085do
3086 local _accum_0 = { }
3087 local _len_0 = 1
3088 local _list_0 = items
3089 for _index_0 = 2, #_list_0 do
3090 local item = _list_0[_index_0]
3091 _accum_0[_len_0] = item
3092 _len_0 = _len_0 + 1
3093 end
3094 slice = _accum_0
3095end
3096local slice
3097do
3098 local _accum_0 = { }
3099 local _len_0 = 1
3100 local _list_0 = items
3101 for _index_0 = 1, #_list_0, 2 do
3102 local item = _list_0[_index_0]
3103 _accum_0[_len_0] = item
3104 _len_0 = _len_0 + 1
3105 end
3106 slice = _accum_0
3107end
3108for i = 10, 20 do
3109 print(i)
3110end
3111for k = 1, 15, 2 do
3112 print(k)
3113end
3114for key, value in pairs(object) do
3115 print(key, value)
3116end
3117do
3118 local _list_0 = items
3119 local _max_0 = 4
3120 for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
3121 local item = _list_0[_index_0]
3122 print(item)
3123 end
3124end
3125local _list_0 = items
3126for _index_0 = 1, #_list_0 do
3127 local item = _list_0[_index_0]
3128 print(item)
3129end
3130for j = 1, 10, 3 do
3131 print(j)
3132end
3133local doubled_evens
3134do
3135 local _accum_0 = { }
3136 local _len_0 = 1
3137 for i = 1, 20 do
3138 if i % 2 == 0 then
3139 _accum_0[_len_0] = i * 2
3140 else
3141 _accum_0[_len_0] = i
3142 end
3143 _len_0 = _len_0 + 1
3144 end
3145 doubled_evens = _accum_0
3146end
3147local func_a
3148func_a = function()
3149 for i = 1, 10 do
3150 print(i)
3151 end
3152end
3153local func_b
3154func_b = function()
3155 local _accum_0 = { }
3156 local _len_0 = 1
3157 for i = 1, 10 do
3158 _accum_0[_len_0] = i
3159 _len_0 = _len_0 + 1
3160 end
3161 return _accum_0
3162end
3163print(func_a())
3164print(func_b())
3165local i = 10
3166repeat
3167 print(i)
3168 i = i - 1
3169until i == 0
3170local i = 10
3171while i > 0 do
3172 print(i)
3173 i = i - 1
3174end
3175while running == true do
3176 my_function()
3177end
3178local i = 10
3179while not (i == 0) do
3180 print(i)
3181 i = i - 1
3182end
3183while not (running == false) do
3184 my_function()
3185end
3186local i = 0
3187while i < 10 do
3188 i = i + 1
3189 if i % 2 == 0 then
3190 goto _continue_0
3191 end
3192 print(i)
3193 ::_continue_0::
3194end
3195local my_numbers = {
3196 1,
3197 2,
3198 3,
3199 4,
3200 5,
3201 6
3202}
3203local odds
3204do
3205 local _accum_0 = { }
3206 local _len_0 = 1
3207 for _index_0 = 1, #my_numbers do
3208 local x = my_numbers[_index_0]
3209 if x % 2 == 1 then
3210 goto _continue_0
3211 end
3212 _accum_0[_len_0] = x
3213 _len_0 = _len_0 + 1
3214 ::_continue_0::
3215 end
3216 odds = _accum_0
3217end
3218local have_coins = false
3219if have_coins then
3220 print("Got coins")
3221else
3222 print("No coins")
3223end
3224local have_coins = false
3225if have_coins then
3226 print("Got coins")
3227else
3228 print("No coins")
3229end
3230local have_coins = false
3231print((function()
3232 if have_coins then
3233 return "Got coins"
3234 else
3235 return "No coins"
3236 end
3237end)())
3238local is_tall
3239is_tall = function(name)
3240 if name == "Rob" then
3241 return true
3242 else
3243 return false
3244 end
3245end
3246local message
3247if is_tall("Rob") then
3248 message = "I am very tall"
3249else
3250 message = "I am not so tall"
3251end
3252print(message)
3253if not (os.date("%A") == "Monday") then
3254 print("it is not Monday!")
3255end
3256if not (math.random() > 0.1) then
3257 print("You're lucky!")
3258end
3259local a = 5
3260if (1 == a or 3 == a or 5 == a or 7 == a) then
3261 print("checking equality with discrete values")
3262end
3263if (function()
3264 local _check_0 = list
3265 for _index_0 = 1, #_check_0 do
3266 if _check_0[_index_0] == a then
3267 return true
3268 end
3269 end
3270 return false
3271end)() then
3272 print("checking if `a` is in a list")
3273end
3274if not (math.random() > 0.1) then
3275 print("You're lucky!")
3276end
3277if name == "Rob" then
3278 print("hello world")
3279end
3280local _list_0 = items
3281for _index_0 = 1, #_list_0 do
3282 local item = _list_0[_index_0]
3283 print("item: ", item)
3284end
3285while game:isRunning() do
3286 game:update()
3287end
3288while not reader:eof() do
3289 reader:parse_line()
3290end
3291local name = "Dan"
3292if "Robert" == name then
3293 print("You are Robert")
3294elseif "Dan" == name or "Daniel" == name then
3295 print("Your name, it's Dan")
3296else
3297 print("I don't know about your name")
3298end
3299local b = 1
3300local next_number
3301if 1 == b then
3302 next_number = 2
3303elseif 2 == b then
3304 next_number = 3
3305else
3306 next_number = error("can't count that high!")
3307end
3308local msg
3309do
3310 local _exp_0 = math.random(1, 5)
3311 if 1 == _exp_0 then
3312 msg = "you are lucky"
3313 elseif 2 == _exp_0 then
3314 msg = "you are almost lucky"
3315 else
3316 msg = "not so lucky"
3317 end
3318end
3319do
3320 local _exp_0 = math.random(1, 5)
3321 if 1 == _exp_0 then
3322 print("you are lucky")
3323 else
3324 print("not so lucky")
3325 end
3326end
3327do
3328 local _exp_0 = math.random(1, 5)
3329 if 1 == _exp_0 then
3330 print("you are lucky")
3331 else
3332 print("not so lucky")
3333 end
3334end
3335local items = {
3336 {
3337 x = 100,
3338 y = 200
3339 },
3340 {
3341 width = 300,
3342 height = 400
3343 }
3344}
3345for _index_0 = 1, #items do
3346 local item = items[_index_0]
3347 do
3348 local _type_0 = type(item)
3349 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3350 local _match_0 = false
3351 if _tab_0 then
3352 local x = item.x
3353 local y = item.y
3354 if x ~= nil and y ~= nil then
3355 _match_0 = true
3356 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3357 end
3358 end
3359 if not _match_0 then
3360 if _tab_0 then
3361 local width = item.width
3362 local height = item.height
3363 if width ~= nil and height ~= nil then
3364 print("size " .. tostring(width) .. ", " .. tostring(height))
3365 end
3366 end
3367 end
3368 end
3369end
3370local item = { }
3371local x, y = item.pos.x, item.pos.y
3372if x == nil then
3373 x = 50
3374end
3375if y == nil then
3376 y = 200
3377end
3378do
3379 local _type_0 = type(item)
3380 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3381 if _tab_0 then
3382 do
3383 local _obj_0 = item.pos
3384 local _type_1 = type(_obj_0)
3385 if "table" == _type_1 or "userdata" == _type_1 then
3386 x = _obj_0.x
3387 end
3388 end
3389 do
3390 local _obj_0 = item.pos
3391 local _type_1 = type(_obj_0)
3392 if "table" == _type_1 or "userdata" == _type_1 then
3393 y = _obj_0.y
3394 end
3395 end
3396 if x == nil then
3397 x = 50
3398 end
3399 if y == nil then
3400 y = 200
3401 end
3402 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3403 end
3404end
3405local Inventory
3406do
3407 local _class_0
3408 local _base_0 = {
3409 add_item = function(self, name)
3410 if self.items[name] then
3411 local _obj_0 = self.items
3412 _obj_0[name] = _obj_0[name] + 1
3413 else
3414 self.items[name] = 1
3415 end
3416 end
3417 }
3418 if _base_0.__index == nil then
3419 _base_0.__index = _base_0
3420 end
3421 _class_0 = setmetatable({
3422 __init = function(self)
3423 self.items = { }
3424 end,
3425 __base = _base_0,
3426 __name = "Inventory"
3427 }, {
3428 __index = _base_0,
3429 __call = function(cls, ...)
3430 local _self_0 = setmetatable({ }, _base_0)
3431 cls.__init(_self_0, ...)
3432 return _self_0
3433 end
3434 })
3435 _base_0.__class = _class_0
3436 Inventory = _class_0
3437end
3438local inv = Inventory()
3439inv:add_item("t-shirt")
3440inv:add_item("pants")
3441local Person
3442do
3443 local _class_0
3444 local _base_0 = {
3445 clothes = { },
3446 give_item = function(self, name)
3447 return table.insert(self.clothes, name)
3448 end
3449 }
3450 if _base_0.__index == nil then
3451 _base_0.__index = _base_0
3452 end
3453 _class_0 = setmetatable({
3454 __init = function() end,
3455 __base = _base_0,
3456 __name = "Person"
3457 }, {
3458 __index = _base_0,
3459 __call = function(cls, ...)
3460 local _self_0 = setmetatable({ }, _base_0)
3461 cls.__init(_self_0, ...)
3462 return _self_0
3463 end
3464 })
3465 _base_0.__class = _class_0
3466 Person = _class_0
3467end
3468local a = Person()
3469local b = Person()
3470a:give_item("pants")
3471b:give_item("shirt")
3472local _list_0 = a.clothes
3473for _index_0 = 1, #_list_0 do
3474 local item = _list_0[_index_0]
3475 print(item)
3476end
3477local Person
3478do
3479 local _class_0
3480 local _base_0 = { }
3481 if _base_0.__index == nil then
3482 _base_0.__index = _base_0
3483 end
3484 _class_0 = setmetatable({
3485 __init = function(self)
3486 self.clothes = { }
3487 end,
3488 __base = _base_0,
3489 __name = "Person"
3490 }, {
3491 __index = _base_0,
3492 __call = function(cls, ...)
3493 local _self_0 = setmetatable({ }, _base_0)
3494 cls.__init(_self_0, ...)
3495 return _self_0
3496 end
3497 })
3498 _base_0.__class = _class_0
3499 Person = _class_0
3500end
3501local BackPack
3502do
3503 local _class_0
3504 local _parent_0 = Inventory
3505 local _base_0 = {
3506 size = 10,
3507 add_item = function(self, name)
3508 if #self.items > size then
3509 error("backpack is full")
3510 end
3511 return _class_0.__parent.__base.add_item(self, name)
3512 end
3513 }
3514 for _key_0, _val_0 in pairs(_parent_0.__base) do
3515 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
3516 _base_0[_key_0] = _val_0
3517 end
3518 end
3519 if _base_0.__index == nil then
3520 _base_0.__index = _base_0
3521 end
3522 setmetatable(_base_0, _parent_0.__base)
3523 _class_0 = setmetatable({
3524 __init = function(self, ...)
3525 return _class_0.__parent.__init(self, ...)
3526 end,
3527 __base = _base_0,
3528 __name = "BackPack",
3529 __parent = _parent_0
3530 }, {
3531 __index = function(cls, name)
3532 local val = rawget(_base_0, name)
3533 if val == nil then
3534 local parent = rawget(cls, "__parent")
3535 if parent then
3536 return parent[name]
3537 end
3538 else
3539 return val
3540 end
3541 end,
3542 __call = function(cls, ...)
3543 local _self_0 = setmetatable({ }, _base_0)
3544 cls.__init(_self_0, ...)
3545 return _self_0
3546 end
3547 })
3548 _base_0.__class = _class_0
3549 if _parent_0.__inherited then
3550 _parent_0.__inherited(_parent_0, _class_0)
3551 end
3552 BackPack = _class_0
3553end
3554local Shelf
3555do
3556 local _class_0
3557 local _base_0 = { }
3558 if _base_0.__index == nil then
3559 _base_0.__index = _base_0
3560 end
3561 _class_0 = setmetatable({
3562 __init = function() end,
3563 __base = _base_0,
3564 __name = "Shelf"
3565 }, {
3566 __index = _base_0,
3567 __call = function(cls, ...)
3568 local _self_0 = setmetatable({ }, _base_0)
3569 cls.__init(_self_0, ...)
3570 return _self_0
3571 end
3572 })
3573 _base_0.__class = _class_0
3574 local self = _class_0;
3575 self.__inherited = function(self, child)
3576 return print(self.__name, "was inherited by", child.__name)
3577 end
3578 Shelf = _class_0
3579end
3580local Cupboard
3581do
3582 local _class_0
3583 local _parent_0 = Shelf
3584 local _base_0 = { }
3585 for _key_0, _val_0 in pairs(_parent_0.__base) do
3586 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
3587 _base_0[_key_0] = _val_0
3588 end
3589 end
3590 if _base_0.__index == nil then
3591 _base_0.__index = _base_0
3592 end
3593 setmetatable(_base_0, _parent_0.__base)
3594 _class_0 = setmetatable({
3595 __init = function(self, ...)
3596 return _class_0.__parent.__init(self, ...)
3597 end,
3598 __base = _base_0,
3599 __name = "Cupboard",
3600 __parent = _parent_0
3601 }, {
3602 __index = function(cls, name)
3603 local val = rawget(_base_0, name)
3604 if val == nil then
3605 local parent = rawget(cls, "__parent")
3606 if parent then
3607 return parent[name]
3608 end
3609 else
3610 return val
3611 end
3612 end,
3613 __call = function(cls, ...)
3614 local _self_0 = setmetatable({ }, _base_0)
3615 cls.__init(_self_0, ...)
3616 return _self_0
3617 end
3618 })
3619 _base_0.__class = _class_0
3620 if _parent_0.__inherited then
3621 _parent_0.__inherited(_parent_0, _class_0)
3622 end
3623 Cupboard = _class_0
3624end
3625local MyClass
3626do
3627 local _class_0
3628 local _parent_0 = ParentClass
3629 local _base_0 = {
3630 a_method = function(self)
3631 _class_0.__parent.__base.a_method(self, "hello", "world")
3632 _class_0.__parent.a_method(self, "hello", "world")
3633 _class_0.__parent.a_method(self, "hello", "world")
3634 return assert(_class_0.__parent == ParentClass)
3635 end
3636 }
3637 for _key_0, _val_0 in pairs(_parent_0.__base) do
3638 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
3639 _base_0[_key_0] = _val_0
3640 end
3641 end
3642 if _base_0.__index == nil then
3643 _base_0.__index = _base_0
3644 end
3645 setmetatable(_base_0, _parent_0.__base)
3646 _class_0 = setmetatable({
3647 __init = function(self, ...)
3648 return _class_0.__parent.__init(self, ...)
3649 end,
3650 __base = _base_0,
3651 __name = "MyClass",
3652 __parent = _parent_0
3653 }, {
3654 __index = function(cls, name)
3655 local val = rawget(_base_0, name)
3656 if val == nil then
3657 local parent = rawget(cls, "__parent")
3658 if parent then
3659 return parent[name]
3660 end
3661 else
3662 return val
3663 end
3664 end,
3665 __call = function(cls, ...)
3666 local _self_0 = setmetatable({ }, _base_0)
3667 cls.__init(_self_0, ...)
3668 return _self_0
3669 end
3670 })
3671 _base_0.__class = _class_0
3672 if _parent_0.__inherited then
3673 _parent_0.__inherited(_parent_0, _class_0)
3674 end
3675 MyClass = _class_0
3676end
3677local b = BackPack()
3678assert(b.__class == BackPack)
3679print(BackPack.size)
3680print(BackPack.__name)
3681local Things
3682do
3683 local _class_0
3684 local _base_0 = { }
3685 if _base_0.__index == nil then
3686 _base_0.__index = _base_0
3687 end
3688 _class_0 = setmetatable({
3689 __init = function() end,
3690 __base = _base_0,
3691 __name = "Things"
3692 }, {
3693 __index = _base_0,
3694 __call = function(cls, ...)
3695 local _self_0 = setmetatable({ }, _base_0)
3696 cls.__init(_self_0, ...)
3697 return _self_0
3698 end
3699 })
3700 _base_0.__class = _class_0
3701 local self = _class_0;
3702 self.some_func = function(self)
3703 return print("Hello from", self.__name)
3704 end
3705 Things = _class_0
3706end
3707Things:some_func()
3708assert(Things().some_func == nil)
3709local Counter
3710do
3711 local _class_0
3712 local _base_0 = { }
3713 if _base_0.__index == nil then
3714 _base_0.__index = _base_0
3715 end
3716 _class_0 = setmetatable({
3717 __init = function(self)
3718 self.__class.count = self.__class.count + 1
3719 end,
3720 __base = _base_0,
3721 __name = "Counter"
3722 }, {
3723 __index = _base_0,
3724 __call = function(cls, ...)
3725 local _self_0 = setmetatable({ }, _base_0)
3726 cls.__init(_self_0, ...)
3727 return _self_0
3728 end
3729 })
3730 _base_0.__class = _class_0
3731 local self = _class_0;
3732 self.count = 0
3733 Counter = _class_0
3734end
3735Counter()
3736Counter()
3737print(Counter.count)
3738self.__class:hello(1, 2, 3, 4)
3739local Things
3740do
3741 local _class_0
3742 local _base_0 = { }
3743 if _base_0.__index == nil then
3744 _base_0.__index = _base_0
3745 end
3746 _class_0 = setmetatable({
3747 __init = function() end,
3748 __base = _base_0,
3749 __name = "Things"
3750 }, {
3751 __index = _base_0,
3752 __call = function(cls, ...)
3753 local _self_0 = setmetatable({ }, _base_0)
3754 cls.__init(_self_0, ...)
3755 return _self_0
3756 end
3757 })
3758 _base_0.__class = _class_0
3759 local self = _class_0;
3760 self.class_var = "hello world"
3761 Things = _class_0
3762end
3763local MoreThings
3764do
3765 local _class_0
3766 local secret, log
3767 local _base_0 = {
3768 some_method = function(self)
3769 return log("hello world: " .. secret)
3770 end
3771 }
3772 if _base_0.__index == nil then
3773 _base_0.__index = _base_0
3774 end
3775 _class_0 = setmetatable({
3776 __init = function() end,
3777 __base = _base_0,
3778 __name = "MoreThings"
3779 }, {
3780 __index = _base_0,
3781 __call = function(cls, ...)
3782 local _self_0 = setmetatable({ }, _base_0)
3783 cls.__init(_self_0, ...)
3784 return _self_0
3785 end
3786 })
3787 _base_0.__class = _class_0
3788 local self = _class_0;
3789 secret = 123
3790 log = function(msg)
3791 return print("LOG:", msg)
3792 end
3793 MoreThings = _class_0
3794end
3795assert(self == self)
3796assert(self.__class == self.__class)
3797local some_instance_method
3798some_instance_method = function(self, ...)
3799 return self.__class(...)
3800end
3801local Something
3802do
3803 local _class_0
3804 local _base_0 = { }
3805 if _base_0.__index == nil then
3806 _base_0.__index = _base_0
3807 end
3808 _class_0 = setmetatable({
3809 __init = function(self, foo, bar, biz, baz)
3810 self.foo = foo
3811 self.bar = bar
3812 self.__class.biz = biz
3813 self.__class.baz = baz
3814 end,
3815 __base = _base_0,
3816 __name = "Something"
3817 }, {
3818 __index = _base_0,
3819 __call = function(cls, ...)
3820 local _self_0 = setmetatable({ }, _base_0)
3821 cls.__init(_self_0, ...)
3822 return _self_0
3823 end
3824 })
3825 _base_0.__class = _class_0
3826 Something = _class_0
3827end
3828do
3829 local _class_0
3830 local _base_0 = { }
3831 if _base_0.__index == nil then
3832 _base_0.__index = _base_0
3833 end
3834 _class_0 = setmetatable({
3835 __init = function(self, foo, bar, biz, baz)
3836 self.foo = foo
3837 self.bar = bar
3838 self.__class.biz = biz
3839 self.__class.baz = baz
3840 end,
3841 __base = _base_0,
3842 __name = "Something"
3843 }, {
3844 __index = _base_0,
3845 __call = function(cls, ...)
3846 local _self_0 = setmetatable({ }, _base_0)
3847 cls.__init(_self_0, ...)
3848 return _self_0
3849 end
3850 })
3851 _base_0.__class = _class_0
3852 Something = _class_0
3853end
3854local new
3855new = function(self, fieldA, fieldB)
3856 self.fieldA = fieldA
3857 self.fieldB = fieldB
3858 return self
3859end
3860local obj = new({ }, 123, "abc")
3861print(obj)
3862local x
3863local Bucket
3864do
3865 local _class_0
3866 local _base_0 = {
3867 drops = 0,
3868 add_drop = function(self)
3869 self.drops = self.drops + 1
3870 end
3871 }
3872 if _base_0.__index == nil then
3873 _base_0.__index = _base_0
3874 end
3875 _class_0 = setmetatable({
3876 __init = function() end,
3877 __base = _base_0,
3878 __name = "Bucket"
3879 }, {
3880 __index = _base_0,
3881 __call = function(cls, ...)
3882 local _self_0 = setmetatable({ }, _base_0)
3883 cls.__init(_self_0, ...)
3884 return _self_0
3885 end
3886 })
3887 _base_0.__class = _class_0
3888 Bucket = _class_0
3889 x = _class_0
3890end
3891local BigBucket
3892do
3893 local _class_0
3894 local _parent_0 = Bucket
3895 local _base_0 = {
3896 add_drop = function(self)
3897 self.drops = self.drops + 10
3898 end
3899 }
3900 for _key_0, _val_0 in pairs(_parent_0.__base) do
3901 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
3902 _base_0[_key_0] = _val_0
3903 end
3904 end
3905 if _base_0.__index == nil then
3906 _base_0.__index = _base_0
3907 end
3908 setmetatable(_base_0, _parent_0.__base)
3909 _class_0 = setmetatable({
3910 __init = function(self, ...)
3911 return _class_0.__parent.__init(self, ...)
3912 end,
3913 __base = _base_0,
3914 __name = "BigBucket",
3915 __parent = _parent_0
3916 }, {
3917 __index = function(cls, name)
3918 local val = rawget(_base_0, name)
3919 if val == nil then
3920 local parent = rawget(cls, "__parent")
3921 if parent then
3922 return parent[name]
3923 end
3924 else
3925 return val
3926 end
3927 end,
3928 __call = function(cls, ...)
3929 local _self_0 = setmetatable({ }, _base_0)
3930 cls.__init(_self_0, ...)
3931 return _self_0
3932 end
3933 })
3934 _base_0.__class = _class_0
3935 if _parent_0.__inherited then
3936 _parent_0.__inherited(_parent_0, _class_0)
3937 end
3938 BigBucket = _class_0
3939end
3940assert(Bucket.__name == "BigBucket")
3941local x
3942do
3943 local _class_0
3944 local _base_0 = { }
3945 if _base_0.__index == nil then
3946 _base_0.__index = _base_0
3947 end
3948 _class_0 = setmetatable({
3949 __init = function() end,
3950 __base = _base_0,
3951 __name = "x"
3952 }, {
3953 __index = _base_0,
3954 __call = function(cls, ...)
3955 local _self_0 = setmetatable({ }, _base_0)
3956 cls.__init(_self_0, ...)
3957 return _self_0
3958 end
3959 })
3960 _base_0.__class = _class_0
3961 x = _class_0
3962end
3963local MyIndex = {
3964 __index = {
3965 var = 1
3966 }
3967}
3968local X
3969do
3970 local _class_0
3971 local _base_0 = {
3972 func = function(self)
3973 return print(123)
3974 end
3975 }
3976 local _list_0 = {
3977 MyIndex
3978 }
3979 for _index_0 = 1, #_list_0 do
3980 local _item_0 = _list_0[_index_0]
3981 local _cls_0, _mixin_0 = (_item_0.__base ~= nil), _item_0.__base or _item_0
3982 for _key_0, _val_0 in pairs(_mixin_0) do
3983 if _base_0[_key_0] == nil and (not _cls_0 or not _key_0:match("^__")) then
3984 _base_0[_key_0] = _val_0
3985 end
3986 end
3987 end
3988 if _base_0.__index == nil then
3989 _base_0.__index = _base_0
3990 end
3991 _class_0 = setmetatable({
3992 __init = function() end,
3993 __base = _base_0,
3994 __name = "X"
3995 }, {
3996 __index = _base_0,
3997 __call = function(cls, ...)
3998 local _self_0 = setmetatable({ }, _base_0)
3999 cls.__init(_self_0, ...)
4000 return _self_0
4001 end
4002 })
4003 _base_0.__class = _class_0
4004 X = _class_0
4005end
4006local x = X()
4007print(x.var)
4008local Y
4009do
4010 local _class_0
4011 local _base_0 = { }
4012 local _list_0 = {
4013 X
4014 }
4015 for _index_0 = 1, #_list_0 do
4016 local _item_0 = _list_0[_index_0]
4017 local _cls_0, _mixin_0 = (_item_0.__base ~= nil), _item_0.__base or _item_0
4018 for _key_0, _val_0 in pairs(_mixin_0) do
4019 if _base_0[_key_0] == nil and (not _cls_0 or not _key_0:match("^__")) then
4020 _base_0[_key_0] = _val_0
4021 end
4022 end
4023 end
4024 if _base_0.__index == nil then
4025 _base_0.__index = _base_0
4026 end
4027 _class_0 = setmetatable({
4028 __init = function() end,
4029 __base = _base_0,
4030 __name = "Y"
4031 }, {
4032 __index = _base_0,
4033 __call = function(cls, ...)
4034 local _self_0 = setmetatable({ }, _base_0)
4035 cls.__init(_self_0, ...)
4036 return _self_0
4037 end
4038 })
4039 _base_0.__class = _class_0
4040 Y = _class_0
4041end
4042local y = Y()
4043y:func()
4044assert(y.__class.__parent ~= X)
4045do
4046 local _with_0 = Person()
4047 _with_0.name = "Oswald"
4048 _with_0:add_relative(my_dad)
4049 _with_0:save()
4050 print(_with_0.name)
4051end
4052local file
4053do
4054 local _with_0 = File("favorite_foods.txt")
4055 _with_0:set_encoding("utf8")
4056 file = _with_0
4057end
4058local create_person
4059create_person = function(name, relatives)
4060 local _with_0 = Person()
4061 _with_0.name = name
4062 for _index_0 = 1, #relatives do
4063 local relative = relatives[_index_0]
4064 _with_0:add_relative(relative)
4065 end
4066 return _with_0
4067end
4068local me = create_person("Leaf", {
4069 dad,
4070 mother,
4071 sister
4072})
4073do
4074 local str = "Hello"
4075 print("original:", str)
4076 print("upper:", str:upper())
4077end
4078do
4079 local _with_0 = tb
4080 _with_0[1] = 1
4081 print(_with_0[2])
4082 do
4083 local _with_1 = _with_0[abc]
4084 _with_1[3] = _with_1[2]:func()
4085 _with_1["key-name"] = value
4086 end
4087 _with_0[#_with_0 + 1] = "abc"
4088end
4089do
4090 local var = "hello"
4091 print(var)
4092end
4093print(var)
4094local counter
4095do
4096 local i = 0
4097 counter = function()
4098 i = i + 1
4099 return i
4100 end
4101end
4102print(counter())
4103print(counter())
4104local tbl = {
4105 key = (function()
4106 print("assigning key!")
4107 return 1234
4108 end)()
4109}
4110local my_object = {
4111 value = 1000,
4112 write = function(self)
4113 return print("the value:", self.value)
4114 end
4115}
4116local run_callback
4117run_callback = function(func)
4118 print("running callback...")
4119 return func()
4120end
4121run_callback(my_object.write)
4122run_callback((function()
4123 local _base_0 = my_object
4124 local _fn_0 = _base_0.write
4125 return _fn_0 and function(...)
4126 return _fn_0(_base_0, ...)
4127 end
4128end)())
4129local i = 100
4130local my_func
4131my_func = function()
4132 i = 10
4133 while i > 0 do
4134 print(i)
4135 i = i - 1
4136 end
4137end
4138my_func()
4139print(i)
4140local i = 100
4141local my_func
4142my_func = function()
4143 local i = "hello"
4144end
4145my_func()
4146print(i)
4147local tmp = 1213
4148local i, k = 100, 50
4149local my_func
4150my_func = function(add)
4151 local tmp = tmp + add
4152 i = i + tmp
4153 k = k + tmp
4154end
4155my_func(22)
4156print(i, k)
diff --git a/spec/outputs/codes_from_doc_zh.lua b/spec/outputs/codes_from_doc_zh.lua
new file mode 100644
index 0000000..15647b2
--- /dev/null
+++ b/spec/outputs/codes_from_doc_zh.lua
@@ -0,0 +1,4144 @@
1local _module_0 = { }
2local p, to_lua
3do
4 local _obj_0 = require("yue")
5 p, to_lua = _obj_0.p, _obj_0.to_lua
6end
7local inventory = {
8 equipment = {
9 "sword",
10 "shield"
11 },
12 items = {
13 {
14 name = "potion",
15 count = 10
16 },
17 {
18 name = "bread",
19 count = 3
20 }
21 }
22}
23print(reduce(filter(map({
24 1,
25 2,
26 3
27}, function(x)
28 return x * 2
29end), function(x)
30 return x > 4
31end), 0, function(a, b)
32 return a + b
33end))
34local apple = setmetatable({
35 size = 15,
36}, {
37 __index = {
38 color = 0x00ffff
39 }
40})
41if (getmetatable(apple) ~= nil) then
42 p(apple.color, getmetatable(apple).__index)
43end
44local _ud83c_udf1b = "月之脚本"
45_module_0["🌛"] = _ud83c_udf1b
46return _module_0
47local area = 6.2831853071796 * 5
48print('你好 世界')
49assert(item ~= nil)
50local value = item
51if (f1() and f2() and f3()) then
52 print("OK")
53end
54local funcA
55funcA = function() end
56funcA = function()
57 return "访问月之脚本定义的变量"
58end
59local function funcB() end
60funcB = function()
61 return "访问Lua代码里定义的变量"
62end
63-- 插入原始Lua代码
64if cond then
65 print("输出")
66end
67print("yuescript")
68print(3)
69if tb ~= nil then
70 tb:func()
71end
72if tb ~= nil then
73 tb:func()
74end
75print(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)
76local a = 5
77print(1 <= a and a <= 10)
78local v
79v = function(x)
80 print(x)
81 return x
82end
83print((function()
84 local _cond_0 = v(2)
85 if not (v(1) < _cond_0) then
86 return false
87 else
88 return _cond_0 <= v(3)
89 end
90end)())
91print((function()
92 local _cond_0 = v(2)
93 if not (v(1) > _cond_0) then
94 return false
95 else
96 return _cond_0 <= v(3)
97 end
98end)())
99local tab = { }
100tab[#tab + 1] = "Value"
101local parts = {
102 "shoulders",
103 "knees"
104}
105local lyrics
106do
107 local _tab_0 = {
108 "head"
109 }
110 local _idx_0 = 1
111 for _key_0, _value_0 in pairs(parts) do
112 if _idx_0 == _key_0 then
113 _tab_0[#_tab_0 + 1] = _value_0
114 _idx_0 = _idx_0 + 1
115 else
116 _tab_0[_key_0] = _value_0
117 end
118 end
119 _tab_0[#_tab_0 + 1] = "and"
120 _tab_0[#_tab_0 + 1] = "toes"
121 lyrics = _tab_0
122end
123local copy
124do
125 local _tab_0 = { }
126 local _idx_0 = 1
127 for _key_0, _value_0 in pairs(other) do
128 if _idx_0 == _key_0 then
129 _tab_0[#_tab_0 + 1] = _value_0
130 _idx_0 = _idx_0 + 1
131 else
132 _tab_0[_key_0] = _value_0
133 end
134 end
135 copy = _tab_0
136end
137local a = {
138 1,
139 2,
140 3,
141 x = 1
142}
143local b = {
144 4,
145 5,
146 y = 1
147}
148local merge
149do
150 local _tab_0 = { }
151 local _idx_0 = 1
152 for _key_0, _value_0 in pairs(a) do
153 if _idx_0 == _key_0 then
154 _tab_0[#_tab_0 + 1] = _value_0
155 _idx_0 = _idx_0 + 1
156 else
157 _tab_0[_key_0] = _value_0
158 end
159 end
160 local _idx_1 = 1
161 for _key_0, _value_0 in pairs(b) do
162 if _idx_1 == _key_0 then
163 _tab_0[#_tab_0 + 1] = _value_0
164 _idx_1 = _idx_1 + 1
165 else
166 _tab_0[_key_0] = _value_0
167 end
168 end
169 merge = _tab_0
170end
171local mt = { }
172local add
173add = function(self, right)
174 return setmetatable({
175 value = self.value + right.value
176 }, mt)
177end
178mt.__add = add
179local a = setmetatable({
180 value = 1
181}, mt)
182local b = setmetatable({
183 value = 2
184}, {
185 __add = add
186})
187local c = setmetatable({
188 value = 3
189}, {
190 __add = mt.__add
191})
192local d = a + b + c
193print(d.value)
194local _ <close> = setmetatable({ }, {
195 __close = function()
196 return print("超出范围")
197 end
198})
199local tb = setmetatable({ }, {
200 ["value"] = 123
201})
202getmetatable(tb).__index = getmetatable(tb)
203print(tb.value)
204setmetatable(tb, {
205 __index = {
206 item = "hello"
207 }
208})
209print(tb.item)
210local item, new, close, getter
211do
212 local _obj_0 = tb
213 item, new = _obj_0[1], _obj_0.new
214 do
215 local _obj_1 = getmetatable(_obj_0)
216 close, getter = _obj_1.__close, _obj_1.__index
217 end
218end
219print(item, new, close, getter)
220do
221 local _obj_0 = func
222 if _obj_0 ~= nil then
223 _obj_0()
224 end
225end
226print((function()
227 local _obj_0 = abc
228 if _obj_0 ~= nil then
229 local _obj_1 = _obj_0["你好 世界"]
230 if _obj_1 ~= nil then
231 return _obj_1.xyz
232 end
233 return nil
234 end
235 return nil
236end)())
237local x
238do
239 local _obj_0 = tab
240 if _obj_0 ~= nil then
241 x = _obj_0.value
242 end
243end
244local len = (function()
245 local _obj_0 = utf8
246 if _obj_0 ~= nil then
247 return _obj_0.len
248 end
249 return nil
250end)() or (function()
251 local _obj_0 = string
252 if _obj_0 ~= nil then
253 return _obj_0.len
254 end
255 return nil
256end)() or function(o)
257 return #o
258end
259if print and (x ~= nil) then
260 print(x)
261end
262do
263 local _with_0 = io.open("test.txt", "w")
264 if _with_0 ~= nil then
265 _with_0:write("你好")
266 _with_0:close()
267 end
268end
269print("你好")
270print(1, 2)
271print(1, 2, 3)
272print(render(emit(parse(extract(readFile("example.txt"), language, { }), language))))
273local a, b, c, d
274if b ~= nil then
275 a = b
276else
277 if c ~= nil then
278 a = c
279 else
280 a = d
281 end
282end
283func((function()
284 if a ~= nil then
285 return a
286 else
287 return { }
288 end
289end)())
290if a == nil then
291 a = false
292end
293local list = {
294 1,
295 2,
296 3
297}
298func({
299 1,
300 2,
301 3
302})
303local tb = {
304 name = "abc",
305 values = {
306 "a",
307 "b",
308 "c"
309 },
310 objects = {
311 {
312 name = "a",
313 value = 1,
314 func = function(self)
315 return self.value + 1
316 end,
317 tb = {
318 fieldA = 1
319 }
320 },
321 {
322 name = "b",
323 value = 2,
324 func = function(self)
325 return self.value + 2
326 end,
327 tb = { }
328 }
329 }
330}
331do
332 local insert, concat = table.insert, table.concat
333 local C, Ct, Cmt
334 do
335 local _obj_0 = require("lpeg")
336 C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt
337 end
338 local x, y, z
339 do
340 local _obj_0 = require('mymodule')
341 x, y, z = _obj_0.x, _obj_0.y, _obj_0.z
342 end
343 local a, b, c
344 do
345 local _obj_0 = require('module')
346 a, b, c = _obj_0.a, _obj_0.b, _obj_0.c
347 end
348end
349do
350 local module = require('module')
351 local module_x = require('module_x')
352 local d_a_s_h_e_s = require("d-a-s-h-e-s")
353 local part = require("module.part")
354end
355do
356 local PlayerModule = require("player")
357 local C, Ct, Cmt
358 do
359 local _obj_0 = require("lpeg")
360 C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt
361 end
362 local one, two, ch
363 do
364 local _obj_0 = require("export")
365 one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1]
366 end
367end
368local _module_0 = { }
369local a, b, c = 1, 2, 3
370_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c
371local cool = "cat"
372_module_0["cool"] = cool
373local What
374if this then
375 What = "abc"
376else
377 What = "def"
378end
379_module_0["What"] = What
380local y
381y = function()
382 local hallo = 3434
383end
384_module_0["y"] = y
385local Something
386do
387 local _class_0
388 local _base_0 = {
389 umm = "cool"
390 }
391 if _base_0.__index == nil then
392 _base_0.__index = _base_0
393 end
394 _class_0 = setmetatable({
395 __init = function() end,
396 __base = _base_0,
397 __name = "Something"
398 }, {
399 __index = _base_0,
400 __call = function(cls, ...)
401 local _self_0 = setmetatable({ }, _base_0)
402 cls.__init(_self_0, ...)
403 return _self_0
404 end
405 })
406 _base_0.__class = _class_0
407 Something = _class_0
408end
409_module_0["Something"] = Something
410return _module_0
411local _module_0 = { }
412local loadstring, tolua
413do
414 local _obj_0 = yue
415 loadstring, tolua = _obj_0.loadstring, _obj_0.to_lua
416end
417_module_0["loadstring"], _module_0["tolua"] = loadstring, tolua
418local fieldA = tb.itemA.fieldA
419if fieldA == nil then
420 fieldA = '默认值'
421end
422_module_0["fieldA"] = fieldA
423return _module_0
424local _module_0 = setmetatable({ }, { })
425_module_0.itemA = tb
426getmetatable(_module_0).__index = items
427_module_0["a-b-c"] = 123
428return _module_0
429local _module_0 = { }
430local d, e, f = 3, 2, 1
431_module_0[#_module_0 + 1] = d
432_module_0[#_module_0 + 1] = e
433_module_0[#_module_0 + 1] = f
434if this then
435 _module_0[#_module_0 + 1] = 123
436else
437 _module_0[#_module_0 + 1] = 456
438end
439do
440 local _with_0 = tmp
441 local j = 2000
442 _module_0[#_module_0 + 1] = _with_0
443end
444return _module_0
445local _module_0 = nil
446_module_0 = function()
447 print("你好")
448 return 123
449end
450return _module_0
451local hello = "world"
452local a, b, c = 1, 2, 3
453hello = 123
454local x = 1
455x = x + 1
456x = x - 1
457x = x * 10
458x = x / 10
459x = x % 10
460local s = s .. "world"
461local arg = arg or "默认值"
462local a = 0
463local b = 0
464local c = 0
465local d = 0
466local e = 0
467local x = f()
468local y = x
469local z = x
470do
471 local a
472 a = 1
473 local x, y, z
474 print("预先声明后续所有变量为局部变量")
475 x = function()
476 return 1 + y + z
477 end
478 y, z = 2, 3
479 instance = Item:new()
480end
481do
482 local X
483 X = 1
484 local B
485 print("只预先声明后续大写的变量为局部变量")
486 local a = 1
487 B = 2
488end
489do
490 a = 1
491 print("预先声明所有变量为全局变量")
492 local x
493 x = function()
494 return 1 + y + z
495 end
496 local y, z = 2, 3
497end
498do
499 x = 1
500 print("只预先声明大写的变量为全局变量")
501 local a = 1
502 local B = 2
503 local Temp
504 Temp = "一个局部值"
505end
506local thing = {
507 1,
508 2
509}
510local a, b = thing[1], thing[2]
511print(a, b)
512local obj = {
513 hello = "world",
514 day = "tuesday",
515 length = 20
516}
517local hello, the_day = obj.hello, obj.day
518print(hello, the_day)
519local day = obj.day
520local obj2 = {
521 numbers = {
522 1,
523 2,
524 3,
525 4
526 },
527 properties = {
528 color = "green",
529 height = 13.5
530 }
531}
532local first, second = obj2.numbers[1], obj2.numbers[2]
533print(first, second, color)
534local first, second, color
535do
536 local _obj_0 = obj2
537 first, second, color = _obj_0.numbers[1], _obj_0.numbers[2], _obj_0.properties.color
538end
539local concat, insert
540do
541 local _obj_0 = table
542 concat, insert = _obj_0.concat, _obj_0.insert
543end
544local mix, max, rand
545do
546 local _obj_0 = math
547 mix, max, rand = _obj_0.mix, _obj_0.max, _obj_0.random
548end
549local name, job
550do
551 local _obj_0 = person
552 name, job = _obj_0.name, _obj_0.job
553 if name == nil then
554 name = "nameless"
555 end
556 if job == nil then
557 job = "jobless"
558 end
559end
560local two, four
561do
562 local _obj_0 = items
563 two, four = _obj_0[2], _obj_0[4]
564end
565local tuples = {
566 {
567 "hello",
568 "world"
569 },
570 {
571 "egg",
572 "head"
573 }
574}
575for _index_0 = 1, #tuples do
576 local _des_0 = tuples[_index_0]
577 local left, right = _des_0[1], _des_0[2]
578 print(left, right)
579end
580do
581 local user = database.find_user("moon")
582 if user then
583 print(user.name)
584 end
585end
586do
587 local hello = os.getenv("hello")
588 if hello then
589 print("你有 hello", hello)
590 else
591 do
592 local world = os.getenv("world")
593 if world then
594 print("你有 world", world)
595 else
596 print("什么都没有 :(")
597 end
598 end
599 end
600end
601do
602 local success, result = pcall(function()
603 return "无报错地获取结果"
604 end)
605 if success then
606 print(result)
607 end
608end
609print("好的")
610local list = {
611 1,
612 2,
613 3,
614 4,
615 5
616}
617local fn
618fn = function(ok)
619 return ok, table.unpack(list)
620end
621(function(_arg_0, ...)
622 local ok = _arg_0
623 local count = select('#', ...)
624 local first = select(1, ...)
625 return print(ok, count, first)
626end)(fn(true))
627Rx.Observable.fromRange(1, 8):filter(function(x)
628 return x % 2 == 0
629end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
630 return value .. '!'
631end):subscribe(print)
632local str = strA .. strB .. strC
633func(3000, "192.168.1.1")
634xpcall(func, function(err)
635 return print(yue.traceback(err))
636end, 1, 2, 3)
637local success, result = xpcall(func, function(err)
638 return yue.traceback(err)
639end, 1, 2, 3)
640xpcall(func, function(err)
641 return print(yue.traceback(err))
642end, 1, 2, 3)
643success, result = pcall(func, 1, 2, 3)
644pcall(function()
645 print("尝试中")
646 return func(1, 2, 3)
647end)
648success, result = xpcall(func, function(err)
649 return print(yue.traceback(err))
650end, 1, 2, 3)
651if success then
652 print(result)
653end
654local a <const> = 123
655local _ <close> = setmetatable({ }, {
656 __close = function()
657 return print("超出范围。")
658 end
659})
660local a, b, c, d
661do
662 local _obj_0 = tb
663 a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
664end
665local some_string = "这是一个字符串\n 并包括一个换行。"
666print("我有" .. tostring(math.random() * 100) .. "%的把握。")
667local integer = 1000000
668local hex = 0xEFBBBF
669local my_function
670my_function = function() end
671my_function()
672local func_a
673func_a = function()
674 return print("你好,世界")
675end
676local func_b
677func_b = function()
678 local value = 100
679 return print("这个值是:", value)
680end
681func_a()
682func_b()
683local sum
684sum = function(x, y)
685 return print("数字的和", x + y)
686end
687sum(10, 20)
688print(sum(10, 20))
689a(b(c("a", "b", "c")))
690print("x:", sum(10, 20), "y:", sum(30, 40))
691local sum
692sum = function(x, y)
693 return x + y
694end
695print("数字的和是", sum(10, 20))
696local sum
697sum = function(x, y)
698 return x + y
699end
700local mystery
701mystery = function(x, y)
702 return x + y, x - y
703end
704local a, b = mystery(10, 20)
705local func
706func = function(self, num)
707 return self.value + num
708end
709local my_function
710my_function = function(name, height)
711 if name == nil then
712 name = "某物"
713 end
714 if height == nil then
715 height = 100
716 end
717 print("你好,我是", name)
718 return print("我的高度是", height)
719end
720local some_args
721some_args = function(x, y)
722 if x == nil then
723 x = 100
724 end
725 if y == nil then
726 y = x + 1000
727 end
728 return print(x + y)
729end
730my_func(5, 4, 3, 8, 9, 10)
731cool_func(1, 2, 3, 4, 5, 6, 7, 8)
732my_func(5, 6, 7, 6, another_func(6, 7, 8, 9, 1, 2), 5, 4)
733local x = {
734 1,
735 2,
736 3,
737 4,
738 a_func(4, 5, 5, 6),
739 8,
740 9,
741 10
742}
743local y = {
744 my_func(1, 2, 3, 4, 5),
745 5,
746 6,
747 7
748}
749if func(1, 2, 3, "你好", "世界") then
750 print("你好")
751 print("我在if内部")
752end
753if func(1, 2, 3, "你好", "世界") then
754 print("hello")
755 print("我在if内部")
756end
757f(function()
758 return print("hello")
759end)
760f(function(self)
761 return print(self.value)
762end)
763map(function(x)
764 return x * 2
765end, {
766 1,
767 2,
768 3
769})
770local result, msg
771do
772 result, msg = readAsync("文件名.txt", function(data)
773 print(data)
774 return processAsync(data, function(info)
775 return check(info)
776 end)
777 end)
778end
779print(result, msg)
780local some_values = {
781 1,
782 2,
783 3,
784 4
785}
786local some_values = {
787 name = "Bill",
788 age = 200,
789 ["favorite food"] = "rice"
790}
791local profile = {
792 height = "4英尺",
793 shoe_size = 13,
794 favorite_foods = {
795 "冰淇淋",
796 "甜甜圈"
797 }
798}
799local values = {
800 1,
801 2,
802 3,
803 4,
804 5,
805 6,
806 7,
807 8,
808 name = "超人",
809 occupation = "打击犯罪"
810}
811my_function({
812 dance = "探戈",
813 partner = "无"
814})
815local y = {
816 type = "狗",
817 legs = 4,
818 tails = 1
819}
820local tbl = {
821 ["do"] = "某事",
822 ["end"] = "饥饿"
823}
824local hair = "金色"
825local height = 200
826local person = {
827 hair = hair,
828 height = height,
829 shoe_size = 40
830}
831print_table({
832 hair = hair,
833 height = height
834})
835local t = {
836 [1 + 2] = "你好",
837 ["你好 世界"] = true
838}
839local some_values = {
840 1,
841 2,
842 3,
843 4
844}
845local list_with_one_element = {
846 1
847}
848local items = {
849 1,
850 2,
851 3,
852 4
853}
854local doubled
855do
856 local _accum_0 = { }
857 local _len_0 = 1
858 for i, item in ipairs(items) do
859 _accum_0[_len_0] = item * 2
860 _len_0 = _len_0 + 1
861 end
862 doubled = _accum_0
863end
864local iter = ipairs(items)
865local slice
866do
867 local _accum_0 = { }
868 local _len_0 = 1
869 for i, item in iter do
870 if i > 1 and i < 3 then
871 _accum_0[_len_0] = item
872 _len_0 = _len_0 + 1
873 end
874 end
875 slice = _accum_0
876end
877local doubled
878do
879 local _accum_0 = { }
880 local _len_0 = 1
881 local _list_0 = items
882 for _index_0 = 1, #_list_0 do
883 local item = _list_0[_index_0]
884 _accum_0[_len_0] = item * 2
885 _len_0 = _len_0 + 1
886 end
887 doubled = _accum_0
888end
889local x_coords = {
890 4,
891 5,
892 6,
893 7
894}
895local y_coords = {
896 9,
897 2,
898 3
899}
900local points
901do
902 local _accum_0 = { }
903 local _len_0 = 1
904 for _index_0 = 1, #x_coords do
905 local x = x_coords[_index_0]
906 for _index_1 = 1, #y_coords do
907 local y = y_coords[_index_1]
908 _accum_0[_len_0] = {
909 x,
910 y
911 }
912 _len_0 = _len_0 + 1
913 end
914 end
915 points = _accum_0
916end
917local evens
918do
919 local _accum_0 = { }
920 local _len_0 = 1
921 for i = 1, 100 do
922 if i % 2 == 0 then
923 _accum_0[_len_0] = i
924 _len_0 = _len_0 + 1
925 end
926 end
927 evens = _accum_0
928end
929local thing = {
930 color = "red",
931 name = "fast",
932 width = 123
933}
934local thing_copy
935do
936 local _tbl_0 = { }
937 for k, v in pairs(thing) do
938 _tbl_0[k] = v
939 end
940 thing_copy = _tbl_0
941end
942local no_color
943do
944 local _tbl_0 = { }
945 for k, v in pairs(thing) do
946 if k ~= "color" then
947 _tbl_0[k] = v
948 end
949 end
950 no_color = _tbl_0
951end
952local numbers = {
953 1,
954 2,
955 3,
956 4
957}
958local sqrts
959do
960 local _tbl_0 = { }
961 for _index_0 = 1, #numbers do
962 local i = numbers[_index_0]
963 _tbl_0[i] = math.sqrt(i)
964 end
965 sqrts = _tbl_0
966end
967local tuples = {
968 {
969 "hello",
970 "world"
971 },
972 {
973 "foo",
974 "bar"
975 }
976}
977local tbl
978do
979 local _tbl_0 = { }
980 for _index_0 = 1, #tuples do
981 local tuple = tuples[_index_0]
982 local _key_0, _val_0 = unpack(tuple)
983 _tbl_0[_key_0] = _val_0
984 end
985 tbl = _tbl_0
986end
987local slice
988do
989 local _accum_0 = { }
990 local _len_0 = 1
991 local _list_0 = items
992 local _max_0 = 5
993 for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
994 local item = _list_0[_index_0]
995 _accum_0[_len_0] = item
996 _len_0 = _len_0 + 1
997 end
998 slice = _accum_0
999end
1000local slice
1001do
1002 local _accum_0 = { }
1003 local _len_0 = 1
1004 local _list_0 = items
1005 for _index_0 = 2, #_list_0 do
1006 local item = _list_0[_index_0]
1007 _accum_0[_len_0] = item
1008 _len_0 = _len_0 + 1
1009 end
1010 slice = _accum_0
1011end
1012local slice
1013do
1014 local _accum_0 = { }
1015 local _len_0 = 1
1016 local _list_0 = items
1017 for _index_0 = 1, #_list_0, 2 do
1018 local item = _list_0[_index_0]
1019 _accum_0[_len_0] = item
1020 _len_0 = _len_0 + 1
1021 end
1022 slice = _accum_0
1023end
1024for i = 10, 20 do
1025 print(i)
1026end
1027for k = 1, 15, 2 do
1028 print(k)
1029end
1030for key, value in pairs(object) do
1031 print(key, value)
1032end
1033do
1034 local _list_0 = items
1035 local _max_0 = 4
1036 for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
1037 local item = _list_0[_index_0]
1038 print(item)
1039 end
1040end
1041local _list_0 = items
1042for _index_0 = 1, #_list_0 do
1043 local item = _list_0[_index_0]
1044 print(item)
1045end
1046for j = 1, 10, 3 do
1047 print(j)
1048end
1049local doubled_evens
1050do
1051 local _accum_0 = { }
1052 local _len_0 = 1
1053 for i = 1, 20 do
1054 if i % 2 == 0 then
1055 _accum_0[_len_0] = i * 2
1056 else
1057 _accum_0[_len_0] = i
1058 end
1059 _len_0 = _len_0 + 1
1060 end
1061 doubled_evens = _accum_0
1062end
1063local func_a
1064func_a = function()
1065 for i = 1, 10 do
1066 print(i)
1067 end
1068end
1069local func_b
1070func_b = function()
1071 local _accum_0 = { }
1072 local _len_0 = 1
1073 for i = 1, 10 do
1074 _accum_0[_len_0] = i
1075 _len_0 = _len_0 + 1
1076 end
1077 return _accum_0
1078end
1079print(func_a())
1080print(func_b())
1081local i = 10
1082repeat
1083 print(i)
1084 i = i - 1
1085until i == 0
1086local i = 10
1087while i > 0 do
1088 print(i)
1089 i = i - 1
1090end
1091while running == true do
1092 my_function()
1093end
1094local i = 10
1095while not (i == 0) do
1096 print(i)
1097 i = i - 1
1098end
1099while not (running == false) do
1100 my_function()
1101end
1102local i = 0
1103while i < 10 do
1104 i = i + 1
1105 if i % 2 == 0 then
1106 goto _continue_0
1107 end
1108 print(i)
1109 ::_continue_0::
1110end
1111local my_numbers = {
1112 1,
1113 2,
1114 3,
1115 4,
1116 5,
1117 6
1118}
1119local odds
1120do
1121 local _accum_0 = { }
1122 local _len_0 = 1
1123 for _index_0 = 1, #my_numbers do
1124 local x = my_numbers[_index_0]
1125 if x % 2 == 1 then
1126 goto _continue_0
1127 end
1128 _accum_0[_len_0] = x
1129 _len_0 = _len_0 + 1
1130 ::_continue_0::
1131 end
1132 odds = _accum_0
1133end
1134local have_coins = false
1135if have_coins then
1136 print("有硬币")
1137else
1138 print("没有硬币")
1139end
1140local have_coins = false
1141if have_coins then
1142 print("有硬币")
1143else
1144 print("没有硬币")
1145end
1146local have_coins = false
1147print((function()
1148 if have_coins then
1149 return "有硬币"
1150 else
1151 return "没有硬币"
1152 end
1153end)())
1154local is_tall
1155is_tall = function(name)
1156 if name == "Rob" then
1157 return true
1158 else
1159 return false
1160 end
1161end
1162local message
1163if is_tall("Rob") then
1164 message = "我很高"
1165else
1166 message = "我不是很高"
1167end
1168print(message)
1169if not (os.date("%A") == "Monday") then
1170 print("今天不是星期一!")
1171end
1172if not (math.random() > 0.1) then
1173 print("你真幸运!")
1174end
1175local a = 5
1176if (1 == a or 3 == a or 5 == a or 7 == a) then
1177 print("检查离散值的相等性")
1178end
1179if (function()
1180 local _check_0 = list
1181 for _index_0 = 1, #_check_0 do
1182 if _check_0[_index_0] == a then
1183 return true
1184 end
1185 end
1186 return false
1187end)() then
1188 print("检查`a`是否在列表中")
1189end
1190if not (math.random() > 0.1) then
1191 print("你很幸运!")
1192end
1193if name == "Rob" then
1194 print("你好,世界")
1195end
1196local _list_0 = items
1197for _index_0 = 1, #_list_0 do
1198 local item = _list_0[_index_0]
1199 print("项目: ", item)
1200end
1201while game:isRunning() do
1202 game:update()
1203end
1204while not reader:eof() do
1205 reader:parse_line()
1206end
1207local name = "Dan"
1208if "Robert" == name then
1209 print("你是Robert")
1210elseif "Dan" == name or "Daniel" == name then
1211 print("你的名字是Dan")
1212else
1213 print("我不知道你的名字")
1214end
1215local b = 1
1216local next_number
1217if 1 == b then
1218 next_number = 2
1219elseif 2 == b then
1220 next_number = 3
1221else
1222 next_number = error("数字数得太大了!")
1223end
1224local msg
1225do
1226 local _exp_0 = math.random(1, 5)
1227 if 1 == _exp_0 then
1228 msg = "你很幸运"
1229 elseif 2 == _exp_0 then
1230 msg = "你差点很幸运"
1231 else
1232 msg = "不太幸运"
1233 end
1234end
1235do
1236 local _exp_0 = math.random(1, 5)
1237 if 1 == _exp_0 then
1238 print("你很幸运")
1239 else
1240 print("不太幸运")
1241 end
1242end
1243do
1244 local _exp_0 = math.random(1, 5)
1245 if 1 == _exp_0 then
1246 print("你很幸运")
1247 else
1248 print("不太幸运")
1249 end
1250end
1251local items = {
1252 {
1253 x = 100,
1254 y = 200
1255 },
1256 {
1257 width = 300,
1258 height = 400
1259 }
1260}
1261for _index_0 = 1, #items do
1262 local item = items[_index_0]
1263 do
1264 local _type_0 = type(item)
1265 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1266 local _match_0 = false
1267 if _tab_0 then
1268 local x = item.x
1269 local y = item.y
1270 if x ~= nil and y ~= nil then
1271 _match_0 = true
1272 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
1273 end
1274 end
1275 if not _match_0 then
1276 if _tab_0 then
1277 local width = item.width
1278 local height = item.height
1279 if width ~= nil and height ~= nil then
1280 print("尺寸 " .. tostring(width) .. ", " .. tostring(height))
1281 end
1282 end
1283 end
1284 end
1285end
1286local item = { }
1287local x, y = item.pos.x, item.pos.y
1288if x == nil then
1289 x = 50
1290end
1291if y == nil then
1292 y = 200
1293end
1294do
1295 local _type_0 = type(item)
1296 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1297 if _tab_0 then
1298 do
1299 local _obj_0 = item.pos
1300 local _type_1 = type(_obj_0)
1301 if "table" == _type_1 or "userdata" == _type_1 then
1302 x = _obj_0.x
1303 end
1304 end
1305 do
1306 local _obj_0 = item.pos
1307 local _type_1 = type(_obj_0)
1308 if "table" == _type_1 or "userdata" == _type_1 then
1309 y = _obj_0.y
1310 end
1311 end
1312 if x == nil then
1313 x = 50
1314 end
1315 if y == nil then
1316 y = 200
1317 end
1318 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
1319 end
1320end
1321local Inventory
1322do
1323 local _class_0
1324 local _base_0 = {
1325 add_item = function(self, name)
1326 if self.items[name] then
1327 local _obj_0 = self.items
1328 _obj_0[name] = _obj_0[name] + 1
1329 else
1330 self.items[name] = 1
1331 end
1332 end
1333 }
1334 if _base_0.__index == nil then
1335 _base_0.__index = _base_0
1336 end
1337 _class_0 = setmetatable({
1338 __init = function(self)
1339 self.items = { }
1340 end,
1341 __base = _base_0,
1342 __name = "Inventory"
1343 }, {
1344 __index = _base_0,
1345 __call = function(cls, ...)
1346 local _self_0 = setmetatable({ }, _base_0)
1347 cls.__init(_self_0, ...)
1348 return _self_0
1349 end
1350 })
1351 _base_0.__class = _class_0
1352 Inventory = _class_0
1353end
1354local inv = Inventory()
1355inv:add_item("t-shirt")
1356inv:add_item("pants")
1357local Person
1358do
1359 local _class_0
1360 local _base_0 = {
1361 clothes = { },
1362 give_item = function(self, name)
1363 return table.insert(self.clothes, name)
1364 end
1365 }
1366 if _base_0.__index == nil then
1367 _base_0.__index = _base_0
1368 end
1369 _class_0 = setmetatable({
1370 __init = function() end,
1371 __base = _base_0,
1372 __name = "Person"
1373 }, {
1374 __index = _base_0,
1375 __call = function(cls, ...)
1376 local _self_0 = setmetatable({ }, _base_0)
1377 cls.__init(_self_0, ...)
1378 return _self_0
1379 end
1380 })
1381 _base_0.__class = _class_0
1382 Person = _class_0
1383end
1384local a = Person()
1385local b = Person()
1386a:give_item("pants")
1387b:give_item("shirt")
1388local _list_0 = a.clothes
1389for _index_0 = 1, #_list_0 do
1390 local item = _list_0[_index_0]
1391 print(item)
1392end
1393local Person
1394do
1395 local _class_0
1396 local _base_0 = { }
1397 if _base_0.__index == nil then
1398 _base_0.__index = _base_0
1399 end
1400 _class_0 = setmetatable({
1401 __init = function(self)
1402 self.clothes = { }
1403 end,
1404 __base = _base_0,
1405 __name = "Person"
1406 }, {
1407 __index = _base_0,
1408 __call = function(cls, ...)
1409 local _self_0 = setmetatable({ }, _base_0)
1410 cls.__init(_self_0, ...)
1411 return _self_0
1412 end
1413 })
1414 _base_0.__class = _class_0
1415 Person = _class_0
1416end
1417local BackPack
1418do
1419 local _class_0
1420 local _parent_0 = Inventory
1421 local _base_0 = {
1422 size = 10,
1423 add_item = function(self, name)
1424 if #self.items > size then
1425 error("背包已满")
1426 end
1427 return _class_0.__parent.__base.add_item(self, name)
1428 end
1429 }
1430 for _key_0, _val_0 in pairs(_parent_0.__base) do
1431 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
1432 _base_0[_key_0] = _val_0
1433 end
1434 end
1435 if _base_0.__index == nil then
1436 _base_0.__index = _base_0
1437 end
1438 setmetatable(_base_0, _parent_0.__base)
1439 _class_0 = setmetatable({
1440 __init = function(self, ...)
1441 return _class_0.__parent.__init(self, ...)
1442 end,
1443 __base = _base_0,
1444 __name = "BackPack",
1445 __parent = _parent_0
1446 }, {
1447 __index = function(cls, name)
1448 local val = rawget(_base_0, name)
1449 if val == nil then
1450 local parent = rawget(cls, "__parent")
1451 if parent then
1452 return parent[name]
1453 end
1454 else
1455 return val
1456 end
1457 end,
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 if _parent_0.__inherited then
1466 _parent_0.__inherited(_parent_0, _class_0)
1467 end
1468 BackPack = _class_0
1469end
1470local Shelf
1471do
1472 local _class_0
1473 local _base_0 = { }
1474 if _base_0.__index == nil then
1475 _base_0.__index = _base_0
1476 end
1477 _class_0 = setmetatable({
1478 __init = function() end,
1479 __base = _base_0,
1480 __name = "Shelf"
1481 }, {
1482 __index = _base_0,
1483 __call = function(cls, ...)
1484 local _self_0 = setmetatable({ }, _base_0)
1485 cls.__init(_self_0, ...)
1486 return _self_0
1487 end
1488 })
1489 _base_0.__class = _class_0
1490 local self = _class_0;
1491 self.__inherited = function(self, child)
1492 return print(self.__name, "被", child.__name, "继承")
1493 end
1494 Shelf = _class_0
1495end
1496local Cupboard
1497do
1498 local _class_0
1499 local _parent_0 = Shelf
1500 local _base_0 = { }
1501 for _key_0, _val_0 in pairs(_parent_0.__base) do
1502 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
1503 _base_0[_key_0] = _val_0
1504 end
1505 end
1506 if _base_0.__index == nil then
1507 _base_0.__index = _base_0
1508 end
1509 setmetatable(_base_0, _parent_0.__base)
1510 _class_0 = setmetatable({
1511 __init = function(self, ...)
1512 return _class_0.__parent.__init(self, ...)
1513 end,
1514 __base = _base_0,
1515 __name = "Cupboard",
1516 __parent = _parent_0
1517 }, {
1518 __index = function(cls, name)
1519 local val = rawget(_base_0, name)
1520 if val == nil then
1521 local parent = rawget(cls, "__parent")
1522 if parent then
1523 return parent[name]
1524 end
1525 else
1526 return val
1527 end
1528 end,
1529 __call = function(cls, ...)
1530 local _self_0 = setmetatable({ }, _base_0)
1531 cls.__init(_self_0, ...)
1532 return _self_0
1533 end
1534 })
1535 _base_0.__class = _class_0
1536 if _parent_0.__inherited then
1537 _parent_0.__inherited(_parent_0, _class_0)
1538 end
1539 Cupboard = _class_0
1540end
1541local MyClass
1542do
1543 local _class_0
1544 local _parent_0 = ParentClass
1545 local _base_0 = {
1546 a_method = function(self)
1547 _class_0.__parent.__base.a_method(self, "你好", "世界")
1548 _class_0.__parent.a_method(self, "你好", "世界")
1549 _class_0.__parent.a_method(self, "你好", "世界")
1550 return assert(_class_0.__parent == ParentClass)
1551 end
1552 }
1553 for _key_0, _val_0 in pairs(_parent_0.__base) do
1554 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
1555 _base_0[_key_0] = _val_0
1556 end
1557 end
1558 if _base_0.__index == nil then
1559 _base_0.__index = _base_0
1560 end
1561 setmetatable(_base_0, _parent_0.__base)
1562 _class_0 = setmetatable({
1563 __init = function(self, ...)
1564 return _class_0.__parent.__init(self, ...)
1565 end,
1566 __base = _base_0,
1567 __name = "MyClass",
1568 __parent = _parent_0
1569 }, {
1570 __index = function(cls, name)
1571 local val = rawget(_base_0, name)
1572 if val == nil then
1573 local parent = rawget(cls, "__parent")
1574 if parent then
1575 return parent[name]
1576 end
1577 else
1578 return val
1579 end
1580 end,
1581 __call = function(cls, ...)
1582 local _self_0 = setmetatable({ }, _base_0)
1583 cls.__init(_self_0, ...)
1584 return _self_0
1585 end
1586 })
1587 _base_0.__class = _class_0
1588 if _parent_0.__inherited then
1589 _parent_0.__inherited(_parent_0, _class_0)
1590 end
1591 MyClass = _class_0
1592end
1593local b = BackPack()
1594assert(b.__class == BackPack)
1595print(BackPack.size)
1596print(BackPack.__name)
1597local Things
1598do
1599 local _class_0
1600 local _base_0 = { }
1601 if _base_0.__index == nil then
1602 _base_0.__index = _base_0
1603 end
1604 _class_0 = setmetatable({
1605 __init = function() end,
1606 __base = _base_0,
1607 __name = "Things"
1608 }, {
1609 __index = _base_0,
1610 __call = function(cls, ...)
1611 local _self_0 = setmetatable({ }, _base_0)
1612 cls.__init(_self_0, ...)
1613 return _self_0
1614 end
1615 })
1616 _base_0.__class = _class_0
1617 local self = _class_0;
1618 self.some_func = function(self)
1619 return print("Hello from", self.__name)
1620 end
1621 Things = _class_0
1622end
1623Things:some_func()
1624assert(Things().some_func == nil)
1625local Counter
1626do
1627 local _class_0
1628 local _base_0 = { }
1629 if _base_0.__index == nil then
1630 _base_0.__index = _base_0
1631 end
1632 _class_0 = setmetatable({
1633 __init = function(self)
1634 self.__class.count = self.__class.count + 1
1635 end,
1636 __base = _base_0,
1637 __name = "Counter"
1638 }, {
1639 __index = _base_0,
1640 __call = function(cls, ...)
1641 local _self_0 = setmetatable({ }, _base_0)
1642 cls.__init(_self_0, ...)
1643 return _self_0
1644 end
1645 })
1646 _base_0.__class = _class_0
1647 local self = _class_0;
1648 self.count = 0
1649 Counter = _class_0
1650end
1651Counter()
1652Counter()
1653print(Counter.count)
1654self.__class:hello(1, 2, 3, 4)
1655local Things
1656do
1657 local _class_0
1658 local _base_0 = { }
1659 if _base_0.__index == nil then
1660 _base_0.__index = _base_0
1661 end
1662 _class_0 = setmetatable({
1663 __init = function() end,
1664 __base = _base_0,
1665 __name = "Things"
1666 }, {
1667 __index = _base_0,
1668 __call = function(cls, ...)
1669 local _self_0 = setmetatable({ }, _base_0)
1670 cls.__init(_self_0, ...)
1671 return _self_0
1672 end
1673 })
1674 _base_0.__class = _class_0
1675 local self = _class_0;
1676 self.class_var = "hello world"
1677 Things = _class_0
1678end
1679local MoreThings
1680do
1681 local _class_0
1682 local secret, log
1683 local _base_0 = {
1684 some_method = function(self)
1685 return log("hello world: " .. secret)
1686 end
1687 }
1688 if _base_0.__index == nil then
1689 _base_0.__index = _base_0
1690 end
1691 _class_0 = setmetatable({
1692 __init = function() end,
1693 __base = _base_0,
1694 __name = "MoreThings"
1695 }, {
1696 __index = _base_0,
1697 __call = function(cls, ...)
1698 local _self_0 = setmetatable({ }, _base_0)
1699 cls.__init(_self_0, ...)
1700 return _self_0
1701 end
1702 })
1703 _base_0.__class = _class_0
1704 local self = _class_0;
1705 secret = 123
1706 log = function(msg)
1707 return print("LOG:", msg)
1708 end
1709 MoreThings = _class_0
1710end
1711assert(self == self)
1712assert(self.__class == self.__class)
1713local some_instance_method
1714some_instance_method = function(self, ...)
1715 return self.__class(...)
1716end
1717local Something
1718do
1719 local _class_0
1720 local _base_0 = { }
1721 if _base_0.__index == nil then
1722 _base_0.__index = _base_0
1723 end
1724 _class_0 = setmetatable({
1725 __init = function(self, foo, bar, biz, baz)
1726 self.foo = foo
1727 self.bar = bar
1728 self.__class.biz = biz
1729 self.__class.baz = baz
1730 end,
1731 __base = _base_0,
1732 __name = "Something"
1733 }, {
1734 __index = _base_0,
1735 __call = function(cls, ...)
1736 local _self_0 = setmetatable({ }, _base_0)
1737 cls.__init(_self_0, ...)
1738 return _self_0
1739 end
1740 })
1741 _base_0.__class = _class_0
1742 Something = _class_0
1743end
1744do
1745 local _class_0
1746 local _base_0 = { }
1747 if _base_0.__index == nil then
1748 _base_0.__index = _base_0
1749 end
1750 _class_0 = setmetatable({
1751 __init = function(self, foo, bar, biz, baz)
1752 self.foo = foo
1753 self.bar = bar
1754 self.__class.biz = biz
1755 self.__class.baz = baz
1756 end,
1757 __base = _base_0,
1758 __name = "Something"
1759 }, {
1760 __index = _base_0,
1761 __call = function(cls, ...)
1762 local _self_0 = setmetatable({ }, _base_0)
1763 cls.__init(_self_0, ...)
1764 return _self_0
1765 end
1766 })
1767 _base_0.__class = _class_0
1768 Something = _class_0
1769end
1770local new
1771new = function(self, fieldA, fieldB)
1772 self.fieldA = fieldA
1773 self.fieldB = fieldB
1774 return self
1775end
1776local obj = new({ }, 123, "abc")
1777print(obj)
1778local x
1779local Bucket
1780do
1781 local _class_0
1782 local _base_0 = {
1783 drops = 0,
1784 add_drop = function(self)
1785 self.drops = self.drops + 1
1786 end
1787 }
1788 if _base_0.__index == nil then
1789 _base_0.__index = _base_0
1790 end
1791 _class_0 = setmetatable({
1792 __init = function() end,
1793 __base = _base_0,
1794 __name = "Bucket"
1795 }, {
1796 __index = _base_0,
1797 __call = function(cls, ...)
1798 local _self_0 = setmetatable({ }, _base_0)
1799 cls.__init(_self_0, ...)
1800 return _self_0
1801 end
1802 })
1803 _base_0.__class = _class_0
1804 Bucket = _class_0
1805 x = _class_0
1806end
1807local BigBucket
1808do
1809 local _class_0
1810 local _parent_0 = Bucket
1811 local _base_0 = {
1812 add_drop = function(self)
1813 self.drops = self.drops + 10
1814 end
1815 }
1816 for _key_0, _val_0 in pairs(_parent_0.__base) do
1817 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
1818 _base_0[_key_0] = _val_0
1819 end
1820 end
1821 if _base_0.__index == nil then
1822 _base_0.__index = _base_0
1823 end
1824 setmetatable(_base_0, _parent_0.__base)
1825 _class_0 = setmetatable({
1826 __init = function(self, ...)
1827 return _class_0.__parent.__init(self, ...)
1828 end,
1829 __base = _base_0,
1830 __name = "BigBucket",
1831 __parent = _parent_0
1832 }, {
1833 __index = function(cls, name)
1834 local val = rawget(_base_0, name)
1835 if val == nil then
1836 local parent = rawget(cls, "__parent")
1837 if parent then
1838 return parent[name]
1839 end
1840 else
1841 return val
1842 end
1843 end,
1844 __call = function(cls, ...)
1845 local _self_0 = setmetatable({ }, _base_0)
1846 cls.__init(_self_0, ...)
1847 return _self_0
1848 end
1849 })
1850 _base_0.__class = _class_0
1851 if _parent_0.__inherited then
1852 _parent_0.__inherited(_parent_0, _class_0)
1853 end
1854 BigBucket = _class_0
1855end
1856assert(Bucket.__name == "BigBucket")
1857local x
1858do
1859 local _class_0
1860 local _base_0 = { }
1861 if _base_0.__index == nil then
1862 _base_0.__index = _base_0
1863 end
1864 _class_0 = setmetatable({
1865 __init = function() end,
1866 __base = _base_0,
1867 __name = "x"
1868 }, {
1869 __index = _base_0,
1870 __call = function(cls, ...)
1871 local _self_0 = setmetatable({ }, _base_0)
1872 cls.__init(_self_0, ...)
1873 return _self_0
1874 end
1875 })
1876 _base_0.__class = _class_0
1877 x = _class_0
1878end
1879local MyIndex = {
1880 __index = {
1881 var = 1
1882 }
1883}
1884local X
1885do
1886 local _class_0
1887 local _base_0 = {
1888 func = function(self)
1889 return print(123)
1890 end
1891 }
1892 local _list_0 = {
1893 MyIndex
1894 }
1895 for _index_0 = 1, #_list_0 do
1896 local _item_0 = _list_0[_index_0]
1897 local _cls_0, _mixin_0 = (_item_0.__base ~= nil), _item_0.__base or _item_0
1898 for _key_0, _val_0 in pairs(_mixin_0) do
1899 if _base_0[_key_0] == nil and (not _cls_0 or not _key_0:match("^__")) then
1900 _base_0[_key_0] = _val_0
1901 end
1902 end
1903 end
1904 if _base_0.__index == nil then
1905 _base_0.__index = _base_0
1906 end
1907 _class_0 = setmetatable({
1908 __init = function() end,
1909 __base = _base_0,
1910 __name = "X"
1911 }, {
1912 __index = _base_0,
1913 __call = function(cls, ...)
1914 local _self_0 = setmetatable({ }, _base_0)
1915 cls.__init(_self_0, ...)
1916 return _self_0
1917 end
1918 })
1919 _base_0.__class = _class_0
1920 X = _class_0
1921end
1922local x = X()
1923print(x.var)
1924local Y
1925do
1926 local _class_0
1927 local _base_0 = { }
1928 local _list_0 = {
1929 X
1930 }
1931 for _index_0 = 1, #_list_0 do
1932 local _item_0 = _list_0[_index_0]
1933 local _cls_0, _mixin_0 = (_item_0.__base ~= nil), _item_0.__base or _item_0
1934 for _key_0, _val_0 in pairs(_mixin_0) do
1935 if _base_0[_key_0] == nil and (not _cls_0 or not _key_0:match("^__")) then
1936 _base_0[_key_0] = _val_0
1937 end
1938 end
1939 end
1940 if _base_0.__index == nil then
1941 _base_0.__index = _base_0
1942 end
1943 _class_0 = setmetatable({
1944 __init = function() end,
1945 __base = _base_0,
1946 __name = "Y"
1947 }, {
1948 __index = _base_0,
1949 __call = function(cls, ...)
1950 local _self_0 = setmetatable({ }, _base_0)
1951 cls.__init(_self_0, ...)
1952 return _self_0
1953 end
1954 })
1955 _base_0.__class = _class_0
1956 Y = _class_0
1957end
1958local y = Y()
1959y:func()
1960assert(y.__class.__parent ~= X)
1961do
1962 local _with_0 = Person()
1963 _with_0.name = "Oswald"
1964 _with_0:add_relative(my_dad)
1965 _with_0:save()
1966 print(_with_0.name)
1967end
1968local file
1969do
1970 local _with_0 = File("favorite_foods.txt")
1971 _with_0:set_encoding("utf8")
1972 file = _with_0
1973end
1974local create_person
1975create_person = function(name, relatives)
1976 local _with_0 = Person()
1977 _with_0.name = name
1978 for _index_0 = 1, #relatives do
1979 local relative = relatives[_index_0]
1980 _with_0:add_relative(relative)
1981 end
1982 return _with_0
1983end
1984local me = create_person("Leaf", {
1985 dad,
1986 mother,
1987 sister
1988})
1989do
1990 local str = "你好"
1991 print("原始:", str)
1992 print("大写:", str:upper())
1993end
1994do
1995 local _with_0 = tb
1996 _with_0[1] = 1
1997 print(_with_0[2])
1998 do
1999 local _with_1 = _with_0[abc]
2000 _with_1[3] = _with_1[2]:func()
2001 _with_1["key-name"] = value
2002 end
2003 _with_0[#_with_0 + 1] = "abc"
2004end
2005do
2006 local var = "hello"
2007 print(var)
2008end
2009print(var)
2010local counter
2011do
2012 local i = 0
2013 counter = function()
2014 i = i + 1
2015 return i
2016 end
2017end
2018print(counter())
2019print(counter())
2020local tbl = {
2021 key = (function()
2022 print("分配键值!")
2023 return 1234
2024 end)()
2025}
2026local my_object = {
2027 value = 1000,
2028 write = function(self)
2029 return print("值为:", self.value)
2030 end
2031}
2032local run_callback
2033run_callback = function(func)
2034 print("运行回调...")
2035 return func()
2036end
2037run_callback(my_object.write)
2038run_callback((function()
2039 local _base_0 = my_object
2040 local _fn_0 = _base_0.write
2041 return _fn_0 and function(...)
2042 return _fn_0(_base_0, ...)
2043 end
2044end)())
2045local i = 100
2046local my_func
2047my_func = function()
2048 i = 10
2049 while i > 0 do
2050 print(i)
2051 i = i - 1
2052 end
2053end
2054my_func()
2055print(i)
2056local i = 100
2057local my_func
2058my_func = function()
2059 local i = "hello"
2060end
2061my_func()
2062print(i)
2063local tmp = 1213
2064local i, k = 100, 50
2065local my_func
2066my_func = function(add)
2067 local tmp = tmp + add
2068 i = i + tmp
2069 k = k + tmp
2070end
2071my_func(22)
2072print(i, k)
2073local _module_0 = { }
2074local p, to_lua
2075do
2076 local _obj_0 = require("yue")
2077 p, to_lua = _obj_0.p, _obj_0.to_lua
2078end
2079local inventory = {
2080 equipment = {
2081 "sword",
2082 "shield"
2083 },
2084 items = {
2085 {
2086 name = "potion",
2087 count = 10
2088 },
2089 {
2090 name = "bread",
2091 count = 3
2092 }
2093 }
2094}
2095print(reduce(filter(map({
2096 1,
2097 2,
2098 3
2099}, function(x)
2100 return x * 2
2101end), function(x)
2102 return x > 4
2103end), 0, function(a, b)
2104 return a + b
2105end))
2106local apple = setmetatable({
2107 size = 15,
2108}, {
2109 __index = {
2110 color = 0x00ffff
2111 }
2112})
2113if (getmetatable(apple) ~= nil) then
2114 p(apple.color, getmetatable(apple).__index)
2115end
2116local _ud83c_udf1b = "月之脚本"
2117_module_0["🌛"] = _ud83c_udf1b
2118return _module_0
2119local area = 6.2831853071796 * 5
2120print('你好 世界')
2121assert(item ~= nil)
2122local value = item
2123if (f1() and f2() and f3()) then
2124 print("OK")
2125end
2126local funcA
2127funcA = function() end
2128funcA = function()
2129 return "访问月之脚本定义的变量"
2130end
2131local function funcB() end
2132funcB = function()
2133 return "访问Lua代码里定义的变量"
2134end
2135-- 插入原始Lua代码
2136if cond then
2137 print("输出")
2138end
2139print("yuescript")
2140print(3)
2141if tb ~= nil then
2142 tb:func()
2143end
2144if tb ~= nil then
2145 tb:func()
2146end
2147print(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)
2148local a = 5
2149print(1 <= a and a <= 10)
2150local v
2151v = function(x)
2152 print(x)
2153 return x
2154end
2155print((function()
2156 local _cond_0 = v(2)
2157 if not (v(1) < _cond_0) then
2158 return false
2159 else
2160 return _cond_0 <= v(3)
2161 end
2162end)())
2163print((function()
2164 local _cond_0 = v(2)
2165 if not (v(1) > _cond_0) then
2166 return false
2167 else
2168 return _cond_0 <= v(3)
2169 end
2170end)())
2171local tab = { }
2172tab[#tab + 1] = "Value"
2173local parts = {
2174 "shoulders",
2175 "knees"
2176}
2177local lyrics
2178do
2179 local _tab_0 = {
2180 "head"
2181 }
2182 local _idx_0 = 1
2183 for _key_0, _value_0 in pairs(parts) do
2184 if _idx_0 == _key_0 then
2185 _tab_0[#_tab_0 + 1] = _value_0
2186 _idx_0 = _idx_0 + 1
2187 else
2188 _tab_0[_key_0] = _value_0
2189 end
2190 end
2191 _tab_0[#_tab_0 + 1] = "and"
2192 _tab_0[#_tab_0 + 1] = "toes"
2193 lyrics = _tab_0
2194end
2195local copy
2196do
2197 local _tab_0 = { }
2198 local _idx_0 = 1
2199 for _key_0, _value_0 in pairs(other) do
2200 if _idx_0 == _key_0 then
2201 _tab_0[#_tab_0 + 1] = _value_0
2202 _idx_0 = _idx_0 + 1
2203 else
2204 _tab_0[_key_0] = _value_0
2205 end
2206 end
2207 copy = _tab_0
2208end
2209local a = {
2210 1,
2211 2,
2212 3,
2213 x = 1
2214}
2215local b = {
2216 4,
2217 5,
2218 y = 1
2219}
2220local merge
2221do
2222 local _tab_0 = { }
2223 local _idx_0 = 1
2224 for _key_0, _value_0 in pairs(a) do
2225 if _idx_0 == _key_0 then
2226 _tab_0[#_tab_0 + 1] = _value_0
2227 _idx_0 = _idx_0 + 1
2228 else
2229 _tab_0[_key_0] = _value_0
2230 end
2231 end
2232 local _idx_1 = 1
2233 for _key_0, _value_0 in pairs(b) do
2234 if _idx_1 == _key_0 then
2235 _tab_0[#_tab_0 + 1] = _value_0
2236 _idx_1 = _idx_1 + 1
2237 else
2238 _tab_0[_key_0] = _value_0
2239 end
2240 end
2241 merge = _tab_0
2242end
2243local mt = { }
2244local add
2245add = function(self, right)
2246 return setmetatable({
2247 value = self.value + right.value
2248 }, mt)
2249end
2250mt.__add = add
2251local a = setmetatable({
2252 value = 1
2253}, mt)
2254local b = setmetatable({
2255 value = 2
2256}, {
2257 __add = add
2258})
2259local c = setmetatable({
2260 value = 3
2261}, {
2262 __add = mt.__add
2263})
2264local d = a + b + c
2265print(d.value)
2266local _ <close> = setmetatable({ }, {
2267 __close = function()
2268 return print("超出范围")
2269 end
2270})
2271local tb = setmetatable({ }, {
2272 ["value"] = 123
2273})
2274getmetatable(tb).__index = getmetatable(tb)
2275print(tb.value)
2276setmetatable(tb, {
2277 __index = {
2278 item = "hello"
2279 }
2280})
2281print(tb.item)
2282local item, new, close, getter
2283do
2284 local _obj_0 = tb
2285 item, new = _obj_0[1], _obj_0.new
2286 do
2287 local _obj_1 = getmetatable(_obj_0)
2288 close, getter = _obj_1.__close, _obj_1.__index
2289 end
2290end
2291print(item, new, close, getter)
2292do
2293 local _obj_0 = func
2294 if _obj_0 ~= nil then
2295 _obj_0()
2296 end
2297end
2298print((function()
2299 local _obj_0 = abc
2300 if _obj_0 ~= nil then
2301 local _obj_1 = _obj_0["你好 世界"]
2302 if _obj_1 ~= nil then
2303 return _obj_1.xyz
2304 end
2305 return nil
2306 end
2307 return nil
2308end)())
2309local x
2310do
2311 local _obj_0 = tab
2312 if _obj_0 ~= nil then
2313 x = _obj_0.value
2314 end
2315end
2316local len = (function()
2317 local _obj_0 = utf8
2318 if _obj_0 ~= nil then
2319 return _obj_0.len
2320 end
2321 return nil
2322end)() or (function()
2323 local _obj_0 = string
2324 if _obj_0 ~= nil then
2325 return _obj_0.len
2326 end
2327 return nil
2328end)() or function(o)
2329 return #o
2330end
2331if print and (x ~= nil) then
2332 print(x)
2333end
2334do
2335 local _with_0 = io.open("test.txt", "w")
2336 if _with_0 ~= nil then
2337 _with_0:write("你好")
2338 _with_0:close()
2339 end
2340end
2341print("你好")
2342print(1, 2)
2343print(1, 2, 3)
2344print(render(emit(parse(extract(readFile("example.txt"), language, { }), language))))
2345local a, b, c, d
2346if b ~= nil then
2347 a = b
2348else
2349 if c ~= nil then
2350 a = c
2351 else
2352 a = d
2353 end
2354end
2355func((function()
2356 if a ~= nil then
2357 return a
2358 else
2359 return { }
2360 end
2361end)())
2362if a == nil then
2363 a = false
2364end
2365local list = {
2366 1,
2367 2,
2368 3
2369}
2370func({
2371 1,
2372 2,
2373 3
2374})
2375local tb = {
2376 name = "abc",
2377 values = {
2378 "a",
2379 "b",
2380 "c"
2381 },
2382 objects = {
2383 {
2384 name = "a",
2385 value = 1,
2386 func = function(self)
2387 return self.value + 1
2388 end,
2389 tb = {
2390 fieldA = 1
2391 }
2392 },
2393 {
2394 name = "b",
2395 value = 2,
2396 func = function(self)
2397 return self.value + 2
2398 end,
2399 tb = { }
2400 }
2401 }
2402}
2403do
2404 local insert, concat = table.insert, table.concat
2405 local C, Ct, Cmt
2406 do
2407 local _obj_0 = require("lpeg")
2408 C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt
2409 end
2410 local x, y, z
2411 do
2412 local _obj_0 = require('mymodule')
2413 x, y, z = _obj_0.x, _obj_0.y, _obj_0.z
2414 end
2415 local a, b, c
2416 do
2417 local _obj_0 = require('module')
2418 a, b, c = _obj_0.a, _obj_0.b, _obj_0.c
2419 end
2420end
2421do
2422 local module = require('module')
2423 local module_x = require('module_x')
2424 local d_a_s_h_e_s = require("d-a-s-h-e-s")
2425 local part = require("module.part")
2426end
2427do
2428 local PlayerModule = require("player")
2429 local C, Ct, Cmt
2430 do
2431 local _obj_0 = require("lpeg")
2432 C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt
2433 end
2434 local one, two, ch
2435 do
2436 local _obj_0 = require("export")
2437 one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1]
2438 end
2439end
2440local _module_0 = { }
2441local a, b, c = 1, 2, 3
2442_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c
2443local cool = "cat"
2444_module_0["cool"] = cool
2445local What
2446if this then
2447 What = "abc"
2448else
2449 What = "def"
2450end
2451_module_0["What"] = What
2452local y
2453y = function()
2454 local hallo = 3434
2455end
2456_module_0["y"] = y
2457local Something
2458do
2459 local _class_0
2460 local _base_0 = {
2461 umm = "cool"
2462 }
2463 if _base_0.__index == nil then
2464 _base_0.__index = _base_0
2465 end
2466 _class_0 = setmetatable({
2467 __init = function() end,
2468 __base = _base_0,
2469 __name = "Something"
2470 }, {
2471 __index = _base_0,
2472 __call = function(cls, ...)
2473 local _self_0 = setmetatable({ }, _base_0)
2474 cls.__init(_self_0, ...)
2475 return _self_0
2476 end
2477 })
2478 _base_0.__class = _class_0
2479 Something = _class_0
2480end
2481_module_0["Something"] = Something
2482return _module_0
2483local _module_0 = { }
2484local loadstring, tolua
2485do
2486 local _obj_0 = yue
2487 loadstring, tolua = _obj_0.loadstring, _obj_0.to_lua
2488end
2489_module_0["loadstring"], _module_0["tolua"] = loadstring, tolua
2490local fieldA = tb.itemA.fieldA
2491if fieldA == nil then
2492 fieldA = '默认值'
2493end
2494_module_0["fieldA"] = fieldA
2495return _module_0
2496local _module_0 = setmetatable({ }, { })
2497_module_0.itemA = tb
2498getmetatable(_module_0).__index = items
2499_module_0["a-b-c"] = 123
2500return _module_0
2501local _module_0 = { }
2502local d, e, f = 3, 2, 1
2503_module_0[#_module_0 + 1] = d
2504_module_0[#_module_0 + 1] = e
2505_module_0[#_module_0 + 1] = f
2506if this then
2507 _module_0[#_module_0 + 1] = 123
2508else
2509 _module_0[#_module_0 + 1] = 456
2510end
2511do
2512 local _with_0 = tmp
2513 local j = 2000
2514 _module_0[#_module_0 + 1] = _with_0
2515end
2516return _module_0
2517local _module_0 = nil
2518_module_0 = function()
2519 print("你好")
2520 return 123
2521end
2522return _module_0
2523local hello = "world"
2524local a, b, c = 1, 2, 3
2525hello = 123
2526local x = 1
2527x = x + 1
2528x = x - 1
2529x = x * 10
2530x = x / 10
2531x = x % 10
2532local s = s .. "world"
2533local arg = arg or "默认值"
2534local a = 0
2535local b = 0
2536local c = 0
2537local d = 0
2538local e = 0
2539local x = f()
2540local y = x
2541local z = x
2542do
2543 local a
2544 a = 1
2545 local x, y, z
2546 print("预先声明后续所有变量为局部变量")
2547 x = function()
2548 return 1 + y + z
2549 end
2550 y, z = 2, 3
2551 instance = Item:new()
2552end
2553do
2554 local X
2555 X = 1
2556 local B
2557 print("只预先声明后续大写的变量为局部变量")
2558 local a = 1
2559 B = 2
2560end
2561do
2562 a = 1
2563 print("预先声明所有变量为全局变量")
2564 local x
2565 x = function()
2566 return 1 + y + z
2567 end
2568 local y, z = 2, 3
2569end
2570do
2571 x = 1
2572 print("只预先声明大写的变量为全局变量")
2573 local a = 1
2574 local B = 2
2575 local Temp
2576 Temp = "一个局部值"
2577end
2578local thing = {
2579 1,
2580 2
2581}
2582local a, b = thing[1], thing[2]
2583print(a, b)
2584local obj = {
2585 hello = "world",
2586 day = "tuesday",
2587 length = 20
2588}
2589local hello, the_day = obj.hello, obj.day
2590print(hello, the_day)
2591local day = obj.day
2592local obj2 = {
2593 numbers = {
2594 1,
2595 2,
2596 3,
2597 4
2598 },
2599 properties = {
2600 color = "green",
2601 height = 13.5
2602 }
2603}
2604local first, second = obj2.numbers[1], obj2.numbers[2]
2605print(first, second, color)
2606local first, second, color
2607do
2608 local _obj_0 = obj2
2609 first, second, color = _obj_0.numbers[1], _obj_0.numbers[2], _obj_0.properties.color
2610end
2611local concat, insert
2612do
2613 local _obj_0 = table
2614 concat, insert = _obj_0.concat, _obj_0.insert
2615end
2616local mix, max, rand
2617do
2618 local _obj_0 = math
2619 mix, max, rand = _obj_0.mix, _obj_0.max, _obj_0.random
2620end
2621local name, job
2622do
2623 local _obj_0 = person
2624 name, job = _obj_0.name, _obj_0.job
2625 if name == nil then
2626 name = "nameless"
2627 end
2628 if job == nil then
2629 job = "jobless"
2630 end
2631end
2632local two, four
2633do
2634 local _obj_0 = items
2635 two, four = _obj_0[2], _obj_0[4]
2636end
2637local tuples = {
2638 {
2639 "hello",
2640 "world"
2641 },
2642 {
2643 "egg",
2644 "head"
2645 }
2646}
2647for _index_0 = 1, #tuples do
2648 local _des_0 = tuples[_index_0]
2649 local left, right = _des_0[1], _des_0[2]
2650 print(left, right)
2651end
2652do
2653 local user = database.find_user("moon")
2654 if user then
2655 print(user.name)
2656 end
2657end
2658do
2659 local hello = os.getenv("hello")
2660 if hello then
2661 print("你有 hello", hello)
2662 else
2663 do
2664 local world = os.getenv("world")
2665 if world then
2666 print("你有 world", world)
2667 else
2668 print("什么都没有 :(")
2669 end
2670 end
2671 end
2672end
2673do
2674 local success, result = pcall(function()
2675 return "无报错地获取结果"
2676 end)
2677 if success then
2678 print(result)
2679 end
2680end
2681print("好的")
2682local list = {
2683 1,
2684 2,
2685 3,
2686 4,
2687 5
2688}
2689local fn
2690fn = function(ok)
2691 return ok, table.unpack(list)
2692end
2693(function(_arg_0, ...)
2694 local ok = _arg_0
2695 local count = select('#', ...)
2696 local first = select(1, ...)
2697 return print(ok, count, first)
2698end)(fn(true))
2699Rx.Observable.fromRange(1, 8):filter(function(x)
2700 return x % 2 == 0
2701end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
2702 return value .. '!'
2703end):subscribe(print)
2704local str = strA .. strB .. strC
2705func(3000, "192.168.1.1")
2706xpcall(func, function(err)
2707 return print(yue.traceback(err))
2708end, 1, 2, 3)
2709local success, result = xpcall(func, function(err)
2710 return yue.traceback(err)
2711end, 1, 2, 3)
2712xpcall(func, function(err)
2713 return print(yue.traceback(err))
2714end, 1, 2, 3)
2715success, result = pcall(func, 1, 2, 3)
2716pcall(function()
2717 print("尝试中")
2718 return func(1, 2, 3)
2719end)
2720success, result = xpcall(func, function(err)
2721 return print(yue.traceback(err))
2722end, 1, 2, 3)
2723if success then
2724 print(result)
2725end
2726local a <const> = 123
2727local _ <close> = setmetatable({ }, {
2728 __close = function()
2729 return print("超出范围。")
2730 end
2731})
2732local a, b, c, d
2733do
2734 local _obj_0 = tb
2735 a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
2736end
2737local some_string = "这是一个字符串\n 并包括一个换行。"
2738print("我有" .. tostring(math.random() * 100) .. "%的把握。")
2739local integer = 1000000
2740local hex = 0xEFBBBF
2741local my_function
2742my_function = function() end
2743my_function()
2744local func_a
2745func_a = function()
2746 return print("你好,世界")
2747end
2748local func_b
2749func_b = function()
2750 local value = 100
2751 return print("这个值是:", value)
2752end
2753func_a()
2754func_b()
2755local sum
2756sum = function(x, y)
2757 return print("数字的和", x + y)
2758end
2759sum(10, 20)
2760print(sum(10, 20))
2761a(b(c("a", "b", "c")))
2762print("x:", sum(10, 20), "y:", sum(30, 40))
2763local sum
2764sum = function(x, y)
2765 return x + y
2766end
2767print("数字的和是", sum(10, 20))
2768local sum
2769sum = function(x, y)
2770 return x + y
2771end
2772local mystery
2773mystery = function(x, y)
2774 return x + y, x - y
2775end
2776local a, b = mystery(10, 20)
2777local func
2778func = function(self, num)
2779 return self.value + num
2780end
2781local my_function
2782my_function = function(name, height)
2783 if name == nil then
2784 name = "某物"
2785 end
2786 if height == nil then
2787 height = 100
2788 end
2789 print("你好,我是", name)
2790 return print("我的高度是", height)
2791end
2792local some_args
2793some_args = function(x, y)
2794 if x == nil then
2795 x = 100
2796 end
2797 if y == nil then
2798 y = x + 1000
2799 end
2800 return print(x + y)
2801end
2802my_func(5, 4, 3, 8, 9, 10)
2803cool_func(1, 2, 3, 4, 5, 6, 7, 8)
2804my_func(5, 6, 7, 6, another_func(6, 7, 8, 9, 1, 2), 5, 4)
2805local x = {
2806 1,
2807 2,
2808 3,
2809 4,
2810 a_func(4, 5, 5, 6),
2811 8,
2812 9,
2813 10
2814}
2815local y = {
2816 my_func(1, 2, 3, 4, 5),
2817 5,
2818 6,
2819 7
2820}
2821if func(1, 2, 3, "你好", "世界") then
2822 print("你好")
2823 print("我在if内部")
2824end
2825if func(1, 2, 3, "你好", "世界") then
2826 print("你好")
2827 print("我在if内部")
2828end
2829f(function()
2830 return print("hello")
2831end)
2832f(function(self)
2833 return print(self.value)
2834end)
2835map(function(x)
2836 return x * 2
2837end, {
2838 1,
2839 2,
2840 3
2841})
2842local result, msg
2843do
2844 result, msg = readAsync("文件名.txt", function(data)
2845 print(data)
2846 return processAsync(data, function(info)
2847 return check(info)
2848 end)
2849 end)
2850end
2851print(result, msg)
2852local some_values = {
2853 1,
2854 2,
2855 3,
2856 4
2857}
2858local some_values = {
2859 name = "Bill",
2860 age = 200,
2861 ["favorite food"] = "rice"
2862}
2863local profile = {
2864 height = "4英尺",
2865 shoe_size = 13,
2866 favorite_foods = {
2867 "冰淇淋",
2868 "甜甜圈"
2869 }
2870}
2871local values = {
2872 1,
2873 2,
2874 3,
2875 4,
2876 5,
2877 6,
2878 7,
2879 8,
2880 name = "超人",
2881 occupation = "打击犯罪"
2882}
2883my_function({
2884 dance = "探戈",
2885 partner = "无"
2886})
2887local y = {
2888 type = "狗",
2889 legs = 4,
2890 tails = 1
2891}
2892local tbl = {
2893 ["do"] = "某事",
2894 ["end"] = "饥饿"
2895}
2896local hair = "金色"
2897local height = 200
2898local person = {
2899 hair = hair,
2900 height = height,
2901 shoe_size = 40
2902}
2903print_table({
2904 hair = hair,
2905 height = height
2906})
2907local t = {
2908 [1 + 2] = "你好",
2909 ["你好 世界"] = true
2910}
2911local some_values = {
2912 1,
2913 2,
2914 3,
2915 4
2916}
2917local list_with_one_element = {
2918 1
2919}
2920local items = {
2921 1,
2922 2,
2923 3,
2924 4
2925}
2926local doubled
2927do
2928 local _accum_0 = { }
2929 local _len_0 = 1
2930 for i, item in ipairs(items) do
2931 _accum_0[_len_0] = item * 2
2932 _len_0 = _len_0 + 1
2933 end
2934 doubled = _accum_0
2935end
2936local iter = ipairs(items)
2937local slice
2938do
2939 local _accum_0 = { }
2940 local _len_0 = 1
2941 for i, item in iter do
2942 if i > 1 and i < 3 then
2943 _accum_0[_len_0] = item
2944 _len_0 = _len_0 + 1
2945 end
2946 end
2947 slice = _accum_0
2948end
2949local doubled
2950do
2951 local _accum_0 = { }
2952 local _len_0 = 1
2953 local _list_0 = items
2954 for _index_0 = 1, #_list_0 do
2955 local item = _list_0[_index_0]
2956 _accum_0[_len_0] = item * 2
2957 _len_0 = _len_0 + 1
2958 end
2959 doubled = _accum_0
2960end
2961local x_coords = {
2962 4,
2963 5,
2964 6,
2965 7
2966}
2967local y_coords = {
2968 9,
2969 2,
2970 3
2971}
2972local points
2973do
2974 local _accum_0 = { }
2975 local _len_0 = 1
2976 for _index_0 = 1, #x_coords do
2977 local x = x_coords[_index_0]
2978 for _index_1 = 1, #y_coords do
2979 local y = y_coords[_index_1]
2980 _accum_0[_len_0] = {
2981 x,
2982 y
2983 }
2984 _len_0 = _len_0 + 1
2985 end
2986 end
2987 points = _accum_0
2988end
2989local evens
2990do
2991 local _accum_0 = { }
2992 local _len_0 = 1
2993 for i = 1, 100 do
2994 if i % 2 == 0 then
2995 _accum_0[_len_0] = i
2996 _len_0 = _len_0 + 1
2997 end
2998 end
2999 evens = _accum_0
3000end
3001local thing = {
3002 color = "red",
3003 name = "fast",
3004 width = 123
3005}
3006local thing_copy
3007do
3008 local _tbl_0 = { }
3009 for k, v in pairs(thing) do
3010 _tbl_0[k] = v
3011 end
3012 thing_copy = _tbl_0
3013end
3014local no_color
3015do
3016 local _tbl_0 = { }
3017 for k, v in pairs(thing) do
3018 if k ~= "color" then
3019 _tbl_0[k] = v
3020 end
3021 end
3022 no_color = _tbl_0
3023end
3024local numbers = {
3025 1,
3026 2,
3027 3,
3028 4
3029}
3030local sqrts
3031do
3032 local _tbl_0 = { }
3033 for _index_0 = 1, #numbers do
3034 local i = numbers[_index_0]
3035 _tbl_0[i] = math.sqrt(i)
3036 end
3037 sqrts = _tbl_0
3038end
3039local tuples = {
3040 {
3041 "hello",
3042 "world"
3043 },
3044 {
3045 "foo",
3046 "bar"
3047 }
3048}
3049local tbl
3050do
3051 local _tbl_0 = { }
3052 for _index_0 = 1, #tuples do
3053 local tuple = tuples[_index_0]
3054 local _key_0, _val_0 = unpack(tuple)
3055 _tbl_0[_key_0] = _val_0
3056 end
3057 tbl = _tbl_0
3058end
3059local slice
3060do
3061 local _accum_0 = { }
3062 local _len_0 = 1
3063 local _list_0 = items
3064 local _max_0 = 5
3065 for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
3066 local item = _list_0[_index_0]
3067 _accum_0[_len_0] = item
3068 _len_0 = _len_0 + 1
3069 end
3070 slice = _accum_0
3071end
3072local slice
3073do
3074 local _accum_0 = { }
3075 local _len_0 = 1
3076 local _list_0 = items
3077 for _index_0 = 2, #_list_0 do
3078 local item = _list_0[_index_0]
3079 _accum_0[_len_0] = item
3080 _len_0 = _len_0 + 1
3081 end
3082 slice = _accum_0
3083end
3084local slice
3085do
3086 local _accum_0 = { }
3087 local _len_0 = 1
3088 local _list_0 = items
3089 for _index_0 = 1, #_list_0, 2 do
3090 local item = _list_0[_index_0]
3091 _accum_0[_len_0] = item
3092 _len_0 = _len_0 + 1
3093 end
3094 slice = _accum_0
3095end
3096for i = 10, 20 do
3097 print(i)
3098end
3099for k = 1, 15, 2 do
3100 print(k)
3101end
3102for key, value in pairs(object) do
3103 print(key, value)
3104end
3105do
3106 local _list_0 = items
3107 local _max_0 = 4
3108 for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
3109 local item = _list_0[_index_0]
3110 print(item)
3111 end
3112end
3113local _list_0 = items
3114for _index_0 = 1, #_list_0 do
3115 local item = _list_0[_index_0]
3116 print(item)
3117end
3118for j = 1, 10, 3 do
3119 print(j)
3120end
3121local doubled_evens
3122do
3123 local _accum_0 = { }
3124 local _len_0 = 1
3125 for i = 1, 20 do
3126 if i % 2 == 0 then
3127 _accum_0[_len_0] = i * 2
3128 else
3129 _accum_0[_len_0] = i
3130 end
3131 _len_0 = _len_0 + 1
3132 end
3133 doubled_evens = _accum_0
3134end
3135local func_a
3136func_a = function()
3137 for i = 1, 10 do
3138 print(i)
3139 end
3140end
3141local func_b
3142func_b = function()
3143 local _accum_0 = { }
3144 local _len_0 = 1
3145 for i = 1, 10 do
3146 _accum_0[_len_0] = i
3147 _len_0 = _len_0 + 1
3148 end
3149 return _accum_0
3150end
3151print(func_a())
3152print(func_b())
3153local i = 10
3154repeat
3155 print(i)
3156 i = i - 1
3157until i == 0
3158local i = 10
3159while i > 0 do
3160 print(i)
3161 i = i - 1
3162end
3163while running == true do
3164 my_function()
3165end
3166local i = 10
3167while not (i == 0) do
3168 print(i)
3169 i = i - 1
3170end
3171while not (running == false) do
3172 my_function()
3173end
3174local i = 0
3175while i < 10 do
3176 i = i + 1
3177 if i % 2 == 0 then
3178 goto _continue_0
3179 end
3180 print(i)
3181 ::_continue_0::
3182end
3183local my_numbers = {
3184 1,
3185 2,
3186 3,
3187 4,
3188 5,
3189 6
3190}
3191local odds
3192do
3193 local _accum_0 = { }
3194 local _len_0 = 1
3195 for _index_0 = 1, #my_numbers do
3196 local x = my_numbers[_index_0]
3197 if x % 2 == 1 then
3198 goto _continue_0
3199 end
3200 _accum_0[_len_0] = x
3201 _len_0 = _len_0 + 1
3202 ::_continue_0::
3203 end
3204 odds = _accum_0
3205end
3206local have_coins = false
3207if have_coins then
3208 print("有硬币")
3209else
3210 print("没有硬币")
3211end
3212local have_coins = false
3213if have_coins then
3214 print("有硬币")
3215else
3216 print("没有硬币")
3217end
3218local have_coins = false
3219print((function()
3220 if have_coins then
3221 return "有硬币"
3222 else
3223 return "没有硬币"
3224 end
3225end)())
3226local is_tall
3227is_tall = function(name)
3228 if name == "Rob" then
3229 return true
3230 else
3231 return false
3232 end
3233end
3234local message
3235if is_tall("Rob") then
3236 message = "我很高"
3237else
3238 message = "我不是很高"
3239end
3240print(message)
3241if not (os.date("%A") == "Monday") then
3242 print("今天不是星期一!")
3243end
3244if not (math.random() > 0.1) then
3245 print("你真幸运!")
3246end
3247local a = 5
3248if (1 == a or 3 == a or 5 == a or 7 == a) then
3249 print("检查离散值的相等性")
3250end
3251if (function()
3252 local _check_0 = list
3253 for _index_0 = 1, #_check_0 do
3254 if _check_0[_index_0] == a then
3255 return true
3256 end
3257 end
3258 return false
3259end)() then
3260 print("检查`a`是否在列表中")
3261end
3262if not (math.random() > 0.1) then
3263 print("你很幸运!")
3264end
3265if name == "Rob" then
3266 print("你好,世界")
3267end
3268local _list_0 = items
3269for _index_0 = 1, #_list_0 do
3270 local item = _list_0[_index_0]
3271 print("项目: ", item)
3272end
3273while game:isRunning() do
3274 game:update()
3275end
3276while not reader:eof() do
3277 reader:parse_line()
3278end
3279local name = "Dan"
3280if "Robert" == name then
3281 print("你是Robert")
3282elseif "Dan" == name or "Daniel" == name then
3283 print("你的名字是Dan")
3284else
3285 print("我不知道你的名字")
3286end
3287local b = 1
3288local next_number
3289if 1 == b then
3290 next_number = 2
3291elseif 2 == b then
3292 next_number = 3
3293else
3294 next_number = error("数字数得太大了!")
3295end
3296local msg
3297do
3298 local _exp_0 = math.random(1, 5)
3299 if 1 == _exp_0 then
3300 msg = "你很幸运"
3301 elseif 2 == _exp_0 then
3302 msg = "你差点很幸运"
3303 else
3304 msg = "不太幸运"
3305 end
3306end
3307do
3308 local _exp_0 = math.random(1, 5)
3309 if 1 == _exp_0 then
3310 print("你很幸运")
3311 else
3312 print("不太幸运")
3313 end
3314end
3315do
3316 local _exp_0 = math.random(1, 5)
3317 if 1 == _exp_0 then
3318 print("你很幸运")
3319 else
3320 print("不太幸运")
3321 end
3322end
3323local items = {
3324 {
3325 x = 100,
3326 y = 200
3327 },
3328 {
3329 width = 300,
3330 height = 400
3331 }
3332}
3333for _index_0 = 1, #items do
3334 local item = items[_index_0]
3335 do
3336 local _type_0 = type(item)
3337 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3338 local _match_0 = false
3339 if _tab_0 then
3340 local x = item.x
3341 local y = item.y
3342 if x ~= nil and y ~= nil then
3343 _match_0 = true
3344 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3345 end
3346 end
3347 if not _match_0 then
3348 if _tab_0 then
3349 local width = item.width
3350 local height = item.height
3351 if width ~= nil and height ~= nil then
3352 print("尺寸 " .. tostring(width) .. ", " .. tostring(height))
3353 end
3354 end
3355 end
3356 end
3357end
3358local item = { }
3359local x, y = item.pos.x, item.pos.y
3360if x == nil then
3361 x = 50
3362end
3363if y == nil then
3364 y = 200
3365end
3366do
3367 local _type_0 = type(item)
3368 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3369 if _tab_0 then
3370 do
3371 local _obj_0 = item.pos
3372 local _type_1 = type(_obj_0)
3373 if "table" == _type_1 or "userdata" == _type_1 then
3374 x = _obj_0.x
3375 end
3376 end
3377 do
3378 local _obj_0 = item.pos
3379 local _type_1 = type(_obj_0)
3380 if "table" == _type_1 or "userdata" == _type_1 then
3381 y = _obj_0.y
3382 end
3383 end
3384 if x == nil then
3385 x = 50
3386 end
3387 if y == nil then
3388 y = 200
3389 end
3390 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3391 end
3392end
3393local Inventory
3394do
3395 local _class_0
3396 local _base_0 = {
3397 add_item = function(self, name)
3398 if self.items[name] then
3399 local _obj_0 = self.items
3400 _obj_0[name] = _obj_0[name] + 1
3401 else
3402 self.items[name] = 1
3403 end
3404 end
3405 }
3406 if _base_0.__index == nil then
3407 _base_0.__index = _base_0
3408 end
3409 _class_0 = setmetatable({
3410 __init = function(self)
3411 self.items = { }
3412 end,
3413 __base = _base_0,
3414 __name = "Inventory"
3415 }, {
3416 __index = _base_0,
3417 __call = function(cls, ...)
3418 local _self_0 = setmetatable({ }, _base_0)
3419 cls.__init(_self_0, ...)
3420 return _self_0
3421 end
3422 })
3423 _base_0.__class = _class_0
3424 Inventory = _class_0
3425end
3426local inv = Inventory()
3427inv:add_item("t-shirt")
3428inv:add_item("pants")
3429local Person
3430do
3431 local _class_0
3432 local _base_0 = {
3433 clothes = { },
3434 give_item = function(self, name)
3435 return table.insert(self.clothes, name)
3436 end
3437 }
3438 if _base_0.__index == nil then
3439 _base_0.__index = _base_0
3440 end
3441 _class_0 = setmetatable({
3442 __init = function() end,
3443 __base = _base_0,
3444 __name = "Person"
3445 }, {
3446 __index = _base_0,
3447 __call = function(cls, ...)
3448 local _self_0 = setmetatable({ }, _base_0)
3449 cls.__init(_self_0, ...)
3450 return _self_0
3451 end
3452 })
3453 _base_0.__class = _class_0
3454 Person = _class_0
3455end
3456local a = Person()
3457local b = Person()
3458a:give_item("pants")
3459b:give_item("shirt")
3460local _list_0 = a.clothes
3461for _index_0 = 1, #_list_0 do
3462 local item = _list_0[_index_0]
3463 print(item)
3464end
3465local Person
3466do
3467 local _class_0
3468 local _base_0 = { }
3469 if _base_0.__index == nil then
3470 _base_0.__index = _base_0
3471 end
3472 _class_0 = setmetatable({
3473 __init = function(self)
3474 self.clothes = { }
3475 end,
3476 __base = _base_0,
3477 __name = "Person"
3478 }, {
3479 __index = _base_0,
3480 __call = function(cls, ...)
3481 local _self_0 = setmetatable({ }, _base_0)
3482 cls.__init(_self_0, ...)
3483 return _self_0
3484 end
3485 })
3486 _base_0.__class = _class_0
3487 Person = _class_0
3488end
3489local BackPack
3490do
3491 local _class_0
3492 local _parent_0 = Inventory
3493 local _base_0 = {
3494 size = 10,
3495 add_item = function(self, name)
3496 if #self.items > size then
3497 error("背包已满")
3498 end
3499 return _class_0.__parent.__base.add_item(self, name)
3500 end
3501 }
3502 for _key_0, _val_0 in pairs(_parent_0.__base) do
3503 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
3504 _base_0[_key_0] = _val_0
3505 end
3506 end
3507 if _base_0.__index == nil then
3508 _base_0.__index = _base_0
3509 end
3510 setmetatable(_base_0, _parent_0.__base)
3511 _class_0 = setmetatable({
3512 __init = function(self, ...)
3513 return _class_0.__parent.__init(self, ...)
3514 end,
3515 __base = _base_0,
3516 __name = "BackPack",
3517 __parent = _parent_0
3518 }, {
3519 __index = function(cls, name)
3520 local val = rawget(_base_0, name)
3521 if val == nil then
3522 local parent = rawget(cls, "__parent")
3523 if parent then
3524 return parent[name]
3525 end
3526 else
3527 return val
3528 end
3529 end,
3530 __call = function(cls, ...)
3531 local _self_0 = setmetatable({ }, _base_0)
3532 cls.__init(_self_0, ...)
3533 return _self_0
3534 end
3535 })
3536 _base_0.__class = _class_0
3537 if _parent_0.__inherited then
3538 _parent_0.__inherited(_parent_0, _class_0)
3539 end
3540 BackPack = _class_0
3541end
3542local Shelf
3543do
3544 local _class_0
3545 local _base_0 = { }
3546 if _base_0.__index == nil then
3547 _base_0.__index = _base_0
3548 end
3549 _class_0 = setmetatable({
3550 __init = function() end,
3551 __base = _base_0,
3552 __name = "Shelf"
3553 }, {
3554 __index = _base_0,
3555 __call = function(cls, ...)
3556 local _self_0 = setmetatable({ }, _base_0)
3557 cls.__init(_self_0, ...)
3558 return _self_0
3559 end
3560 })
3561 _base_0.__class = _class_0
3562 local self = _class_0;
3563 self.__inherited = function(self, child)
3564 return print(self.__name, "被", child.__name, "继承")
3565 end
3566 Shelf = _class_0
3567end
3568local Cupboard
3569do
3570 local _class_0
3571 local _parent_0 = Shelf
3572 local _base_0 = { }
3573 for _key_0, _val_0 in pairs(_parent_0.__base) do
3574 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
3575 _base_0[_key_0] = _val_0
3576 end
3577 end
3578 if _base_0.__index == nil then
3579 _base_0.__index = _base_0
3580 end
3581 setmetatable(_base_0, _parent_0.__base)
3582 _class_0 = setmetatable({
3583 __init = function(self, ...)
3584 return _class_0.__parent.__init(self, ...)
3585 end,
3586 __base = _base_0,
3587 __name = "Cupboard",
3588 __parent = _parent_0
3589 }, {
3590 __index = function(cls, name)
3591 local val = rawget(_base_0, name)
3592 if val == nil then
3593 local parent = rawget(cls, "__parent")
3594 if parent then
3595 return parent[name]
3596 end
3597 else
3598 return val
3599 end
3600 end,
3601 __call = function(cls, ...)
3602 local _self_0 = setmetatable({ }, _base_0)
3603 cls.__init(_self_0, ...)
3604 return _self_0
3605 end
3606 })
3607 _base_0.__class = _class_0
3608 if _parent_0.__inherited then
3609 _parent_0.__inherited(_parent_0, _class_0)
3610 end
3611 Cupboard = _class_0
3612end
3613local MyClass
3614do
3615 local _class_0
3616 local _parent_0 = ParentClass
3617 local _base_0 = {
3618 a_method = function(self)
3619 _class_0.__parent.__base.a_method(self, "你好", "世界")
3620 _class_0.__parent.a_method(self, "你好", "世界")
3621 _class_0.__parent.a_method(self, "你好", "世界")
3622 return assert(_class_0.__parent == ParentClass)
3623 end
3624 }
3625 for _key_0, _val_0 in pairs(_parent_0.__base) do
3626 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
3627 _base_0[_key_0] = _val_0
3628 end
3629 end
3630 if _base_0.__index == nil then
3631 _base_0.__index = _base_0
3632 end
3633 setmetatable(_base_0, _parent_0.__base)
3634 _class_0 = setmetatable({
3635 __init = function(self, ...)
3636 return _class_0.__parent.__init(self, ...)
3637 end,
3638 __base = _base_0,
3639 __name = "MyClass",
3640 __parent = _parent_0
3641 }, {
3642 __index = function(cls, name)
3643 local val = rawget(_base_0, name)
3644 if val == nil then
3645 local parent = rawget(cls, "__parent")
3646 if parent then
3647 return parent[name]
3648 end
3649 else
3650 return val
3651 end
3652 end,
3653 __call = function(cls, ...)
3654 local _self_0 = setmetatable({ }, _base_0)
3655 cls.__init(_self_0, ...)
3656 return _self_0
3657 end
3658 })
3659 _base_0.__class = _class_0
3660 if _parent_0.__inherited then
3661 _parent_0.__inherited(_parent_0, _class_0)
3662 end
3663 MyClass = _class_0
3664end
3665local b = BackPack()
3666assert(b.__class == BackPack)
3667print(BackPack.size)
3668print(BackPack.__name)
3669local Things
3670do
3671 local _class_0
3672 local _base_0 = { }
3673 if _base_0.__index == nil then
3674 _base_0.__index = _base_0
3675 end
3676 _class_0 = setmetatable({
3677 __init = function() end,
3678 __base = _base_0,
3679 __name = "Things"
3680 }, {
3681 __index = _base_0,
3682 __call = function(cls, ...)
3683 local _self_0 = setmetatable({ }, _base_0)
3684 cls.__init(_self_0, ...)
3685 return _self_0
3686 end
3687 })
3688 _base_0.__class = _class_0
3689 local self = _class_0;
3690 self.some_func = function(self)
3691 return print("Hello from", self.__name)
3692 end
3693 Things = _class_0
3694end
3695Things:some_func()
3696assert(Things().some_func == nil)
3697local Counter
3698do
3699 local _class_0
3700 local _base_0 = { }
3701 if _base_0.__index == nil then
3702 _base_0.__index = _base_0
3703 end
3704 _class_0 = setmetatable({
3705 __init = function(self)
3706 self.__class.count = self.__class.count + 1
3707 end,
3708 __base = _base_0,
3709 __name = "Counter"
3710 }, {
3711 __index = _base_0,
3712 __call = function(cls, ...)
3713 local _self_0 = setmetatable({ }, _base_0)
3714 cls.__init(_self_0, ...)
3715 return _self_0
3716 end
3717 })
3718 _base_0.__class = _class_0
3719 local self = _class_0;
3720 self.count = 0
3721 Counter = _class_0
3722end
3723Counter()
3724Counter()
3725print(Counter.count)
3726self.__class:hello(1, 2, 3, 4)
3727local Things
3728do
3729 local _class_0
3730 local _base_0 = { }
3731 if _base_0.__index == nil then
3732 _base_0.__index = _base_0
3733 end
3734 _class_0 = setmetatable({
3735 __init = function() end,
3736 __base = _base_0,
3737 __name = "Things"
3738 }, {
3739 __index = _base_0,
3740 __call = function(cls, ...)
3741 local _self_0 = setmetatable({ }, _base_0)
3742 cls.__init(_self_0, ...)
3743 return _self_0
3744 end
3745 })
3746 _base_0.__class = _class_0
3747 local self = _class_0;
3748 self.class_var = "hello world"
3749 Things = _class_0
3750end
3751local MoreThings
3752do
3753 local _class_0
3754 local secret, log
3755 local _base_0 = {
3756 some_method = function(self)
3757 return log("hello world: " .. secret)
3758 end
3759 }
3760 if _base_0.__index == nil then
3761 _base_0.__index = _base_0
3762 end
3763 _class_0 = setmetatable({
3764 __init = function() end,
3765 __base = _base_0,
3766 __name = "MoreThings"
3767 }, {
3768 __index = _base_0,
3769 __call = function(cls, ...)
3770 local _self_0 = setmetatable({ }, _base_0)
3771 cls.__init(_self_0, ...)
3772 return _self_0
3773 end
3774 })
3775 _base_0.__class = _class_0
3776 local self = _class_0;
3777 secret = 123
3778 log = function(msg)
3779 return print("LOG:", msg)
3780 end
3781 MoreThings = _class_0
3782end
3783assert(self == self)
3784assert(self.__class == self.__class)
3785local some_instance_method
3786some_instance_method = function(self, ...)
3787 return self.__class(...)
3788end
3789local Something
3790do
3791 local _class_0
3792 local _base_0 = { }
3793 if _base_0.__index == nil then
3794 _base_0.__index = _base_0
3795 end
3796 _class_0 = setmetatable({
3797 __init = function(self, foo, bar, biz, baz)
3798 self.foo = foo
3799 self.bar = bar
3800 self.__class.biz = biz
3801 self.__class.baz = baz
3802 end,
3803 __base = _base_0,
3804 __name = "Something"
3805 }, {
3806 __index = _base_0,
3807 __call = function(cls, ...)
3808 local _self_0 = setmetatable({ }, _base_0)
3809 cls.__init(_self_0, ...)
3810 return _self_0
3811 end
3812 })
3813 _base_0.__class = _class_0
3814 Something = _class_0
3815end
3816do
3817 local _class_0
3818 local _base_0 = { }
3819 if _base_0.__index == nil then
3820 _base_0.__index = _base_0
3821 end
3822 _class_0 = setmetatable({
3823 __init = function(self, foo, bar, biz, baz)
3824 self.foo = foo
3825 self.bar = bar
3826 self.__class.biz = biz
3827 self.__class.baz = baz
3828 end,
3829 __base = _base_0,
3830 __name = "Something"
3831 }, {
3832 __index = _base_0,
3833 __call = function(cls, ...)
3834 local _self_0 = setmetatable({ }, _base_0)
3835 cls.__init(_self_0, ...)
3836 return _self_0
3837 end
3838 })
3839 _base_0.__class = _class_0
3840 Something = _class_0
3841end
3842local new
3843new = function(self, fieldA, fieldB)
3844 self.fieldA = fieldA
3845 self.fieldB = fieldB
3846 return self
3847end
3848local obj = new({ }, 123, "abc")
3849print(obj)
3850local x
3851local Bucket
3852do
3853 local _class_0
3854 local _base_0 = {
3855 drops = 0,
3856 add_drop = function(self)
3857 self.drops = self.drops + 1
3858 end
3859 }
3860 if _base_0.__index == nil then
3861 _base_0.__index = _base_0
3862 end
3863 _class_0 = setmetatable({
3864 __init = function() end,
3865 __base = _base_0,
3866 __name = "Bucket"
3867 }, {
3868 __index = _base_0,
3869 __call = function(cls, ...)
3870 local _self_0 = setmetatable({ }, _base_0)
3871 cls.__init(_self_0, ...)
3872 return _self_0
3873 end
3874 })
3875 _base_0.__class = _class_0
3876 Bucket = _class_0
3877 x = _class_0
3878end
3879local BigBucket
3880do
3881 local _class_0
3882 local _parent_0 = Bucket
3883 local _base_0 = {
3884 add_drop = function(self)
3885 self.drops = self.drops + 10
3886 end
3887 }
3888 for _key_0, _val_0 in pairs(_parent_0.__base) do
3889 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
3890 _base_0[_key_0] = _val_0
3891 end
3892 end
3893 if _base_0.__index == nil then
3894 _base_0.__index = _base_0
3895 end
3896 setmetatable(_base_0, _parent_0.__base)
3897 _class_0 = setmetatable({
3898 __init = function(self, ...)
3899 return _class_0.__parent.__init(self, ...)
3900 end,
3901 __base = _base_0,
3902 __name = "BigBucket",
3903 __parent = _parent_0
3904 }, {
3905 __index = function(cls, name)
3906 local val = rawget(_base_0, name)
3907 if val == nil then
3908 local parent = rawget(cls, "__parent")
3909 if parent then
3910 return parent[name]
3911 end
3912 else
3913 return val
3914 end
3915 end,
3916 __call = function(cls, ...)
3917 local _self_0 = setmetatable({ }, _base_0)
3918 cls.__init(_self_0, ...)
3919 return _self_0
3920 end
3921 })
3922 _base_0.__class = _class_0
3923 if _parent_0.__inherited then
3924 _parent_0.__inherited(_parent_0, _class_0)
3925 end
3926 BigBucket = _class_0
3927end
3928assert(Bucket.__name == "BigBucket")
3929local x
3930do
3931 local _class_0
3932 local _base_0 = { }
3933 if _base_0.__index == nil then
3934 _base_0.__index = _base_0
3935 end
3936 _class_0 = setmetatable({
3937 __init = function() end,
3938 __base = _base_0,
3939 __name = "x"
3940 }, {
3941 __index = _base_0,
3942 __call = function(cls, ...)
3943 local _self_0 = setmetatable({ }, _base_0)
3944 cls.__init(_self_0, ...)
3945 return _self_0
3946 end
3947 })
3948 _base_0.__class = _class_0
3949 x = _class_0
3950end
3951local MyIndex = {
3952 __index = {
3953 var = 1
3954 }
3955}
3956local X
3957do
3958 local _class_0
3959 local _base_0 = {
3960 func = function(self)
3961 return print(123)
3962 end
3963 }
3964 local _list_0 = {
3965 MyIndex
3966 }
3967 for _index_0 = 1, #_list_0 do
3968 local _item_0 = _list_0[_index_0]
3969 local _cls_0, _mixin_0 = (_item_0.__base ~= nil), _item_0.__base or _item_0
3970 for _key_0, _val_0 in pairs(_mixin_0) do
3971 if _base_0[_key_0] == nil and (not _cls_0 or not _key_0:match("^__")) then
3972 _base_0[_key_0] = _val_0
3973 end
3974 end
3975 end
3976 if _base_0.__index == nil then
3977 _base_0.__index = _base_0
3978 end
3979 _class_0 = setmetatable({
3980 __init = function() end,
3981 __base = _base_0,
3982 __name = "X"
3983 }, {
3984 __index = _base_0,
3985 __call = function(cls, ...)
3986 local _self_0 = setmetatable({ }, _base_0)
3987 cls.__init(_self_0, ...)
3988 return _self_0
3989 end
3990 })
3991 _base_0.__class = _class_0
3992 X = _class_0
3993end
3994local x = X()
3995print(x.var)
3996local Y
3997do
3998 local _class_0
3999 local _base_0 = { }
4000 local _list_0 = {
4001 X
4002 }
4003 for _index_0 = 1, #_list_0 do
4004 local _item_0 = _list_0[_index_0]
4005 local _cls_0, _mixin_0 = (_item_0.__base ~= nil), _item_0.__base or _item_0
4006 for _key_0, _val_0 in pairs(_mixin_0) do
4007 if _base_0[_key_0] == nil and (not _cls_0 or not _key_0:match("^__")) then
4008 _base_0[_key_0] = _val_0
4009 end
4010 end
4011 end
4012 if _base_0.__index == nil then
4013 _base_0.__index = _base_0
4014 end
4015 _class_0 = setmetatable({
4016 __init = function() end,
4017 __base = _base_0,
4018 __name = "Y"
4019 }, {
4020 __index = _base_0,
4021 __call = function(cls, ...)
4022 local _self_0 = setmetatable({ }, _base_0)
4023 cls.__init(_self_0, ...)
4024 return _self_0
4025 end
4026 })
4027 _base_0.__class = _class_0
4028 Y = _class_0
4029end
4030local y = Y()
4031y:func()
4032assert(y.__class.__parent ~= X)
4033do
4034 local _with_0 = Person()
4035 _with_0.name = "Oswald"
4036 _with_0:add_relative(my_dad)
4037 _with_0:save()
4038 print(_with_0.name)
4039end
4040local file
4041do
4042 local _with_0 = File("favorite_foods.txt")
4043 _with_0:set_encoding("utf8")
4044 file = _with_0
4045end
4046local create_person
4047create_person = function(name, relatives)
4048 local _with_0 = Person()
4049 _with_0.name = name
4050 for _index_0 = 1, #relatives do
4051 local relative = relatives[_index_0]
4052 _with_0:add_relative(relative)
4053 end
4054 return _with_0
4055end
4056local me = create_person("Leaf", {
4057 dad,
4058 mother,
4059 sister
4060})
4061do
4062 local str = "你好"
4063 print("原始:", str)
4064 print("大写:", str:upper())
4065end
4066do
4067 local _with_0 = tb
4068 _with_0[1] = 1
4069 print(_with_0[2])
4070 do
4071 local _with_1 = _with_0[abc]
4072 _with_1[3] = _with_1[2]:func()
4073 _with_1["key-name"] = value
4074 end
4075 _with_0[#_with_0 + 1] = "abc"
4076end
4077do
4078 local var = "hello"
4079 print(var)
4080end
4081print(var)
4082local counter
4083do
4084 local i = 0
4085 counter = function()
4086 i = i + 1
4087 return i
4088 end
4089end
4090print(counter())
4091print(counter())
4092local tbl = {
4093 key = (function()
4094 print("分配键值!")
4095 return 1234
4096 end)()
4097}
4098local my_object = {
4099 value = 1000,
4100 write = function(self)
4101 return print("值为:", self.value)
4102 end
4103}
4104local run_callback
4105run_callback = function(func)
4106 print("运行回调...")
4107 return func()
4108end
4109run_callback(my_object.write)
4110run_callback((function()
4111 local _base_0 = my_object
4112 local _fn_0 = _base_0.write
4113 return _fn_0 and function(...)
4114 return _fn_0(_base_0, ...)
4115 end
4116end)())
4117local i = 100
4118local my_func
4119my_func = function()
4120 i = 10
4121 while i > 0 do
4122 print(i)
4123 i = i - 1
4124 end
4125end
4126my_func()
4127print(i)
4128local i = 100
4129local my_func
4130my_func = function()
4131 local i = "hello"
4132end
4133my_func()
4134print(i)
4135local tmp = 1213
4136local i, k = 100, 50
4137local my_func
4138my_func = function(add)
4139 local tmp = tmp + add
4140 i = i + tmp
4141 k = k + tmp
4142end
4143my_func(22)
4144print(i, k)
diff --git a/spec/outputs/compile_doc.lua b/spec/outputs/compile_doc.lua
new file mode 100644
index 0000000..7597cb8
--- /dev/null
+++ b/spec/outputs/compile_doc.lua
@@ -0,0 +1,57 @@
1local outputFolder = ...
2local _list_0 = {
3 {
4 "codes_from_doc.lua",
5 "doc/docs/doc/README.md"
6 },
7 {
8 "codes_from_doc_zh.lua",
9 "doc/docs/zh/doc/README.md"
10 }
11}
12for _index_0 = 1, #_list_0 do
13 local _des_0 = _list_0[_index_0]
14 local compiledFile, docFile = _des_0[1], _des_0[2]
15 local input <close> = (function()
16 local _with_0 = io.open(docFile)
17 if _with_0 ~= nil then
18 local to_lua = require("yue").to_lua
19 local text = _with_0:read("*a")
20 local codes = { }
21 for code in text:gmatch("```moonscript(.-)```") do
22 do
23 local result, err = to_lua(code, {
24 implicit_return_root = false,
25 reserve_line_number = false
26 })
27 if result then
28 codes[#codes + 1] = result
29 elseif not err:match("macro exporting module only accepts macro definition") then
30 print(err)
31 os.exit(1)
32 end
33 end
34 end
35 for code in text:gmatch("<pre>(.-)</pre>") do
36 do
37 local result, err = to_lua(code:gsub("&lt;", "<"):gsub("&gt;", ">"), {
38 implicit_return_root = false,
39 reserve_line_number = false
40 })
41 if result then
42 codes[#codes + 1] = result
43 else
44 print(err)
45 os.exit(1)
46 end
47 end
48 end
49 local output <close> = (function()
50 local _with_1 = io.open(tostring(outputFolder) .. "/" .. tostring(compiledFile), "w+")
51 _with_1:write(table.concat(codes))
52 return _with_1
53 end)()
54 end
55 return _with_0
56 end)()
57end