2023-06-28 18:08:38 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-06-29 18:12:56 +08:00
|
|
|
|
-- 2023.6.29
|
|
|
|
|
-- 使用算数运算代替位运算
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-06-28 18:08:38 +08:00
|
|
|
|
module = {}
|
|
|
|
|
|
|
|
|
|
function module:print_t ( t )
|
|
|
|
|
local print_r_cache={}
|
|
|
|
|
local function sub_print_r(t,indent)
|
|
|
|
|
if (print_r_cache[tostring(t)]) then
|
|
|
|
|
print(indent.."*"..tostring(t))
|
|
|
|
|
else
|
|
|
|
|
print_r_cache[tostring(t)]=true
|
|
|
|
|
if (type(t)=="table") then
|
|
|
|
|
for pos,val in pairs(t) do
|
|
|
|
|
if (type(val)=="table") then
|
|
|
|
|
print(indent.."["..pos.."] => "..tostring(t).." {")
|
|
|
|
|
sub_print_r(val,indent..string.rep(" ",string.len(pos)+8))
|
|
|
|
|
print(indent..string.rep(" ",string.len(pos)+6).."}")
|
|
|
|
|
elseif (type(val)=="string") then
|
|
|
|
|
print(indent.."["..pos..'] => "'..val..'"')
|
|
|
|
|
else
|
|
|
|
|
print(indent.."["..pos.."] => "..tostring(val))
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
print(indent..tostring(t))
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if (type(t)=="table") then
|
|
|
|
|
print(tostring(t).." {")
|
|
|
|
|
sub_print_r(t," ")
|
|
|
|
|
print("}")
|
|
|
|
|
else
|
|
|
|
|
sub_print_r(t," ")
|
|
|
|
|
end
|
|
|
|
|
print()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function byte_to_hex(byte,size)
|
|
|
|
|
local str_table="0123456789ABCDEF"
|
|
|
|
|
local str_ret=""
|
|
|
|
|
if(size==2) then
|
|
|
|
|
str_ret=string.char(
|
2023-06-29 18:12:56 +08:00
|
|
|
|
-- 右移12位,//4096
|
|
|
|
|
string.byte( str_table,(math.floor(byte/4096)%16)+1),
|
|
|
|
|
string.byte( str_table,(math.floor(byte/256)%16)+1),
|
|
|
|
|
string.byte( str_table,(math.floor(byte/16)%16)+1),
|
|
|
|
|
string.byte(str_table,(byte%16)+1))
|
2023-06-28 18:08:38 +08:00
|
|
|
|
else
|
2023-06-29 18:12:56 +08:00
|
|
|
|
str_ret=string.char(string.byte(str_table,math.floor((byte%256)/16)+1),string.byte(str_table,(byte%256)%16+1))
|
2023-06-28 18:08:38 +08:00
|
|
|
|
end
|
|
|
|
|
return str_ret
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- function byte_to_num(byte)
|
|
|
|
|
-- local str_ret=""
|
|
|
|
|
-- while true do
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- 打印数组
|
|
|
|
|
function module:print_a ( a,size ,fmt)
|
|
|
|
|
local str=""
|
|
|
|
|
if(a==nil) then return end
|
|
|
|
|
if(size==nil) then size=1 end
|
|
|
|
|
for pos,val in pairs(a) do
|
|
|
|
|
str=str..byte_to_hex(val,size)..", "
|
|
|
|
|
end
|
|
|
|
|
print(str)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function module:__tostring()
|
|
|
|
|
return "print table package"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return module
|