I found out that this is a valid Luau syntax.
local a b: c, d: e, f: g
I had a quick look at the grammar and this does not seem to be included at it only accounts for bindinglist:
'local' bindinglist ['=' explist]
…
binding = NAME [':' TypeAnnotation]
bindinglist = binding [',' bindinglist] (* equivalent of Lua 5.1 'namelist', except with optional type annotations *)
…and then I decided to quickly look at the source code of Luau AST, Parser::parseLocal function is Parser.cpp, and nothing about this seems to be coded here.
matchRecoveryStopOnToken['=']++;
TempVector<Binding> names(scratchBinding);
parseBindingList(names);
matchRecoveryStopOnToken['=']--;
TempVector<AstLocal*> vars(scratchLocal);
TempVector<AstExpr*> values(scratchExpr);
std::optional<Location> equalsSignLocation;
if (lexer.current().type == '=')
{
My question is, what does the identifer between the local
and the first variable name do? e.g. local identifier varname
, local foo bar: Type, baz: number
.
Apparently local xnil xnil = nil
makes the table clear loop go faster but that doen’t explain why other identifiers are also allowed. e.g. local this_also_works nil =nil
.
Is other identifiers aside from xnil made allowed to be a valid syntax by accident?
Starting to think about it, does other identifiers between local keyword and the variable name even do anything?