If may use LiveCode to create web pages as a webserver. This guide will get you started. The guide explains how to install LiveCode Server on Mac, Windows and Linux servers, create a “Hello World” example, handle user input using Post and Get and debug your scripts.
The LiveCode Server product brings our English like language to the server environment. The server engine is a separate build of the LiveCode engine with specific syntax and functionality that makes it suitable for use in command-line contexts and, in particular, as a CGI processor.
< html> < head></head> < body> <?lc put "< H1>hello world</H1>" ?> </body> </html>
Notice that the LiveCode script is contained within special tags. Code within these tags is executed as the page loads allowing you to dynamically generate webpage content. The example above outputs the title “hello world”. The following tags are recognized by LiveCode Server:
<?lc ... LiveCode script ... ?>
<?livecode ... LiveCode script ... ?>
<?rev ... LiveCode script ... ?>
File Extensions Edit
You can configure your server to accept the file extension(s) of your choice.
LiveCode Server can be installed on Mac, Windows and Linux servers.
For each supported platform, LiveCode Server is distributed as a single .zip file containing the server engine, drivers and externals as well as release notes. The engine can be run in two separate modes, command line mode or CGI mode. To run the engine in command line mode, unzip the appropriate archive for your platform, then execute the livecode-server binary (e.g. livecode-server.exe on Windows) from the command line, passing the initial script as the first argument. For example:
To run the engine in CGI mode, the engine needs to be integrated with the web server software running on your machine. There are various web server packages available, most of which should be compatible with LiveCode Server. In the lessons below we describe how to setup for the most popular package, Apache. Here some guides:
Getting Started Edit
Hello World Example Edit
The most basic example using LiveCode Server is to display the text “Hello World” on the screen. To do this create a new file in any text or script editor and add the following line of script:
<?lc put "< i>Hello World!</i>" ?>
Save the file as: hello.lc
Upload the file to your newly configured server and navigate to the file: http://www.yourwebsite.com/hello.lc
The result: Hello World!
To see the hello world example in action along with other practical uses of LiveCode on the server go to samples page http://samples.on-rev.com/iframe.irev
Using Stacks Edit
The LiveCode Server engine supports loading stacks in a similar manner to that of the desktop engines. Stacks provide the programmer with an additional means to store data and manage code, allowing for improved scope and function name management.
Note: Visual and graphical commands are not supported (e.g. export snapshot).
For a detailed guide on using stacks with LiveCode Server, take a look at lesson: http://lessons.livecode.com/s/lessons/m/4070/l/36656-How-do-I-use-stacks-with-LiveCode-Server-
Using Post / Get Edit
There are two main ways of handling user input when developing for the web:
Web forms are a common way to get user input. They take the user’s entries and pass the data to your scripts using a method called POST. For a detailed step by step guide of how to set up a form and process the POST data with LiveCode script, take a look at lesson http://lessons.livecode.com/s/lessons/m/4070/l/36650-How-do-I-handle-user-input-using-LiveCode-Server- You can also try out a practical example here: http://samples.on-rev.com/get.irev
You can also pass data to your scripts via the page URL and the ‘query string‘. Take the following URL as a example: http://www.runrev.com/my_script.lc?key=value&key2=value2 The part of the URL in bold, everything after the question mark, is known as the ‘query string’. The GET method provides a way to access that information. For a guide and example on how to use this in LiveCode take a look at this lesson: http://lessons.livecode.com/s/lessons/m/4070/l/36649-How-do-I-pass-information-to-LiveCode-Server-scripts- You can also try out a practical example here: http://samples.on-rev.com/get.irev
Using Include / Require Edit
LiveCode Server provides include and require commands as a way of linking scripts together. This is useful if you want to create libraries which are then used by a variety of other website pages. For example a database library script: http://www.yourwebsite.com/database_library.lc
To include the libary:
<?lc require "database_library.lc" ?>
The example below shows the inclusion of the LiveCode database library and the use of two commands contained within it:
<?lc require "database_library.lc" ?> <html> <head></head> <body> <?lc databaseConnect() put databaseShowData() ?> </body> </html>
- include: Includes the given script each time it is called.
- require: Only includes the given script if it has not already been included or required.
For more information and a detailed example of these two commands in use see the lesson: http://lessons.livecode.com/s/lessons/m/4070/l/36662-How-do-I-add-Multiple-LiveCode-Files-in-LiveCode-Server-
Debugging / Errors Edit
When developing on the server it is vital that you receive as much information on script errors as possible. You to tell LiveCode Server to output error messages in a variety of different ways.
The error mode specifies the action the engine takes when an error occurs. The errorMode property can be set dynamically to one of 4 types:
- inline – Indicates that errors should be output to the browser.
- stderr – Specifies that the error should be written out to stderr.
- quiet – Indicates that nothing is output anywhere when an error occurs.
- debugger – For information only and indicates that the script is being run in ‘remote debug’ mode. This is only relevant to the on-rev engine.
For an example of how to use this see the lesson: http://lessons.livecode.com/s/lessons/m/4070/l/6914-How-to-display-errors-when-using-LiveCode-Server
Additional Tutorials and Examples Edit
- AJAX Tutorial: http://lessons.livecode.com/s/lessons/m/4070/l/14117-How-Do-I-Use-AJAX-with-LiveCode-Server-
- AJAX Example: http://samples.on-rev.com/ajax.irev
- Database Example: http://samples.on-rev.com/database.irev