This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
bWGi's profile picture

Index Expected, Got Nil In Md5 Library

Started by bWGi, 12 February 2012 - 09:08 PM
bWGi #1
Posted 12 February 2012 - 10:08 PM
i am trying to make a set of hashing and encryption libraries for this mod however i am not that skilled in lua, without a line number i do not see who i am getting this error, the code is attached

i am trying to adapt this from this library that relies on the C implementation of lua with the bit library.

rom/apis/md5
Spoiler

ff=tonumber("ffffff",16)
t={}
for i=1,64,1 do
t[i]=(4294967296*math.abs(math.sin(i)))
end
local a,b,c,d
local function f(x,y,z)
return bit.bor(bit.band(x,y),bit.band(-x-1,z))
end
local function g(x,y,z)
return bit.bor(bit.band(x,z),bit.band(y,-z-1))
end
local function h(x,y,z)
return bit.bxor(x,bit.bxor(y,z))
end
local function i(x,y,z)
return bit.bxor(y,but.bor(x,-z-1))
end
local function z(f,a,b,c,d,x,s,ac)
a=bit.band(a+f(b,c,d)+x+ac,ff)
-- be *very* careful that left shift does not cause rounding!
return bit.bor(bit.lshift(bit.band(a,bit.rshift(ff,s)),s),bit.rshift(a,32-s))+b
end
local function pad(s)
msgLen=strlen(s)
local padLen=56-imod(msgLen,64)
if imod(msgLen,64)>56 then padLen=padLen+64 end
if padLen==0 then padLen=64 end
s=s..strchar(128)..strrep(strchar('0'),padLen-1)
s=s..leIstr(8*msgLen)..leIstr('0')
return s
end
local function initializeBuffers()
local a=tonumber("10234567",16)
local b=tonumber("89abcdef",16)
local c=tonumber("fedcba98",16)
local d=tonumber("76543210",16)
end
local function transform(a,b,c,d)
local a,b,c,d=A,B,C,D
a=z(f,a,b,c,d,X[ 0], 7,t[ 1])
d=z(f,d,a,b,c,X[ 1],12,t[ 2])
c=z(f,c,d,a,b,X[ 2],17,t[ 3])
b=z(f,b,c,d,a,X[ 3],22,t[ 4])
a=z(f,a,b,c,d,X[ 4], 7,t[ 5])
d=z(f,d,a,b,c,X[ 5],12,t[ 6])
c=z(f,c,d,a,b,X[ 6],17,t[ 7])
b=z(f,b,c,d,a,X[ 7],22,t[ 8])
a=z(f,a,b,c,d,X[ 8], 7,t[ 9])
d=z(f,d,a,b,c,X[ 9],12,t[10])
c=z(f,c,d,a,b,X[10],17,t[11])
b=z(f,b,c,d,a,X[11],22,t[12])
a=z(f,a,b,c,d,X[12], 7,t[13])
d=z(f,d,a,b,c,X[13],12,t[14])
c=z(f,c,d,a,b,X[14],17,t[15])
b=z(f,b,c,d,a,X[15],22,t[16])
a=z(g,a,b,c,d,X[ 1], 5,t[17])
d=z(g,d,a,b,c,X[ 6], 9,t[18])
c=z(g,c,d,a,b,X[11],14,t[19])
b=z(g,b,c,d,a,X[ 0],20,t[20])
a=z(g,a,b,c,d,X[ 5], 5,t[21])
d=z(g,d,a,b,c,X[10], 9,t[22])
c=z(g,c,d,a,b,X[15],14,t[23])
b=z(g,b,c,d,a,X[ 4],20,t[24])
a=z(g,a,b,c,d,X[ 9], 5,t[25])
d=z(g,d,a,b,c,X[14], 9,t[26])
c=z(g,c,d,a,b,X[ 3],14,t[27])
b=z(g,b,c,d,a,X[ 8],20,t[28])
a=z(g,a,b,c,d,X[13], 5,t[29])
d=z(g,d,a,b,c,X[ 2], 9,t[30])
c=z(g,c,d,a,b,X[ 7],14,t[31])
b=z(g,b,c,d,a,X[12],20,t[32])
a=z(h,a,b,c,d,X[ 5], 4,t[33])
d=z(h,d,a,b,c,X[ 8],11,t[34])
c=z(h,c,d,a,b,X[11],16,t[35])
b=z(h,b,c,d,a,X[14],23,t[36])
a=z(h,a,b,c,d,X[ 1], 4,t[37])
d=z(h,d,a,b,c,X[ 4],11,t[38])
c=z(h,c,d,a,b,X[ 7],16,t[39])
b=z(h,b,c,d,a,X[10],23,t[40])
a=z(h,a,b,c,d,X[13], 4,t[41])
d=z(h,d,a,b,c,X[ 0],11,t[42])
c=z(h,c,d,a,b,X[ 3],16,t[43])
b=z(h,b,c,d,a,X[ 6],23,t[44])
a=z(h,a,b,c,d,X[ 9], 4,t[45])
d=z(h,d,a,b,c,X[12],11,t[46])
c=z(h,c,d,a,b,X[15],16,t[47])
b=z(h,b,c,d,a,X[ 2],23,t[48])
a=z(i,a,b,c,d,X[ 0], 6,t[49])
d=z(i,d,a,b,c,X[ 7],10,t[50])
c=z(i,c,d,a,b,X[14],15,t[51])
b=z(i,b,c,d,a,X[ 5],21,t[52])
a=z(i,a,b,c,d,X[12], 6,t[53])
d=z(i,d,a,b,c,X[ 3],10,t[54])
c=z(i,c,d,a,b,X[10],15,t[55])
b=z(i,b,c,d,a,X[ 1],21,t[56])
a=z(i,a,b,c,d,X[ 8], 6,t[57])
d=z(i,d,a,b,c,X[15],10,t[58])
c=z(i,c,d,a,b,X[ 6],15,t[59])
b=z(i,b,c,d,a,X[13],21,t[60])
a=z(i,a,b,c,d,X[ 4], 6,t[61])
d=z(i,d,a,b,c,X[11],10,t[62])
c=z(i,c,d,a,b,X[ 2],15,t[63])
b=z(i,b,c,d,a,X[ 9],21,t[64])
return A+a,B+b,C+c,D+d
end
function calc(s)
pad(s)
initializeBuffers()
for i=0,strlen(s),64 do
  X=leStrCuts(strsub(s,i,i+63),4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4)
  X[0]=tremove(X,1) -- zero based!
