ascii() supported? [RESOLVED]

Trying to do some vector font stuff - and I can’t do ‘ascii(“a”)’ which I thought was stock Lua.

Is there some alternate way to translate between characters and their ascii values?

function setup()

print("\"")

print(xascii("~"))

end

function draw()

end

function xascii(xchar)

return string.find(" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghijklmnopqrstuvwxyz{|}~",xchar) + 31

end

It looks horrid in the Codify editor but it works

Remove the carriage return between ? And @

I figure the optional ascii() parm that looks for which char ascii(“ABC”,2) for B can be done with other string functions if you need it

+1 for including all possible standard Lua functions.

I’m not sure if ascii() is a standard Lua function in the latest version. I can’t find mention of it in the newest documentation.

Edit: Looking into this further, it might be that string.byte() is what you’re looking for

string.byte (s [, i [, j]])

Returns the internal numerical codes of the characters s[i], s[i+1], ···, s[j]. The default value for i is 1; the default value for j is i.

Note that numerical codes are not necessarily portable across platforms.

http://www.lua.org/manual/5.1/

I meant to ask about it - Is the lua version embedded 5.1 or some other version? And did you include any optional libraries (other than the graphics API)?

I found ascii() in some random google search - I come from perl-land, so the concepts aren’t new, but the exact vocabulary and syntax can be.

It’s using 5.1.4, which was the latest version at the time of release.

Can I mark this thread as resolved? Is string.byte() a suitable alternative?

Yes indeed - looks like exactly what I was hoping ascii() would be. I’ll dig into the 5.1 docs. Thanks!