Protecting stacks
Richard Gaskin
ambassador at fourthworld.com
Sat Nov 3 13:18:19 EDT 2012
Francis Nugent Dixon wrote:
> Hi from Beautiful Brittany,
>
> Mark wrote :
>
>> and even if it is part of a standalone it isn't too difficult
>> to detach the stack and save it as a stackfile again.
>
> Mark, That intrigued me ! Could you clarify that statement
> a little, or point me to a link which will explain how to
> do this.
Stacks are data, and LC handled both textual and binary data with ease.
When you open a stack from disk, what you "go" to is a blob of binary
data in memory.
This allows us to also "go" to stacks that have no on-disk copy, such as
when obtained via HTTP:
go url "http://www.domain.com/somestack.livecode"
Similarly, you can put a stack into the clipboard and "go" to it:
copy stack "SomeStack"
put the clipboardData["objects"] into tStack
go stack tStack
Taking this further, you can stuff stacks into custom properties:
put url "binfile:MyDrive/MyStack.livecode" into tData
set the uStoredStack of btn 1 to tData
And you can use that to recreate the stack file again:
put the uStoredStack of btn 1 into \
url "binfile:MyDrive/MyStack.livecode"
You can also clone stacks, and when cloned they have no filename but you
can set this to save them, useful for making documents:
clone stack "DocTemplate"
set the filename of it to "MyDrive/MyStack.livecode"
save stack it
In addition to the clone command, you can also turn a substack into a
mainstack by setting its mainstack property to itself, or move a
substack to become a substack in a different stack file by setting its
mainstack property to that other stack file.
And as with any other data, you can compress stacks so they use less
storage space, and can run them through encrypt and decrypt to protect
them on disk.
Or as Stephen suggested, if you store them in custom props you can
protect only the parts you need protected (the stack data in the props),
while leaving the stack containing them in its native format so it's
easy to work with in the IDE.
There are a great many useful things that can be done with stacks both
in memory and on disk and everything in between. And with the
simplicity and robustness of custom properties, they're often a favorite
file format of mine for data which would otherwise be cumbersome to parse.
Stack files are specially well-suited for hierarchically ordered data of
minimal depth, as they load faster in many cases than running an array
through arrayDecode.
For more on using stack files for storage, see:
<http://lists.runrev.com/pipermail/use-livecode/2002-July/006158.html>
--
Richard Gaskin
Fourth World
LiveCode training and consulting: http://www.fourthworld.com
Webzine for LiveCode developers: http://www.LiveCodeJournal.com
Follow me on Twitter: http://twitter.com/FourthWorldSys
More information about the use-livecode
mailing list