Script Only Stacks

by Mark Waddingham on March 3, 2016 14 comments

In LiveCode 8 there is a new option in the (new) ‘New Stack’ submenu:

script-only-select

This new option allows you to create what is called a ‘script only stack’.

Now, ‘script only’ stacks have been around for a quite a few versions now – they were added by me a couple of years ago after much frustration battling with merging updates across three branches for the IDE’s iOS deployment code.

At that time, the library which actually does iOS standalone building was a conventional library stack, it was a binary stackfile with just a stack script. Binary stackfiles are very convenient, but they do cause problems for version control systems such as git. Git is great at dealing with text based files, but will not deal in any way with binary files (beyond allowing you to store and fetch them).

At the time, we were having to patch the iOS standalone builder a lot, and having to do so across 3 separate branches. Not only was this tedious but also highly error prone. So, one day when battling with this particular task I decided to try and do something about it…

The key library stack which was in question was ‘revsaveasiosstandalone.livecode’ which sat (at the time) in the LiveCode IDE open-source repository. Now this stack was a pure library stack – it has no controls, no custom properties, and the only non-default properties were the stack’s script and the stack’s name. Indeed, the values of these properties was the only ‘interesting’ information in the stackfile itself. This observation led to the ‘script only stack’ feature.

In a nutshell, a script only stack is a text file, structured in a specific way, which the engine can load and save as if it were a normal stackfile. When the engine loads a script only stack, it creates a stack with the name specified in text file and sets the stacks script property to the script specified in the text file. When the engine saves a script only stack it reverses this process, writing out a text file containing the stack name and stack script and absolutely nothing else.

The beauty of script only stacks is that they work incredibly well in version control systems like git. Indeed, a script-only stack is nothing more than a source-file in the same vein as you would see if writing code for C++ or a similar lower-level language.

One can see the difference by getting text edit to display the content of a script-only stackfile and a normal binary stackfile:

scriptonlyexample1

On the left you see the content of the stackfile when ‘ExampleLibrary’ is saved as a script only stack; on the right you see the content of the stackfile when ‘ExampleLibrary’ is saved as a normal stack.

The key thing is that the left hand file is a true bonafide text file. It has no sequences of binary data in it which cause git to throw up its hands, and very clearly shows the two bits of information which represent any script only stack: the stack name, and the stack script.

The fact that script only stack files really are just text files is really important! It means you can edit and create them in any text editor you choose, and use any text based processing tool on them (the key thing for git is that you can diff and patch them)! The only thing to remember is that the very first line in the text file has to be of the form:

script "<name>"

With every line after the first being taken as the stack script.

After the initial implementation of the script only stack feature it gained more and more use in the IDE as we converted most of the IDE libraries into script only stacks (things such as revLibURL, revCommon, revBackScript, …). In almost all cases this was trivial, the most we found was that some of the libraries stored constants in custom properties which were easily moved to be in the script. This process meant that more and more of the IDE’s components which did not have a UI part were now much easier to modify. Furthermore the process of reviewing and merging patches to those components as part of our GitHub-based engineering workflow became a great deal less time intensive!

Some time later we made one more tweak to the engine to increase the scope of script-only stacks even further: we made it so that any behavior reference could not only be a button, but also a stack. This final piece of the puzzle meant that even more of the IDE could be factored out into text files. Any component which relied heavily on behaviors could now be split up into a small (binary only) UI part, and a collection of (text only) script only stacks. This model has been the basis for a good part of the restructuring of the IDE which has occurred in the work for LiveCode 8.

So, that’s probably enough background, the question now is how do you use them?

Beyond the new option in the ‘New Stack’ menu in LiveCode 8 there are a couple of pieces of engine syntax which are useful to know about.

The first is the command which you can use to create a script only stack:

create script only stack theName

The second is the property you can use to not only find out if a stack would be saved in script only format, but also to change whether it will be or not:

the scriptOnly of stack theName

I, personally, find the best way to think about script only stacks is to consider the scriptOnly property as controlling the output format of the stackfile. If the scriptOnly property is true, then the stack will be written out as a textfile and anything other than the stack name and stack script will be discarded. If the property is false, then the stack will be written out as a normal stackfile and nothing will be discarded.

