From 7ee395d918b97795f151c24ed877bfcc2edf602a Mon Sep 17 00:00:00 2001 From: Li Jin Date: Thu, 25 Dec 2025 00:00:08 +0800 Subject: Added named vararg support. --- spec/outputs/codes_from_doc_zh.lua | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'spec/outputs/codes_from_doc_zh.lua') 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 local first = select(1, ...) return print(ok, count, first) end)(fn(true)) +local f +f = function(...) + local t = { + n = select("#", ...), + ... + } + print("参数个数:", t.n) + print("表长度:", #t) + for i = 1, t.n do + print(t[i]) + end +end +f(1, 2, 3) +f("a", "b", "c", "d") +f() +local process +process = function(...) + local args = { + n = select("#", ...), + ... + } + local sum = 0 + for i = 1, args.n do + if args[i] ~= nil and type(args[i]) == "number" then + sum = sum + args[i] + end + end + return sum +end +process(1, nil, 3, nil, 5) Rx.Observable.fromRange(1, 8):filter(function(x) return x % 2 == 0 end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) @@ -3209,6 +3239,36 @@ end local first = select(1, ...) return print(ok, count, first) end)(fn(true)) +local f +f = function(...) + local t = { + n = select("#", ...), + ... + } + print("参数个数:", t.n) + print("表长度:", #t) + for i = 1, t.n do + print(t[i]) + end +end +f(1, 2, 3) +f("a", "b", "c", "d") +f() +local process +process = function(...) + local args = { + n = select("#", ...), + ... + } + local sum = 0 + for i = 1, args.n do + if args[i] ~= nil and type(args[i]) == "number" then + sum = sum + args[i] + end + end + return sum +end +process(1, nil, 3, nil, 5) Rx.Observable.fromRange(1, 8):filter(function(x) return x % 2 == 0 end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) -- cgit v1.2.3-55-g6feb