[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Why does this work: ('5'):rep(4) --> 5555 ?
- From: Ką Mykolas <kamicc@...>
- Date: Wed, 10 Sep 2014 17:25:12 +0300
Also on 5.1 reference manual: http://www.lua.org/manual/5.1/manual.html#2.5
"Any expression enclosed in parentheses always results in only one value."
So, basically, an expression enclosed in parentheses returns a value.
String functions (according to
http://www.lua.org/manual/5.1/manual.html#5.4) can be called in object
oriented fashion.
"Therefore, you can use the string functions in object-oriented style.
For instance, string.byte(s, i) can be written as s:byte(i)." This
line does apply to some io.* functions too.
On 9/10/14, Thierry@spoludo <thierry@spoludo.com> wrote:
> 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.
>
>
>