Creating reusable code libraries

Gordon Tillman got at mindspring.com
Sun Nov 21 12:53:03 EST 2004


Hi Gordon,

I am fairly new to RR myself, but have been using it a lot lately and 
so I thought I would try and respond to a couple of your questions.

On Nov 21, 2004, at 11:36, <gwalias-rev at yahoo.com> wrote:

> What would be the best way in Rev. to create a
> reusable code library - e.g. to do 3D mathematics?
> Would I create it as a stack script in an otherwise
> empty stack and then load the stack into my apps and
> keep it invisible? Do all stacks have to have a
> toplevel window?

This is how I do reusable code libraries.  I create a very simple stack 
with one card and one or more buttons on the card.  The button script 
contains the reusable code.

In the stack script I have handler for preopenstack and closestack.  
The preopenstack handler just inserts the  button script into the 
message path.  Here is an example.  Suppose you have a button whose 
name is "exportedHandlers" that lives on the card named "codeLibrary".  
In the preOpenStack method you can have this:

insert the script of button "exportedHandlers" of card "codeLibrary" 
into back

In the closeStack handler you can have

remove the script of button "exportedHandlers" of card "codeLibrary" 
from back

So to use the code in the button, you just have to go invisible to 
stack "name of your stack"

This way the stack is responsible for inserting and deleting code - 
your other stacks that use that code library do not have to know the 
details of accessing the code.


> Can I call a function in an external library from rev.
> e.g. from a windows DLL? If so, how would I do this
> exactly?


You cannot do this directly.  You have to write an external and from 
that external you can call whatever code you need.  I have written one 
that does CRC32 calculations and also puts an icon for any stack into 
the windows task bar so that you can keep it running "faceless" and 
then show it just by clicking on the icon.

The external is built for windows and for Mac OS X.  (Well, the crc32 
part works for OS X).

If you like I can post everything somewhere where you can download it.  
I used Metrowerks codewarrior to build the window's external and used 
Apple's free xtools to build the mac  external.

Regards,

Gordon (no, really!)



More information about the use-livecode mailing list