aboutsummaryrefslogtreecommitdiff
path: root/spec/outputs/codes_from_doc.lua
diff options
context:
space:
mode:
Diffstat (limited to 'spec/outputs/codes_from_doc.lua')
-rw-r--r--spec/outputs/codes_from_doc.lua142
1 files changed, 82 insertions, 60 deletions
diff --git a/spec/outputs/codes_from_doc.lua b/spec/outputs/codes_from_doc.lua
index de5abdd..02f36d1 100644
--- a/spec/outputs/codes_from_doc.lua
+++ b/spec/outputs/codes_from_doc.lua
@@ -409,6 +409,17 @@ local tb = {
409 } 409 }
410} 410}
411do 411do
412 local math = math
413 local print = print
414 print("hello")
415 math.random(3)
416end
417do
418 local print = print
419 print(FLAG)
420 FLAG = 123
421end
422do
412 local insert, concat = table.insert, table.concat 423 local insert, concat = table.insert, table.concat
413 local C, Ct, Cmt 424 local C, Ct, Cmt
414 do 425 do
@@ -737,36 +748,6 @@ end
737 local first = select(1, ...) 748 local first = select(1, ...)
738 return print(ok, count, first) 749 return print(ok, count, first)
739end)(fn(true)) 750end)(fn(true))
740local f
741f = function(...)
742 local t = {
743 n = select("#", ...),
744 ...
745 }
746 print("argument count:", t.n)
747 print("table length:", #t)
748 for i = 1, t.n do
749 print(t[i])
750 end
751end
752f(1, 2, 3)
753f("a", "b", "c", "d")
754f()
755local process
756process = function(...)
757 local args = {
758 n = select("#", ...),
759 ...
760 }
761 local sum = 0
762 for i = 1, args.n do
763 if args[i] ~= nil and type(args[i]) == "number" then
764 sum = sum + args[i]
765 end
766 end
767 return sum
768end
769process(1, nil, 3, nil, 5)
770Rx.Observable.fromRange(1, 8):filter(function(x) 751Rx.Observable.fromRange(1, 8):filter(function(x)
771 return x % 2 == 0 752 return x % 2 == 0
772end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) 753end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
@@ -1000,6 +981,36 @@ local arg1 = {
1000 a = 0 981 a = 0
1001} 982}
1002f2(arg1, arg2) 983f2(arg1, arg2)
984local f
985f = function(...)
986 local t = {
987 n = select("#", ...),
988 ...
989 }
990 print("argument count:", t.n)
991 print("table length:", #t)
992 for i = 1, t.n do
993 print(t[i])
994 end
995end
996f(1, 2, 3)
997f("a", "b", "c", "d")
998f()
999local process
1000process = function(...)
1001 local args = {
1002 n = select("#", ...),
1003 ...
1004 }
1005 local sum = 0
1006 for i = 1, args.n do
1007 if args[i] ~= nil and type(args[i]) == "number" then
1008 sum = sum + args[i]
1009 end
1010 end
1011 return sum
1012end
1013process(1, nil, 3, nil, 5)
1003f(function() 1014f(function()
1004 return print("hello") 1015 return print("hello")
1005end) 1016end)
@@ -2917,6 +2928,17 @@ local tb = {
2917 } 2928 }
2918} 2929}
2919do 2930do
2931 local math = math
2932 local print = print
2933 print("hello")
2934 math.random(3)
2935end
2936do
2937 local print = print
2938 print(FLAG)
2939 FLAG = 123
2940end
2941do
2920 local insert, concat = table.insert, table.concat 2942 local insert, concat = table.insert, table.concat
2921 local C, Ct, Cmt 2943 local C, Ct, Cmt
2922 do 2944 do
@@ -3245,36 +3267,6 @@ end
3245 local first = select(1, ...) 3267 local first = select(1, ...)
3246 return print(ok, count, first) 3268 return print(ok, count, first)
3247end)(fn(true)) 3269end)(fn(true))
3248local f
3249f = function(...)
3250 local t = {
3251 n = select("#", ...),
3252 ...
3253 }
3254 print("argument count:", t.n)
3255 print("table length:", #t)
3256 for i = 1, t.n do
3257 print(t[i])
3258 end
3259end
3260f(1, 2, 3)
3261f("a", "b", "c", "d")
3262f()
3263local process
3264process = function(...)
3265 local args = {
3266 n = select("#", ...),
3267 ...
3268 }
3269 local sum = 0
3270 for i = 1, args.n do
3271 if args[i] ~= nil and type(args[i]) == "number" then
3272 sum = sum + args[i]
3273 end
3274 end
3275 return sum
3276end
3277process(1, nil, 3, nil, 5)
3278Rx.Observable.fromRange(1, 8):filter(function(x) 3270Rx.Observable.fromRange(1, 8):filter(function(x)
3279 return x % 2 == 0 3271 return x % 2 == 0
3280end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) 3272end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
@@ -3538,6 +3530,36 @@ findFirstEven = function(list)
3538 end 3530 end
3539 return nil 3531 return nil
3540end 3532end
3533local f
3534f = function(...)
3535 local t = {
3536 n = select("#", ...),
3537 ...
3538 }
3539 print("argument count:", t.n)
3540 print("table length:", #t)
3541 for i = 1, t.n do
3542 print(t[i])
3543 end
3544end
3545f(1, 2, 3)
3546f("a", "b", "c", "d")
3547f()
3548local process
3549process = function(...)
3550 local args = {
3551 n = select("#", ...),
3552 ...
3553 }
3554 local sum = 0
3555 for i = 1, args.n do
3556 if args[i] ~= nil and type(args[i]) == "number" then
3557 sum = sum + args[i]
3558 end
3559 end
3560 return sum
3561end
3562process(1, nil, 3, nil, 5)
3541f(function() 3563f(function()
3542 return print("hello") 3564 return print("hello")
3543end) 3565end)