View Single Post
01/15/16, 05:48 AM   #9
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Votan's idea is brilliant. Although it could still suffer small inconsistencies when e.g.:
export_to == 1
add-on saves data into table 1
reloadui
add-on still uses table 1
external app reads table 1, sets export_to = 2
you need to reloadui again to make add-on wipe table 1 and use table 2

Here's my suggestion: save it in time-stamped tables

Lua Code:
  1. -- ON_ADD_ON_LOADED
  2. local prune_stamp = tonumber(EXTERNAL_APP_SEEN_DATA_UNTIL) or 0
  3. for key in next, saved_vars do
  4.   key = tonumber(key)
  5.   if key and key <= prune_stamp then
  6.     saved_vars[key] = nil
  7.   end
  8. end
  9.  
  10. local now = GetTimeStamp()
  11. local new_data_table = {} -- gather new data in this table
  12. saved_vars[now] = new_data_table

The external app would then, after reading the saved vars, alter the special file export_timestamp.lua inside your addon (note: missing file is not an error, so it doesn't need to exist until your app creates it; it doesn't have to be shipped with the addon, just list it in the manifest):
Lua Code:
  1. -- make this identifier unique,
  2. -- or put in in your add-on global table if it has one
  3. EXTERNAL_APP_SEEN_DATA_UNTIL = 123456789
  4. -- the highest timestamp it has seen

It would still take a second reloadui to actually wipe that data from saved vars, but it wouldn't wipe the data gathered between the 1st and 2nd reloadui.
  Reply With Quote