Plua
Encyclopedia
Plua is a port of the programming language
Programming language
A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....

 Lua 5.0.3, along with a small IDE
Integrated development environment
An integrated development environment is a software application that provides comprehensive facilities to computer programmers for software development...

, for the Palm Computing platform
Palm OS
Palm OS is a mobile operating system initially developed by Palm, Inc., for personal digital assistants in 1996. Palm OS is designed for ease of use with a touchscreen-based graphical user interface. It is provided with a suite of basic applications for personal information management...

. Lua is a programming language designed at TeCGraf, the Computer Graphics Technology Group of PUC-Rio, Brazil
Brazil
Brazil , officially the Federative Republic of Brazil , is the largest country in South America. It is the world's fifth largest country, both by geographical area and by population with over 192 million people...

. Plua includes some extensions to Lua to better support the Palm platform.

Development has ceased on Plua, and the latest stable version of Plua 2.0 can only be downloaded from a discussion board. The prior version, Plua 1.1, is a port of Lua 4.0. The extensions differ somewhat between versions. The new version is thus sometimes called Plua 2 to avoid confusion.

Language resources

Plua has some special functions, or extensions, to support the Palm platform, including:
  • Graphical user interface
    Graphical user interface
    In computing, a graphical user interface is a type of user interface that allows users to interact with electronic devices with images rather than text commands. GUIs can be used in computers, hand-held devices such as MP3 players, portable media players or gaming devices, household appliances and...

     (GUI) components, defined by position: buttons, checkboxes, etc.
  • Direct plotting of graphics based on vertex information: lines, circles, etc.
  • Can work with streams, databases or computer files on memory cards.
  • Supports communication via infrared
    Infrared
    Infrared light is electromagnetic radiation with a wavelength longer than that of visible light, measured from the nominal edge of visible red light at 0.74 micrometres , and extending conventionally to 300 µm...

     and serial ports.
  • Rudimentary sprite engine.

Sample code, Plua 1

The compiler
Compiler
A compiler is a computer program that transforms source code written in a programming language into another computer language...

 and interpreter
Interpreter (computing)
In computer science, an interpreter normally means a computer program that executes, i.e. performs, instructions written in a programming language...

 is approximately 150 KB, and the compiled helloworldApp.prc shown below is approximately 2 KB.

The classic hello world program
Hello world program
A "Hello world" program is a computer program that outputs "Hello world" on a display device. Because it is typically one of the simplest programs possible in most programming languages, it is by tradition often used to illustrate to beginners the most basic syntax of a programming language, or to...

 (in the old version) can be written as follows:


-- HelloWorld.lua
ptitle("Hello World")
print ("Hello, world!")
pevent


This text will be saved as a normal memo in the Palm, and executed by tapping the "Run" button in the IDE. Alternatively, the program can be compiled into a PRC
PRC (Palm OS)
PRC is a container format for code databases in Palm OS, Garnet OS and Access Linux Platform. Its structure is similar to PDB databases. Usually, a PRC file is a flat representation of a Palm OS application that is stored as forked database on the PDA....

(Palm OS Program File, which is executable on any Palm Platform, provided that the runtime program is present) from the same IDE.

A breakdown of the program:

-- HelloWorld.lua

The double dashes define the above line as a comment. All Plua memo files must be defined as such before it can be run or compiled in Plua.

ptitle("Hello World")

Defines the title at the top of the page.

print("Hello, world!")

Prints the message "Hello, world!" onscreen under the title bar.

pevent

The above command pauses the execution of the programs and waits for any interaction from the user. These include button taps, character input, or the push of a hard button.

Sample code, Plua 2

The equivalent program with the new extensions can be written as follows:


-- HelloWorld.lua
gui.title 'Hello world'
print 'Hello world!'
gui.event(ioPending)


A breakdown of the program:
The first line comment is the same as before, but the rest is a little different.

gui.title 'Hello world'

The gui.title function defines the title at the top of the page. Parentheses are optional for a Lua function call with a single string argument (and also for a single table constructor). String literals may be either single-quoted or double-quoted.

print 'Hello world!'

Prints the message "Hello, world!" onscreen under the title bar. If the optional parentheses and double quotes had been used (and they could have been), this line would be identical to the first version.

gui.event(ioPending)

The above command pauses the execution of the programs and waits for any interaction from the user. The argument ioPending is simply a predefined number included in Plua 2 representing a request for this behavior.

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK