Sunday, July 27, 2014

Working with Library Stacks

Pre-Conditions

This tutorial is written explicitly for LiveCode 6.6.2 Stable and might not work with other versions. The tutorial will not be updated!

Using Mainstacks as Libraries

When you work on a large Livecode project you'll want to include libraries that contain re-usable commands and functions. You can do this by adding a mainstack to your project as substack. This is neat but when an update has been added to the library stack you'll have to delete the Substack and add it again.

The better solution is to load the libraries in as Mainstacks. This way each time you open your stack the library stacks will be loaded on demand. The Mainstacks will only be loaded if you have loaded them using the "start using" command. Otherwise they'll not be loaded.

To tell the Mainstack to load in other Mainstacks as libraries open the Property Inspector of the Mainstack and choose Stack Files. Click on to the small folder icon to choose Mainstacks that should be loaded if you open your stack.

inspector-stacks

Once you've added the stack files you can load them with the the start using command:

on preOpenStack 
  start using "LibJson" 
  start using "LibUuid" 
  start using "GenericCouchDb" 
end preOpenStack

Once you've loaded the Mainstacks with the start using commands and re-open your stack you'll see that the other stack files are loaded in automatically:

project-explorer

Including the stacks in to your application when building

The above works nice in development mode. But you'll also have to make sure that the stacks are built in to your standalone application. To do this you'll have to copy the files in to your application folder.

Click on to File -> Standalone Application Settings -> Copy Files

standalone-app-settings-copy

If all the files are in a lib directory for example you can choose Add Folder and choose the lib folder. But you can also add single stack files by clicking on to Add File.

Using relative paths

If you want to open the stacks from a relative directory as for example ../lib you will have to load the stacks over script.

put the effective filename of this stack into tPath
set the itemDel to slash
delete the last item of tPath -- deleting the stack file name
delete the last item of tPath -- deleting the folder the stack is in
put tPath & "/lib" into tPath
set the defaultFolder to tPath -- sets the default folder to the new path

open stack "YourStack.livecode"
start using "YourStack"

As an alternative you can use following command:

set the stackFiles of this stack to "My Dialog,Custom Dialogs.rev,..."

Wednesday, July 9, 2014

Install LiveCode Community Server 6.6.2 on Debian

Pre-Conditions

This tutorial is written explicitly for LiveCode 6.6.2 Stable and might not work with other versions. The tutorial will not be updated!

Install Apache

sudo apt-get install apache2

LiveCode currently depends on 32bit libraries. If the Debian distribution is 64bit then following commands need to be executed:

dpkg --add-architecture i386
apt-get update
apt-get install libc6:i386

Setup directory structure

cd /var/www
sudo mkdir cgi-bin
sudo mkdir www.yourhostname.com
sudo mkdir www.yourhostname.com/public
sudo mkdir www.yourhostname.com/log

Download the LiveCode Community Server

Login to the LiveCode site. Or you can also go to downloads.livecode.com.

Click on to the Download link on the left and then click on to View All LiveCode Downloads

downloads

Click on to Linux just below the header called Community Server

downloads-community-server

Upload the zip file to your server:

scp ~/Downloads/LiveCodeCommunityServer-6_6_2-Linux.zip user@your.server.com:./

Unzip the file in your home directory on the server:

mkdir livecode662
mv LiveCodeCommunityServer-6_6_2-Linux.zip livecode662
cd livecode662
unzip LiveCodeCommunityServer-6_6_2-Linux.zip

Make sure that the livecode-community-server file is executable:

chmod 755 livecode-community-server

Move the folder in to /var/www/cgi-bin

sudo mv livecode662 /var/www/cgi-bin/

Setup the Apache configuration

Enable mod_actions:

cd /etc/apache2/mods-enabled
ln -s ../mods-available/actions.conf .
ln -s ../mods-available/actions.load .

Go in to the configuration directory:

cd /etc/apache2/sites-available

Create Apache configuration file /etc/apache2/sites-available/www.yourhostname.com:

<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName www.yourhostname.com

DocumentRoot /var/www/www.yourhostname.com/public
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>

<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

