aboutsummaryrefslogtreecommitdiff
path: root/spec/outputs/codes_from_doc_zh.lua
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2026-01-15 17:07:11 +0800
committerLi Jin <dragon-fly@qq.com>2026-01-15 17:07:11 +0800
commitfced0c4f4101ad7c8d81432a0e8c45d38b72616c (patch)
treeed673461c7ef3c614cb5d56905c437f6a6b27454 /spec/outputs/codes_from_doc_zh.lua
parent4177d237e3ed642b2bba5bec13127a44d2b0524d (diff)
downloadyuescript-fced0c4f4101ad7c8d81432a0e8c45d38b72616c.tar.gz
yuescript-fced0c4f4101ad7c8d81432a0e8c45d38b72616c.tar.bz2
yuescript-fced0c4f4101ad7c8d81432a0e8c45d38b72616c.zip
Added `import global` syntax.
Diffstat (limited to 'spec/outputs/codes_from_doc_zh.lua')
-rw-r--r--spec/outputs/codes_from_doc_zh.lua142
1 files changed, 82 insertions, 60 deletions
diff --git a/spec/outputs/codes_from_doc_zh.lua b/spec/outputs/codes_from_doc_zh.lua
index 6a6c38c..87944e0 100644
--- a/spec/outputs/codes_from_doc_zh.lua
+++ b/spec/outputs/codes_from_doc_zh.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("参数个数:", t.n)
747 print("表长度:", #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)
@@ -994,6 +975,36 @@ local arg1 = {
994 a = 0 975 a = 0
995} 976}
996f2(arg1, arg2) 977f2(arg1, arg2)
978local f
979f = function(...)
980 local t = {
981 n = select("#", ...),
982 ...
983 }
984 print("参数个数:", t.n)
985 print("表长度:", #t)
986 for i = 1, t.n do
987 print(t[i])
988 end
989end
990f(1, 2, 3)
991f("a", "b", "c", "d")
992f()
993local process
994process = function(...)
995 local args = {
996 n = select("#", ...),
997 ...
998 }
999 local sum = 0
1000 for i = 1, args.n do
1001 if args[i] ~= nil and type(args[i]) == "number" then
1002 sum = sum + args[i]
1003 end
1004 end
1005 return sum
1006end
1007process(1, nil, 3, nil, 5)
997f(function() 1008f(function()
998 return print("hello") 1009 return print("hello")
999end) 1010end)
@@ -2911,6 +2922,17 @@ local tb = {
2911 } 2922 }
2912} 2923}
2913do 2924do
2925 local math = math
2926 local print = print
2927 print("hello")
2928 math.random(3)
2929end
2930do
2931 local print = print
2932 print(FLAG)
2933 FLAG = 123
2934end
2935do
2914 local insert, concat = table.insert, table.concat 2936 local insert, concat = table.insert, table.concat
2915 local C, Ct, Cmt 2937 local C, Ct, Cmt
2916 do 2938 do
@@ -3239,36 +3261,6 @@ end
3239 local first = select(1, ...) 3261 local first = select(1, ...)
3240 return print(ok, count, first) 3262 return print(ok, count, first)
3241end)(fn(true)) 3263end)(fn(true))
3242local f
3243f = function(...)
3244 local t = {
3245 n = select("#", ...),
3246 ...
3247 }
3248 print("参数个数:", t.n)
3249 print("表长度:", #t)
3250 for i = 1, t.n do
3251 print(t[i])
3252 end
3253end
3254f(1, 2, 3)
3255f("a", "b", "c", "d")
3256f()
3257local process
3258process = function(...)
3259 local args = {
3260 n = select("#", ...),
3261 ...
3262 }
3263 local sum = 0
3264 for i = 1, args.n do
3265 if args[i] ~= nil and type(args[i]) == "number" then
3266 sum = sum + args[i]
3267 end
3268 end
3269 return sum
3270end
3271process(1, nil, 3, nil, 5)
3272Rx.Observable.fromRange(1, 8):filter(function(x) 3264Rx.Observable.fromRange(1, 8):filter(function(x)
3273 return x % 2 == 0 3265 return x % 2 == 0
3274end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) 3266end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
@@ -3526,6 +3518,36 @@ findFirstEven = function(list)
3526 end 3518 end
3527 return nil 3519 return nil
3528end 3520end
3521local f
3522f = function(...)
3523 local t = {
3524 n = select("#", ...),
3525 ...
3526 }
3527 print("参数个数:", t.n)
3528 print("表长度:", #t)
3529 for i = 1, t.n do
3530 print(t[i])
3531 end
3532end
3533f(1, 2, 3)
3534f("a", "b", "c", "d")
3535f()
3536local process
3537process = function(...)
3538 local args = {
3539 n = select("#", ...),
3540 ...
3541 }
3542 local sum = 0
3543 for i = 1, args.n do
3544 if args[i] ~= nil and type(args[i]) == "number" then
3545 sum = sum + args[i]
3546 end
3547 end
3548 return sum
3549end
3550process(1, nil, 3, nil, 5)
3529f(function() 3551f(function()
3530 return print("hello") 3552 return print("hello")
3531end) 3553end)