end
abcd=transform(a,b,c,d)
local swap=function (w) return beInt(leIstr(w)) end
return format("%08x%08x%08x%08x",swap(a),swap(;)/>/>,swap(c),swap(d))
end
md5.calc=calc
rom/apis/ble
Spoiler

-- convert little-endian 32-bit int to a 4-char string
function leIstr(i)
  local f=function (s) return strchar(bit.band(bit.rshift(i,s),255)) end
  return f(0)..f(8)..f(16)..f(24)
end
do -- from util.lua
  -- convert raw string to big-endian int
  function beInt(s)
    local v=0
    for i=1,strlen(s) do v=v*256+strbyte(s,i) end
    return v
  end
  -- convert raw string to little-endian int
  function leInt(s)
    local v=0
    for i=strlen(s),1,-1 do v=v*256+strbyte(s,i) end
    return v
  end
  -- cut up a string in little-endian ints of given size
  function leStrCuts(s,...)
    local o,r=1,{}
    for i=1,getn(arg) do
	  tinsert(r,leInt(strsub(s,o,o+arg[i]-1)))
	  o=o+arg[i]
    end
    return r
  end
end
Casper7526 #2
Posted 12 February 2012 - 10:21 PM
You have to make sure all the functions exist. Off the top of my head with most of those kinds of things alot of the errors come from the bit functions.

Like in that example I see bit.rshift whereas we have bit.brshift
Espen #3
Posted 12 February 2012 - 10:35 PM
[…] i am trying to make a set of hashing and encryption libraries for this mod however i am not that skilled in lua, without a line number i do not see who i am getting this error […]
To see the line number of where the error occurs, do the following:
  1. Type "lua" to enter Lua interactive mode.
  2. Once in there type:
    require "org.luaj.vm2.lib.DebugLib"
  3. You'll get an error message which isn't important and can be ignored.
  4. To exit interactive mode type:
    exit()
