Library stacks using handlers from one another

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 539
Joined: Sun Dec 18, 2011 7:23 pm
Contact:

Library stacks using handlers from one another

Post by kaveh1000 » Wed Dec 25, 2019 3:21 pm

Hi all

I am working on splitting a large code, as discussed here:

https://forums.livecode.com/viewtopic.php?f=9&t=33461

into several library stacks. But some of the code is used in multiple areas of the current large script. I want to find the best way of implementing that.

As an example, suppose that i have a button that says "clean text", that carries out a large number of operations in a text field. It will call a library stack to clean spacing, then call another to color text. These libraries both need to refer to another library called, say, text scripts.

What is the right tactic to allow the libraries to have access to other libraries?
Kaveh

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Library stacks using handlers from one another

Post by bogs » Wed Dec 25, 2019 4:18 pm

I'm not sure my understanding is complete in this area, but doesn't "start using ..." ensure the stack (and therefore, its handlers/functions/etc) is placed in the message path?
Image

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 539
Joined: Sun Dec 18, 2011 7:23 pm
Contact:

Re: Library stacks using handlers from one another

Post by kaveh1000 » Wed Dec 25, 2019 4:22 pm

Thanks Bogs. So suppose I have two stacks and each needs access to handlers in the other, do you think I can say "start using stack A" in the openstack of B and vice versa?
Kaveh

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Library stacks using handlers from one another

Post by bogs » Wed Dec 25, 2019 4:38 pm

I have no idea, but why would you call it from a sub stack instead of calling them all from the main stack? When I said -
bogs wrote:
Wed Dec 25, 2019 4:18 pm
'm not sure my understanding is complete in this area...
I wasn't kidding. To make sure I'm being clear as I can be, I am responding to -
kaveh1000 wrote:
Wed Dec 25, 2019 3:21 pm
splitting a large code, as discussed here:
https://forums.livecode.com/viewtopic.php?f=9&t=33461
into several library stacks
From what I get about library stacks, you just call them by putting 'start using [stack name]'. Me, I'd put that right into the preOpenStack for your main stack to ensure they are loaded and ready for use.

Of course, I could be completely off, again, I don't use them a lot.
Image

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

Re: Library stacks using handlers from one another

Post by Klaus » Wed Dec 25, 2019 4:43 pm

Hi friends,
bogs wrote:
Wed Dec 25, 2019 4:38 pm
From what I get about library stacks, you just call them by putting 'start using [stack name]'. Me, I'd put that right into the preOpenStack for your main stack to ensure they are loaded and ready for use.
that is correct!


Best

Klaus

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 539
Joined: Sun Dec 18, 2011 7:23 pm
Contact:

Re: Library stacks using handlers from one another

Post by kaveh1000 » Wed Dec 25, 2019 5:20 pm

Thank both. Attached is a diagram to show what I mean. I have a main stack that as you say opens the 3 Lib files and says "Start using..." for each Lib. But I want each lib to be able to access handlers and functions from there other Libs. So can I have an openstack in each of these Libs to "Start using" the other two Libs?
Attachments
lib.png
Kaveh

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

Re: Library stacks using handlers from one another

Post by Klaus » Wed Dec 25, 2019 5:23 pm

When you "start using xyz" then all open stacks can access its scripts, so no need to take further actions! 8)

SparkOut
Posts: 2949
Joined: Sun Sep 23, 2007 4:58 pm

Re: Library stacks using handlers from one another

Post by SparkOut » Wed Dec 25, 2019 7:09 pm

You can also check whether you library stack name is in the stacksInUse and only start using if it's not there. I don't think it makes a difference if you try to "start using" a stack more than once but, just one of those tidy things.

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Library stacks using handlers from one another

Post by bogs » Wed Dec 25, 2019 7:49 pm

Here is the BYU page on libraries, the picture shows you where a library sits in the message path and gives examples of the various posts in this thread.
Image

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 539
Joined: Sun Dec 18, 2011 7:23 pm
Contact:

Re: Library stacks using handlers from one another

Post by kaveh1000 » Wed Dec 25, 2019 7:58 pm

Thanks Bogs. Actually the BYU pages are the best, and I did read them. What I was unsure of was whether each library could also access any other libraries that are open. It seems they can. I will keep working and come back if there are more questions.
Kaveh

Post Reply