Confused about Library Stacks

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Confused about Library Stacks

Post by Simon Knight » Thu Sep 23, 2010 9:18 am

While I have played with RunRev for some months I still have not fully understood the possibilities of multiple stacks used within an application. So I thought I would review the tutorial material but in doing so I have become confused.

The lesson named "Getting Started - Objects and Components" contains a figure on the second page
Card structure.jpg
Card structure.jpg (39.61 KiB) Viewed 10640 times
which shows a main stack with two sub stacks. The main stack is labeled as "Splash screen Common libraries & shared functionality". My confusion is that I thought that a common library stack was a stack that was used by the main stack and its substacks and was invoked in code with a "uses command". The uses command placing the routines in the "so called" library stack in the message path after the main stack which means that all the sub stacks may use the routines held in the library stack.

Please will someone set me straight? :?:

best wishes

Simon
best wishes
Skids

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

Re: Confused about Library Stacks

Post by Klaus » Thu Sep 23, 2010 10:36 am

Hi Simon,

you almost answered your own question!
...
The main stack is labeled as...
...
Yep, this is just a badly chosen LABEL!

A mainstack is of course some kind of library since all substacks can access its scripts and it is "automatically" used,
but only for its substacks. Other stacks can not access its scripts UNLESS you "start using" this mainstack.

I hope you are a bit more erm... less confused now :)


Best

Klaus

Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Re: Confused about Library Stacks

Post by Simon Knight » Thu Sep 23, 2010 2:17 pm

Thanks Klaus for your reply. I am now more certain :)

best wishes
Simon
best wishes
Skids

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Confused about Library Stacks

Post by FourthWorld » Thu Sep 23, 2010 3:19 pm

This may also help:


Extending the Revolution Message Path
An introduction to using Libraries, FrontScripts, BackScripts and Behaviors
in Runtime Revolution's RevTalk Programming Language
http://www.fourthworld.com/embassy/arti ... _path.html
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Re: Confused about Library Stacks

Post by Simon Knight » Fri Sep 24, 2010 10:35 am

Thank you for the links and help which I am attempting to digest. I have also been looking at one of BlueMango Training's videos which recommends creating a number of main stacks with sub stacks and using them to group code in logical functional areas.

If I follow this advice and have for example have four main stacks called Splash, Application, Program and Components plus a library stack called libUsefulRoutines how do I ensure that all the routines and assets are "visible" to all the stacks that need them? Is it sufficient to place a list of "start using" commands in the first tack to loaded i.e. the splash stack?

tia
Simon
best wishes
Skids

Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Re: Confused about Library Stacks

Post by Simon Knight » Fri Sep 24, 2010 7:14 pm

Hi Again,

I have spent some time attempting to put a structure for a new application together. My aim is to have a splash stack that opens the other main stacks that do the real work.

The code listed below is in the PreOpenStack of the Splash stack. My first attempts with the command 'start using "stackname" ' failed because I omitted the full path to the stack on my hard drive. This failure led me to add the other stacks as stack items listed in the build settings of my splash stack. At this point the three start using commands stopped throwing an error but the stacks are not always being loaded (why? :?: ) as they do not always appear in the browser.

Code: Select all

On preOpenStack
   
   start using "Wisper_Program_UI"
   start using "Wisper_Application"
   start using "Wisper_Components"
   
end preOpenStack


Next I added a single open command to the routine:

Code: Select all

On preOpenStack
  
   set the itemDel to slash  
   put (item 1 to -2 of the effective filename of this stack) & "/" into tFilePath
   open stack tFilePath &  "Wisper_Program_UI" in new window
   start using "Wisper_Program_UI"
   start using "Wisper_Application"
   start using "Wisper_Components"
   
end preOpenStack
The addition of this command seems to ensure that all three stacks are displayed in the application browser (why? :?: ) but it does not actually open the stack (why? :?: ).

My aim is to be able to double click on the splash stack and cause all the stacks associated with the application to be loaded into the IDE. Have I done something wrong and/or is there a better way?
best wishes
Skids

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

Re: Confused about Library Stacks

