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:
-- ON_ADD_ON_LOADED
local prune_stamp = tonumber(EXTERNAL_APP_SEEN_DATA_UNTIL) or 0
for key in next, saved_vars do
key = tonumber(key)
if key and key <= prune_stamp then
saved_vars[key] = nil
end
end
local now = GetTimeStamp()
local new_data_table = {} -- gather new data in this table
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:
-- make this identifier unique,
-- or put in in your add-on global table if it has one
EXTERNAL_APP_SEEN_DATA_UNTIL = 123456789
-- 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.