aboutsummaryrefslogtreecommitdiff
path: root/spec/outputs/codes_from_doc.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.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.lua')
-rw-r--r--spec/outputs/codes_from_doc.lua4156
1 files changed, 4156 insertions, 0 deletions
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)