Strangely inconsistent results - dev vs compiled

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
rumplestiltskin
Posts: 223
Joined: Wed Jun 21, 2006 7:33 pm
Contact:

Strangely inconsistent results - dev vs compiled

Post by rumplestiltskin » Mon Dec 21, 2015 11:51 pm

When I use this code:

Code: Select all

 put the filename of this stack into theStartingApp 
...it seems to behave differently when I'm in the standalone app than when I'm in the dev environment. I added a line of debugging to 'answer theStartingApp'.
Screen Shot 2015-12-21 at 1.50.00 PM.png
That's the expected result.

However, when I do this in the standalone app, the filename of the Stack points to my "compiled stack" inside the app package.
Screen Shot 2015-12-21 at 1.54.53 PM.png
To make this even more confusing, I use some code that changes the delimiter to a "/", removes the last item of that variable, and puts in its place "List Management.livecode". That new string is stored in a global variable named "theListManager" and that is the name of the stack to which I may make changes in data. But there is some confusing code behind consistent behavior. If I use :

Code: Select all

go stack theListManager in a new window
...it works whether I'm in the dev environment or the standalone (even though the path to the "List Management.livecode" stack is totally wrong based upon theListManager variable that shows up when checking it within the standalone.
Here's the contents of "theListManager" variable when examined from within the standlone:
Screen Shot 2015-12-21 at 2.11.29 PM.png
There is no stack inside of the app package; the stack that opens is the correct one inside the folder named "Donation Tracker v1.01"

Now, I understand why there would be different behavior although I can't understand why there should be; after all, if this behavior is to be expected, should the compiling process within Livecode take this into account and permit code that's perfectly acceptable within the dev environment perform in the same manner when in the standalone? I can understand the need to use an additional stack to which I may write data so I'm not including this in my question. Maybe I'm using the wrong code but shouldn't code that refers to a free-standing Livecode stack in the dev environment be consistent from dev to standalone (and I haven't checked how this behaves in the Windows version of the standalone yet)?

In addition, the goofy result of the location of the stack referred to in the variable theListManager results in the correct behavior regardless of dev vs standalone when I use the "go stack theListManager in a new window" so I'm seeing different code that should result in an error actually perform properly in the standalone when it actually should not.

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

Re: Strangely inconsistent results - dev vs compiled

Post by mwieder » Tue Dec 22, 2015 12:31 am

Yeah, Macs are weird.
There's no real problem here, but it sure looks confusing.

What the OSX Finder shows you for an application is actually a folder (with a hidden ".app" suffix. i.e., "MyApplication.app" would show up as "MyApplication")
Inside that folder is one named "contents", and within that is one named "MacOS", and *finally* within that is your stack.
So when you're asking for the filename you're getting back the complete path all the way down through the folders to the stack itself.
When you're in the dev environment the stack is a single file, so that's what you see.

If you right-click an application in the OSX Finder you'll get a contextual menu... select "Show Package Contents" and you'll see the folders.

Windows and linux don't do this... when you ask for a filename you'll see the monolithic application, no extra folders involved.

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm

Re: Strangely inconsistent results - dev vs compiled

Post by quailcreek » Tue Dec 22, 2015 1:06 am

Here's what I use to develop x-platform app a=for getting the path.

Code: Select all

put StackPath (filename of this stack) into tPath


function StackPath pPath
   set the itemDelimiter to slash
   
   if the platform = "MacOS" and the environment = "standalone application" then -- if this is a standalone running on a MAC, find the path to the .app file
      
      get the effective filename of stack pPath
      put item 1 to -3 of it into pPath
      put "/_MacOS" after pPath -- depends on where you want to go
      return pPath & "/"
   else
      delete last item of pPath -- remove the last item to get the path to the containing folder
      return pPath & "/"
   end if
end StackPath
Tom
MacBook Pro OS Mojave 10.14

rumplestiltskin
Posts: 223
Joined: Wed Jun 21, 2006 7:33 pm
Contact:

Re: Strangely inconsistent results - dev vs compiled

Post by rumplestiltskin » Tue Dec 22, 2015 1:46 am

I don't see a difference in the results of:

Code: Select all

answer the filename of this stack
and

Code: Select all

answer the effective filename of this stack
If invoked from the dev environment, both provide path/to/this/stack
if invoked from standalone, both provide path/to/this/stack/inside/of/Mac/standalone

I see how you "put item 1 to -3 of it into tPath" so that should return path/to/this/compiled/app (and no further inside the hierarchy). That appears to be the solution as long as I use the rest of your function code.

Might you write a line or two on the differences between "the filename of this stack" and "the effective filename of this stack"?

Thanks very much for your timely assistance.

Regards,
Barry

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

Re: Strangely inconsistent results - dev vs compiled

Post by mwieder » Tue Dec 22, 2015 2:39 am

As far as I know, the "filename" and "effective filename" will return the same thing
*except*
when you try to get that property of a substack.
The filename of a substack is empty, while the effective filename is the path to the main stack.

