GithubHelp home page GithubHelp logo

control4 / drivers-common-public Goto Github PK

View Code? Open in Web Editor NEW
5.0 5.0 10.0 163 KB

Control4-developed libraries to provide specific functionality on top of that built-in to Driverworks.

License: Other

Lua 100.00%

drivers-common-public's People

Contributors

rericksonc4 avatar wwalshc4 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

drivers-common-public's Issues

No examples?

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.

Refined version of dbg()

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.