aboutsummaryrefslogtreecommitdiff
path: root/spec/outputs/codes_from_doc_zh.lua
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/outputs/codes_from_doc_zh.lua
parentca6f13ea62e1fb566a604a00176beb6dda0dcb1a (diff)
downloadyuescript-9908433cc0d493c6910d0aed5cdf263397cee87f.tar.gz
yuescript-9908433cc0d493c6910d0aed5cdf263397cee87f.tar.bz2
yuescript-9908433cc0d493c6910d0aed5cdf263397cee87f.zip
add doc codes check.
Diffstat (limited to 'spec/outputs/codes_from_doc_zh.lua')
-rw-r--r--spec/outputs/codes_from_doc_zh.lua4144
1 files changed, 4144 insertions, 0 deletions
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)