Old 02-11-2018, 04:02 AM   #1
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default Lua: How to store project specific script data (tables)?

What would be the best way to store project specific Lua script data, especially tables?
spk77 is offline   Reply With Quote
Old 02-11-2018, 09:57 AM   #2
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,900
Default

It depends on what you trying to do, you can saves as external files, or as ProjExtState, or hardcoding things right in the script.
Really depends on what you are trying to do, and what variables.
X-Raym is offline   Reply With Quote
Old 02-11-2018, 10:51 AM   #3
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

I would prefer to store data directly to project file, but I don't know an easy way to store table data.
I know it's possible to store tables to external files, but I wish there was a "better" way :
https://forum.cockos.com/showpost.ph...&postcount=190


Here's an example - each button is a Lua table (and should be stored when the script is closed):
spk77 is offline   Reply With Quote
Old 02-11-2018, 11:03 AM   #4
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,968
Default

In my opinion a "better" way is one that doesn't execute the data as code (loadstring/loadfile). It really depends on the contents of the table and structure of the data though.

I used this for serializing a flat table (without nesting): https://github.com/ReaTeam/ReaScript...s.lua#L118-146.

One thing to keep in mind is project extstates are limited of 2^12-(key length)-2 bytes (less if the key contains spaces) after the project is loaded.
https://forum.cockos.com/showthread.php?p=1945880

Last edited by cfillion; 02-11-2018 at 11:21 AM.
cfillion is offline   Reply With Quote
Old 02-11-2018, 11:18 AM   #5
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,689
Default

try pickle:
http://lua-users.org/wiki/PickleTable

I used it for never released playlist
Sexan is offline   Reply With Quote
Old 02-11-2018, 02:30 PM   #6
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,900
Default

Quote:
Originally Posted by cfillion
2^12-(key length)-2 bytes
For the whole Exstate section, or for each sub categories/keys ?

If it is for keys, the string can be split under several ones.

Though, it makes thing more complex than it could be.

@spk77
Maybe a dirty solution would be to use ProjectNotes.
I don't know if there is a limitation in size to this.
X-Raym is offline   Reply With Quote
Old 02-11-2018, 10:21 PM   #7
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,968
Default

Quote:
Originally Posted by X-Raym View Post
If it is for keys, the string can be split under several ones.

Though, it makes thing more complex than it could be.
Yup, it is.
cfillion is offline   Reply With Quote
Old 02-12-2018, 03:55 AM   #8
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,900
Default

@cfillion
Ok so a workarround can be done ;P

@spk77
Note that your script seems pretty close to SpacemanTree Reazard of Oz :P
https://m.youtube.com/watch?v=sJJ9pe5ehTU
(But different though. You dont use Slots for eg)

Also, check lua native table.join and table.concat.
X-Raym is offline   Reply With Quote
Old 02-12-2018, 07:35 AM   #9
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

Thanks everyone! I think I'll just try different options.

Quote:
Originally Posted by X-Raym View Post
@cfillion
Ok so a workarround can be done ;P

@spk77
Note that your script seems pretty close to SpacemanTree Reazard of Oz :P
https://m.youtube.com/watch?v=sJJ9pe5ehTU
(But different though. You dont use Slots for eg)

Also, check lua native table.join and table.concat.
Thanks!
I'm trying to do a "Tracktion style track tags" -script:




Here's the Reazard of Oz by SpacemanTree (I have this script and I also donated one of these animal shelters )
https://forum.cockos.com/showthread....hlight=reazard
spk77 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 03:13 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.