From now on, whenever an error occurs, you'll get the line number as well.
When you restart Minecraft it's back to normal again. (Or does restarting the world suffice? Didn't try yet.)
Hope it helps you isolating the error, good luck! ;)/>/>
Casper7526 #4
Posted 13 February 2012 - 03:44 AM
Yeah use this while you can!
Espen #5
Posted 13 February 2012 - 10:51 AM
Yeah use this while you can!
Was that a hint that this probably won't work in 1.3 anymore? ;)/>/>
Casper7526 #6
Posted 13 February 2012 - 02:25 PM
Correct
bWGi #7
Posted 13 February 2012 - 02:46 PM
ok, so i am now getting an error from the bit api, line 40 saying it got nil instead of double, however since this is the check_int function i have no way of knowing what is wrong with my code. is there a way to print a stack trace so i can check?
md5
Spoiler

do
-- convert little-endian 32-bit int to a 4-char string
local function leIstr(i)
   local f=function (s) return string.char(bit.band(bit.brshift(i,s),255)) end
   return f(0)..f(8)..f(16)..f(24)
end
-- convert raw string to big-endian int
local function beInt(s)
  local v=0
  for i=1,string.len(s) do v=v*256+string.byte(s,i) end
  return v
end
-- convert raw string to little-endian int
local function leInt(s)
  local v=0
  for i=string.len(s),1,-1 do v=v*256+string.byte(s,i) end
  return v
end
-- cut up a string in little-endian ints of given size
local function leStrCuts(s,...)
  local o,r=1,{}
  for i=1,table.getn(arg) do
	table.insert(r,leInt(string.sub(s,o,o+arg[i]-1)))
	o=o+arg[i]
  end
  return r
end
ff=tonumber("ffffff",16)
t={}
for i=1,64,1 do
  t[i]=(4294967296*math.abs(math.sin(i)))
end
local a,b,c,d
local function f(x,y,z)
  return bit.bor(bit.band(x,y),bit.band(-x-1,z))
end
local function g(x,y,z)
  return bit.bor(bit.band(x,z),bit.band(y,-z-1))
end
local function h(x,y,z)
  return bit.bxor(x,bit.bxor(y,z))
end
local function i(x,y,z)
  return bit.bxor(y,but.bor(x,-z-1))
end
local function z(f,a,b,c,d,x,s,ac)
  a=bit.band(a+f(b,c,d)+x+ac,ff)
  return bit.bor(bit.lshift(bit.band(a,bit.brshift(ff,s)),s),bit.brshift(a,32-s))+b
end
local function pad(s)
  msgLen=string.len(s)
  local padLen=56-msgLen%64
  if msgLen%64>56 then padLen=padLen+64 end
  if padLen==0 then padLen=64 end
  s=s..string.char(128)..string.rep(string.char('0'),padLen-1)
  s=s..leIstr(8*msgLen)..leIstr(0)
  return s
end
local function initializeBuffers()
  a=tonumber("10234567",16)
  b=tonumber("89abcdef",16)
  c=tonumber("fedcba98",16)
  d=tonumber("76543210",16)
