An extension for storing global variables

The variables declared in gpscript are only visible in the script where they are declared, for example a rack-script, gig script, scriptlet or song-script. But sometimes it comes in handy to have some variables available everywhere. Therefore, I created this extension. It extends gpscript with some functions to created a ‘store’ with variables. These variables can be access by all scripts using these functions.

Disclaimer: This is version 0.0.1, so use at your own risk. Feel free to clone it and correct my mistakes, or create an issue. Maybe I’m smart enough to fix it.

I hope it might prove useful for somebody.

BTW: The extension-SDK is rather usable, not very hard to understand and well thought-through (or whatever the English idiom might be :slight_smile: ). My compliments to the people that created Gig Performer.

7 Likes

Hi @Frank1119. I’ve attempted to build and test this on MacOS.
A few things:

  • GlobalVarsMapArray header and implementation file were not listed in CMakeLists.txt
  • The extension name defined in XMLProductDescription was “StateFullness” rather than “GlobalVars”
  • The GP Script function definitions don’t appear to match your examples in the readme e.g. the CreateString definition requires two variables (handle and name), but your example indicates you only pass it one variable.

{"CreateString", "handle:String, name:String", "Returns boolean", "Creates a global string ", CreateString},

String declaration

var
    b : boolean
    
    b = GlobalVars_CreateString("Author")
  • The SetString function example in readme passes an integer for the string length, but the function definition is a string:

{"SetString", "handle:String, name:String, value:String", "Returns boolean", "Assigns a string value", SetString},

Assigning a string

var
    b : boolean
    author : string
    
    author = "Frank"
    
    b = GlobalVars_SetString("Author", author, Length(author))

I think I pushed some files from a different project. I’ll retrieve the original project (is somewhere on my computer) and possibly recreate the github project. I hope I can do that tonight

Thanks. No rush - I thought I’d check it out :slight_smile:
BTW I did successfully compile on MacOS and can get it working within the same rackspace type e.g. string set in one local rackspace and retrieved in another local rackspace. But I haven’t got it working from global to local.

I think I managed to reset it to a working version. In a while I might be updating this one, because with the GP5.0 extension api I can retrieve the string length, so no need anymore to pass that. Also I want to revise it to use unique_ptr, instead of ‘old school’ new/delete.

Sample project with changes in global rackspace showing up in the local rackspace and vice versa:

GlobalVarsDemo.gig (55.5 KB)

1 Like

(The StateFullness extension is rather different: It works in conjunction with a plugin to save custom variables in the state of a gigfile. I leans on the possibility in Windows to load a dll at runtime. In this case it ‘reloads’ the extension dll. This way the plugin can make calls to the entrypoints in the extension dll. I don’t know how to do that on mac, so therefore it’s Windows only.

Result: You can set variables using scripting (much like GlobalsVars, actually I use the same object) and these will persist in the gigfile (because the plugin will export these variables as its own state: each plugin manages the variables associated with the rackspace it is in). When you duplicate a rackspace the plugin will also be copied and get this way its own copy of the state.)

Thanks @Frank1119 all working well!

The only additional change I needed to make in order for it to compile for MacOS is to replace the include for malloc.h with stdlib.h

I’ll do the same. If it still compiles for windows, then I’ll keep it, otherwise I will make it conditional

1 Like