control4 / drivers-common-public Goto Github PK
View Code? Open in Web Editor NEWControl4-developed libraries to provide specific functionality on top of that built-in to Driverworks.
License: Other
Control4-developed libraries to provide specific functionality on top of that built-in to Driverworks.
License: Other
I can't find an example of using the drivers-common-public
libraries anywhere in github.com/control4.
Maybe I'm just not looking in the right place?
Help.
I got annoyed by the confusing/sloppy output from dbg()
and decided to do something about it.
_indentLevel = 0
function debugOut(...)
if (_indentLevel > 10) then
_indentLevel = _indentLevel - 1;
return;
end
_indentLevel = _indentLevel + 1
if (DEBUGPRINT) then
if (select("#", ...) > 0) then
local args = {}
local hasTable = false
local isRecord = false
for argnum, argval in ipairs({...}) do
if (type(argval) == 'table') then
hasTable = true
if (argval[1] == nil) then
table.insert(args, '{' .. argnum - 1 .. '}')
else
table.insert(args, '[' .. argnum - 1 .. ']')
end
else
table.insert(args, argval)
end
end
if (hasTable) then
debugOut((isRecord and '' or '') .. args[1] .. '', unpack(args, 2))
for argnum, val in ipairs({...}) do
if (type(val) == 'table') then
if (val[1] == nil) then
local newVal = {}
for k, v in pairs(val) do
debugOut(string.rep(' ', _indentLevel * 2) .. '{' .. argnum - 1 .. '}', k .. " =", v)
end
else
debugOut(string.rep(' ', _indentLevel * 2) .. '' .. args[argnum] .. '', unpack(val))
end
end
end
else
print(os.date('%x %X: '), unpack(args))
C4:DebugLog(unpack(args))
end
else
print(os.date('%x %X: '))
end
end
_indentLevel = _indentLevel - 1
end
My goal was to ensure
a) I never saw table:3048039
; instead seeing the contents of the table, no matter how deeply nested
b) Records were pretty
c) To learn Lua better
My test cases:
debugOut("big table", {99, {"r1", "r2", "r3"}}, {100, {"s1", "s2", "s3"}})
t = {HELLO = "hello", WORLD = "world"}
t2 = { FOO = "foo", BAR = { "b", "a", "r" }}
t3 = { FOOD = "food", BARD = { b = "b", a ="a", r = "r", d = "d" }}
debugOut("--------- Records", "string", t, "third", t2, t3, { 7, 8} )
debugOut("--------- Tables", "string", {7, 8}, {"a", "b", {"x", "y"}} )
t = { DATA = "bar", bar = { 1, 2, 3 }}
ExecuteCommand("========= Command", t )
08/18/21 01:51:13: big table [1] [2]
08/18/21 01:51:13: [1] 99 [2]
08/18/21 01:51:13: [2] r1 r2 r3
08/18/21 01:51:13: [2] 100 [2]
08/18/21 01:51:13: [2] s1 s2 s3
08/18/21 01:51:13: --------- Records string {2} third {4} {5} [6]
08/18/21 01:51:13: {2} WORLD = world
08/18/21 01:51:13: {2} HELLO = hello
08/18/21 01:51:13: {4} BAR = [2]
08/18/21 01:51:13: [2] b a r
08/18/21 01:51:13: {4} FOO = foo
08/18/21 01:51:13: {5} FOOD = food
08/18/21 01:51:13: {5} BARD = {2}
08/18/21 01:51:13: {2} a = a
08/18/21 01:51:13: {2} d = d
08/18/21 01:51:13: {2} r = r
08/18/21 01:51:13: {2} b = b
08/18/21 01:51:13: [6] 7 8
08/18/21 01:51:13: --------- Tables string [2] [3]
08/18/21 01:51:13: [2] 7 8
08/18/21 01:51:13: [3] a b [3]
08/18/21 01:51:13: [3] x y
08/18/21 01:51:13: --- ExecuteCommand ========= Command {2}
08/18/21 01:51:13: {2} DATA = bar
08/18/21 01:51:13: {2} bar = [2]
08/18/21 01:51:13: [2] 1 2 3
08/18/21 01:51:13: SendCommand ========= Command
08/18/21 01:51:13: send >>> ========= Command \r\n
Hope someone finds this useful.
I'm sure this code is crap and there's far better ways of doing this.... I'd love feedback.
Cheers.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.