end
local function transform(a,b,c,d)
  local a,b,c,d=A,B,C,D
  a=z(f,a,b,c,d,X[ 0], 7,t[ 1])
  d=z(f,d,a,b,c,X[ 1],12,t[ 2])
  c=z(f,c,d,a,b,X[ 2],17,t[ 3])
  b=z(f,b,c,d,a,X[ 3],22,t[ 4])
  a=z(f,a,b,c,d,X[ 4], 7,t[ 5])
  d=z(f,d,a,b,c,X[ 5],12,t[ 6])
  c=z(f,c,d,a,b,X[ 6],17,t[ 7])
  b=z(f,b,c,d,a,X[ 7],22,t[ 8])
  a=z(f,a,b,c,d,X[ 8], 7,t[ 9])
  d=z(f,d,a,b,c,X[ 9],12,t[10])
  c=z(f,c,d,a,b,X[10],17,t[11])
  b=z(f,b,c,d,a,X[11],22,t[12])
  a=z(f,a,b,c,d,X[12], 7,t[13])
  d=z(f,d,a,b,c,X[13],12,t[14])
  c=z(f,c,d,a,b,X[14],17,t[15])
  b=z(f,b,c,d,a,X[15],22,t[16])
  a=z(g,a,b,c,d,X[ 1], 5,t[17])
  d=z(g,d,a,b,c,X[ 6], 9,t[18])
  c=z(g,c,d,a,b,X[11],14,t[19])
  b=z(g,b,c,d,a,X[ 0],20,t[20])
  a=z(g,a,b,c,d,X[ 5], 5,t[21])
  d=z(g,d,a,b,c,X[10], 9,t[22])
  c=z(g,c,d,a,b,X[15],14,t[23])
  b=z(g,b,c,d,a,X[ 4],20,t[24])
  a=z(g,a,b,c,d,X[ 9], 5,t[25])
  d=z(g,d,a,b,c,X[14], 9,t[26])
  c=z(g,c,d,a,b,X[ 3],14,t[27])
  b=z(g,b,c,d,a,X[ 8],20,t[28])
  a=z(g,a,b,c,d,X[13], 5,t[29])
  d=z(g,d,a,b,c,X[ 2], 9,t[30])
  c=z(g,c,d,a,b,X[ 7],14,t[31])
  b=z(g,b,c,d,a,X[12],20,t[32])
  a=z(h,a,b,c,d,X[ 5], 4,t[33])
  d=z(h,d,a,b,c,X[ 8],11,t[34])
  c=z(h,c,d,a,b,X[11],16,t[35])
  b=z(h,b,c,d,a,X[14],23,t[36])
  a=z(h,a,b,c,d,X[ 1], 4,t[37])
  d=z(h,d,a,b,c,X[ 4],11,t[38])
  c=z(h,c,d,a,b,X[ 7],16,t[39])
  b=z(h,b,c,d,a,X[10],23,t[40])
  a=z(h,a,b,c,d,X[13], 4,t[41])
  d=z(h,d,a,b,c,X[ 0],11,t[42])
  c=z(h,c,d,a,b,X[ 3],16,t[43])
  b=z(h,b,c,d,a,X[ 6],23,t[44])
  a=z(h,a,b,c,d,X[ 9], 4,t[45])
  d=z(h,d,a,b,c,X[12],11,t[46])
  c=z(h,c,d,a,b,X[15],16,t[47])
  b=z(h,b,c,d,a,X[ 2],23,t[48])
  a=z(i,a,b,c,d,X[ 0], 6,t[49])
  d=z(i,d,a,b,c,X[ 7],10,t[50])
  c=z(i,c,d,a,b,X[14],15,t[51])
  b=z(i,b,c,d,a,X[ 5],21,t[52])
  a=z(i,a,b,c,d,X[12], 6,t[53])
  d=z(i,d,a,b,c,X[ 3],10,t[54])
  c=z(i,c,d,a,b,X[10],15,t[55])
  b=z(i,b,c,d,a,X[ 1],21,t[56])
  a=z(i,a,b,c,d,X[ 8], 6,t[57])
  d=z(i,d,a,b,c,X[15],10,t[58])
  c=z(i,c,d,a,b,X[ 6],15,t[59])
  b=z(i,b,c,d,a,X[13],21,t[60])
  a=z(i,a,b,c,d,X[ 4], 6,t[61])
  d=z(i,d,a,b,c,X[11],10,t[62])
  c=z(i,c,d,a,b,X[ 2],15,t[63])
  b=z(i,b,c,d,a,X[ 9],21,t[64])
  return A+a,B+b,C+c,D+d
end
local function calc(s)
  pad(s)
  initializeBuffers()
  for i=0,string.len(s),64 do
   X=leStrCuts(string.sub(s,i,i+63),4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4)
   X[0]=table.remove(X,1) -- zero based!
  end
  abcd=transform(a,b,c,d)
  local swap=function (w) return beInt(leIstr(w)) end
  return format("%08x%08x%08x%08x",swap(a),swap(;)/>/>,swap(c),swap(d))
end
md5_calc=calc
end
md5_calc(5)
rockymc #8
Posted 13 February 2012 - 03:29 PM
What's a md5?
bWGi #9
Posted 13 February 2012 - 03:32 PM
What's a md5?
md5 is a hashing algorithm commonly used for file integrity verification and storage of passwords, it stands for "Message Degest 5"
bWGi #10
Posted 14 February 2012 - 06:20 PM
I fixed the previous error and now am getting an error saying "attempt to call nil" on line 162 which is my test call to calc(5) but in the line above i can get the address of the calc function. attached is the source
Spoiler
do
-- convert little-endian 32-bit int to a 4-char string
local function leIstr(i)
   local f=function (s) return string.char(bit.band(bit.brshift(i,s),255)) end
   return f(0)..f(8)..f(16)..f(24)
