Guidelines for Using Stacks on Web Back End
Andre Garzia
andre at andregarzia.com
Tue Aug 14 22:42:53 EDT 2007
Me guessing here,
when your CGI runs, revolution creates a stack named "script" and put the
content of your cgi script in there for it to run. This alone allows you to
have temporary props and stuff, but you can't save it.
To use an external stack as a data storage, I use the format:
go invisible stack "mySweetStack.rev"
because that opens the stack but do not put any of it's scripts and stuff
into the message path. If my stack has no code in it and will be used only
for data, then this is what I use.
If my stack is a library stack and I want to put its script on the message
path, I use the form:
start using stack "mySweetLibraryStack.rev"
I also make use of backscripts and front scripts if I need them. This way
you can have a inheritance-like mechanism.
For example: in the EasyCGI libraries we have a function called cgiOutput
that will simply flush the argument we pass to it back to the browser,
you're supposed to generate the html or text on your own. This stack is put
into use by using the start using form. This function does not touch it's
arguments, it just pass them to the browser.
If I want to do a simple templating engine that uses 'merge' to put data
into placeholders, I can simply use a frontscript to override cgiOutput so
that it merges the content and then pass the message on to the rest of the
path where it will eventually reach cgiOutput of EasyCGI and then be flushed
to the browser.
The message path is your friend, use it wisely and you'll be very
productive.
One thing, when you're opening stacks using 'go' or 'libraryStack', you pass
the file reference to it but when you're trying to access a control or a
custom property after the stack is open, you need to use the stack name to
refer to it. Trying to do something like
get the sweetprop of stack "mySweetStack.rev"
will not work, you need to use the stack name (actually, I don't know if it
will work). On CGIs, your script is a part of stack 'script', trying to do
stuff such as save this stack will not work. If you want to save a stack you
need to tell exact what you want like save stack 'myStack' as 'myStack.rev'
or something like that.
Some commands don't work on CGIs, most notably the go commands for moving to
some card, you can't do go next card in CGIs, if you need to refer to some
control on some card you need to use long ids or full references such as fld
"Artist" of card 2 of stack "artists".
Hope this help
andre
More information about the use-livecode
mailing list