lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Cf http://www.lua.org/manual/5.2/manual.html#3.4
Last paragraph :
 Any _expression_ enclosed in parentheses always results in only one value....


From: Robert McLay
Sent: mercredi 10 septembre 2014 16:59
To: Lua mailing list
Reply To: Lua mailing list
Subject: Why does this work: ('5'):rep(4) --> 5555 ?

The question I'm asking is why a string literal can be used with string member function like format and rep:

  s = ('5'):rep(10)   --> 5555555555

I would have normally done:

    ss = 5
    s   = ss:rep(10)

I am unable to find this trick discussed in the "Programming in Lua" books or the Lua reference manual.  It clearly works on lua 5.1, 5.2 and luajit 2.0.2.  But is this something that I can assume that it will continue to work?   Is this trick somehow buried in the manuals and I just missed it?  

I found this in some microlight code so I am presuming that it is save to use, but I'd like to know.

Thanks for any light on this subject.
R.