rumplestiltskin
Posts: 223
Joined: Wed Jun 21, 2006 7:33 pm
Contact:

Re: Strangely inconsistent results - dev vs compiled

Post by rumplestiltskin » Tue Dec 22, 2015 3:27 am

quailcreek,

Tried your suggestion but am getting a bizarre result. Take a look at my code:

Code: Select all

on mouseUp
   global theListManager
   put StackPath (filename of this stack) into theStartingApp
   answer theStartingApp -- added for debugging, be sure to delete before distribution
   set the itemDelimiter to "/"
   put theStartingApp into theListManager
   put "/List Management.livecode" after the last item of theListManager -- NOTICE. NO "/" AT THE END, but it shows up in the next line...
   answer theListManager -- added for debugging, be sure to delete before distribution. Where did the extra slash come from??
   answer the last char of theListManager -- ...WHY IS THERE THIS EXTRA "/" AT THE END??  added for debugging, be sure to delete before distribution
   delete the last char of theListManager -- We have to delete that last "/" but why was it there at the end???
   go stack theListManager in a new window
end mouseUp

function StackPath pPath
   set the itemDelimiter to slash
   if the platform = "MacOS" and the environment = "standalone application" then -- if this is a standalone running on a MAC, find the path to the .app file     
      get the effective filename of stack pPath
      put item 1 to -3 of it into pPath
      -- put "/_MacOS" after pPath -- depends on where you want to go
      return pPath & "/"
   else
      delete last item of pPath -- remove the last item to get the path to the containing folder
      return pPath & "/"
   end if
end StackPath
I'm in the dev environment and, for some reason I can't fathom, the variable "theListManager" ends up with an extra slash at the end although the line

Code: Select all

put "/List Management.livecode" after the last item of theListManager
---doesn't have the slash at the end. Can't figure out where that slash is coming from. Any ideas?

Thanks,
Barry

rumplestiltskin
Posts: 223
Joined: Wed Jun 21, 2006 7:33 pm
Contact:

Re: Strangely inconsistent results - dev vs compiled

Post by rumplestiltskin » Tue Dec 22, 2015 4:06 am

Okay, I think I found my mistake. I was using this line of code:

Code: Select all

put "/List Management.livecode" after the last item of theListManager
but have now changed it to this:

Code: Select all

  put "List Management.livecode" after the last char of theListManager
AFAICT, the "last item" doesn't include the trailing "/" so I was inserting the extra slash and the name of the stack before the trailing slash. Now there's no trailing slash and it opens the stack as expected.

At least in the dev environment, it seems to work properly.

Now to check whether standalone behaves, as well.

Barry

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm

Re: Strangely inconsistent results - dev vs compiled

Post by quailcreek » Tue Dec 22, 2015 4:08 am

Hi,
I always have a slash at the end of the path when I use this function. Try taking out the & "/"

Code: Select all

return pPath
Last edited by quailcreek on Tue Dec 22, 2015 4:17 am, edited 1 time in total.
Tom
MacBook Pro OS Mojave 10.14

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm

Re: Strangely inconsistent results - dev vs compiled

Post by quailcreek » Tue Dec 22, 2015 4:16 am

Barry,
Ah... glad you figured it out! Something else I do, because I hate globals, is I set a userProperty of the stack to the path. Like set the uMainPath of this stack to theListManager. That way I can grab the path anytime I need it without calling the stackPath function. Am I making sense?
Tom
MacBook Pro OS Mojave 10.14

rumplestiltskin
Posts: 223
Joined: Wed Jun 21, 2006 7:33 pm
Contact:

Re: Strangely inconsistent results - dev vs compiled

Post by rumplestiltskin » Tue Dec 22, 2015 5:46 am

quailcreek wrote:Barry,
Ah... glad you figured it out! Something else I do, because I hate globals, is I set a userProperty of the stack to the path. Like set the uMainPath of this stack to theListManager. That way I can grab the path anytime I need it without calling the stackPath function. Am I making sense?
Yes; making sense. :D
Thanks for your help!

Barry

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

Re: Strangely inconsistent results - dev vs compiled

Post by Klaus » Tue Dec 22, 2015 12:04 pm

Hi guys,

why not simply use -> specialfolderpath("resources") ?
That is where all files go when using the "Copy files..." tab in the standalone builder settings!
And this also works in the IDE, too! :D

And remember that we are NOT allowed to write in -> specialfolderpath("engine")
nnd also not in -> specialfolderpath("resources")!
Actually NOWHERE inside of the OS X application package.


Best

Klaus

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

Re: Strangely inconsistent results - dev vs compiled

Post by mwieder » Tue Dec 22, 2015 8:08 pm

Well, yes... maybe we should take a step back and ask the OP *why* you're trying to get the filename of the mainstack inside a standalone app?
Probably there's some better way of solving whatever problem you're attempting.

Post Reply