File paths in web-based stacks
devin_asay at byu.edu
Fri Nov 3 11:49:57 CST 2006
I am teaching my students about launching stacks from a web server
using 'go stack url ...'. I mentioned to them that they can launch
any stack on any web server as long as they know the URL (and
assuming permissions are set correctly, etc.) But I ran into a
conundrum that I'm trying to figure out.
When I write stacks that are intended to run from the web, I avoid
using relative file paths for accessing external resources, instead I
store the base URL in a custom property and make everything relative
to that. But what if, as I told my students, one of them is sitting
at home and launches an example stack from our classroom discussion
from my web server, and one of the things in that example stack is a
handler that sets the defaultFolder to the folder containing the
current stack? You know the drill...
set the itemDelimiter to "/"
get the [effective] filename of this stack
set the defaultFolder to item 1 to -2 of it
Of course, when you read your stack from a web server, it resides
completely in memory, so the filename is empty. So the routine above
So I started thinking, could I write a handler and put it in a
library or frontscript that would check to see if the called stack
sets the defaultFolder, and if it does, would somehow substitute a
base URL for the defaultFolder? Then every time a relative file path
was used in the called stack it would look instead at the URL. I can
see two problems with this:
1. How to thoroughly search the stack for the presence of the command
'set the defaultFolder' (or 'set the folder' or 'set the directory').
Is there a 'search all scripts in a stack' command? It's obviously
possible, because the Search and Replace utility in the IDE can do
that. (Yes, I know I can loop through the entire stack and check
every script, but is there something that already does this?)
2. How to intercept references to file paths in handlers and "recast"
them as URLs. Short of adding decision structures in all of the
stacks I might want to launch from a server, which would defeat the
purpose, is there any conceivable way to do this from a calling stack
or compiled app?
Before I spend hours trying to script this, what do you all think? Is
such a thing feasible? A pipe dream? So blatantly obvious that you're
all snickering at me?
Thanks for any ideas.
Humanities Technology and Research Support Center
Brigham Young University
More information about the use-livecode