278 posts
Posted 24 January 2013 - 11:22 AM
Hello again.
I've been playing with DCPU-16 assembly for quite some time now, and after writing a checksum calculator for the DCPU-16, I've decided to write something similar in Lua.
This API simply provides a means to calculate CRC checksums with user-specified generator polynomials, and also includes functions to convert to/from hexadecimal and decimal.
For best results, use the calculate_crc function with the constants 0x04C11DB7 or 0x1EDC6F41. Note: Not a secure or suitable replacement for secure hashes such as SHA-1 or SHA-2.
Get it here.
392 posts
Location
Christchurch, New Zealand
Posted 24 January 2013 - 11:30 AM
This is fantastic!
And like any CRC Algorithm needs to be, it looks like it will be fast.
I do suggest using
for i=1, #data do
local v = data[i]
Simply because ipairs will be retired in Lua 5.2, and although there is no indication yet that CC will be changing. It might.
That and an incremental for loop is faster than a pairs loop :P/>
Thanks for the submission.
278 posts
Posted 24 January 2013 - 03:36 PM
This is fantastic!
And like any CRC Algorithm needs to be, it looks like it will be fast.
I do suggest using
for i=1, #data do
local v = data[i]
Simply because ipairs will be retired in Lua 5.2, and although there is no indication yet that CC will be changing. It might.
That and an incremental for loop is faster than a pairs loop :P/>
Thanks for the submission.
They're retiring
ipairs()? Wow. Then again, I can see why one would use incremental loops vs. ipairs/pairs. Function overhead and all that. Anyways, thanks for the tip.
392 posts
Location
Christchurch, New Zealand
Posted 24 January 2013 - 03:42 PM
You're welcome :)/>
Thanks for the CRC code.
496 posts
Location
New Zealand
Posted 24 January 2013 - 11:28 PM
Just some small things:
function intToHex(input)
return string.format("%X", input)
end
function hexToInt(input)
return tonumber(input, 16)
end
278 posts
Posted 25 January 2013 - 01:25 AM
Just some small things:
function intToHex(input)
return string.format("%X", input)
end
function hexToInt(input)
return tonumber(input, 16)
end
Heh. I forgot about
string.format and I didn't know that
tonumber took a base as well.
73 posts
Location
Yes
Posted 06 February 2013 - 12:07 PM
This is fantastic!
And like any CRC Algorithm needs to be, it looks like it will be fast.
I do suggest using
for i=1, #data do
local v = data[i]
Simply because ipairs will be retired in Lua 5.2, and although there is no indication yet that CC will be changing. It might.
That and an incremental for loop is faster than a pairs loop :P/>/>/>/>/>/>
Thanks for the submission.
Are you sure about that? I see both 'pairs' and 'ipairs' in the
Lua 5.2 documentation and nothing about it being removed/deprecated in the 'Incompatibilities with the Previous Version' section
Not to mention that that code wont work if
data = {"a", "b", nil, "c"}
(it would loop 2 times, not 3)
1604 posts
Posted 06 February 2013 - 12:26 PM
Not to mention that that code wont work if
data = {"a", "b", nil, "c"}
(it would loop 2 times, not 3)
Well, that would happen with ipairs too. Not with pairs, but it doesn't iterate in order, so you could get "c", "a", "b" (from your example) or anything.
278 posts
Posted 10 February 2013 - 07:24 PM
Are you sure about that? I see both 'pairs' and 'ipairs' in the
Lua 5.2 documentation and nothing about it being removed/deprecated in the 'Incompatibilities with the Previous Version' section
Not to mention that that code wont work if
data = {"a", "b", nil, "c"}
(it would loop 2 times, not 3)
Note to self: replace #[table] with table.maxn( [table] ) and conditionals