Sharing Reusable code - guidance
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Sharing Reusable code - guidance
I am looking for advice on application design with the goal of code reuse. I am working on a project that will produce a few reusable libraries that I will want to use in other projects. For example one library is for generic database access while another library is for web service access.
In other environments, I would probably split these two libraries out into code modules. Then in each project that I want to use these libraries I just make a link to the reusable code modules wherever they reside. (Some shared location). It seems that the LiveCode idea is to import these modules (or standalone stacks) into your Main stack. However, then I have to worry about keeping the projects up to date with code fixes.
What is the best way to accomplish code sharing between projects?
Example 1: Save each module as its own stack and then load the stack realtime? If I do this, what happens when I compile and need to distribute the project.
Example 2: Is there some way to reference these external stacks with my resuable libraries in the mainstack so that when they are compiled into an EXE, they are merged together into the application?
Thanks for any suggestions and guidance you can offer.
K
In other environments, I would probably split these two libraries out into code modules. Then in each project that I want to use these libraries I just make a link to the reusable code modules wherever they reside. (Some shared location). It seems that the LiveCode idea is to import these modules (or standalone stacks) into your Main stack. However, then I have to worry about keeping the projects up to date with code fixes.
What is the best way to accomplish code sharing between projects?
Example 1: Save each module as its own stack and then load the stack realtime? If I do this, what happens when I compile and need to distribute the project.
Example 2: Is there some way to reference these external stacks with my resuable libraries in the mainstack so that when they are compiled into an EXE, they are merged together into the application?
Thanks for any suggestions and guidance you can offer.
K
-
- VIP Livecode Opensource Backer
- Posts: 9679
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Sharing Reusable code - guidance
K.
The letter rings a bell...
Craig
The letter rings a bell...
Craig
Re: Sharing Reusable code - guidance
Thanks for the ... vague reply. Any guidance on this is appreciated. This is more about good design and maintenance than it is purely technical.
Any takers, any advise?
Any takers, any advise?
Re: Sharing Reusable code - guidance
kunicki wrote:Thanks for the ... vague reply.
Hi K,
I would go with example 1!
1. Keep your library stacks anywhere on your harddrive
2. Add a script to your mainstack(s) that need to use the libs like this:
Code: Select all
on preopenstack
if the environment = "development" then
put "path/to/your library stack/on your harddisk.livecode" into tLib
else
put the filename of this stack into tLib
## Create the new necessary path to your lib
set itemdel to "/"
delete item -1 of tSttLibackPath
put "/Libs/myLib1.livecode" after tLib
## I used a subfolder "Libs" in my example.
end if
## Now you can:
start using stack tLib
## more preopenstack stuff...
end preopenstack
Get the picture?
Best
Klaus
Re: Sharing Reusable code - guidance
Klaus,
Thank you for this guidance and it is helpful. I am experimenting with this suggestion and it seems logical. Just a followup question:
Does it seem that this concept would also work equally well for mobile development, I assume that when I create my standalone application that all the modules are put together and I just have to load them dynamically from the mainstack using the same directory where the mainstack sits?
Thanks,
K
Thank you for this guidance and it is helpful. I am experimenting with this suggestion and it seems logical. Just a followup question:
Does it seem that this concept would also work equally well for mobile development, I assume that when I create my standalone application that all the modules are put together and I just have to load them dynamically from the mainstack using the same directory where the mainstack sits?
Thanks,
K
Re: Sharing Reusable code - guidance
Hi K,
What dou you mean "...all the modules are put togehter..."?
You can use the standalone builder settings to copy all your lib stacks to the final app bundle.
On iOS you can query:
specialfolderpath("engine")
to get the folder where your standalone and all copied resources/stacks/subfolders are in.
Is that what you mean?
Best
Klaus
I'm not sure to understand?!kunicki wrote:... I assume that when I create my standalone application that all the modules are put together and I just have to load them dynamically from the mainstack using the same directory where the mainstack sits?
What dou you mean "...all the modules are put togehter..."?
You can use the standalone builder settings to copy all your lib stacks to the final app bundle.
On iOS you can query:
specialfolderpath("engine")
to get the folder where your standalone and all copied resources/stacks/subfolders are in.
Is that what you mean?
Best
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 7242
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Sharing Reusable code - guidance
Basically, the work flow would be to "start using" your library stack(s) during development. That way you only need to keep a single library updated and all your development stacks will use the latest one dynamically.
When it is time to build a standalone, use the Stacks pane in the Standalone Settings dialog to add your library stack as an inclusion. When you build, the library stack will be copied to the standalone. It's pretty painless.
When it is time to build a standalone, use the Stacks pane in the Standalone Settings dialog to add your library stack as an inclusion. When you build, the library stack will be copied to the standalone. It's pretty painless.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Sharing Reusable code - guidance
Thank you all,
You have helped with my question. Sorry for mixing words. I am still getting use to the idea of stacks (as opposed to code modules). So sorry for mixing up the language.
This is fascinating! Every language has their means for handling the dev environment and production and it is nice, the LiveCode way is very straight forward, though it wasn't self-evident from the beginning.
Thanks again,
K
You have helped with my question. Sorry for mixing words. I am still getting use to the idea of stacks (as opposed to code modules). So sorry for mixing up the language.
This is fascinating! Every language has their means for handling the dev environment and production and it is nice, the LiveCode way is very straight forward, though it wasn't self-evident from the beginning.
Thanks again,
K
Re: Sharing Reusable code - guidance
Hi Klaus,
Your code was very helpful for me. However this was only used for one livecode file.
In my case, I use the modules folder to contains all modules and It might have more than one livecode files.
I can use repeat statement to get all files in modules folder and start using them as you mention before. But I thought that is not the good solutions
Could you please give me some solutions how I can use all files in that modules folder ?
Thank you so much
Regards,
Quang
Your code was very helpful for me. However this was only used for one livecode file.
Code: Select all
put "/Libs/myLib1.livecode" after tLib
start using stack tLib
In my case, I use the modules folder to contains all modules and It might have more than one livecode files.
I can use repeat statement to get all files in modules folder and start using them as you mention before. But I thought that is not the good solutions
Could you please give me some solutions how I can use all files in that modules folder ?
Thank you so much
Regards,
Quang
Re: Sharing Reusable code - guidance
Hi Quang,
there are two solutions to your problem:
1. put ALL scripts of your modules into ONE stack.
but maybe this is not possible, so you have to load all modules! see 2.
2. in a standalone you can load up to 50 (FIFTY!) stacks as a library!
So as long as the number of your modules <= 50 you can load all modules in a repeat loop.
Here is a little script that will load ALL available modules automatically, means you do
not have to type all the names of the modules, simply load all existing modules in that folder
Best
Klaus
there are two solutions to your problem:
1. put ALL scripts of your modules into ONE stack.
but maybe this is not possible, so you have to load all modules! see 2.
2. in a standalone you can load up to 50 (FIFTY!) stacks as a library!
So as long as the number of your modules <= 50 you can load all modules in a repeat loop.
Here is a little script that will load ALL available modules automatically, means you do
not have to type all the names of the modules, simply load all existing modules in that folder
Code: Select all
...
put "/Libs/" after tLibFolder
## Store current DEFAULTFOLDER and restore it later, this is good programming style! ;-)
put the folder into tOldFolder
set the folder to tLibFolder
## Get all files in that folder
put the files into tFiles
## This is not necessary if you only have LiveCode files in that folder:
filter tFiles with "*.livecode"
## Now load all libs:
repeat for each line tLib in tFiles
put tLibFolder & tLib into tLibraryStack
start using tLibraryStack
end repeat
## Good style :-)
set the folder to tOldFolder
...
Klaus
Re: Sharing Reusable code - guidance
Hi Klaus,
Thank you so much that was exactly I want ^^
Quang
Thank you so much that was exactly I want ^^
Quang