我的lua代码编译不过去,有没有大神帮我指点指点,代码和编译结果如下
--------base64----------
function str2hex(str)
if (type(str)~="string") then
return nil,"str2hex invalid input type"
end
if(str:len()%2~=0) then
return nil,"str2hex invalid input lenth"
end
local index=1
local ret=""
for index=1,str:len(),2 do
ret=ret..string.char(tonumber(str:sub(index,index+1),16))
end
return ret
end
-----编译结果------
mqtt.lua:56: bad argument #1 to 'char' (number expected, got nil)
stack traceback:
[C]: in function 'char'
mqtt.lua:56: in function 'str2hex'
mqtt.lua:65: in main chunk
[C]: in function 'dofile'
stdin:1: in main chunk
>