end
-- convert raw string to big-endian int
local function beInt(s)
  local v=0
  for i=1,string.len(s) do v=v*256+string.byte(s,i) end
  return v
end
-- convert raw string to little-endian int
local function leInt(s)
  local v=0
  for i=string.len(s),1,-1 do v=v*256+string.byte(s,i) end
  return v
end
-- cut up a string in little-endian ints of given size
local function leStrCuts(s,...)
  local o,r=1,{}
  for i=1,table.getn(arg) do
	table.insert(r,leInt(string.sub(s,o,o+arg[i]-1)))
	o=o+arg[i]
  end
  return r
end
ff=tonumber("ffffff",16)
consts={}
string.gsub([[ d76aa478 e8c7b756 242070db c1bdceee
f57c0faf 4787c62a a8304613 fd469501
698098d8 8b44f7af ffff5bb1 895cd7be
6b901122 fd987193 a679438e 49b40821
f61e2562 c040b340 265e5a51 e9b6c7aa
d62f105d 02441453 d8a1e681 e7d3fbc8
21e1cde6 c33707d6 f4d50d87 455a14ed
a9e3e905 fcefa3f8 676f02d9 8d2a4c8a
fffa3942 8771f681 6d9d6122 fde5380c
a4beea44 4bdecfa9 f6bb4b60 bebfbc70
289b7ec6 eaa127fa d4ef3085 04881d05
d9d4d039 e6db99e5 1fa27cf8 c4ac5665
f4292244 432aff97 ab9423a7 fc93a039
655b59c3 8f0ccc92 ffeff47d 85845dd1
6fa87e4f fe2ce6e0 a3014314 4e0811a1
f7537e82 bd3af235 2ad7d2bb eb86d391
67452301 efcdab89 98badcfe 10325476 ]],
  '(%w+)', function (s) table.insert(consts,tonumber(s,16)) end)
local function f(x,y,z)
  return bit.bor(bit.band(x,y),bit.band(-x-1,z))
end
local function g(x,y,z)
  return bit.bor(bit.band(x,z),bit.band(y,-z-1))
end
local function h(x,y,z)
  return bit.bxor(x,bit.bxor(y,z))
end
local function i(x,y,z)
  return bit.bxor(y,bit.bor(x,-z-1))
end
local function z(f,a,b,c,d,x,s,ac)
  a=bit.band(a+f(b,c,d)+x+ac,ff)
  return bit.bor(bit.blshift(bit.band(a,bit.brshift(ff,s)),s),bit.brshift(a,32-s))+b
end
local function pad(s)
  msgLen=string.len(s)
  local padLen=56-msgLen%64
  if msgLen%64>56 then padLen=padLen+64 end
  if padLen==0 then padLen=64 end
  s=s..string.char(128)..string.rep(string.char('0'),padLen-1)
  s=s..leIstr(8*msgLen)..leIstr(0)
  return s
