Skip to content

Instantly share code, notes, and snippets.

@cfillion
Last active April 30, 2024 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cfillion/8d82e5ea64807ba9efe834a2cbb1c83a to your computer and use it in GitHub Desktop.
Save cfillion/8d82e5ea64807ba9efe834a2cbb1c83a to your computer and use it in GitHub Desktop.
-- @version 1.0.1
-- @changelog Add whitespace tolerance
-- @author cfillion
package.path = reaper.ImGui_GetBuiltinPath() .. '/?.lua'
local ImGui = require 'imgui' '0.9'
local SCRIPT_NAME = 'imgui.lua 0.9 upgrader'
local FLT_MIN, FLT_MAX = ImGui.NumericLimits_Float()
local ctx = ImGui.CreateContext(SCRIPT_NAME)
local code
local function upgrade()
code = code:gsub('reaper%s*%.%s*ImGui_', 'ImGui.')
code = code:gsub('r%s*%.%s*ImGui_', 'ImGui.')
for key, val in pairs(ImGui) do
if type(val) == 'number' then
code = code:gsub('(ImGui%.' .. key .. ')%s*%([^%)]*%)', '%1')
end
end
end
local function window()
if ImGui.Button(ctx, 'Upgrade', -FLT_MIN) then upgrade() end
ImGui.InputTextMultiline(ctx, '##preamble',
"package.path = reaper.ImGui_GetBuiltinPath() .. '/?.lua'\n\z
local ImGui = require 'imgui' '0.9'", -FLT_MIN, 40, ImGui.InputTextFlags_ReadOnly)
code = select(2, ImGui.InputTextMultiline(ctx, '##code', code, -FLT_MIN, -FLT_MIN))
end
local function loop()
ImGui.SetNextWindowSize(ctx, 512, 256, ImGui.Cond_FirstUseEver)
local visible, open = ImGui.Begin(ctx, SCRIPT_NAME, true)
if visible then window(); ImGui.End(ctx) end
if open then reaper.defer(loop) end
end
reaper.defer(loop)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment