View Single Post
Old 09-09-2018, 07:39 AM   #6
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

Quote:
Originally Posted by tompad View Post
Code:
 
 reaper.SetProjExtState(0,"ToDoList",1,tostring(GUI.table_list(items)))
Shouldn't that "tostring(GUI.table_list(items))" make a string with table content?
Yes, GUI.table_list will do that. It also adds pretty indenting though, which might cause trouble.

However, the logic is pretty simple:

Code:
local settings = {
  flag1 = true,
  flag2 = false,
  param1 = 4,
  param2 = 5,
  param3 = "tompad"
}

local function settingsToStr()
  local strs = {}
  for k, v in pairs(settings) do
    strs[#strs+1] = k .. "=" .. tostring(v)
  end
  return table.concat(strs, ",")
end

Msg(settingsToStr())
--> flag1=true,param2=5,param1=4 ...etc...

-- Note that pairs() doesn't maintain any sort of order in the
-- table, but Lua doesn't either so it doesn't matter.

local function formatValue(v)
  if tonumber(v) then
    return tonumber(v)
  elseif (v == "true" or v == "false") then
    return v == "true"
  else
    return v
  end
end

local function settingsFromStr(str)
  for k, v in str:gmatch("([^,]+)=([^,]+)") do
    settings[k] = formatValue(v)
  end
end
Quote:
By the way - I watched some other examples with SetProjExtState that used "for k, v in pairs(s) do"
but if I want to save just ONE long string in SetProjExtState do I really need to do a for loop?
If you know it's one long string, then no - you should be able to plop it straight in there. Might need to replace any \ns with a placeholder and then swap them back on reload - I'm not sure.

Quote:
Originally Posted by tompad View Post
When closing project starting a new project my script window says open
Reaper doesn't send any events for the script to know that you've changed projects. AFAIK your best option would be to make use of the SWS Project Startup action or whatever it's called, but I don't think you'd be able to save into the previous project's ExtState that way.
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate

Last edited by Lokasenna; 09-09-2018 at 07:53 AM.
Lokasenna is offline   Reply With Quote