aboutsummaryrefslogtreecommitdiff
path: root/spec/outputs/codes_from_doc_zh.lua
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2025-12-25 00:00:08 +0800
committerLi Jin <dragon-fly@qq.com>2025-12-25 00:00:08 +0800
commit7ee395d918b97795f151c24ed877bfcc2edf602a (patch)
tree0fbb5f4d3011ee6459e011416a1307d74cf331a7 /spec/outputs/codes_from_doc_zh.lua
parentbb563257953628a9849c8532a684b5064bf8e655 (diff)
downloadyuescript-7ee395d918b97795f151c24ed877bfcc2edf602a.tar.gz
yuescript-7ee395d918b97795f151c24ed877bfcc2edf602a.tar.bz2
yuescript-7ee395d918b97795f151c24ed877bfcc2edf602a.zip
Added named vararg support.
Diffstat (limited to 'spec/outputs/codes_from_doc_zh.lua')
-rw-r--r--spec/outputs/codes_from_doc_zh.lua60
1 files changed, 60 insertions, 0 deletions
diff --git a/spec/outputs/codes_from_doc_zh.lua b/spec/outputs/codes_from_doc_zh.lua
index ec84112..6a6c38c 100644
--- a/spec/outputs/codes_from_doc_zh.lua
+++ b/spec/outputs/codes_from_doc_zh.lua
@@ -737,6 +737,36 @@ end
737 local first = select(1, ...) 737 local first = select(1, ...)
738 return print(ok, count, first) 738 return print(ok, count, first)
739end)(fn(true)) 739end)(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)
740Rx.Observable.fromRange(1, 8):filter(function(x) 770Rx.Observable.fromRange(1, 8):filter(function(x)
741 return x % 2 == 0 771 return x % 2 == 0
742end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) 772end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
@@ -3209,6 +3239,36 @@ end
3209 local first = select(1, ...) 3239 local first = select(1, ...)
3210 return print(ok, count, first) 3240 return print(ok, count, first)
3211end)(fn(true)) 3241end)(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)
3212Rx.Observable.fromRange(1, 8):filter(function(x) 3272Rx.Observable.fromRange(1, 8):filter(function(x)
3213 return x % 2 == 0 3273 return x % 2 == 0
3214end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) 3274end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)