Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the code "local a = (...);" in a required script mean?

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.

like image 792
RoyHu Avatar asked Mar 17 '23 23:03

RoyHu


1 Answers

... 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.

like image 190
Tom Blodget Avatar answered Apr 27 '23 05:04

Tom Blodget