[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Why does this work: ('5'):rep(4) --> 5555 ?
- From: Rob Kendrick <rjek@...>
- Date: Wed, 10 Sep 2014 15:03:03 +0100
On Wed, Sep 10, 2014 at 08:58:34AM -0500, Robert McLay wrote:
> 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)
rep() is a method for strings. '5' is a string, 5 is a number. It would
make no sense to execute it on a number. Indeed, rep() is not a method
on numbers (not via the default metatables, at least.)
B.