Page 1 of 1

Export script from livecode file

Posted: Mon Oct 21, 2013 7:22 pm
by SteveTX
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?

Re: Export script from livecode file

Posted: Mon Oct 21, 2013 7:35 pm
by jmburnod
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

Re: Export script from livecode file

Posted: Mon Oct 21, 2013 7:40 pm
by SteveTX
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.

Re: Export script from livecode file

Posted: Mon Oct 21, 2013 7:48 pm
by Simon
Hi Stevetx,
Would you go as far as adding a new function to the stacks to output text files?

Simon

Re: Export script from livecode file

Posted: Mon Oct 21, 2013 8:03 pm
by SteveTX
No, it must be fully external. the external applications are not readily executable.

Re: Export script from livecode file

Posted: Mon Oct 21, 2013 8:07 pm
by Simon
Suppose a custom property contained all the scripts in the stack?
Any good?

Re: Export script from livecode file

Posted: Mon Oct 21, 2013 8:10 pm
by SteveTX
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.

Re: Export script from livecode file

Posted: Mon Oct 21, 2013 9:56 pm
by Klaus
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

Re: Export script from livecode file

Posted: Tue Oct 22, 2013 12:12 am
by SteveTX
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