Table of Contents
You can compile your applications for any of several runtimes using any of several techniques. In this chapter we'll look at the various ways of invoking the compiler and its various options:
Using the Developer's Console to invoke the OpenLaszlo Server
Using URLs to invoke the OpenLaszlo Server
Invoking the lzc compiler directly from the command line
You can cause compilation either by implicitly calling the compiler through the OpenLaszlo Server, or by explicitly calling it from the command line. The most usual way to invoke the server is using the Developer's Console.
The Developer's Console is a small OpenLaszlo application for selecting things like the target runtime, the deployment mode (proxied or SOLO) and whether the debugger is included. When you first compile an OpenLaszlo application (as explained below), by default it is returned with the Developer's Console appearing at the bottom of the application.
Depending on whether your compile to SWF (the default) or DHTML, a slightly different version of the Developer's Console is returned. The illustrations below call out features of both versions.
In OpenLaszlo, 'the compiler' consists (currently) of two phases: 1) 'the view compiler', which compiles LZX to Javascript, and 2) 'the script compiler', which compiles Javascript to the target runtime (SWF7, SWF8 and DHTML). `lzc` invokes both those phases (although you can ask for the intermediate output).
The Debugger needs an OL server to be able to evaluate forms (it calls the server to compile the form and then loads and runs the result). It will try to talk to OL server (using the url the application was loaded from), so it should 'just work', so long as you are running a server, even if you don't use the server for compiling your application.
To run lzc you must do so from a current directory that matches the value of LPS_HOME, and LPS_HOME must be set to the correct value for the build.
Say the application to be compiled is
$LPS_HOME/laszlo-explorer/basics/mediatst.lzx
To compile it correctly you would set the current directory first:
cd $LPS_HOME;
and then compile using
lzc --script --runtime=dhtml laszlo-explorer/basics/mediatst.lzx;
Let's say the file $LPS_HOME/laszlo-explorer/basics/mediatst.lzx wants to reference the file $LPS_HOME/laszlo-explorer/basics/assets/background.jpg. It might contain the following reference.
<canvas> <view resource="assets/background.jpg"/> </canvas>
Running LZC from other than LPS_HOME will result in a file not found error.
Here are the options available for compilation:
Options:
Set the name/var property to value (See Compiler.getProperties).
Short for -Dname=true.
Write progress information to standard output.
Turns on/off media cache. Default is off.
Action to take on compilation errors. Defaults to warn.
lists all options.
Doesn't flush script cache before compiling.
Output options:
Compile to swf7, swf8, or dhtml.
Output directory.
Add debugging information into the output object.
Add profiling information into the output object.
Logging options:
Logging level (See org.apache.log4j.Level)
Logging level (See org.apache.log4j.Level)
Log4j properties files
Specify logfile (output still goes to console as well)
Writes the schema to standard output.
Writes JavaScript to standard output.
You can define compile-time constants to `lzc` by using `-D_name_=_value_`, where _value_ should be either `true` or `false`. By convention, we use `$` as the first character of _name_, but nothing enforces that.
The compiler will compile only the chosen branch of an if statement when the condition expression is a compile-time constant (i.e., just the constant name, no other computation). For example:
if ($slow) { ... slow way ... } else { ... fast way ... }
You can define compile-time constants to `lzc` by using `-D_name_=_value_`, where _value_ should be either `true` or `false`. By convention, we use `$` as the first character of _name_, but nothing enforces that. The compiler will compile only the chosen branch of an if statement when the condition expression is a compile-time constant (i.e., just the constant name, no other computation).
For example:
if ($slow) { ... slow way ... } else { ... fast way ... } Can be made to run fast by `lzc -Dslow=false`
As part of the architectural overhaul, we have created a new version of the client runtime (LFC plus kernel). To invoke
an application compiled for DHMTML, use the ?lzr=dhtml
query.
The ?lzr
parameter selects the runtime. Your choices are swf7, swf8, dhtml. The default is specified in lps/config/lps.properties
as compiler.runtime.default. The default runtime selector is swf7.
The ?lzt
parameter is the 'request type', in general what kind of 'wrapper' page will be generated around your application. Your
choices are: app_console or html. app_console is the developer console, html is your app in an html page. The latter can
be used as a model for embedding your app in a custom page, or you can simply embed using an iframe:
<iframe src=".../app.lzx?lzt=html"></iframe>
The default for ?lzt
is specified in lps/config/lps.properties as defaultRequestType. The default value is app_console.
Mnemonics:
lzr - Laszlo Runtime
lzt - Laszlo request Type
So, for example, to view an LZX application in DHTML within a browser, download it from a live server with an url parameter
requesting the DHTML runtime lzt=html
: http://myserver/mylaszloapp.lzx?lzr=dhtml. To request the SWF runtime, use http://myserver/mylaszloapp.lzx?lzr=swf.
To specify that the application run in the Developer's Console, use the lzt
flag:
lzt=app_console
loads the application with the Developer's Console.
lzr=swf7
and lzr=swf8
loads the application compiled for the SWF7 or SWF8 runtime, with the Developer's Console.
Several lzr values have been added for future use, but are not currently supported: swf9, j2me, svg
When the compiler detects an error that makes it impossible to compile the application, the error is reported in the browser window, or, if you invoked compilation using lzc, in the terminal window.
When the compiler detects code that may be problematic but does not prevent compilation, it issues a warning. If you have debugging enabled, the warning is displayed there. See Chapter 50, Debugging for a detailed discussion of how to detect errors.
You can enclose blocks of code within <switch>
elements that are associated with a specific runtime. The <switch>
is a compiler directive that instructs the compiler to compile or omit blocks according to the target runtime to which the
application is being compiled. Within a <switch>
block, use the <when>
to specify the runtime.
Example 48.1. switch tag for condtional compilation
<canvas height="20"> <switch> <when runtime="dhtml"> <text>This program has been compiled for DHTML</text> </when> <otherwise> <text>This program has been compiled for SWF</text> </otherwise> </switch> </canvas>
Copyright © 2002-2007 Laszlo Systems, Inc. All Rights Reserved. Unauthorized use, duplication or distribution is strictly prohibited. This is the proprietary information of Laszlo Systems, Inc. Use is subject to license terms.