Page 2 of 2

Re: Int to String

Posted: Sun Jul 19, 2015 12:52 am
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. ;)

Re: Int to String

Posted: Sun Jul 19, 2015 10:05 am
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).

Re: Int to String

Posted: Sun Jul 19, 2015 2:18 pm
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'.