<Directory "/var/www/www.yourhostname.com/public/">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
AddHandler livecode-script .lc
Action livecode-script /livecode-cgi/livecode-community-server
</Directory>

<Directory "/usr/lib/cgi-bin/livecode662/">
Options ExecCGI
Order allow,deny
Allow from all
</Directory>

ScriptAlias /livecode-cgi/livecode-community-server /usr/lib/cgi-bin/livecode662/livecode-community-server

ErrorLog ${APACHE_LOG_DIR}/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.

LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

Enable the configuration:

cd /etc/apache2/sites-enabled/
ln -s ../sites-available/www.yourhostname.com .

Restart apache:

sudo apache2ctl start

Once finished try logging in over following URL: http://www.yourhostname.com/

Troubleshooting

  • Make sure that the directories are "chmod 755" within the cgi-bin folder.
  • Make sure that the slashes at the end of the directory pathes are present in the user apache conf script.

Development Frameworks

RevIgniter - Full blown MVC Framework - Use with TextMate 2.0-Alpha for Color Coding
RevSpark - Minimal Web Framework - Use with TextMate 2.0-Alpha for Color Coding

Friday, June 20, 2014

Naming Conventions

Pre-Conditions

This tutorial is written explicitly for LiveCode 6.6.2 Stable and might not work with other versions. The tutorial will not be updated!

Namespace

LiveCode does currently not have anything like a namespace as found in in C or PHP. There are two different ways how you can handle this.

Possibility 1

ee = first and last letter of company name

Player = what the substack does

Example: eePlayerStart, eePlayerStop, eeDbGet, eeDbInsert

Possibility 2

Since a few month I've started with a new naming convention with dots.

ee = first and last letter of company name

player = what the stack/library does

playVideo = method name

Example:

  • ee.player.playVideo
  • ee.sql.insert
  • ee.couchdb.createDocument

This naming convention does not clash with the Livecode engine. I've asked my Account Manager at Livecode and got positive feedback by the core team.

 

Variable Prefixes

The variable prefixes have been defined as best practice in the comprehensive manual that comes with LiveCode which you can find within the install directory.

Prefix Variable Type Example
g Global Variable gMyVar
s Script Local Variable sMyVar
t Handler Local Variable tMyVar
p Parameter pMyVar
k Constant KMYVAR
 

Tool Prefixes

These are my personal prefixes for the tool names.
Prefix Variable Type Example
btn Button btnSave
lbl Label lblName
fld Text Field fldName
chb Check Box chbName
cob Combo Box cobName
rdb Radio Button rdbName
lst Scrolling List lstName
mnu Option Menu mnuName
tab Tab Panel tabName
img Image Area imgName
tbl Basic Table tblName
dg DataGrid dgName

LiveCode and OOP

With some small scripts you can turn your way of writing applications in LiveCode in to full OOP (object oriented programing).

This article explains the details.

Monday, June 16, 2014

Install LiveCode Community Server 6.6.2 on MacOS X

Pre-Conditions

This tutorial is written explicitly for LiveCode 6.6.2 Stable and might not work with other versions. The tutorial will not be updated!

Create Directories and copy community server directory

Go in to the user directory and create the Sites and cgi-bin folder:

cd ~/
mkdir Sites
mkdir Sites/cgi-bin
Copy the LiveCode Directory that you downloaded and unzipped over to the cgi-bin directory:
cp -R ~/Downloads/LiveCodeCommunityServer-6_6_2-Mac ~/Sites/cgi-bin/livecode662

Create Apache Configuration in user directory

Edit /etc/apache2/users/your_mac_user.conf file and add following configuration:

<Directory "/Users/your_mac_user/Sites/">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
AddHandler livecode-script .lc
Action livecode-script /livecode-cgi/livecode-community-server
</Directory>
<Directory "/Users/your_mac_user/Sites/cgi-bin/livecode662/">
Options ExecCGI
Order allow,deny
Allow from all
</Directory>
ScriptAlias /livecode-cgi/livecode-community-server /Users/your_mac_user/Sites/cgi-bin/livecode662/livecode-community-server

Create file ~/Sites/test.lc for testing:

<html>
<head>
<title>My LiveCode Server Test Page</title>
</head>
<body>
<h1>My LiveCode Server Test Page</h1>
<?lc
put "<p>Hello World! from LiveCode Server</p>"
put "<p>The date is" && the date & "</p>"
?>

The Apache Webserver is installed by default on MacOS X. To start Apache you can type following command:

sudo apache2ctl start

Once finished try logging in over following URL: http://127.0.0.1/~your_mac_user/

Troubleshooting

  • Make sure that the directories are "chmod 755" within the cgi-bin folder.
  • Make sure that the slashes at the end of the directory pathes are present in the user apache conf script.

Some notes on Yosemite

After upgrading to Yosemite I had to do following:

In /etc/apache2/httpd.conf - Comment all modules except:

  • LoadModule authz_host_module libexec/apache2/mod_authz_host.so
  • LoadModule authz_core_module libexec/apache2/mod_authz_core.so
  • LoadModule access_compat_module libexec/apache2/mod_access_compat.so
  • LoadModule mime_module libexec/apache2/mod_mime.so
  • LoadModule log_config_module libexec/apache2/mod_log_config.so
  • LoadModule log_debug_module libexec/apache2/mod_log_debug.so
  • LoadModule log_forensic_module libexec/apache2/mod_log_forensic.so

