Page 1 of 3 123 LastLast
Results 1 to 10 of 27

Thread: How do I get a boolen from the registry or convert a string "false" to boolean false?

  1. #1
    Join Date
    Jul 2001
    Location
    Risør - Norway
    Posts
    5,477

    Default How do I get a boolen from the registry or convert a string "false" to boolean false?

    I need to fill a table from the system registry at startup, and for that I'm using this:

    Code:
    LydogBilde.Forsterkere = {
    [1] = win.CreateRegistry('HKCU', 'Software\\Automatisering\\Lydogbilde\\Forsterkere', 0):Read('1'),
    [2] = win.CreateRegistry('HKCU', 'Software\\Automatisering\\Lydogbilde\\Forsterkere', 0):Read('2'),
    }
    Of course there are many more lines, but that's the syntax anyway. The problem comes because it's getting a string. I can of course do another "if then" for each table entry in this startup script to make it into a boolean (which I need for set of true/false stuff to check if amps are on), but it's both untidy and complicating, and I'm trying to make everything as easy to understand as possible now since I'm planning to sell the house as a full on smarthouse next yea. If I try to write as a boolean the registry gets 0/1 values, and that comes back in string 0/1 in the scipt. Isn't there a nice, little command to fix this? I tried the opposite of tostring, like this:

    Code:
    toboolean(win.CreateRegistry('HKCU', 'Software\\Automatisering\\Lydogbilde\\Forsterkere', 0):Read('1'))
    That did of course not work. Any tips on how I do this?

    (It's really for Girder 5, but I figured it should be pretty much the same stuff for G6, and this forum is a bit more active...)
    Last edited by Mastiff; February 14th, 2015 at 07:57 AM.
    Tor - managing director of the Cinema Inferno home theater and multi-zone sound system with Girder running the show in the back, NetRemote as the GUI and Media Center 17, PowerDVD and ZoomPlayer as playback software
    Hobsyssel mastiffs: http://www.hobsyssel.no

  2. #2
    Join Date
    Jul 2001
    Location
    Risør - Norway
    Posts
    5,477

    Default

    To elaborate (since I have a few reads but no answers...), this is the closest I have gotten so far:

    Code:
    LydogBilde.Forsterkere [1] = win.CreateRegistry('HKCU', 'Software\\Automatisering\\Lydogbilde\\Forsterkere', 0):Read(1)
    if LydogBilde.Forsterkere [1] == "true" then LydogBilde.Forsterkere [1] = true else LydogBilde.Forsterkere [1] = false end
    it is only two lines per entry in the table, but it's ugly as hell.

    At the same time is it possible to get the table out of the registry in one line for the full table, or do I have to do it like this, with one line per entry?
    Tor - managing director of the Cinema Inferno home theater and multi-zone sound system with Girder running the show in the back, NetRemote as the GUI and Media Center 17, PowerDVD and ZoomPlayer as playback software
    Hobsyssel mastiffs: http://www.hobsyssel.no

  3. #3
    Join Date
    Jul 2001
    Location
    Risør - Norway
    Posts
    5,477

    Default

    Can nobody help me out with this? Please? Especially the last part, about populating a table from the registry. I know how to interact with the registry, I would just like to populate a nested table from a registry key that's formatted the same way (with subkeys from 1 to whatever, and each subkey has DWORDS named the correct way, with it's values being the nested part).
    Tor - managing director of the Cinema Inferno home theater and multi-zone sound system with Girder running the show in the back, NetRemote as the GUI and Media Center 17, PowerDVD and ZoomPlayer as playback software
    Hobsyssel mastiffs: http://www.hobsyssel.no

  4. #4
    Join Date
    May 2004
    Location
    Dallas, TX
    Posts
    1,125

    Default

    You can try something like this

    Code:
    LydogBilde.Forsterkere = {
    [1] = (win.CreateRegistry('HKCU', 'Software\\Automatisering\\Lydogbilde\\Forsterkere', 0):Read('1') == "true" and true) or false,
    [2] = (win.CreateRegistry('HKCU', 'Software\\Automatisering\\Lydogbilde\\Forsterkere', 0):Read('2') == "true" and true) or false,
    }
    I think I have all the right bits in the right places. I cannot test as I do not have those strings in my registry.
    Rick

    Girder 6.0 - Elk M1 Gold - JRMC 11.1 w/ M-Audio Delta 410 - NetRemote - BlueIris DVR
    Girder 6 Plugins - Elk M1/EZ8, Pushover Connector and more on the way.


    Visit My Showcase

  5. #5
    Join Date
    Jul 2001
    Location
    Risør - Norway
    Posts
    5,477

    Default

    Yep, that works, thanks a lot! Is it possible to pick a nested table out from the registry in the same way? The nested table would be built on this registry setup:

    Code:
    Windows Registry Editor Version 5.00
    
    [HKEY_CURRENT_USER\Software\Automatisering\Termostat]
    "1"="22"
    "2"="16"
    "3"="5"
    "4"="-"
    "0"=""
    
    [HKEY_CURRENT_USER\Software\Automatisering\Termostat\1]
    "1"="22"
    "2"="16"
    "3"="5"
    "4"="-"
    "0"=""
    
    [HKEY_CURRENT_USER\Software\Automatisering\Termostat\10]
    "1"="20"
    "2"="16"
    "3"="5"
    "4"="-"
    "0"=""
    
    [HKEY_CURRENT_USER\Software\Automatisering\Termostat\11]
    "1"="20"
    "2"="16"
    "3"="5"
    "4"="-"
    "0"=""
    
    [HKEY_CURRENT_USER\Software\Automatisering\Termostat\12]
    "1"="20"
    "2"="16"
    "3"="5"
    "4"="-"
    "0"=""
    
    [HKEY_CURRENT_USER\Software\Automatisering\Termostat\13]
    "1"="20"
    "2"="16"
    "3"="5"
    "4"="-"
    "0"=""
    
    [HKEY_CURRENT_USER\Software\Automatisering\Termostat\2]
    "1"="20"
    "2"="16"
    "3"="5"
    "4"="-"
    "0"=""
    
    [HKEY_CURRENT_USER\Software\Automatisering\Termostat\3]
    "1"="20"
    "2"="16"
    "3"="5"
    "4"="-"
    "0"=""
    
    [HKEY_CURRENT_USER\Software\Automatisering\Termostat\4]
    "1"="21"
    "2"="16"
    "3"="5"
    "4"="-"
    "0"=""
    
    [HKEY_CURRENT_USER\Software\Automatisering\Termostat\5]
    "1"="10"
    "2"="16"
    "3"="5"
    "4"="20"
    "0"=""
    
    [HKEY_CURRENT_USER\Software\Automatisering\Termostat\6]
    "1"="23"
    "2"="16"
    "3"="5"
    "4"="-"
    "0"=""
    
    [HKEY_CURRENT_USER\Software\Automatisering\Termostat\7]
    "1"="20"
    "2"="16"
    "3"="5"
    "4"="-"
    "0"=""
    
    [HKEY_CURRENT_USER\Software\Automatisering\Termostat\8]
    "1"="20"
    "2"="16"
    "3"="5"
    "4"="-"
    "0"=""
    
    [HKEY_CURRENT_USER\Software\Automatisering\Termostat\9]
    "1"="20"
    "2"="16"
    "3"="5"
    "4"="-"
    "0"=""
    So the "outer" table is the room number, and the inner table is the different temperatures. The actual nested table looks like this:

    Code:
    Temperaturstyring.Nettside.SettTemperatur ={
    [1] = {[1] = "22", [2] = "16", [3] = "5", [4] = "-", [0] = ""},
    [2] = {[1] = "20", [2] = "16", [3] = "5", [4] = "-", [0] = ""},
    [3] = {[1] = "20", [2] = "16", [3] = "5", [4] = "-", [0] = ""},
    [4] = {[1] = "21", [2] = "16", [3] = "5", [4] = "-", [0] = ""},
    [5] = {[1] = "10", [2] = "16", [3] = "5", [4] = "20", [0] = ""},
    [6] = {[1] = "23", [2] = "16", [3] = "5", [4] = "-", [0] = ""},
    [7] = {[1] = "20", [2] = "16", [3] = "5", [4] = "-", [0] = ""},
    [8] = {[1] = "20", [2] = "16", [3] = "5", [4] = "-", [0] = ""},
    [9] = {[1] = "20", [2] = "16", [3] = "5", [4] = "-", [0] = ""},
    [10] = {[1] = "20", [2] = "16", [3] = "5", [4] = "-", [0] = ""},
    [11] = {[1] = "20", [2] = "16", [3] = "5", [4] = "-", [0] = ""},
    [12] = {[1] = "20", [2] = "16", [3] = "5", [4] = "-", [0] = ""},
    [13] = {[1] = "20", [2] = "16", [3] = "5", [4] = "-", [0] = ""}
    }
    I can put the nested table into the registry like this:

    Code:
    for x in Temperaturstyring.Nettside.SettTemperatur do
    for y,z in Temperaturstyring.Nettside.SettTemperatur[x] do   
    win.CreateRegistry('HKEY_CURRENT_USER', 'Software\\Automatisering\\Termostat\\'..x, 1):Write(y,z)
    print (x,y,z)
    end
    end
    I just cant get it out.
    Tor - managing director of the Cinema Inferno home theater and multi-zone sound system with Girder running the show in the back, NetRemote as the GUI and Media Center 17, PowerDVD and ZoomPlayer as playback software
    Hobsyssel mastiffs: http://www.hobsyssel.no

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

    Default

    So you want to read the registry back in and end up with a lua table?
    Ron
    No support through PM

  7. #7
    Join Date
    Jul 2001
    Location
    Risør - Norway
    Posts
    5,477

    Default

    Yep, that's it. End up with a nested LUA table like the one I got when I put stuff into the registry. It's for reboots and restarts of Girder, since these settings have to be preserved and not change except when I actually do somethign to change them (from the web page or with a timer).
    Tor - managing director of the Cinema Inferno home theater and multi-zone sound system with Girder running the show in the back, NetRemote as the GUI and Media Center 17, PowerDVD and ZoomPlayer as playback software
    Hobsyssel mastiffs: http://www.hobsyssel.no

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

    Default

    I wanna say there is an easier way to do this. Store the whole table as one entry then reload the whole table in one go. OF the top of my head there is the "pickle"

    Code:
    local pickled = pickle(Temperaturstyring)
    local reg = win.CreateRegistry('HKEY_CURRENT_USER', 'Software\\Automatisering\\Termostat\\Pickle", 1)
    reg:Write("Value", pickled)
    reg:CloseKey()
    Code:
    local reg = win.CreateRegistry('HKEY_CURRENT_USER', 'Software\\Automatisering\\Termostat\\Pickle", 0);
    local pickled = reg:Read("Value")
    Temperaturstyring = unpickle(pickled)
    reg:CloseKey()
    Last edited by Ron; March 16th, 2015 at 07:25 AM.
    Ron
    No support through PM

  9. #9
    Join Date
    Jul 2001
    Location
    Risør - Norway
    Posts
    5,477

    Default

    Thanks for answering! The problem is that I do not write to the registry in one go, I write the changed state each time one of the states is changed, in case of a power outage or other form of unexpected shutdown. Wouldn't that crash with this way of doing it?
    Tor - managing director of the Cinema Inferno home theater and multi-zone sound system with Girder running the show in the back, NetRemote as the GUI and Media Center 17, PowerDVD and ZoomPlayer as playback software
    Hobsyssel mastiffs: http://www.hobsyssel.no

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

    Default

    As long as the whole table is available at the time of the write I don't see any difference between writing each value individually and writing them all at once.
    Ron
    No support through PM

Page 1 of 3 123 LastLast

Posting Permissions

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