Closed cfillion closed 4 months ago
local ImGui
if APIExists('ImGui_GetBuiltinPath') then
if not reaper.ImGui_GetBuiltinPath then return reaper.MB('This script require ReaImGui extension','',0) end
package.path = reaper.ImGui_GetBuiltinPath() .. '/?.lua'
ImGui = require 'imgui' '0.9'
else
return reaper.MB('This script require ReaImGui extension 0.9+','',0)
end
Am I right to do this, because ImGui_GetBuiltinPath doesn`t exists before 0.9 so it produce error?
if APIExists('ImGui_GetBuiltinPath') then
and if not reaper.ImGui_GetBuiltinPath
contradict each other. APIExists
is only useful in EEL.
Checking once is enough:
if not reaper.ImGui_GetBuiltinPath then return reaper.MB('This script require ReaImGui extension 0.9+','',0) end
package.path = reaper.ImGui_GetBuiltinPath() .. '/?.lua'
local ImGui = require 'imgui' '0.9'
Dear ImGui and ReaImGui often have breaking API changes. Public scripts ideally should enable backward compatibility to be shielded from those and continue working without having to update them every time. The second commit enables the basic form (needs to be before
_G[key]=reaper[key]
):...where '0.9' is whichever API version the script was written for. The API is downgraded to that version as necessary. It also checks that the user has at least that version installed and shows an error message otherwise.
The third commit fully migrates to 0.9's new versioned API for enhanced backward compatibility (by not exposing features newer than the specified version). Constants also become numbers instead of functions. I used this script to convert automatically.
More details here: https://forum.cockos.com/showthread.php?p=2775338.