In /etc/apache2/extra/httpd-userdir.conf - Uncomment following line:

  • Include /private/etc/apache2/users/*.conf

Do a restart:

apachectl restart

Development Frameworks

RevIgniter - Full blown MVC Framework - Use with TextMate 2.0-Alpha for Color Coding
RevSpark - Minimal Web Framework - Use with TextMate 2.0-Alpha for Color Coding

Thursday, March 6, 2014

What is LiveCode?

Pre-Conditions

This tutorial is written explicitly for LiveCode 6.6.2 Stable and might not work with other versions. The tutorial will not be updated!

Wikipedia Definition

The LiveCode programming language (formerly the "Revolution" programming language) is both an open-source and proprietary cross-platform rapid application development language inspired by HyperCard's programming language.

The language was introduced in 2001. The "Revolution" development system was based on the MetaCard engine technology which Runtime Revolution later acquired from MetaCard Corporation in 2003. The platform won the Macworld Annual Editor's Choice Award for "Best Development Software" in 2004. "Revolution" was renamed "LiveCode" in the fall of 2010. "LiveCode" is developed and sold by Runtime Revolution Ltd., based in Edinburgh, Scotland. In April 2013 a free/open source version 'LiveCode Community Edition 6.0' was published after a successful kickstarter campaign to make it available on floss.

LiveCode runs on iOS, Android, Mac OS X, Windows 95 through Windows 7, and several variations of Unix, including Linux, Solaris, and BSD. It can be used for mobile, desktop and server/CGI applications. The iOS (iPhone and iPad) version was released in December 2010. The first version to deploy to the Web was released in 2009. It is the most widely used HyperCard/HyperTalk clone,[citation needed] and the only one that runs on all major operating systems. LiveCode is currently in v. 6.1, which includes many enhancements for deployment in every OS platform, including iOS and Android. LiveCode released an open source version in April 2013.

Source: http://en.wikipedia.org/wiki/LiveCode

Features

Here some of the features I've discovered:

  • Runs on MacOS X, Windows, Linux, iOS, Android
  • For Web you can use LiveCode Community Server (similar to PHP, see here how to use it)
  • The web version can be integrated as CGI in Apache and is similar to PHP to use
  • Uses a language similar to HyperTalk which is very near to written sentences, thus easy to understand
  • Extremly rapid prototyping and development is possible. It's amazing.
  • The learning curve is nearly zero. You'll get up to speed in no time.
  • It is OpenSource. If you want to sell an application closed source you'll have to buy a license.
  • Extremly helpful volunteers in the support forum.
  • Under very active development.
  • A lot of effort is spent in documentation.

Place for improvement

Here some place for improvements I've discovered:

  • IDE looks a little Motif like 80's style. So it's not an eye catcher with which you see by intuition what's inside. But as with many cars the Engine is important. And LiveCode does a good job there.
  • Currently FTPS is not supported. Plain FTP transfers are a BIG security risk. (Workaround possible by using HTTPS uploads)
  • Videos are not working well on Linux. I didn't get mp4 Videos running. This is actually on the roadmap and should be solved by implementing a new media library.
  • There is currently no socket support for mobile which means you can't write any servers (FTP, HTTP or other) that run on Android and iOS (Possible Showstopper)
  • Currently a feature for Barcode Scanning is still missing
  • The web version is less documented. You need time to find all the tools
  • JSON is available through free unsupported third party libraries but generally works well. Webservices over XML however is fully supported.
  • Sometimes it's hard to find examples for your use-case as the community is smaller
  • Android still lacks some features, but is usable and under active development
  • Commands can differ depending on the OS. So sometimes you'll have to check on which OS you are and execute different code. But they keep it to the minimum and there are methods with which you can determine very easy on what OS you are.
  • Two Videos in layers over each other won't play. There are redraw issues.
  • The stack files are binaries so versioning with Subversion, Git will not display the changes so you loose the ability to view changes between versions, but you can still use these tools for versioning. There is a tool called lcVCS that exports and imports stack files to a structured folder of json, script and image files.
  • No namespace handling. You'll have to define your namespace on handlers (functions, methods). Example: eePlayerStart, eePlayerStop, dbOpen, dbClose. You can however use OOP. Read the following article to see how it can be done.
  • Code documentation such as you are used to with tools like JavaDoc are not yet part of the core product. There are however some third party libraries.

Main language highlights

Rapid Prototyping

When developing an application for a customer the best way in my eyes to gather the requirements is to sit down with him and sketch out the interfaces. As LiveCode is pure WYSIWYG you can start sketching in the application itself by placing form elements on to the cards (pages). The customer is seeing instantly how the application will look like and can give his input. This is a tremendous time saver because as soon the layout has been created you only need to code the interaction between the elements.

Cross Platform Development

This is the first coding tool I see that has all the functionality for real cross platform development including the most important mobile OS's.

Mobile / Desktop

Imagine you have to write an application that supports Android AND IOS? Or you also have to support Windows and MacOS? What a tremendous effort. Not only do you have to be proficient developing in C and Java, but you also have to understand the philosophy of all frameworks. You'll have to repeat writing the same code in different languages on different frameworks. You'll also go through updating all frameworks individually during the Lifecycle process. With LiveCode you just have to adopt to the simple Philosophy of Stacks, Cards and Message Paths and only maintain one code base.

Game Development

LiveCode is purely ready for 2D games. All widgets (tools) can be skinned with images and you can use collision detection through transparency.

Support

I've started using LiveCode without a license and asked questions on the forum. The community is great and growing. Most of my questions were answered by the volunteers in the forum. For small projects this is sufficient. I wanted however to build closed source applications. If you want to build closed source applications you'll need at least an Indy license. So I bought one. This enabled me to write to the support team and build closed source applications. When working with LiveCode you'll come however to the point which may require that bugs are fixed quicker or you need expert knowledge from LiveCode to solve certain issues. I've decided to upgrade to a business license out of this reason. I had a call with a dedicated Account Manager and I can ask questions based on their "fair-use" principal. As long you spend enough time investigating your issues before contacting them and the issue you have is really justified they will answer instantly and do their best to solve your issues. Up to now I'm very satisfied with the support provided. I've never experienced this with any other development language.

Alternative to Java?

From a licensing point of view it could be considered as alternative to Java. It also runs on several operating systems and it even supports mobile devices. People that love the Java coding style however may not be satisfied with LiveCode at first and will miss many libraries that they'll have to write themselves. On the other hand LiveCode is OpenSource and for some companies it may be an advantage to develop their own plugins and externals together with the benefit of lower Licensing costs. Or the benefit to sell certain libraries back to the community.

Since Java is belonging to Oracle, they started to sue other companies for using parts of Java commercially. See for example claims against Google.

  • Since LiveCode has gone Open Source you can be sure that the Engine itself is purely LiveCode and does not contain any other third party libraries that conflicts with a license from any other company.
  • Through the Licensing Model you can be sure that you won't receive claims from LiveCode when you payed for the License.
  • Additionally try to get support from Oracle if you're not a monster company with infinite financial background.

Source

The source can be found on GitHub: https://github.com/runrev/livecode