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 
Binary string library
Author Message
jpjacobs
Member
***


Posts: 113
Group: Registered
Joined: Jul 2007
Status: Offline
Reputation: 0
Post: #1
Binary string library

Hi!

I know it's entirely off topic, but since there's not so much talk here anyway, I'll just dump itSmile
Instead of studying, I made a binary stringlib yesterday, based on the use of metatables. There's a newBin() function which takes about any sensible input (number, string of 0's and 1's optionally prefixed by 0b, table of trues and falses).
This returns a table of trues and falses _with_ a useful metatable defining operations as follows:
a+b = element by element xor
a*b = element by element and
-a = element by element inversion
a-b = a+ (-b)
a/b : gives error, if anyone has a useful suggestion for sensible behavior
a..b does what it's supposed to do, if one of them is a string then do string concat, if one is a number then convert it to bin first.

The metatable also has a __tostring function so they get printed in a sensible way.
The bins also come with a toDec method for easy conversion back to numbers.

I don't make any claims about correctness or performance, but suggestions are always welcome...

Right: you can find the thing here: http://jpjacobs.ulyssis.org/scripts/binlib.lua
greetz,
JP

BTW i'm really really looking forward to have a new murgaLua version Wink
BTW2 added lunit tests at http://jpjacobs.ulyssis.org/scripts/binlibtests.lua

This post was last modified: 01-16-2009 10:12 PM by jpjacobs.

12-23-2008 08:43 AM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

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

Forum Jump: