The whole bug seem to be, that AddRemoveReaScript doesn't take properly into account \ versus / in the path when adding/removing a script.
This code always adds and removes the script:
Code:
A=reaper.GetResourcePath().."\\Scripts\\tudelu_22_01_2021_13_05_31.lua"
B=reaper.AddRemoveReaScript(false, 0, A, true)
This however, always adds but never removes the script:
Code:
A=reaper.GetResourcePath().."/Scripts/tudelu_22_01_2021_13_05_31.lua"
B=reaper.AddRemoveReaScript(false, 0, A, true)
The only difference between them is the used separators for the script.
I can also add duplicates of the same script, just by messing with separators.
Code:
add=false -- set to try add/remove all of them:
-- working: always add/removable
-- uses no path to the script in kb.ini, therefore assumes, script is in scripts-folder
-- SCR 4 0 RSff9b74aafc3bfa98202c626616d491ffc529e196 "Custom: tudelu_22_01_2021_13_05_31.lua" tudelu_22_01_2021_13_05_31.lua
reaper.GetResourcePath().."\\Scripts\\tudelu_22_01_2021_13_05_31.lua"
reaper.AddRemoveReaScript(add, 0, A, true)
-- buggy: alternative way, which adds(if the above way of adding hasn't been done before), but doesn't remove again
-- will use full path to the script in kb.ini
-- SCR 4 0 RS27ff500b6631c7b6131d341e58bec834d3f3c90d "Custom: tudelu_22_01_2021_13_05_31.lua" C:\Ultraschall-US_API_4.1.001\Scripts\tudelu_22_01_2021_13_05_31.lua
reaper.GetResourcePath().."/Scripts/tudelu_22_01_2021_13_05_31.lua"
reaper.AddRemoveReaScript(add, 0, A, true)
-- buggy: always added but never removable
-- will use full path to the script in kb.ini with variations of the separator
-- SCR 4 0 RSd9b04495ff208d80f0ffb945670ab5a19b8fff6f "Custom: tudelu_22_01_2021_13_05_31.lua" C:\Ultraschall-US_API_4.1.001\Scripts\\tudelu_22_01_2021_13_05_31.lua
reaper.GetResourcePath().."/Scripts//tudelu_22_01_2021_13_05_31.lua"
reaper.AddRemoveReaScript(add, 0, A, true)
-- SCR 4 0 RScdaed2b56ab23eda5aff9a979f945ada5d7c3bb0 "Custom: tudelu_22_01_2021_13_05_31.lua" C:\Ultraschall-US_API_4.1.001\Scripts\\\tudelu_22_01_2021_13_05_31.lua
reaper.GetResourcePath().."/Scripts///tudelu_22_01_2021_13_05_31.lua"
reaper.AddRemoveReaScript(add, 0, A, true)
-- SCR 4 0 RSa4ffe8a79ef8969af42e5db1aee0c9548ab55dbf "Custom: tudelu_22_01_2021_13_05_31.lua" C:\Ultraschall-US_API_4.1.001\Scripts\\\\tudelu_22_01_2021_13_05_31.lua
reaper.GetResourcePath().."/Scripts////tudelu_22_01_2021_13_05_31.lua"
reaper.AddRemoveReaScript(add, 0, A, true)
When this duplication happens, it leads to kb-ini-entries like this:
SCR 4 0 RS27ff500b6631c7b6131d341e58bec834d3f3c90d "Custom: tudelu_22_01_2021_13_05_31.lua" C:\Ultraschall-US_API_4.1.001\Scripts\tudelu_22_01_2021_13_05_31. lua
SCR 4 0 RSff9b74aafc3bfa98202c626616d491ffc529e196 "Custom: tudelu_22_01_2021_13_05_31.lua" tudelu_22_01_2021_13_05_31.lua
SCR 4 0 RSa4ffe8a79ef8969af42e5db1aee0c9548ab55dbf "Custom: tudelu_22_01_2021_13_05_31.lua" C:\Ultraschall-US_API_4.1.001\Scripts\\\\tudelu_22_01_2021_13_05_ 31.lua
With differences in the used path/separators to the script.
Means, depending on the used separator, AddRemoveReaScript seems to confuse, whether the script shall be added located in the ReaScript-path vs added using the entire absolute path.
I think, this is a Lua-only problem, as Lua allows using / and \ as file-separators which might confuse AddRemoveReaScript, so other languages should(tm) not be affected, if I got it right.
Tested on Reaper6.53x64 on Windows 7.
FWIW: My test-file is located in the path: "C:\Ultraschall-US_API_4.1.001\Scripts\tudelu_22_01_2021_13_05_31. lua"
Just in case, this has an effect on reproducing the bug.