Page 1 of 2

Simple example of start using stack

Posted: Mon May 27, 2019 9:13 pm
by dntknwjck
New to live code and trying to create a library stack for use with Sqlite.
Have found some information by searching for:livecode library script stack example on the internet.

so if I have:
start using "myLib.livecode"
How do I find if the stack loaded?
What is the proper syntax to call a function in "myLib.livecode" from another stack?
Thanks in advance for your help.

Re: Simple example of start using stack

Posted: Mon May 27, 2019 9:54 pm
by bogs
dntknwjck wrote:
Mon May 27, 2019 9:13 pm
How do I find if the stack loaded?
You could look in the openStacks. Put a button on your main stack, and in mouseUp put -

Code: Select all

on mouseUp
   answer the openStacks
end mouseUp
obviously, you would want to not use an answer dialog in a real application, this is just an example. If you are running in the IDE, you will see something like this -
Selection_001.png
myLib is the #3 stack!
Selection_001.png (10.21 KiB) Viewed 6894 times
Here is a pretty good explanation of how library stacks work -
http://livecode.byu.edu/messages/libraries.php
What is the proper syntax to call a function in "myLib.livecode" from another stack?
Your question is pretty literally the answer. Look up call in the dictionary.

Re: Simple example of start using stack

Posted: Mon May 27, 2019 9:57 pm
by jmburnod
Hi dntknwjck,
If I believe LC dictionary (no tested)
The start using command places a stack's script into the message path after the current stack and before any objects in the backScripts.
You may call your function by its name

Code: Select all

put myFunction(something) into tVar
Best regards
Jean-Marc

Re: Simple example of start using stack

Posted: Mon May 27, 2019 10:50 pm
by SparkOut
A slight correction
start using "myLib.livecode"
should be

Code: Select all

start using stack "myLib.livecode"

Re: Simple example of start using stack

Posted: Mon May 27, 2019 11:53 pm
by dntknwjck
Thanks to all. I now have a working script file.

Re: Simple example of start using stack

Posted: Tue May 28, 2019 9:33 am
by LiveCode_Panos
Hello all,

See also the "libraryStack" message in the Dictionary.

Kind regards,
Panos
--

Re: Simple example of start using stack

Posted: Tue May 28, 2019 11:00 am
by bogs
Thanks Panos, I had forgot to mention that with the BYU link :oops:

Re: Simple example of start using stack

Posted: Tue May 28, 2019 6:50 pm
by dntknwjck
Here is a simple example of script stack
in the resource folder put this as file testing.livecodescript
script "testing"

command doSomething
answer "The command doSomething in test.livecodescript has executed"
end doSomething

put his in a button's mouseup event:
on mouseUp
--resources is /home/user on Linux
start using stack (SpecialFolderPath("resources") & "/testing.livecodescript")
doSomething
end mouseup

Tested this on Linux Mint 18.3 and it was successful

Re: Simple example of start using stack

Posted: Tue May 28, 2019 6:57 pm
by Klaus
dntknwjck wrote:
Tue May 28, 2019 6:50 pm
...
on mouseUp
--resources is /home/user on Linux
start using stack (SpecialFolderPath("resources") & "/testing.livecodescript")
doSomething
end mouseup
To be precise in the IDE -> SpecialFolderPath("resources")
points to the folder in which the current stack resides, the one that executes the script.
In a standalone to the folder where you added all of your resources via the "Copy files" tab in then "Standalone Application Settings".

This way we can use this SpecialFolderPath as well in the IDE as in a standalone, works on ANY platform!

Re: Simple example of start using stack

Posted: Tue May 28, 2019 7:56 pm
by bogs
Klaus wrote:
Tue May 28, 2019 6:57 pm
This way we can use this SpecialFolderPath as well in the IDE as in a standalone, works on ANY platform!
Unless the user has made changes (on linux, anyway, not sure about win and mac). There was a thread recently that highlighted just such an issue, where the user changed their 'Documents' folder (linux) to just plain "docs", which specialFolderPath failed to notice.

Note - I don't think this applies to, in this case, ("resources"), but I am still a big fan of building the path manually.

Ah yes, this was the thread I was thinking of: https://forums.livecode.com/viewtopic.p ... ilit=linux

Re: Simple example of start using stack

Posted: Tue May 28, 2019 8:22 pm
by Klaus
Hi Bogs,

yes, I remember that thread, but not using Linux, I did not pay much attention to it.
bogs wrote:
Tue May 28, 2019 7:56 pm
Note - I don't think this applies to, in this case, ("resources")...
Exactly, this is a special case, I think.
bogs wrote:
Tue May 28, 2019 7:56 pm
... but I am still a big fan of building the path manually.
Yep, I bet you HAVE TO, as a Linux user! :D


Best

Klaus

Re: Simple example of start using stack

Posted: Tue May 28, 2019 8:38 pm
by bogs
Klaus wrote:
Tue May 28, 2019 8:22 pm
Hi Bogs,

yes, I remember that thread, but not using Linux, I did not pay much attention to it.
bogs wrote:
Tue May 28, 2019 7:56 pm
Note - I don't think this applies to, in this case, ("resources")...
Exactly, this is a special case, I think.
Agreed :wink:
bogs wrote:
Tue May 28, 2019 7:56 pm
... but I am still a big fan of building the path manually.
Yep, I bet you HAVE TO, as a Linux user! :D
Actually, that preference goes back to VS5 on Win, I've seen no reason to change it in all these years :)

The formula I go with is usually the appPath, which I make sure all sub folders are contained within, although if I ever start writing stuff for Mac again, I suppose I'll have to change that up a bit :|

Re: Simple example of start using stack

Posted: Tue May 28, 2019 10:01 pm
by Klaus
Yes, sure. On a Mac these specialfolderpaths are extremely handy, especially regarding the "unusual" folder hierachy of a Mac standalone. And Mac users ususally do not mess (e.g. rename) with the system folders like "Documents". Ok, some do, but then they are usually erm... licked! :-D

Re: Simple example of start using stack

Posted: Tue May 28, 2019 10:26 pm
by bogs
LOL!
Klaus wrote:
Tue May 28, 2019 10:01 pm
some do, but then they are usually erm... licked! :-D
Wonder if that leaves a 'sour taste in the mouth' :P

Re: Simple example of start using stack

Posted: Tue May 28, 2019 11:09 pm
by dntknwjck
To be precise in the IDE -> SpecialFolderPath("resources")
points to the folder in which the current stack resides, the one that executes the script.
In a standalone to the folder where you added all of your resources via the "Copy files" tab in then "Standalone Application Settings".

This way we can use this SpecialFolderPath as well in the IDE as in a standalone, works on ANY platform!
[/quote]

Went back and looked at this:
SpecialFolderPath("resources") points to the folder the current stack is
I had used SpecialFolderPath("/resources") which points to my home directory
Don't know is that is the same for Linux or just my configuration.