View Single Post
07/08/14, 10:37 AM   #2
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Some suggestions.

a) either allow more exludes (make it a table) to make things like this work (because Lua's regular expressions are so weak they can't accomplish this in one go):
Lua Code:
  1. { mapping = "Stats", pattern = "^STAT_", exclude = {"^STAT_BONUS_OPTION_", "^STAT_SOFT_CAP_OPTION", "^STAT_VALUE_COLOR"} }
b) or replace excludes with a non-mapping...
Lua Code:
  1. { mapping = false, pattern = "^CHAT_CATEGORY_HEADER_" }, -- non-mapping
  2. { mapping = "ChatCategories", pattern = "^CHAT_CATEGORY_" },
  3. { mapping = "StatBonusOptions", pattern = "^STAT_BONUS_OPTION_" },
  4. { mapping = "StatSoftCapOptions", pattern = "^STAT_SOFT_CAP_OPTION_" },
  5. { mapping = false, pattern = "^STAT_VALUE_COLOR" }, -- non-mapping
  6. { mapping = "Stats", pattern = "^STAT_" },
...and stop after the first match
Lua Code:
  1. --For every entry in the Global table
  2. for key, value in zo_insecurePairs(_G) do
  3.     --Compare it to every mapping
  4.     local foundMap = nil
  5.     for _, currentMap in ipairs(Mappings) do
  6.         if key:find(currentMap.pattern) then
  7.             foundMap = currentMap
  8.             break -- stop at the first match
  9.         end
  10.     end
  11.     if foundMap and foundMap.mapping then
  12.             --found a Value for this mapping, so store it in the table
  13.             local newentry = { key = key, value = value}
  14.             table.insert(data[foundMap.mapping], newentry)
  15.     end
  16. end

Also it would be nice to have direct [value] => "key" mapping in addition to the table of pairs (I'm aware there might be collisions and the library would have to deal somehow, that's why wrote in addition to )

Last edited by merlight : 07/08/14 at 10:40 AM.
  Reply With Quote