View Single Post
07/12/14, 04:36 AM   #11
zgrssd
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 280
The above code (after adding some missing = in the table assignment at the botom) has been uploaded as version 0.2.
I also started work on a function that gives you a value indexed array of the keys. This is my code so far (not done any testruns):
Lua Code:
  1. function lib:getValIndexedKeyList(input)
  2.     --assert that input is remotely valid
  3.     assert (input ~= nil and type(input) == "table", "input must be not nil and a table")
  4.    
  5.     local result = {}
  6.    
  7.     for outerkey, outervalue in input do
  8.         --assert that this index of input has the right contained elements
  9.         assert (type(outervalue) == "table" and outervalue.key ~= nil and outervalue.value ~= nil, "Key: '" .. outerkey .. "' is not a table or does not contain a pair of key/value indexes")
  10.        
  11.         --Some local variables to shorten the syntax
  12.         local innerkey, innervalue = outervalue.key, outervalue.value
  13.        
  14.         --Check if this value has already been used as key
  15.         assert(result[innervalue] == nil, "Key: '" .. outerkey .. "' contains the duplicate value '" .. innervalue .. "'")
  16.         result[innervalue] = innerkey
  17.     end
  18.    
  19.     return result
  20. end

Last edited by zgrssd : 07/12/14 at 04:38 AM.
  Reply With Quote