MessagePath - backScripts question

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
stam
Posts: 2682
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

MessagePath - backScripts question

Post by stam » Mon Feb 14, 2022 2:52 am

Hi all,

I presume it is possible to insert the script of stack <xxx> into back for any number of stacks and handlers from all of these stacks would be accessible to each other?

Is there any significant disadvantage to doing this?

many thanks
Stam

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9662
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: MessagePath - backScripts question

Post by dunbarx » Mon Feb 14, 2022 4:21 am

Hi.

Inserting a script into back places it just before the engine. If you place more than one script into back, they order themselves with the most recently inserted placed in front of any others previously inserted.

So it is just a way to manually adjust the scripts in the message path. There is nothing bad about doing that, nor how many you decide you want to put there. But know that since you are custom building your own "back" of the message path, you have to remember the order of the ones you put there.

Craig

stam
Posts: 2682
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: MessagePath - backScripts question

Post by stam » Mon Feb 14, 2022 10:24 am

Thanks Craig, that is very good to know.
I had assumed that rather than an another series of hierarchical steps in the message path, this might be a 'bubble' with no internal hierarchy, clearly i was very wrong!
There will be a place for me to use this, but not as i had originally guessed - thank you.

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1209
Joined: Thu Apr 11, 2013 11:27 am

Re: MessagePath - backScripts question

Post by LCMark » Mon Feb 14, 2022 4:57 pm

@stam: I think Craig's characterization may be slightly misleading...

Whenever a message is sent to an object, the message flows through the message path - first through the front scripts, then to the object targetted by the call, then up the ownership chain, then through the backscripts - the frontscripts and backscripts are always passed through (until a matching handler is hit) regardless of the target object.

So if you have a stack called Foo with script, whose script is inserted into back:

Code: Select all

command myBackscriptCommand
   myOtherBackscriptCommand
end myBackscriptCommand
The call to 'myOtherBackscriptCommand' is the same as `send myOtherBackscriptCommand to me` - it will still go through all frontscripts, then to the stack Foo, then through all the backscripts (and yes, this does mean it is possible to engineer things such that a backscript handler is called twice!).

The order of insertion controls the order in which scripts are checked for handlers - however, that is only really a concern if you have multiple scripts in back (or front, or anywhere) with the same name and are using pass. If all handlers have different names, then the backScripts are exactly as you suggest a 'bubble' where order does not matter.

So, for all intents and purposes, you have your 'bubble' - two backscripts can each refer to each others handlers without a problem.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9662
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: MessagePath - backScripts question

Post by dunbarx » Mon Feb 14, 2022 5:01 pm

@LCMArk.

What did I say in my post that was misleading?

I think what Stam meant as a "bubble" was a self-contained mini message path, not part of the ordinary message path. But I never said anything, I believe, that implied such a bubble existed.

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9662
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: MessagePath - backScripts question

Post by dunbarx » Mon Feb 14, 2022 5:08 pm

Hmmm.

Was it "...since you are custom building your own "back" of the message path...?

Perhaps that should have been worded better. I certainly did not mean to imply that a separate message path was created when one inserts a script "into back", but rather that such scripts are placed "just before the engine", but in the only message path we have.

Craig

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1209
Joined: Thu Apr 11, 2013 11:27 am

Re: MessagePath - backScripts question

Post by LCMark » Mon Feb 14, 2022 5:53 pm

@dunbarx: No - it was due to suggesting the order was important - which it isn't if all your handlers are named differently (order *only* matters if you are using handlers with the same name and pass).

I think what Stam was asking was whether a handler in backscript can call any handler in any other backscript - regardless of any order of insertion - which it can. i.e. (Assuming all your handlers in all your backscripts are named differently) The backscripts as a whole can be thought of as collection of handlers which can be called from anywhere, including any other backscript.

[ The reason I said 'misleading' was mainly because Stam had asked whether things worked a certain way, but after your description appeared to think that what he wanted to do wouldn't work, when it would - that's all ].

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9662
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: MessagePath - backScripts question

Post by dunbarx » Mon Feb 14, 2022 6:26 pm

LCMArk.

Ah, I see.

Checking the dictionary, it says:
Objects added to the front or back are placed at the start of the frontScripts or backScripts list: the last-inserted object gets messages first.
This is true, i suppose, but irrelevant, since, as you say, if handlers are named differently, it does not matter where in the "pile" of backScripts a particular handler might be placed. If in a back script at all, they have equal status

So why mention that, unless it is to warn that one might want to be careful to order scripts with similar names? This seems insane to me on the face of it.

Craig

stam
Posts: 2682
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: MessagePath - backScripts question

Post by stam » Mon Feb 14, 2022 9:32 pm

Thanks both, this discussion was very illuminating and while I’m not quite certain how I’ll end up implementing things yet, my take-away is that an easy way to ensure a handler is accessible to other libraries is to put its script in the backscript, caution with namespacing notwithstanding…
Thanks both! (And I hope I understood correctly!)
Stam
Last edited by stam on Tue Feb 15, 2022 1:07 am, edited 1 time in total.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9662
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: MessagePath - backScripts question

Post by dunbarx » Mon Feb 14, 2022 9:58 pm

Stam.

I bet you do indeed get it, but does "name spacing" mean handler naming?

Craig

stam
Posts: 2682
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: MessagePath - backScripts question

Post by stam » Tue Feb 15, 2022 1:06 am

dunbarx wrote:
Mon Feb 14, 2022 9:58 pm
but does "name spacing" mean handler naming?
avoid conflicting names... or for a fancypants clarification, wikipedia is your friend ;) https://en.wikipedia.org/wiki/Namespace

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”