View Single Post
07/09/14, 04:01 PM   #7
zgrssd
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 280
After another set of pondering I reduced it to the following KISS case and even added some sanity checks on the input data:
Lua Code:
  1. --Use lib stub to figure out if the same or higher version was already used
  2. local major, minor = "LibConstantMapper", 1
  3. local lib = LibStub:NewLibrary(major, minor)
  4.  
  5. if not lib then
  6.     return
  7. end
  8.  
  9. function lib:getMappedData(pattern, exclude)
  10.     --Sanity check on values
  11.     assert(pattern ~= nil and type(pattern) == "string", "pattern must not be nil and of type string")
  12.     assert(exlcude == nil or type(exclude) == "string", "exclude must be nil or of type string")
  13.    
  14.     local result = {}
  15.  
  16.     --For every entry in the Global table
  17.     for key, value in zo_insecurePairs(_G) do
  18.         --Compare it to the given mapping
  19.         if (key):find(pattern) and (exclude == nil or not(key):find(exclude)) then
  20.             --found a Value for this mapping, so store it in the result table
  21.             local newentry = { key = key, value = value}
  22.            
  23.             table.insert(result, newentry)
  24.         end
  25.     end
  26.  
  27.     return result
  28. end
I will also work on giving you some default pattern/exclusion pairs to work with (propably a "getMaps" and "addMap" function, similar to LibMediaProvider:List()).

Last edited by zgrssd : 07/09/14 at 04:03 PM. Reason: Had forgotten to throw out some debug messages
  Reply With Quote