Created
November 4, 2016 08:36
-
-
Save Pillar1989/5e9ca72fcb080c8d804f4e61161c164a to your computer and use it in GitHub Desktop.
Lua打印table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function PrintTable( tbl , level, filteDefault) | |
local msg = "" | |
filteDefault = filteDefault or true | |
level = level or 1 | |
local indent_str = "" | |
for i = 1, level do | |
indent_str = indent_str.." " | |
end | |
print(indent_str .. "{") | |
for k,v in pairs(tbl) do | |
if filteDefault then | |
if k ~= "_class_type" and k ~= "DeleteMe" then | |
local item_str = string.format("%s%s = %s", indent_str .. " ",tostring(k), tostring(v)) | |
print(item_str) | |
if type(v) == "table" then | |
PrintTable(v, level + 1) | |
end | |
end | |
else | |
local item_str = string.format("%s%s = %s", indent_str .. " ",tostring(k), tostring(v)) | |
print(item_str) | |
if type(v) == "table" then | |
PrintTable(v, level + 1) | |
end | |
end | |
end | |
print(indent_str .. "}") | |
end | |
function system_filesystems(opts) | |
local res = {}; | |
local lines = {}; | |
res["channel"] = lines; | |
local stdout = juci.shell("iwpriv ra0 get_site_survey | tail -n+3"); | |
for line in stdout:gmatch("[^\r\n]+") do | |
local channel,ssid,bssid,security,siganl,mode,extch,nt,wps,dpid= line:match("([^%s]*)%s*([^%s]*)%s*([^%s]*)%s*([^%s]*)%s*([^%s]*)%s*([^%s]*)%s*([^%s]*)%s*([^%s]*)%s*"); | |
local obj = { | |
["channel"] = channel, | |
["ssid"] = ssid, | |
["bssid"] = bssid, | |
["security"] = security, | |
["siganl"] = siganl, | |
["mode"] = mode, | |
["extch"] = extch, | |
["nt"] = nt, | |
["wps"] = wps, | |
["dpid"] = dpid, | |
}; | |
table.insert(lines, obj); | |
end | |
return res; | |
end | |
PrintTable(system_filesystems()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment