diff options
| author | Li Jin <dragon-fly@qq.com> | 2025-12-25 00:00:08 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2025-12-25 00:00:08 +0800 |
| commit | 7ee395d918b97795f151c24ed877bfcc2edf602a (patch) | |
| tree | 0fbb5f4d3011ee6459e011416a1307d74cf331a7 /spec/inputs | |
| parent | bb563257953628a9849c8532a684b5064bf8e655 (diff) | |
| download | yuescript-7ee395d918b97795f151c24ed877bfcc2edf602a.tar.gz yuescript-7ee395d918b97795f151c24ed877bfcc2edf602a.tar.bz2 yuescript-7ee395d918b97795f151c24ed877bfcc2edf602a.zip | |
Added named vararg support.
Diffstat (limited to 'spec/inputs')
| -rw-r--r-- | spec/inputs/vararg.yue | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/spec/inputs/vararg.yue b/spec/inputs/vararg.yue index 6100250..4f8a0d7 100644 --- a/spec/inputs/vararg.yue +++ b/spec/inputs/vararg.yue | |||
| @@ -86,3 +86,47 @@ join = (...) -> | |||
| 86 | print ... | 86 | print ... |
| 87 | nil | 87 | nil |
| 88 | 88 | ||
| 89 | do | ||
| 90 | f1 = (...t) -> | ||
| 91 | print t.n | ||
| 92 | print #t | ||
| 93 | for i = 1, t.n | ||
| 94 | print t[i] | ||
| 95 | |||
| 96 | f1 1, 2, 3 | ||
| 97 | f1 "a", "b", "c", "d" | ||
| 98 | f1! | ||
| 99 | |||
| 100 | f2 = (...args) -> | ||
| 101 | print "args count:", args.n | ||
| 102 | print "args length:", #args | ||
| 103 | for i = 1, args.n | ||
| 104 | if args[i] == nil | ||
| 105 | print "position", i, "is nil" | ||
| 106 | else | ||
| 107 | print "position", i, ":", args[i] | ||
| 108 | |||
| 109 | f2 1, nil, 3, nil, 5 | ||
| 110 | |||
| 111 | f3 = (prefix, ...items) -> | ||
| 112 | result = {} | ||
| 113 | for i = 1, items.n | ||
| 114 | result[i] = prefix .. tostring items[i] | ||
| 115 | result | ||
| 116 | |||
| 117 | f3 "item_", 1, 2, 3 | ||
| 118 | |||
| 119 | f4 = (...empty) -> | ||
| 120 | print "empty count:", empty.n | ||
| 121 | print "empty length:", #empty | ||
| 122 | |||
| 123 | f4! | ||
| 124 | |||
| 125 | process = (...data) -> | ||
| 126 | sum = 0 | ||
| 127 | for i = 1, data.n | ||
| 128 | if type(data[i]) == "number" | ||
| 129 | sum += data[i] | ||
| 130 | sum | ||
| 131 | |||
| 132 | process 1, 2, 3, "skip", 5 | ||
