https://www.lua.org/manual/5.4/manual.html
9 – The Complete Syntax of Lua
...
var ::= Name | prefixexp ‘[’ exp ‘]’ | prefixexp ‘.’ Name
...
prefixexp ::= var | functioncall | ‘(’ exp ‘)’
functioncall ::= prefixexp args | prefixexp ‘:’ Name args
...
Basically:
- A "method"
functioncall
is made of four parts: prefixexp
, the colon, the name of the method, and its arguments.
- A
prefixexp
can be either a functioncall
itself, an exp
wrapped inside parenthesis, or a var
.
- A
var
can be an identifier, or its indexed/dotted counterpart.
This effectively disallow using the shorthand :method
syntax on all kinds of literal expressions, not just strings. That said, these are all invalid syntax:
nil:has_no_method()
true:or_false()
2:too()
[[long strings]]:same_thing()
function() end:really()
{}:h_yes_definitely()