Creating and using library stacks

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
andyh1234
Posts: 476
Joined: Mon Aug 13, 2007 4:44 pm
Contact:

Creating and using library stacks

Post by andyh1234 » Wed Aug 31, 2011 4:05 pm

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10356
Joined: Wed May 06, 2009 2:28 pm

Re: Creating and using library stacks

Post by dunbarx » Wed Aug 31, 2011 4:10 pm

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.

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Creating and using library stacks

Post by Dixie » Wed Aug 31, 2011 4:41 pm

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
Last edited by Dixie on Wed Aug 31, 2011 5:12 pm, edited 2 times in total.

andyh1234
Posts: 476
Joined: Mon Aug 13, 2007 4:44 pm
Contact:

Re: Creating and using library stacks

Post by andyh1234 » Wed Aug 31, 2011 4:46 pm

Thanks, it was item (1) that I was missing.

Ive added that and it works!

Andy

Klaus
Posts: 14212
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Creating and using library stacks

Post by Klaus » Wed Aug 31, 2011 4:54 pm

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

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Creating and using library stacks

Post by mwieder » Wed Aug 31, 2011 5:29 pm

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.

Post Reply