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

JohnMurga Wrote:

Juergen Wrote:
I'd like to ask the Kepler guys, if they include it in the md5 library, since they have the bin2hex version already (also in Lua). If they take it, it would make sense to use the version from the md5 library. Since the functionality is new, I think there aren't many users.


Thanks :-)

I'll try it out and replace my methods with this in the next build (along with an acknowledgment).

Cheers
JohnM


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

Juergen

Code:
static int hex2bin(lua_State *L) {
  unsigned char switch_case=0,i,j=0,obyte=0;
  size_t l1;
  unsigned char ll[]="0123456789abcdef";
  unsigned char lu[]="0123456789ABCDEF";
  unsigned char *lookup=lu;
  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--) {
    switch_case++;
    for(i=0;i<16;i++) {
       if ((unsigned char) *s1==lookup[i]) {
         obyte+=(j==0)?i<<4:i;
         if (j==1) { luaL_putchar(&b, (char) obyte); obyte=0; }
         j^=1;
         s1++;
         switch_case=0; // everything is ok
         break;
       }
    }
    if (switch_case>0) { // we haven't found our letter
      if (switch_case>1) { //switching was fruitless -> exit
        lua_error(L);
      }

    lookup=(lookup==ll)?lu:ll; //switch lookup table
    l1++; //
    switch_case++; //try again
    }
  }
  luaL_pushresult(&b);
  return 1;
}

02-06-2008 09:29 AM
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: