News : The level of daily SPAM has reached insane proportions, all registrations are now manual. I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.


Post Reply  Post Thread 
MurgaLua Compiler
Author Message
Juergen
Member
***


Posts: 81
Group: Registered
Joined: May 2007
Status: Offline
Reputation: 0
Post: #1
RE: MurgaLua Compiler

Juergen Wrote:
I improved the hex2bin function a little. The hex2bin function now accepts every even numbered string, that contains valid characters ([0123456789aAbBcCdDeEfF]).

Juergen

Another change. It looks now much simpler. Although it might be a little bit slower in some cases (lower case hex) and faster when used with upper case letters. But it is much more readable and also smaller.

Juergen

Code:
static int hex2bin(lua_State *L) {
  unsigned char found=0,i,j=0,obyte=0;
  size_t l1;
  char lookup[]="0123456789ABCDEF0123456789abcdef";
  const char *s1 = luaL_checklstring(L, 1, &l1);
  luaL_Buffer b;
  luaL_buffinit(L, &b);
  lua_pushstring(L,"This isn't a valid hex string!");
  if (l1%2!=0) lua_error(L);
  while (l1--) {
     found++;
     for(i=0;i<32;i++) {
       if (*s1==lookup[i]) {
         if (j==0) obyte=(i%16)<<4;
           else { obyte+=i%16; luaL_putchar(&b,(char)obyte); }
         j^=1;
         s1++;
         found--;
         break;
       }
    }
    if (found==1) lua_error(L);
  }
  luaL_pushresult(&b);
  return 1;
}

02-06-2008 08:14 PM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

Messages In This Thread
MurgaLua Compiler - iGame3D - 01-31-2008, 09:54 PM
RE: MurgaLua Compiler - mikshaw - 02-01-2008, 12:00 AM
RE: MurgaLua Compiler - JohnMurga - 02-01-2008, 02:45 AM
RE: MurgaLua Compiler - JohnMurga - 02-01-2008, 02:50 AM
RE: MurgaLua Compiler - iGame3D - 02-01-2008, 08:05 AM
RE: MurgaLua Compiler - Juergen - 02-01-2008, 09:08 AM
RE: MurgaLua Compiler - JohnMurga - 02-01-2008, 09:38 AM
RE: MurgaLua Compiler - iGame3D - 02-01-2008, 03:26 PM
RE: MurgaLua Compiler - Juergen - 02-01-2008, 09:08 PM
RE: MurgaLua Compiler - JohnMurga - 02-01-2008, 11:47 PM
RE: MurgaLua Compiler - Juergen - 02-06-2008, 04:33 AM
RE: MurgaLua Compiler - JohnMurga - 02-06-2008, 08:21 AM
MurgaLua Compiler Platforms - iGame3D - 02-06-2008, 09:24 AM
RE: MurgaLua Compiler - Juergen - 02-06-2008, 09:29 AM
RE: MurgaLua Compiler - Juergen - 02-06-2008 08:14 PM

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: