Export script from livecode file

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
SteveTX
Posts: 170
Joined: Sun Jan 17, 2010 9:00 pm

Export script from livecode file

Post by SteveTX » Mon Oct 21, 2013 7:22 pm

I am interested in exporting the script of a stack of an external livecode file to textfile. This is so I can simply see changes in it on git which does text file processing. Livecode files are a mix of binary resources and text. I can open the file as text, but I am more specifically wanting to process the binary and extract the scripts for the mainstack and substacks and simply save them to text file. I can open external livecode files with 'go to stack' but is there a way to simply read the scripts without executing the stacks in livecode?

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Export script from livecode file

Post by jmburnod » Mon Oct 21, 2013 7:35 pm

Hi steveTX,

I'm not sur I understand what you want but for this part
is there a way to simply read the scripts without executing the stacks in livecode?
You can try

Code: Select all

set the lockmessages to true
Best regards
Jean-Marc
https://alternatic.ch

SteveTX
Posts: 170
Joined: Sun Jan 17, 2010 9:00 pm

Re: Export script from livecode file

Post by SteveTX » Mon Oct 21, 2013 7:40 pm

I want to build a command line application that reads the livecode file and spits out the scripts inside it to a text file. I want to do this without reading the livecode file as text.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Export script from livecode file

Post by Simon » Mon Oct 21, 2013 7:48 pm

Hi Stevetx,
Would you go as far as adding a new function to the stacks to output text files?

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

SteveTX
Posts: 170
Joined: Sun Jan 17, 2010 9:00 pm

Re: Export script from livecode file

Post by SteveTX » Mon Oct 21, 2013 8:03 pm

No, it must be fully external. the external applications are not readily executable.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Export script from livecode file

Post by Simon » Mon Oct 21, 2013 8:07 pm

Suppose a custom property contained all the scripts in the stack?
Any good?
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

SteveTX
Posts: 170
Joined: Sun Jan 17, 2010 9:00 pm

Re: Export script from livecode file

Post by SteveTX » Mon Oct 21, 2013 8:10 pm

This isn't about changing the target file. This is about being able to arbitrarily extract the scripts of external livecode files and dump them to text.

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Export script from livecode file

Post by Klaus » Mon Oct 21, 2013 9:56 pm

Hi Steve,

as simple as:
...
put the script of stack "/Users/klaus/Documents/RRMC/cool_stack.livecode" into tStackScript
put the script of cd 1 of stack "/Users/klaus/Documents/RRMC/cool_stack.livecode" into tCardScript
put the substacks of stack "/Users/klaus/Documents/RRMC/cool_stack.livecode" into tSubstacks
put the num of btns of cd 1 of stack "/Users/klaus/Documents/RRMC/cool_stack.livecode" into tNumbOfButtonsOfCd1
etc...
etc...
### extract whatever you like, you get the picture

## Important, after you are done:
close stack "/Users/klaus/Documents/RRMC/cool_stack.livecode"
...
:D

You can access properties of closed stack files without executing any script!

If that is what you mean.


Best

Klaus

SteveTX
Posts: 170
Joined: Sun Jan 17, 2010 9:00 pm

Re: Export script from livecode file

Post by SteveTX » Tue Oct 22, 2013 12:12 am

Thanks Klaus, here is a working stack.

Code: Select all

global theStack, theCard, theOutfile, theData

on preOpenStack
   put $1 into theStack
   put $2 into theCard
   set the visible of this stack to false
   set the destroyStack of this stack to true
   set the destroyWindow of this stack to true
end preOpenStack

on openStack
   if theCard is empty then 
      pullStack
   else
      pullCard
   end if
   close stack theStack
   open file theOutfile for write
   write theData to file theOutfile
   close file theOutfile
   quit
end openStack

command pullCard
   put the script of card theCard of stack theStack into theData
   put (theCard & ".txt") into theOutfile
end pullCard

command pullStack
   put the script of stack theStack into theData
   put (theStack & ".txt") into theOutfile
end pullStack

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”