Go to Page... |
Compatibility: | Update 3 (1.3.3) |
Updated: | 08/11/14 09:17 AM |
Created: | 07/10/14 04:51 AM |
Monthly downloads: | 65 |
Total downloads: | 3,942 |
Favorites: | 0 |
MD5: |
ReturnsNote: The prefered way of getting data since implemented in 0.2.If a map of this name exists it will do 1-2 things:Arguments
If no cache exists or rebuidChache is true, it will build the cache from scratch by itterating over the global table, sort the result by value first and then store it in the cache.
In any case it will return a deep copy of whatever the cache contains now.
map_name
Name of the mapping. As defined durign registering and retrieved by listMaps
(optional)rebuildCache
If this parameter is true an existing cache for this mapping will be discarded and the data will be read in from the global table again.
Returns
A well formed array containing all the Keys and thier values that match pattern, but do not match exclude. Due to the nature of the source and extraction, no guarantees over the order of the key/value pairs or thier uniqueness of each value can be given (that is entirely up to the data, what order pairs uses today and the two patterns given).
Arguments
:getValIndexedKeyList(input [, noDuplicateAssertion])pattern
The string pattern that has to match for the key/value to land in the output
exclude
(Optional) another string pattern. If an global table entry matches the pattern and the exclude pattern, it is not included in the output (see the example case below)
ReturnsA table that uses the Values's as indexes and the keys as values. Thus allows quick value->key mapping. The input table is itterated via ipairs, so the result should be deterministic (if you should be using the noDuplicateAssertion override).
No guarantee that the keys are consecutive can be made (this depends entirly on the input).
ThrowsAn assertion error if the same a value has already been used as index. This error implies that something in the input is wrong - usually that the pattern/exclude combo is somehow not excluding everything it should. Thus resulting in the same value being more then once in the input table.
Argumentsinput
The return values of a getDataByMapping() or getMappedData() should be given here.
But every table that can be itterated over with ipairs and contains nested tables with key&value indexes should be just as valid.noDuplicateAssertion
Normally the function will throw an exception if it finds the same value a second time (and thus tries to write the same index again). If this is set to true, it will instead ignore the problem and overwrite the old value of the index.
Use at own risk: Duplicate values mean either you should not use this function on the data in the first place, or that something with the retrieval patterns is wrong. Supressing the assertion could lead to unforseen consequences down the road.
Returns:addMap(map, pattern [, exclude])The names of all the currently registered maps, wheter they are defined with the library or registered by other code.
Argumentsmap
A unique string that identifies this mapping. If a map with this value already exists, it is overwritten and it's cached values are discared.
pattern
The pattern associated with this map
exlcude
(Optional)The exclude pattern associated with this map
ReturnsA table containing the pattern and exlucde entires under correspondingly named keys.Arguments
mapThe string that identifies the map, as given under addMap
["key"] = "CHAT_CATEGORY_COMBAT_ALLIANCE_POINTS"[2]
["value"] = 48
["key"] = "CHAT_CATEGORY_COMBAT_BATTLE_TOKENS"[3]
["value"] = 46
["key"] = "CHAT_CATEGORY_COMBAT_BLOCK_ABSORBED_DEFEND"[4]
["value"] = 58
["key"] = "CHAT_CATEGORY_COMBAT_DEATH"[5]
["value"] = 61
["key"] = "CHAT_CATEGORY_COMBAT_DIRECT_DAMAGE"[6]
["value"] = 51
["key"] = "CHAT_CATEGORY_COMBAT_DIRECT_HEAL"...
["value"] = 53
["key"] = "CHAT_CATEGORY_ZONE"[39]
["value"] = 6
["key"] = "CHAT_CATEGORY_ZONE_ENGLISH"[40]
["value"] = 20
["key"] = "CHAT_CATEGORY_ZONE_FRENCH"[41]
["value"] = 21
["key"] = "CHAT_CATEGORY_ZONE_GERMAN"Feeding it to getMappedData would get you a table looking like this (keys will not be continous, as there are only 41 Constants/Keys that map to channel ID's. But there are 61 Channel ID's (so 20 remain unused)):
["value"] = 22
File Name |
Version |
Size |
Uploader |
Date |
0.6 |
4kB |
zgrssd |
07/19/14 01:56 AM |
|
0.5 |
4kB |
zgrssd |
07/18/14 09:34 AM |
|
0.4 |
4kB |
zgrssd |
07/18/14 02:15 AM |
|
0.3 |
3kB |
zgrssd |
07/13/14 05:54 AM |
|
0.2 |
3kB |
zgrssd |
07/11/14 12:13 PM |
|
0.1 |
3kB |
07/10/14 04:51 AM |
![]() |
Comment Options |
calia1120 |
View Public Profile |
Send a private message to calia1120 |
Send email to calia1120 |
Find More Posts by calia1120 |
Add calia1120 to Your Buddy List |
![]() |
|
Forum posts: 0
File comments: 120
Uploads: 0
|
Unified chat tabs error
Unified chat tabs addon has an error that seems to point to this lib. Is this a fault of this lib or the addon?
2016-03-07T14:06:36.436-06:00 |cff0000Lua Error: Key: '2' contains the duplicate value '1' stack traceback: [C]: in function 'assert' user:/AddOns/UnifiedChatTabs/libs/LibConstantMapper.lua:47: in function 'lib:getValIndexedKeyList' user:/AddOns/UnifiedChatTabs/UCT_main.lua:272: in function 'OnAddOnLoaded'|r Edit: It looks like the TG patch changed the key structure. Is there a fix?
Last edited by MK32 : 04/05/16 at 01:04 PM.
|
![]() |
![]() |
MK32 |
View Public Profile |
Send a private message to MK32 |
Send email to MK32 |
Find More Posts by MK32 |
Add MK32 to Your Buddy List |
![]() |
||
|
A wonderfull example as to why this library is usefull just poppoed up in the PTS Changenotes 1.3:
All I have to do now is add a pattern that matches for "BIND_TYPE_". This also gives me a better name for a later version: EnumHarvester perhaps? |
|
![]() |
![]() |
zgrssd |
View Public Profile |
Send a private message to zgrssd |
Send email to zgrssd |
Find More Posts by zgrssd |
Add zgrssd to Your Buddy List |
![]() |
||
|
Re: Re: Re: That's kind of why symbols exist in the first place
It would fail if they ever renamed that constant, till I rework the code. It would also fail if they ever added a category. There are 41* of those constants as it is now. I would hate it to even have to write an array containing all those constant names (could itterate over it via a for loop then). Most importantly they might add more with later API releases. All reason I much prefer to have code make this array for me, then making it myself. As the programming is now, I would have to look at the Global table every time the API version changes. And risk making something wrong in the time between the API update and my code update. With this library my code adopts automatically. I can write code that can easily survive changes to those constants (be it value changes, minor renames, removals or additions). *And that is one of the smaller amounts. There are currently 469 Event ID's in the global table. With my library you get a nice, int indexed list of those. You can simply figure out in wich event your code is running by looking it up in the list. Without it - you would hate to be the one who has to write that array.
Last edited by zgrssd : 07/14/14 at 07:05 AM.
|
|
![]() |
![]() |
zgrssd |
View Public Profile |
Send a private message to zgrssd |
Send email to zgrssd |
Find More Posts by zgrssd |
Add zgrssd to Your Buddy List |
![]() |
|
Forum posts: 1
File comments: 3
Uploads: 0
|
Re: Re: That's kind of why symbols exist in the first place
Code:
if(mysteriousValue == CHAT_CATEGORY_SAY) then DoWhatYouNeedForSay(...) end So, I must be missing something here, I'm just trying to make sure you're not solving a problem that these symbols were specifically invented to solve. Why else would there be so many globals? |
![]() |
![]() |
LoquaciousAndroid |
View Public Profile |
Send a private message to LoquaciousAndroid |
Send email to LoquaciousAndroid |
Find More Posts by LoquaciousAndroid |
Add LoquaciousAndroid to Your Buddy List |
![]() |
||
|
Re: That's kind of why symbols exist in the first place
It is hard to figure out that Chat Category ID 1 equates to SAY. Much less figuring that out at runtime in a non-localised fashion - when my code needs that data. I can't just hardcode that 1 is CHAT_CATEGORY_SAY, because it might not be this way in future revision of the API. I needed an unambigious name for each named chat category. So that even in the case that the order changed between runs of my addon (like a API update) I would still assign the right values to the right category. During saving I figure out wich Chat Category that number equates too. And just store it under that chat categories name. During application I can just use the respective constant from the global table. |
|
![]() |
![]() |
zgrssd |
View Public Profile |
Send a private message to zgrssd |
Send email to zgrssd |
Find More Posts by zgrssd |
Add zgrssd to Your Buddy List |
![]() |
|
Forum posts: 1
File comments: 3
Uploads: 0
|
That's kind of why symbols exist in the first place
ESO actually makes those global symbols so that addons don't have to depend on magic numbers. If addons used the constants the the configuration problem you mentioned wouldn't exist.
Or maybe I am missing something here... |
![]() |
![]() |
LoquaciousAndroid |
View Public Profile |
Send a private message to LoquaciousAndroid |
Send email to LoquaciousAndroid |
Find More Posts by LoquaciousAndroid |
Add LoquaciousAndroid to Your Buddy List |
![]() |