Using the livecode standalone engine to run script only stacks on a server

Years ago I set up a license key generator on our server to generate license keys for our products. I used a revolution standalone engine and a plain text LiveCode script that was processed using the engine. Recently, a server upgrade removed a file that was necessary for the old revolution engine to function so I was forced to update my setup. Below is a description of the solution I came up with after a few hours of trial and error.

LiveCode Community Standalone Engine

To process my plain text LiveCode script files I installed the 64-bit version of the community version of the Linux standalone engine on my server. I grabbed the file named Standalone from the Tools/Runtime/Linux/x86-64 folder of a LiveCode Community installation. I renamed the file to <code> on my server and made it executable (e.g. chmod 755).

Note that you need to use the community version as it doesn’t need to be licensed. If you grab the Standalone engine from an Indy or Business installation the engine won’t run because it is unlicensed. Licensing occurs when you build a standalone in LiveCode.

The Script

For the script I created a Script Only Stack which looks like this:

script "clarifykeygenerator"

on startup
   put generateKey(the commandArguments)
   quit
end startup

function generateKey pParams
   ...
   return tKey
end generateKey

The script generates the key, outputs it to STDOUT, and then quits. That’s it.

You can now test this setup on the command line. Assuming the lc-standalone-v8 engine and a keygenerator.livecode script are in the same directory the following call would work:

./lc-standalone-v8 -ui keygenerator.livecode theLicenseCount theLicenseName

Note that when processing parameters in your script, -ui and keygenerator.livecode would be the first two parameters. Actual parameters that your script is interested in processing would start with parameter number 3 in the commandArguments.

Calling The License Generator From PHP

The final thing I had to do was call the license generator from PHP. You can do that using the exec() function. Below is some sample code. Note that I am base64 encoding the name. If the name for the license has accented characters in it then PHP will throw an error if you try to include it in the exec() function. Just make sure you call base64decode in your LiveCode script that generates the license key.

$license_generator = '/usr/home/name/public_html/cgi-bin/';

$execStr = $license_generator . 'lc-standalone-v8 -ui ' . $license_generator .         'keygenerator.livecode ' . 
        escapeshellarg($license_count) . ' ' . 
        escapeshellarg(base64_encode($name));

$key = exec($execStr, $output, $return_var);

Accounting for new widget properties in an OnLoad handler

When writing a LIveCode widget the OnLoad handler is used to populate variables in the current instance of the widget with values that were stored with the widget. Version 1 of an OnLoad handler looks something like this:

public handler OnLoad(in pProperties as Array)
   put pProperties["text"] into mText
   put stringToColor(pProperties["text color"]) into mTextColor
   put stringToColor(pProperties["button color"]) into mButtonColor
end handler

Now assume that you released this widget and there are stacks using it. You then decide that you want to add some more properties to the widget. You make the necessary changes to your OnLoad handler so that version 1.0.1 looks like this:

public handler OnLoad(in pProperties as Array)
   put pProperties["text"] into mText
   put stringToColor(pProperties["text color"]) into mTextColor
   put stringToColor(pProperties["button color"]) into mButtonColor

   // New properties added in version 1.0.1
   put stringToColor(pProperties["border color"]) into mBorderColor
   put pProperties["stroke width"] into mStrokeWidth
end handler

You compile the widget and then launch your project. When your existing widgets are displayed on the screen they aren’t rendered. All you see is an empty area. You try to check the properties in the property inspector but no properties are set. What is going on?

Since your widgets created with version 1 of your widget they didn’t store any properties named “border color” or “stroke width”. When you try to access a key of the pProperties array that doesn’t exist LCB is unhappy and refuses to go on.

There is an easy fix, however. Whenever you release a new version of your widget with new properties you need to add a check to make sure the new properties are keys in the pProperties array.

public handler OnLoad(in pProperties as Array)
   put pProperties["text"] into mText
   put stringToColor(pProperties["text color"]) into mTextColor
   put stringToColor(pProperties["button color"]) into mButtonColor

   // New properties added in version 1.0.1
   if "border color" is among the keys of pProperties then
      put stringToColor(pProperties["border color"]) into mBorderColor
      put pProperties["stroke width"] into mStrokeWidth
   end if
end handler

Since I added “border color” and “stroke width” in version 1.0.1 I just check for the presence of one of the keys. If one of the keys is present then the other will be present as well.

With this change to the code, your existing widgets will still load when running with version 1.0.1 of your widget.

Creating a Busy Indicator in LiveCode Builder

One of my favorite aspects of creating Widgets with LiveCode Builder (LCB) is that I don’t have to create multiple image assets in order to support various display resolutions. Since it is possible to create very complex shapes using the new drawing routines I no longer have to resort to using PNG images exported from Photoshop for more complicated aspects of my UI.

Busy indicators are one control in particular that are quite a pain to manage. You needed to generate a PNG image for each frame in the animation and you had to create the animation for at least two sizes (1x and 2x). With widgets creating a busy indicator is much simpler and you get better results. Here are a couple of notes from a busy indicator that I just finished working on. You can get the source from my livecode-extensions github repository.

Continue reading

Dawn of the Planet of the Widgets

On March 12th Kevin Miller announced the first LiveCode 8 developer preview at the LiveCode Unconference in Brooklyn. At the heart of the announcement was the introduction of widgets, a new control available to LiveCode developers. Thanks to the LiveCode Github respository, I had been using LiveCode 8 in the weeks leading up to the announcement. As LiveCode engineers made improvements I would update my local repository, rebuild using Xcode, and test. I was so impressed with what I saw that I decided to move a project I’ve been working on for the last few months to version 8 right away. Why would I trust my project to a LiveCode engine that hadn’t even reached a public beta yet? Let’s take a look.

Continue reading

Using SourceTree to monitor progress on LiveCode

When LiveCode became open source after the Kickstarter campaign all of the source code was moved to Github. Because the livecode repository on Github is public, you can monitor all changes which are submitted to it.

I’m going to show you how to easily monitor progress on the LiveCode engine using SourceTree, a free Git client for Mac and Windows made by Atlassian.

Continue reading

A Plugin For Monitoring the focusedObject

Knowing which object currently has focus can help you troubleshoot situations when messages aren’t being sent to the object you think should be getting them. I have a plugin I use called ReportTheFocusedObject which continually monitors the focusedObject and selectedField so that you can quickly determine which object is the target of messages.

You can download the plugin here.

For instructions on how to install plugins for Revolution see this lesson.

RunRevLive 09 Resources

I took down the original page of links to my session materials that  I posted for the RunRevLive 09 conference so I’m reposting the content here.

Behaviors and Custom Controls

Behavior Helper Plugin

http://www.bluemangolearning.com/download/revolution/tools/BehaviorHelper.rev.zip

Custom Control Helper Plugin

http://www.bluemangolearning.com/download/revolution/tools/CustomControlHelper.rev.zip

Behaviors & Custom Controls Stacks

http://www.bluemangolearning.com/download/revolution/tools/behaviors_customcontrols.zip

Instructions Showing How To Install a Plugin

http://revolution.screenstepslive.com/spaces/revolution/manuals/plugins/lessons/5489-Installing-the-Plugin

Password Font

http://www.bluemangolearning.com/download/revolution/tutorials/passwordentry.zip

Presenting Data with the Data Grid

Data Grid Sample MP3 Library

http://www.bluemangolearning.com/download/revolution/tools/data_grid_sample_mp3_library.zip

Creating a Music Library Interface Part I

http://revolution.screenstepslive.com/spaces/public_staging/manuals/740

SQL Yoga 1.0.1 Released with New IDE Plugin


New Features and Bug Fixes

SQL Yoga 1.0.1 is now available for immediate download from the SQL Yoga site. The new version has a number of bug fixes as well as some new features.

Two new time-saving commands have been added to the library that will speed up creating and updating records:

Both of these commands allow you to pass in arrays with the values you want to insert/update in the database.

For a full list of changes please see the change log.

New Plugin

A new IDE plugin is now included with the SQL Yoga distribution. The plugin automates a few tasks and provides logging. You can read about how to install and use the plugin in the new plugin manual.

Learn More

To learn more about SQL Yoga, download a demo or purchase please visit the SQL Yoga page.