LUA code to convert Hex to String based on Table

Discussion in 'C-Bus Automation Controllers' started by Ks04, Sep 2, 2022.

  1. Ks04

    SgrAystar

    Joined:
    Oct 4, 2018
    Messages:
    64
    Likes Received:
    5
    Location:
    Melbourne, Australia
    SgrAystar, Sep 8, 2022
    #21
  2. Ks04

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,558
    Likes Received:
    182
    Location:
    Adelaide, Australia
    Dictionaries work by converting the key into a unique integer value using a hashing algorithm. The hash value then becomes an index into an array. So the dictionary is actually sorted by the hash value, which is what the 'pairs' goes by. Not very useful, but not arbitrary. If you use ipairs, this is implemented as a 'for' loop starting from one, looking up each key in succession. However it will stop on the first miss (i.e. the first gap in integer keys), which is why it would only retrieve the 1 and 2 keys, as key 3 is missing.

    In Lua (since V5), if you create a dictionary with consecutive integer keys starting from one, Lua will forgo the dictionary structure and just create a linear array. This is transparent to the end user however.
     
    Ashley, Sep 9, 2022
    #22
    ssaunders likes this.
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.