cross-stack globals, also, file inclusion
Rob Cozens
rcozens at pon.net
Mon Oct 20 10:37:27 EDT 2003
Hello Joel,
>Is there an easy way to set up something similar to file inclusion?
Not that I've found or read of so far...and it would be nice if one existed.
Example: Serendipity Library defines about 265 constants; but much
of the code independence is lost because a constant must be defined
in each script that uses it rather than in a master list that can be
included in each script but maintained in a single copy.
>What I've settled on to deal with this [finding a full path name to
>a subStack] is a handler in the primary stack
>which sets several global variables, including the path of the primary
>stack directory and the sub-directory where the independent sub-stacks
>are stored. [snip]
>
>But I have not been able to come up with a way to get the primary
>stack's path unless the primary stack is already running, because the
>global "stacks" property/function will execute in the environment of the
>independent sub-stack.
"get the effective fileName of this stack" returns the complete path
name of the stack, or its mainStack if its a subStack.
>
>But I want to generalize a bit. I don't want to have to know the name of
>the enclosing directory in advance, and I want to be able to bury
>sub-stacks several directories deep.
>
My approach to generalization is a file search handler that looks for
a stack or file in several different places, depending in part on the
current platform. All file searching is relative to the main
standalone; so the level of nested directories can be as deep or
shallow as the placement of the standalone.
This handler looks for a file by name in the same folder as the
caller, in folders, "PlugIns" & "Data" (or their equivalent in other
supported languages), in the same folder as the caller, on all
platforms. It will also find the file if it is in the
specialFolderPath, "Documents" on Windows or if it is in a folder,
"PlugIns" or "Data", in the same folder as the application bundle on
Mac OS X. [Note: This means it will work with OS X standalones
whether the PlugIns/Data folder is in the Mac OS folder in the bundle
OR in a PlugIns/Data folder in the folder containing the bundle.]
on sdbFindFile theFileName,doThis2It
constant sdbPlugInFolderName=226
constant sdbDataFolderName=227
set the itemDelimiter to "/"
put the effective fileName of this stack into filePath
put theFileName into item -1 of filePath
if there is a file filePath then return doTheDo(filePath,doThis2It)
put sdbMessage(sdbPlugInFolderName) into plugInTranslated
put plugInTranslated into item -1 of filePath
put "/"&theFileName after filePath
if there is a file filePath then return doTheDo(filePath,doThis2It)
put sdbMessage(sdbDataFolderName) into item -2 of filePath
if there is a file filePath then return doTheDo(filePath,doThis2It)
switch (the platform)
case "Win32"
get specialFolderPath("Documents")&"/"&theFileName
if there is a file it then return doTheDo(it,doThis2It)
break
case "MacOS"
if char 1 of the systemVersion < 7 then
delete item -5 to -3 of filePath
if there is a file filePath then return doTheDo(filePath,doThis2It)
put plugInTranslated into item -2 of filePath
if there is a file filePath then return doTheDo(filePath,doThis2It)
delete item -2 of filePath
if there is a file filePath then return doTheDo(filePath,doThis2It)
end if
break
end switch
return true -- = error
end sdbFindFile
function doTheDo filePath,doThis2It
switch (item 1 of doThis2It)
case "open"
do "open file" && filePath && "for" && (item 2 of doThis2It) &&
(item 3 of doThis2It)
get the result
break
case "use"
start using stack filePath
get the result
break
default
get empty
end switch
if it is empty then return false&return&filePath else return true&return&it
end doTheDo
>Hopefully, I can get the paths problem fixed enough before I convert the
>stacks to RunRev that the converted stacks will run under Mac OS X, to
>make the further cross-platform conversions easier.)
Unfortunately, starting with Mac OS X will make cross-platform
conversions more difficult because of the application bundle issue.
There are, for example, restrictions on Windows XP installations that
can require that modifiable files to be placed in the
specialFolderPath, "Documents" (or somewhere other than the folder
containing the standalone).
>
>Pointers anyone? Or should I just write in the manual that people
>clicking on sub-stacks should expect the sub-stacks not to run? (And
>probably use the global-fetching handlers to stop them.)
>
As noted above, "get the effective fileName of this stack" returns
the path to the mainStack if "this stack" is a subStack.
--
Rob Cozens
CCW, Serendipity Software Company
http://www.oenolog.net/who.htm
"And I, which was two fooles, do so grow three;
Who are a little wise, the best fooles bee."
from "The Triple Foole" by John Donne (1572-1631)
More information about the use-livecode
mailing list