10/19/14, 03:03 AM | #1 |
How to find out API version
Hi,
ist there a reliable, robust way to find out the API version under which an addon is running? This would be useful when changing addon code in order to support an upcoming ESO version on the PTS server if the addon should run on both the current and the future API version. I couldn't find any function like GetAPIversion() or so. Is there any? I was thinking of writing such a function by examining "typical properties" of a certain API version, such as the existence of a function or a global value, like this: Lua Code:
The shown approach is not very reliable since it checks for existence of a "magic" function which is no longer supported in a certain API version. Maybe there is a better way? Any ideas? // Klaro Last edited by klaro00 : 10/22/14 at 01:13 AM. |
|
10/19/14, 06:23 AM | #2 |
|
IIRC, at some point APIVersion on PTS wasn't even bumped immediately after the API changed, so even if there was GetAPIVersion() function, it wouldn't be 100% reliable.
I believe branching your code on some kind of GetAPIVersion (regardless of whether it's provided by the API or guessed from missing functions) is not the right way to support different APIs. If you need functionWhichWasRemovedInVersion100010, check for it's existence before you call it. Or alternatively, write a safety wrapper which will do the test and provide fallback functionality. Then your add-on will have a chance to function properly without being updated much longer. The fact that APIVersion>=100010 doesn't mean functionWhichWasRemovedInVersion100010 doesn't exist. An compatibility add-on could provide it. Or the function may be revived in 100012. There is also the possibility of a function changing arguments (which has already happened, and the compatibility tool provided a wrapper that worked with add-ons using either) or returned values (which no compatibility tool can fix, because it can't tell what type of return you want; here you'd have to use your own wrapper that would catch unexpected returns after the call). |
10/19/14, 08:49 AM | #3 |
It's better to check if some new function exists instead:
Lua Code:
My Compatibility Tool tries to emulate removed functions, so you can get wrong results.
Warning: Spoiler
CompatibilityTool.lua (version 5A for Update 5):
Lua Code:
Last edited by Garkin : 10/19/14 at 02:19 PM. Reason: fixed typo |
|
10/19/14, 01:09 PM | #4 |
Thanks,
so I was right that there is no direct way. I think I will test for new functions like GetLatency (in fact, I currently test for GetMaxLevel). Also thank you Garkin for the list of functions emulating older API functions; might be useful one day... Cheers, Klaro00 (Just in case you are interested in my current problem which led me to my questions, here are some details. It's not about missing functions, it's rather about access to the "settings menu" interface via ZO_OptionsWindow_InitializeControl(). ZO changed quite a lot behind the scenes, and kept this function for backward compatibility. But the data structure has been slightly changed by ZO as well, so I needed to do some fixes for 10010 which go beyond missing functions. This is solved, so I'm not asking for help with the settings menu; I'm also aware that there are approches like "LibAddonMenu" on the market... Because I don't want to fork my code to maintain two code versions, I was looking for a cheap way to support the current and the upcoming API version. That's it.) |
|
10/19/14, 02:14 PM | #5 | |
For example this is part of the function which creates checkbox in LibAddonMenu-1.0 (works on live server): Lua Code:
This is the same part of the function modified for Update 5 (keys are moved to the "data" table): Lua Code:
If you want it working for both live and PTS, use original function + metatable with __index metamethod: Lua Code:
If key doesn't exist in the checkbox.data table, it will look for metamethod __index. If __index is a function, it will return value from the function. If __index is a table, it will return key from that table. I.e. calling d(checkbox.data.tooltipText) will give the same result as calling d(checkbox.tooltipText). (A bit more about metatables: http://nova-fusion.com/2011/06/30/lu...bles-tutorial/) Last edited by Garkin : 10/19/14 at 02:17 PM. |
||
10/21/14, 09:12 AM | #6 |
I quickly threw in a GetAPIVersion function to make this easier in the future.
|
|
10/21/14, 10:11 AM | #7 |
10/21/14, 12:11 PM | #8 |
10/21/14, 04:04 PM | #9 |
It's likely to be in 1.5.
|
|
10/21/14, 07:07 PM | #10 |
|
|
10/21/14, 11:31 PM | #11 |
Good one
|
|
ESOUI » Developer Discussions » Lua/XML Help » How to find out API version |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|