Shortly after the initial implementation there was various amounts of discussion about certain aspects of the feature. In particular should the engine control what you can do to a script only stack at runtime? (i.e. only let you change the name and script, and not create any controls or add any other properties), and can we extend the script only format to include more than just the stack script? In both these cases we decided that neither would be appropriate. All things being equal, simplicity is always the best option. Keeping the feature simple and slim means that it is incredibly easy to use and incredibly easy to explain.

I have to say that I think script only stacks (although such a simple idea) have made one of the biggest improvements to our workflow for working on the IDE. Indeed, I’d go as far to say that they are perhaps a big part of why we have been able to accelerate IDE development so much over the last couple of years whilst we have been working on LiveCode 8.

So, if you have projects with lots of library stacks, or lots of behaviors and want to start using version control to help your development process then why not give script only stacks a try – you won’t ever look back!

Mark WaddinghamScript Only Stacks

Related Posts

Take a look at these posts

14 comments

Join the conversation
  • MaxV - March 3, 2016 reply

    I can’t understand: on script stacks I put all the code without messages and it’s executed, or I need to use some special message like “on OpenScript”?

    Mark Waddingham - March 4, 2016 reply

    Hi MaxV. Script only stacks are just a different way to store a stackfile on disk – thus the script should have the same structure as a stack script would. (i.e. script only stacks have nothing to do with the scripts you can write to run through LiveCode server, where you can mix commands and definitions at top-level).

  • Jim Lambert - March 3, 2016 reply

    Thanks for the clear explanation of script only stacks and how to use them.

  • MattyJ - March 3, 2016 reply

    As an ‘SCM guy’ for the last 20 years, this is the thing I’m most excited about with LiveCode 8. The ability to support patching, diffing, a proper history, indexing and perhaps search has suddenly made LiveCode into a tool for professional development teams.

    Add to that a way to formally audit and review code, and if someone should happen to hit on a hot technology, a way to actually sell your technology/code … you might actually be underplaying the ramifications of this new feature.

    Welcome to the 21st century, LiveCode! I’m glad you’re here!

    MaxV - March 16, 2016 reply

    You can diff also normal liveocde stack, here the tool: http://forums.livecode.com/viewtopic.php?f=9&t=26740

  • Torsten - March 4, 2016 reply

    Mark, this seems to be a powerfull feature.
    you wrote: “…we made it so that any behavior reference could not only be a button, but also a stack” Iam very keen to learn, how to set a behavior to a stack instead of a button. What is the syntax?
    Usually I am setting the behavior of an item to the longID of a button. How do I set the behavior to a script only stack?

    Mark Waddingham - March 4, 2016 reply

    Hi Torsten. You can use exactly the same formalism – “set the behavior of myObject to the long id of myStack”. Internally behavior references are stored as a control id / stack (short) name pair – in the case of a behavior pointing to a stack the control id is set to 0. (It was one of those serendipitous things which could be added without having to change the stackfile format as you cannot have a control with id 0!).

  • Mark Smith - March 4, 2016 reply

    So, when is it a good idea for me as a developer to think about using a script only stack? Is it whenever I encounter a situation where I want to create some functionality in livecode that does not require a UI? Or does some other deliberation need to take place?

    Mark Waddingham - March 8, 2016 reply

    Hi Mark. The use-case for script only stacks was to allow them to be easily worked on by a team using source control such as GitHub so I would say this is still the main one for them. Internally we’ve worked to try and separate the IDE into mostly UI only binary stacks, and then script only stack libraries which provide most of the (coded) functionality.

  • IVANOR - March 8, 2016 reply

    HOLA QUIERO SABER SI PUEDO PONER PUBLICIDAD EN MI APP LIVECODE

  • Dave Kilroy - March 9, 2016 reply

    I’m using a mac (el cap) and have found that Text Wrangler, TextMate and Coda are fine as external editors for script-only stacks, whilst TextEdit and Atom (surprisingly) can’t hack it

  • Dave Kilroy - March 24, 2016 reply

    This is a follow up to the issue of bad line endings when working on a script only stack in Atom. Just to note that once I used a “.livecodescript” file extension rather than “.livecode” that I was once again able to use Atom as it’s editor without LiveCode objecting to the line endings…

  • Erik Hansen - July 17, 2016 reply

    Is there a step-by-step guide to converting all of my stacks to script only stacks? Preferably for the less advanced? No idea what patching & diffing are but would like to get on board and start learning. There must be hundreds like me.

  • Ethan - November 1, 2016 reply

    Can a script only stack be used in iOS at runtime or is this feature only viable as a pre-compilation construct ?

Join the conversation

*