by David Simpson
This article describes real-world examples for using LiveCode to develop code generator apps for a variety of software development languages.
You might have a situation in which it is necessary to write the same types of applications on a routine basis. If there are commonly used features you need within an application there is no reason to write that code manually for each application. Of course, commonly used routines can be put into a library files for most development languages. However a static library is not going to be the best fit for every situation. Sometimes it may be better to custom generate code and use variables within the code generator to substitute changes you desire to make throughout the app.
At other times, it may be helpful to take code from one programming language and convert it into a different programming language. An automated code conversion process might be the first step to take when converting a large IT system from one development environment to another.
There is no reason to manually re-type all of the code when doing a conversion like this. Building even a simple code generator can save a lot of typing, reduce errors, and provide the developer with a sense of accomplishment. Sometimes, one of the biggest hurdles to performing a large-scale conversion project is just overcoming the inertia of starting the task.
LiveCode is very well designed for text processing, reading, and generating files. Furthermore, LiveCode can build your application as a standalone app for multiple operating systems and mobile devices. This is the route I have followed during the development of FmPro Migrator Platinum Edition.
LiveCode is a great development environment for quickly building little utilities to help you with your development projects. This tool is one of the first I created to help generate LiveCode scripts from other languages. Now, just because the title is "XML to LiveCode Converter" doesn't mean a whole lot. This little utility will take any source text and turn it into a series of PUT statements which you can paste into the LiveCode IDE script editor.
This annotated screenshot shows the how to use this little stack.
The source text is converted into lines of PUT statements, written into the LiveCode field which is also put onto the clipboard.
Here is what the code looks like within the button:
It is just a matter of looping thru the lines of code copied from the source field into the tSourceCode variable, and processing each line. The simple bit of processing being done here is the replacement of embedded quote characters with the quote constant surrounded by concatenation characters. This is followed by adding a PUT statement before the text, followed by the ending of the statement which substitutes the supplied variable name.
Following the processing of all of the lines of code in the source field, the output code is written into the output field and then copied to the clipboard using the copy command on line 20.
The result may be dozens or hundreds of lines of LiveCode code which is ready for pasting directly into the IDE. From this point onward I usually will perform my own variable substitution within the generated code. As a result of using this simple little utility, I immediately have blocks of syntactically correct code for my project. This process results in a great reduction in typing errors, syntax errors and overall frustration.
One of the unique features built into LiveCode is the storage of custom properties within stack files. This feature is immediately useful when generating LiveCode stack files from databases. FmPro Migrator Platinum Edition internally stores a binary copy of a template stack file which FmPro Migrator Platinum Edition populates with cards created from the layouts of a source database (FileMaker Pro, Microsoft Access and Visual FoxPro).
The contents of Custom Properties do not get modified by LiveCode when opening a stack on different platforms. However the contents of regular fields are modified with the correct line endings for the platform upon which the stack has been opened. This feature insures that if you put a binary file within a Custom Property, its contents won't be unexpectedly changed.
In addition to creating the objects on each card (graphic objects, fields, vector graphics and text objects), FmPro Migrator Platinum Edition writes customized handlers onto each card for reading the data from the database file into the stack fields. Scripts from the source database are also converted into LiveCode instructions, and written into a text file.
As was shown in the LiveCode example, I make use of custom properties to store a variety of source files for a CakePHP website. First, I store the entire CakePHP distribution as a zip file and unzip the file to create the entire CakePHP project directory.
The entire directory structure within the app1 directory, has been created by writing out a custom property having the CakePHP application directory within a zip file. Then the zip file is expanded to the directory structure shown in the screenshot.
This little bit of code writes out the zip file (#590), opens the zip archive (#592), then loops thru each of the items within the archive to extract the contents (#600 - 614). The features of this code have been turned into a function for use in multiple places, but this example shows how the function works as well.
This is an example I wrote myself as a commercial application sold through the Mac App Store. Yes, you can make applications that convert code that are very sellable software products. Don't feel limited by the code examples here - just about any language will work, using the same principles here.
Another valuable result is the list of conversion statistics showing the estimated conversion percentage, including coverage of commented lines, unsupported lines, and the unprocessed keywords list. If the unprocessed keywords list shows a high incidence of certain keywords getting missed during processing, then it represents a good feedback statistic for future enhancements.
The Database to LiveCode Conversion feature built into FmPro Migrator Platinum Edition enables LiveCode developers to quickly convert popular database files into full-featured LiveCode database front end applications, revLets or even mobile apps (IOS, Android). A working application can be created in seconds, without manual coding for commonly requested database features. SQL Yoga is used as the database API for generated LiveCode stack files - and SQL Yoga is also included in OmegaBundle 2012.
For the OmegaBundle, FmPro Migrator Platinum Edition includes license keys for the following features:
David Simpson is the president of .com Solutions Inc., and a LiveCode developer of database applications since 2001.