Page 1 of 1

Library stacks using handlers from one another

Posted: Wed Dec 25, 2019 3:21 pm
by kaveh1000
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?

Re: Library stacks using handlers from one another

Posted: Wed Dec 25, 2019 4:18 pm
by bogs
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?

Re: Library stacks using handlers from one another

Posted: Wed Dec 25, 2019 4:22 pm
by kaveh1000
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?

Re: Library stacks using handlers from one another

Posted: Wed Dec 25, 2019 4:38 pm
by bogs
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.

Re: Library stacks using handlers from one another

Posted: Wed Dec 25, 2019 4:43 pm
by Klaus
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

Re: Library stacks using handlers from one another

Posted: Wed Dec 25, 2019 5:20 pm
by kaveh1000
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?

Re: Library stacks using handlers from one another

Posted: Wed Dec 25, 2019 5:23 pm
by Klaus
When you "start using xyz" then all open stacks can access its scripts, so no need to take further actions! 8)

Re: Library stacks using handlers from one another

Posted: Wed Dec 25, 2019 7:09 pm
by SparkOut
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.

Re: Library stacks using handlers from one another

Posted: Wed Dec 25, 2019 7:49 pm
by bogs
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.

Re: Library stacks using handlers from one another

Posted: Wed Dec 25, 2019 7:58 pm
by kaveh1000
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.