Page 1 of 1

Creating and using library stacks

Posted: Wed Aug 31, 2011 4:05 pm
by andyh1234
Ive created a stack of common items Id like to include in many apps.

Id like to be able to use it in the same was as animation engine, charts engine etc where I can just issue the command..

'start using stack mylibrarystack' and everything in the stack becomes available.

This works if the library stack is loaded in memory, but when I close the code down and re-open it the library stack is not automatically opened into memory, so the start using command fails.

What do I need to do to get the stack to load automatically on startup like the commercial add ons????

Thanks

Andy

Re: Creating and using library stacks

Posted: Wed Aug 31, 2011 4:10 pm
by dunbarx
It is a bit tricky, in that LC wants to see certain files in certain places. I think Jacque sent me this recipe a while back:


1. Just make any stack you like, and add a preOpenStack handler in its card script to put the stack into use as a library:

on preOpenStack
start using this stack
end preOpenStack

You'll want to do this in the card script rather than the stack
script, since once the stack is brought into use as a library
any handlers in it will be triggered from any such messages.

2. Save the stack in a folder named "Plugins" in a folder named "LiveCode", somewhere, likely the "documents" folder:
~/Documents/LiveCode/Plugins/

3. You may need to quit Rev before your plugin is recognized; I
believe their Plugin manager is not as adept as MC's in allowing
you to add stuff to it on the fly.

4. Launch Rev, and choose Plugin Settings from the Development->Plugins menu.

5. Select your plugin stack from the popup list at the top of the
Plugins Manager, and choose the appropriate radio control for "Open plugin when: Revolution starts").

Navigate to the enclosing ("Livecode") folder in the files and memory pane of the LC preferences.

Re: Creating and using library stacks

Posted: Wed Aug 31, 2011 4:41 pm
by Dixie
Craig...

Your take is interesting, in that, I use library stacks quite a lot... I too use a 'preOpenStack' handler to launch them, but have always put the 'preOpenStack' in the script of the stack... Have not had any problems with the handler placed there, both under OSX and windows...

be well,

Dixie

Re: Creating and using library stacks

Posted: Wed Aug 31, 2011 4:46 pm
by andyh1234
Thanks, it was item (1) that I was missing.

Ive added that and it works!

Andy

Re: Creating and using library stacks

Posted: Wed Aug 31, 2011 4:54 pm
by Klaus
Hi Andy,

you can also "start using stack XYZ" WITHOUT opening it first!
Just supply the correct (relative or absolute) filename of the stack:
...
start using stack "subfolder/theLib.rev"
...

Best

Klaus

Re: Creating and using library stacks

Posted: Wed Aug 31, 2011 5:29 pm
by mwieder
Dixie- technically the preOpenStack handler should reside in the script of the first card of the stack. For stacks with no substacks it doesn't make much difference, but if you have a preOpenStack (openStack, closeStack, openCard, etc...) handler in the script of the mainstack itself then it will get called when a substack opens as well. And this may not be what you want and cause unforseen consequences, forcing you to do ugly things like

Code: Select all

on preOpenStack
  if the name of this stack is the name of stack the mainStack of this stack then
    ...
The first card of the stack is guaranteed to get the preOpenStack (openStack, etc...) messages, and if not handled there it will be passed down to the stack script.