character constants

  • From: William Adams <william_a_adams@xxxxxxx>
  • To: <luajit@xxxxxxxxxxxxx>
  • Date: Thu, 17 May 2012 00:41:20 +0000

Does anyone know of a set of predefined constants for characters? In C, I 
typically have: switch(c){  case ' ':  case '\t':    // whitespace handling    
break;   case 'a':  case 'b':    break;  // etc}
 In lua, there are only strings right?  And the single quotes are just dummies 
for double quotes, so 'a' ~= single byte representation of the ascii character 
a. I find myself having do to: string.byte('a'), and that can't be particular 
performant. Before I go ahead and create the constants for all the ascii 
characters, is there a better way of doing this, or some magical character I 
can put in front of a string literal to get the constant for the first 
character without having to make a function call? I wish Lua would have 
followed the C convention of single quote means ascii code of a single 
character, and double quote is for strings.  I mean, we also have [[ ]] for 
string literals, and we have escape sequences for everything else, so I don't 
see the need to use both single and double quotes for strings.  But then again, 
I wasn't there at the beginning, so I'm sure the design choice made sense at 
the time. -- William
===============================

- Shaping clay is easier than digging it out of the ground.


http://williamaadams.wordpress.com
http://www.thingiverse.com/WilliamAAdams
https://github.com/Wiladams
                                          

Other related posts: