添加错误代码
This commit is contained in:
84
python/file/prints.lua
Normal file
84
python/file/prints.lua
Normal file
@@ -0,0 +1,84 @@
|
||||
|
||||
|
||||
|
||||
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(
|
||||
string.byte( str_table,((byte>>12)&0xf)+1),
|
||||
string.byte( str_table,((byte>>8)&0xf)+1),
|
||||
string.byte( str_table,((byte>>4)&0xf)+1),
|
||||
string.byte(str_table,(byte&0xf)+1))
|
||||
else
|
||||
str_ret=string.char(string.byte(str_table,(byte%256)//16+1),string.byte(str_table,(byte%256)%16+1))
|
||||
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
|
Reference in New Issue
Block a user