In a Lua file, I got the following code:
local mod_name = (...);
I have tried the code print(mod_name), and I got the file name "pb".
The whole script is called from another script by require('pb');.
I knew the meaning of (...) in function for multiple arguments, but I'm confused with this.
... represents a list of arguments, either to the chunk (e.g., script) or to a function declared as function (named_arg_1, named_arg_2, ...) or function (...).
A list can be concatenated to a list, as in {1, 2, ...} or print("args:",...). In these examples it is used in the context of a list. Otherwise, it expands only to the first value.
In local a = (...), the context is not a list due to the parentheses forming the expression. So, it assigns a the first value.
The parentheses seem to be stylistic because although local a = ... has a list context, a is still assigned the first value. Other examples: local a, b = ... would assign the second value to b and local a, b = (...) would assign nil to b.
From this, it should be clear that module(...) calls the value held by module as a function with a list of parameters expanded from the ... list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With