Results 1 to 10 of 10

Thread: Adding an event listener to a variable to track changes

  1. #1
    Join Date
    Jun 2012
    Location
    Wabash, IN
    Posts
    99

    Default Adding an event listener to a variable to track changes

    Is there any way to attach an event listener to a variable to track changes to it's value? It looks to me like the event handler in Girder is meant strictly for listening to Girder events, please correct me if I'm wrong.

    Thanks,
    Casey

  2. #2
    Join Date
    Jan 1998
    Location
    Jupiter, FL
    Posts
    13,550

    Default

    There are some tricks you can do that do this but they have side effects. What are you trying to achieve?

    The nitty gritty can be found under http://www.lua.org/pil/13.4.2.html
    Ron
    No support through PM

  3. #3
    Join Date
    Jun 2012
    Location
    Wabash, IN
    Posts
    99

    Default

    Hi Ron,
    Since I store the status of all my devices in a table I thought it would be a convenient way of updating clients on status changes. As I have it now, each time something sets a value I also have to add another line to transmit that change to the client and it's just creating messy code. If event listeners aren't a good way to go I think I might try another approach, something like properties in vb.net.

    example:
    Code:
    function SetReceiverZoneMainVolume(value)
         HomeControl.Receiver.ZoneMainVolume = value
         TransmitStatus("ZoneMainVolume:" .. value)
    end
    This will keep everything in one place where it can be easier to modify....I think. What do you think?

    Thanks,
    Casey
    Last edited by caseyp; July 28th, 2014 at 08:35 AM.

  4. #4
    Join Date
    Jan 1998
    Location
    Jupiter, FL
    Posts
    13,550

    Default

    Yep that is a very good way to go. Keep the variable 'private' and only use that function to modify the value. If you could see the Girder source code you'd find that pattern all over.
    Ron
    No support through PM

  5. #5
    Join Date
    Jun 2012
    Location
    Wabash, IN
    Posts
    99

    Default

    I'm going to put all this in a Lua file Ron and I'd like to keep it in a folder in my Girder web directory so that all my custom code is in one place and the Girder directory is virtually untouched. Is there an easy way to "include" or "require" this file in another directory or is this going to require a full path?

    Thanks,
    Casey

    P.S. My web directory is NOT in the standard Girder location. It's in a Data partition on my hard drive rather than a program partition.
    Last edited by caseyp; July 28th, 2014 at 08:40 AM.

  6. #6
    Join Date
    Jan 1998
    Location
    Jupiter, FL
    Posts
    13,550

    Default

    modify the package.path to your directory like this:

    Imagine your path is: C:\users\caseyp\girderlua
    Code:
    package.path = package.path .. ";C:/users/caseyp/girderlua/?.lua;C:/users/caseyp/girderlua/?/init.lua"
    Ron
    No support through PM

  7. #7
    Join Date
    Jan 1998
    Location
    Jupiter, FL
    Posts
    13,550

    Default

    place that code in the rootstartup.lua file in the girder directory, that is the earliest you can hit lua code.
    Last edited by Ron; July 28th, 2014 at 10:10 AM. Reason: I am refering to the package.path post above...
    Ron
    No support through PM

  8. #8
    Join Date
    Jun 2012
    Location
    Wabash, IN
    Posts
    99

    Default

    I actually just found a way to add a package directory Ron. I'm creating an initialization script action in Girder which will load the external Lua files. The top line of this script has the following line...

    Code:
    package.path = package.path .. ";E:\\ServerFolders\\My Documents\\Data\\Web Sites\\HomeControlWebsite\\lua\\HomeControl\\?.lua;"
    Now I can do a require just like with the Girder Lua files... (ex. StatusTable.lua)

    Code:
    require('StatusTable')
    My hope is to move most of my Lua code to separate files to clean up my Girder mess. It gets a little out of control in a hurry.

    Thanks,
    Casey

  9. #9
    Join Date
    Jan 1998
    Location
    Jupiter, FL
    Posts
    13,550

    Default

    I guess you missed my post 2 up
    Ron
    No support through PM

  10. #10
    Join Date
    Jun 2012
    Location
    Wabash, IN
    Posts
    99

    Default

    I sure did Ron

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •