Author Topic: values stored in a global varible  (Read 4476 times)

boaz

  • Community Member
  • Posts: 43
  • Hero Points: 0
values stored in a global varible
« on: January 09, 2012, 10:02:15 am »
Hi All,

I have a global variable in a macro as follows:

#if __UNIX__
_str SLASH = "/";
#else //windows
_str SLASH = "\\";
#endif

These lines are in the beginning of the macro, so hopefully they run each time the module is loaded
I'm getting weird stuff after running this macro on a windows/linux machines - the value of slash stays the wrong OS
(but when I make sure the right #if is called I get that I'm in the correct OS

Is there a magical place that old global values are stored?


Graeme

  • Senior Community Member
  • Posts: 2432
  • Hero Points: 322
Re: values stored in a global varible
« Reply #1 on: January 09, 2012, 10:27:11 am »
A global variable won't get re-initialised when a module is loaded but a static variable will.  You can change or view the value of a global variable using the set-var command on the slick command line and it will get saved to vusrdefs.e when you close slick (I think).

You can use definit to set the value of a variable when a module is loaded or slickedit starts - see definit in the help.


slick.sh already has this
Code: [Select]
#if __UNIX__
   #define FILESEP "/"              /* Primary filename,directory separator */
   #define FILESEP2 "\\"              /* Secondary filename,directory separator */
   #define PATHSEP ":"
   #define EXTENSION_EXE ""
   #define EXTENSION_BATCH ""
   #define COMMANDSEP ";"
#else
   #define FILESEP "\\"              /* Primary filename,directory separator */
   #define FILESEP2  "/"              /* Secondary filename,directory separator */
   #define PATHSEP ";"
   #define EXTENSION_EXE ".exe"
   #define EXTENSION_BATCH ".cmd"
   #define COMMANDSEP "&"
#endif

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: values stored in a global varible
« Reply #2 on: January 09, 2012, 10:30:53 am »
There are a few things that will help clear this up:

1.  Yes, global values are stored in the state file.
2.  The module is only loaded when you explicitly use Load Module.  That loads the compiled macro (.ex) into the editor's internal state, which is persisted between sessions in the editor's state file (along with key bindings, etc).  Launching the editor later doesn't load the .ex file again, it simply restores from the persisted state file.
3.  Globals declared like that don't get reset each time you load the module -- they only get set either the first time you load it, or when the global variable doesn't yet have a value -- I'm not clear on specifically which it is but in practice it doesn't matter.
4.  Slick-C defines FILESEP to be the directory separator for the current platform.  So you could remove SLASH and just use FILESEP.

If you want to set a variable each time the editor is invoked, take a look at definit and defload in the Help.

boaz

  • Community Member
  • Posts: 43
  • Hero Points: 0
Re: values stored in a global varible
« Reply #3 on: January 09, 2012, 11:58:23 am »
Thanks for all the info!

I have some more variables like this and I understand that static is what I need (sharing variables between functions in the same module)

I just wanted to understand the mechanism:
1. Where can I see all the variables that are stored?
2. How can I flush them (so they won't cause any trouble - I'd rather not change the entire variable names)

hs2

  • Senior Community Member
  • Posts: 2744
  • Hero Points: 288
Re: values stored in a global varible
« Reply #4 on: January 09, 2012, 06:04:54 pm »
@boaz: You can't see statics except you write your own macro to show them. Globals can be set/checked by 'set-var' (supporting TAB completion) or by 'gui-set-var' command on SE cmdline resp. 'Macro>Set Macro Variable'.
What do you mean with 'flush' a variable ?
You can remove a variable by removing it's definition from the macro module and reload it.
Exit SE with saving the changed configuration and restart it.
HS2

boaz

  • Community Member
  • Posts: 43
  • Hero Points: 0
Re: values stored in a global varible
« Reply #5 on: January 10, 2012, 06:43:52 am »
I meant a global variable
as I understood, it's values are stored somewhere so when I re-open SE the values are still there.
So how do I make them go away?

hs2

  • Senior Community Member
  • Posts: 2744
  • Hero Points: 288
Re: values stored in a global varible
« Reply #6 on: January 10, 2012, 09:25:29 am »
As chrisant explained global variables are stored persistently in the so called state file (vslick.sta resp. vslick.stu). Their value can be interactively examined and/or changed e.g by (gui-)set-var command.
The variables itself can be removed (also from SE state file) as described in my prev. post.
Their initialization on SE startup ie. macro module (re-)load is handled in definit resp. defload (see Help>Index: Module Initializations).
Sorry - I'm not sure what 'make them go away' really means..
Hope it helps, HS2

boaz

  • Community Member
  • Posts: 43
  • Hero Points: 0
Re: values stored in a global varible
« Reply #7 on: January 10, 2012, 09:50:39 am »
It helped a lot! Thanks!