Post by Klaus » Sat Sep 25, 2010 10:28 am

Hi Simon,

"start using xyz" does not actually open that stack as the "go stack xyz" command does.
This command will "only" load the scripts of these stack(s) into memory, so they might
not appear in the "application browser".

To have them appear there and being able to edit them, you will need to actually
open them via the "Open" menu or doubleclick in the IDE.


Best

Klaus

P.S.
You can always check the stacks you started using with a "answer the stacksinuse" in the message box or button.

Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Re: Confused about Library Stacks

Post by Simon Knight » Sat Sep 25, 2010 11:25 am

Klaus,
Thanks for your clarification. I have just re-read section 2.2.3/4/5 of the the user guide and realise that there is a difference between being loaded and being open.

Is the following correct ?

I have a button on a sub-stack that wishes to call a library function stored on a sub-stack of a different main stack. I need to place a start using "library sub-stack name" anywhere in the "stack file" that holds the sub-stack that is attempting to call the library function?

In other words if I place the start using command in the open stack routine of the main stack, do the functions of the library stack referred to become available to all the sub-stacks of the main stack (because the library sub-stack is now placed after the main stack in the message path).

From the dictionary:
The start using command places a stack's script into the message path after the current stack and before any objects in the backScripts.

Also, am I correct in thinking that referring to a main stack with the "start using" command does not mean that any sub-stacks of the main stack will be placed in the message path.

Thanks
best wishes
Skids

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

Re: Confused about Library Stacks

Post by Klaus » Sat Sep 25, 2010 12:11 pm

Hi Simon,
Simon Knight wrote:Klaus,
Thanks for your clarification. I have just re-read section 2.2.3/4/5 of the the user guide and realise that there is a difference between being loaded and being open.
Yep!
Simon Knight wrote:Is the following correct ?

I have a button on a sub-stack that wishes to call a library function stored on a sub-stack of a different main stack. I need to place a start using "library sub-stack name" anywhere in the "stack file" that holds the sub-stack that is attempting to call the library function?
Yes!!
But you can also "start" this substack from some other stack that might get loaded first:
start using stack "name of substack here" of stack "mainstack here"
Simon Knight wrote:In other words if I place the start using command in the open stack routine of the main stack, do the functions of the library stack referred to become available to all the sub-stacks of the main stack (because the library sub-stack is now placed after the main stack in the message path).
Yes, but also to ALL open and "to be opened during this session" stacks!
Simon Knight wrote:From the dictionary:
The start using command places a stack's script into the message path after the current stack and before any objects in the backScripts.

Also, am I correct in thinking that referring to a main stack with the "start using" command does not mean that any sub-stacks of the main stack will be placed in the message path.
You are correct. Only the scripts of stacks that you explicitely "start using" will be available to all stacks.
Simon Knight wrote:Thanks
You're welcome :)

Best

Klaus

Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Re: Confused about Library Stacks

Post by Simon Knight » Sat Sep 25, 2010 12:54 pm

Hi Klaus et al,

I have created three small stacks that help me (and I hope others) to understand how library stacks interact with other stacks. With luck it should be attached here.
LibraryStackScopeTest.zip
Crude demo of Library stack with two main stacks
(4.34 KiB) Downloaded 456 times
Oh its a zip archive.

Many thanks for the help
best wishes
Skids

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

Re: Confused about Library Stacks

Post by mwieder » Mon Oct 11, 2010 6:31 pm

Nicely done - and nice use of the try/catch construct to catch the exceptions.

Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Re: Confused about Library Stacks

Post by Simon Knight » Tue Oct 12, 2010 9:09 pm

Thanks for your kind comments.
best wishes
Skids

Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Re: Confused about Library Stacks

Post by Simon Knight » Thu Nov 20, 2014 10:45 am

Hi,

I needed to remind myself how library stacks could be used and revisited my old demo code. I found it a little confusing so have updated it.

20 Nov 2014

best wishes

Simon Knight
Attachments
ScopeTestDemoUpdatedNov14.zip
Zip Archive of three stacks and a text readme
(8.58 KiB) Downloaded 274 times
best wishes
Skids

Post Reply