end
local function transform(A,B,C,D)
  local a,b,c,d=A,B,C,D
  local t=consts

  a=z(f,a,b,c,d,X[ 0], 7,t[ 1])
  d=z(f,d,a,b,c,X[ 1],12,t[ 2])
  c=z(f,c,d,a,b,X[ 2],17,t[ 3])
  b=z(f,b,c,d,a,X[ 3],22,t[ 4])
  a=z(f,a,b,c,d,X[ 4], 7,t[ 5])
  d=z(f,d,a,b,c,X[ 5],12,t[ 6])
  c=z(f,c,d,a,b,X[ 6],17,t[ 7])
  b=z(f,b,c,d,a,X[ 7],22,t[ 8])
  a=z(f,a,b,c,d,X[ 8], 7,t[ 9])
  d=z(f,d,a,b,c,X[ 9],12,t[10])
  c=z(f,c,d,a,b,X[10],17,t[11])
  b=z(f,b,c,d,a,X[11],22,t[12])
  a=z(f,a,b,c,d,X[12], 7,t[13])
  d=z(f,d,a,b,c,X[13],12,t[14])
  c=z(f,c,d,a,b,X[14],17,t[15])
  b=z(f,b,c,d,a,X[15],22,t[16])

  a=z(g,a,b,c,d,X[ 1], 5,t[17])
  d=z(g,d,a,b,c,X[ 6], 9,t[18])
  c=z(g,c,d,a,b,X[11],14,t[19])
  b=z(g,b,c,d,a,X[ 0],20,t[20])
  a=z(g,a,b,c,d,X[ 5], 5,t[21])
  d=z(g,d,a,b,c,X[10], 9,t[22])
  c=z(g,c,d,a,b,X[15],14,t[23])
  b=z(g,b,c,d,a,X[ 4],20,t[24])
  a=z(g,a,b,c,d,X[ 9], 5,t[25])
  d=z(g,d,a,b,c,X[14], 9,t[26])
  c=z(g,c,d,a,b,X[ 3],14,t[27])
  b=z(g,b,c,d,a,X[ 8],20,t[28])
  a=z(g,a,b,c,d,X[13], 5,t[29])
  d=z(g,d,a,b,c,X[ 2], 9,t[30])
  c=z(g,c,d,a,b,X[ 7],14,t[31])
  b=z(g,b,c,d,a,X[12],20,t[32])

  a=z(h,a,b,c,d,X[ 5], 4,t[33])
  d=z(h,d,a,b,c,X[ 8],11,t[34])
  c=z(h,c,d,a,b,X[11],16,t[35])
  b=z(h,b,c,d,a,X[14],23,t[36])
  a=z(h,a,b,c,d,X[ 1], 4,t[37])
  d=z(h,d,a,b,c,X[ 4],11,t[38])
  c=z(h,c,d,a,b,X[ 7],16,t[39])
  b=z(h,b,c,d,a,X[10],23,t[40])
  a=z(h,a,b,c,d,X[13], 4,t[41])
  d=z(h,d,a,b,c,X[ 0],11,t[42])
  c=z(h,c,d,a,b,X[ 3],16,t[43])
  b=z(h,b,c,d,a,X[ 6],23,t[44])
  a=z(h,a,b,c,d,X[ 9], 4,t[45])
  d=z(h,d,a,b,c,X[12],11,t[46])
  c=z(h,c,d,a,b,X[15],16,t[47])
  b=z(h,b,c,d,a,X[ 2],23,t[48])

  a=z(i,a,b,c,d,X[ 0], 6,t[49])
  d=z(i,d,a,b,c,X[ 7],10,t[50])
  c=z(i,c,d,a,b,X[14],15,t[51])
  b=z(i,b,c,d,a,X[ 5],21,t[52])
  a=z(i,a,b,c,d,X[12], 6,t[53])
  d=z(i,d,a,b,c,X[ 3],10,t[54])
  c=z(i,c,d,a,b,X[10],15,t[55])
  b=z(i,b,c,d,a,X[ 1],21,t[56])
  a=z(i,a,b,c,d,X[ 8], 6,t[57])
  d=z(i,d,a,b,c,X[15],10,t[58])
  c=z(i,c,d,a,b,X[ 6],15,t[59])
  b=z(i,b,c,d,a,X[13],21,t[60])
  a=z(i,a,b,c,d,X[ 4], 6,t[61])
  d=z(i,d,a,b,c,X[11],10,t[62])
  c=z(i,c,d,a,b,X[ 2],15,t[63])
  b=z(i,b,c,d,a,X[ 9],21,t[64])
  return A+a,B+b,C+c,D+d
end
local function lcalc(s)
  pad(s)
  local t=consts
  local a,b,c,d=t[65],t[66],t[67],t[68]
  for i=0,string.len(s),64 do
   X=leStrCuts(string.sub(s,i,i+63),4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4)
   X[0]=table.remove(X,1) -- zero based!
  end
  abcd=transform(a,b,c,d)
  local swap=function (w) return beInt(leIstr(w)) end
  return format("%08x%08x%08x%08x",swap(a),swap(:(/>/>,swap(c),swap(d))
end
calc=lcalc
end
print(calc)
print(calc(5))
Espen #11
Posted 14 February 2012 - 06:48 PM
I fixed the previous error and now am getting an error saying "attempt to call nil" on line 162 which is my test call to calc(5) but in the line above i can get the address of the calc function. attached is the source
- snip -
First of all: In the code you posted, the return of lcalc has a swap(B) where , I think, it should be swap(b).
The answer to your original problem:
calc(5) returns nil, because the return statement of lcalc makes use of an unknown function: format
I think you meant string.format and must've just mistyped it. ^^

So the proper line should be:
return string.format("%08x%08x%08x%08x",swap(a),swap(b),swap(c),swap(d))