Int to String

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: Int to String

Post by davisdude »

time thief wrote:
bartbes wrote:Reading is difficult!
It's the ulgy trooth
Reading is difficult, though!
TsT wrote:You code is ulgy and be able to break the check with metatable/__add meta handler.
Yeah, I know, it was just a joke. ;)
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Int to String

Post by T-Bone »

I've always done it like this

Code: Select all

as_int = 42
as_string = "" .. as_int
Not sure if there are any advantages/disadvantages over tostring. I guess tostring is more readable, while my way is more compact (which is helpful when putting many strings and numbers together).
User avatar
DaedalusYoung
Party member
Posts: 407
Joined: Sun Jul 14, 2013 8:04 pm

Re: Int to String

Post by DaedalusYoung »

I think with your method, if at some point as_int accidentally is nil, it will crash, while tostring simply converts the nil value to the string 'nil'.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 4 guests