In this video I just go over how to explore objects in CE using a object print function.
Code: Select all
---- Inspection Helpers
---- Object/Table Print
function oprint(...)
local function write(...)
print(...)
end
local function _oprint(obj, indent)
if not indent then indent = 0 end
local t = type(obj)
local start = false
local df = function(o) return o end
if t == 'userdata' then df = getmetatable end
if t == 'table' or t == 'userdata' then
if indent == 0 then
write('--->> : '..t..' : {')
indent = 1
start = true
end
if t == 'table' then
local mt = getmetatable(obj)
if mt then
local padd = string.rep('\t', indent + 1)
write(padd..'metatable : table : {')
_oprint(mt, indent + 2)
write(padd..'}')
end
end
for k, v in pairs(df(obj)) do
if type(k) == 'number'
or (type(k) == 'string' and k:sub(1, 1) ~= '_') then
local padding = string.rep('\t', indent)
t = type(v)
if type(k) == 'number' then
k = tostring(k)
else
k = '"'..k..'"'
end
local str = k..' : '..t..' : '
if t == 'table' or t == 'userdata' then
write(padding..str..'{')
_oprint(v, indent + 1)
write(padding..'}')
else
if t == 'string' then
write(padding..str..'"'..v..'"')
else
write(padding..str..tostring(v))
end
end
end
end
if start then
write('}')
end
else
write('--->> : '..t..' : '..tostring(obj))
end
end
if ... then
local args = {...}
for i = 1, #args do
_oprint(args[i])
end
else -- print nil object
_oprint(...)
end
end
registerLuaFunctionHighlight('oprint')
---- Windows Control Print
function wcprint(...)
local function write(...)
print(...)
end
local function _wcprint(winControl, indent)
indent = indent or 0
if type(winControl) == 'userdata' then
local formatting = string.rep('\t', indent)
write(formatting..winControl.Name)
if winControl.ControlCount and winControl.ControlCount > 1 then
for i = 0, winControl.ControlCount - 1 do
if type(winControl.Control[i]) == 'userdata' then
write(formatting..winControl.Control[i].Name)
_wcprint(winControl.Control[i], indent + 1)
end
end
end
end
end
if ... then
local t = {...}
for i, v in ipairs(t) do
_wcprint(v)
end
else
write(tostring(...))
end
end
registerLuaFunctionHighlight('wcprint')