我的lua代码编译不过去,有没有大神帮我指点指点,代码和编译结果如下

Jason_gao999 2020-04-20 04:10:03
--------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
>
...全文
325 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

3,846

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 无线
社区管理员
  • 无线
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