albertodemichelis / squirrel

Official repository for the programming language Squirrel
http://www.squirrel-lang.org
MIT License
913 stars 156 forks source link

Feature idead char(c) or similar to convert an int to a string according to ASCII #218

Closed ten3roberts closed 4 years ago

ten3roberts commented 4 years ago

When you index a string or have a function that returns a character, it is returned as an int

This is perfectly normal

However when concatenating it to a string it is treated as an integer This most commonly happens with File.readn('c')

Example:

local s = ""

foreach (c in characters)
{
    s += c
}

// Prints "979899", the ascii values for the supplied characters
print(s + "\n")

The only workaround for this is to use the format("%c", c), but it is unnecesarrily complex for such a simple task

I propose a char(c) function that returns a 1 long string representing the ascii value supplied

This is similar to the chr(c) function in Python

I can implement it and create a PR if it is wanted

albertodemichelis commented 4 years ago

try this:

s+= c.tochar()

ten3roberts commented 4 years ago

Awesome. Love the language