Retrieve the length of variable argument list

Robert
function countargs(...)
  return #arg
end

> countargs(1, 2, 3)
0

In this case, countargs returns 0 and not 3. How to retrieve the length of the variable argument list?

I tested against Lua 5.3 and 5.4 on Windows.

Nicol Bolas

The number of elements in ... can be computed via select("#", ...). Note that this will include any embedded nil elements, unlike syntaxes like #{...}.

However, you generally don't need the length directly; what you really need is a table containing the elements in question. To build this, call table.pack(...). This will return a table containing all of the ... elements, and the length will be at the key "n", which allows you to iterate over even the embedded nil elements of ....

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Java multiple variable length argument

分類Dev

Variable-Length Argument List passing generics and generic arrays as params - Java

分類Dev

pass a list of variable names as an argument to an R function

分類Dev

Variable argument list: use va_list or address of formal parameter?

分類Dev

In a Python List - How to retrieve a variable stored in a known position? Python 2.7

分類Dev

better way to get a list of variable length strings in fortran

分類Dev

Import python dict with variable-length list items into pandas

分類Dev

Retrieve back a variable property

分類Dev

Integer array of variable length

分類Dev

Android FireStore retrieve as list

分類Dev

Passing $this variable as an argument

分類Dev

argument "variable" is missing, with no default

分類Dev

Verifying a List of List argument in Mockito

分類Dev

Error unpack requires a string argument of length 16

分類Dev

unpack requires a string argument of length 24

分類Dev

How to retrieve the content of a variable that is in a function?

分類Dev

Leading Zeros for Variable Length Field

分類Dev

Custom Audience list or retrieve users

分類Dev

Retrieve a mailchimp list via GET

分類Dev

Retrieve MongoDB data and store it in a list

分類Dev

How to put variable as argument in system()

分類Dev

Length of a list with multiple entries is 1?

分類Dev

while statement that goes with list and length

分類Dev

Count list length in a column of a DataFrame

分類Dev

Updating the range of list in function argument

分類Dev

Mockito: Verify generic list as argument

分類Dev

Argument list when calling a function

分類Dev

python sort list of objects by length of a containing list

分類Dev

check if argument is not a list , then display message if it isnt a list

Related 関連記事

  1. 1

    Java multiple variable length argument

  2. 2

    Variable-Length Argument List passing generics and generic arrays as params - Java

  3. 3

    pass a list of variable names as an argument to an R function

  4. 4

    Variable argument list: use va_list or address of formal parameter?

  5. 5

    In a Python List - How to retrieve a variable stored in a known position? Python 2.7

  6. 6

    better way to get a list of variable length strings in fortran

  7. 7

    Import python dict with variable-length list items into pandas

  8. 8

    Retrieve back a variable property

  9. 9

    Integer array of variable length

  10. 10

    Android FireStore retrieve as list

  11. 11

    Passing $this variable as an argument

  12. 12

    argument "variable" is missing, with no default

  13. 13

    Verifying a List of List argument in Mockito

  14. 14

    Error unpack requires a string argument of length 16

  15. 15

    unpack requires a string argument of length 24

  16. 16

    How to retrieve the content of a variable that is in a function?

  17. 17

    Leading Zeros for Variable Length Field

  18. 18

    Custom Audience list or retrieve users

  19. 19

    Retrieve a mailchimp list via GET

  20. 20

    Retrieve MongoDB data and store it in a list

  21. 21

    How to put variable as argument in system()

  22. 22

    Length of a list with multiple entries is 1?

  23. 23

    while statement that goes with list and length

  24. 24

    Count list length in a column of a DataFrame

  25. 25

    Updating the range of list in function argument

  26. 26

    Mockito: Verify generic list as argument

  27. 27

    Argument list when calling a function

  28. 28

    python sort list of objects by length of a containing list

  29. 29

    check if argument is not a list , then display message if it isnt a list

ホットタグ

アーカイブ