Put a stack into a variable?

Richard Gaskin ambassador at fourthworld.com
Sat Jun 14 13:51:59 EDT 2014


Mike Bonner wrote:

> On the clipboard data question.. is it possible to compress the data in
> memory on one end and decompress it on the other?  (talking about lc server
> interactions)  Am now also wondering if it would be worthwhile to have rev
> be able to load and decompress stack files on the fly.

LiveCode's built-in support for gzip is well suited for this:

on mouseUp
    GoStack "http://www.fourthworld.net/revnet/devolution/4W_gzipper.mc.gz"
end mouseUp


on GoStack pURL
    put url pURL into tStackData
    -- Try to decompress .gz files:
    if char -3 to -1 of pURL = ".gz" then
       try
          put decompress(tStackData) into tStackData
       catch tErr
          answer "Corrupted gzip data in URL "&quote& pURL &quote
          exit to top
       end try
    end if
    --
    go stack tStackData
end GoStack

The URL there may also be of interest: it's a simple LC stack I keep in 
my Plugins folder that will compress any file dropped onto it, and add a 
.gz suffix to the compressed copy.


Side note: Why is it that some LC commands (like decompress) throw an 
error when they fail, but others (like decrypt) set "the result"?

Is there a rule somewhere that I missed that would make it easy for 
scripters to anticipate when "try" is necessary?


> As far as getting stacks from a database, shouldn't it be possible to
> have a database interface script, and have actuall stack files saved
> to a db that can be requested with go stack "
> http://wheres.the.stack.com/grabstack?which=stackname.livecode", query
> the db and send the stackfile back intact?

Yes, in any context where you can read from disk (pretty much anytime 
unless you have the securityPermissions set to disallow it) reading the 
stack file as binary allows you to store that data in a way that you can 
later "go" to it.

That's one of the oddities about "go url" - when I write:

   put url tUrlToSomeStackFile into tVar

...I can later write:

   go tVar

...and it'll go just as if I'd passed a file name rather than a binary 
blob of stack data.

But once we "go" to a stack contained a variable, it becomes unpacked 
into a form that's no longer reachable within the language, except to 
write it to disk (or get parts of it in a nearly duplicated strange 
format with clipboardData["objects"]).

-- 
  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  ____________________________________________________________________
  Ambassador at FourthWorld.com                http://www.FourthWorld.com




More information about the use-livecode mailing list