lua: the programming language

34
Lua: The Programming Language

Upload: conner

Post on 17-Jan-2016

37 views

Category:

Documents


1 download

DESCRIPTION

Lua: The Programming Language. Some Things that Need to be Said. Because of increasing demand for customizable applications, the trend nowadays is to split complex systems into two parts: Kernel & Configuration. Kernel implements the basic classes and objects of the system - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Lua: The Programming Language

Lua: The Programming

Language

Page 2: Lua: The Programming Language

Some Things that Need to be Said

Because of increasing demand for customizable applications, the trend nowadays is to split complex systems into two parts: Kernel & Configuration

Page 3: Lua: The Programming Language

Kernel VS Configuration

Kernel implements the basic classes and objects of the system

Usually written in a compiled, statically typed language

Configuration connects the basic classes and objects to give the application its final shape

Usually written in an interpreted, flexible language

Page 4: Lua: The Programming Language

Configuration Languages

Range from simple languages for selecting preferences (usually implemented as parameter lists in command lines or as variable-value pairs read from configuration files) to embedded languages

Page 5: Lua: The Programming Language

Embedded Languages

Used for extending applications with user-defined functions based on primitives provided by the application

Can be quite powerful being sometimes simplified versions of mainstream programming languages – extension languages

Page 6: Lua: The Programming Language

Extension Languages

Are called such because the allow the extension of the basic kernel semantics with new user defined capabilities

Only work embedded in a host client, called the host program

Page 7: Lua: The Programming Language

Requirements for Extension Languages need good data description facilities, since

they are frequently used as configuration languages

should have a clear and simple syntax, because their main users are not professional programmers

Page 8: Lua: The Programming Language

More Requirements for Extension Languages should be small, and should have a small

implementation; otherwise, the cost of adding the library to an application may be too high

should also be extensible. Unlike conventional languages, extension languages are used in a very high abstraction level, adequate for interfacing with users in quite diverse domains

Page 9: Lua: The Programming Language

An Overview of Lua

An extensible procedural language with data description facilities

It is used to extend programs written in a full programming language

Page 10: Lua: The Programming Language

An Overview of Lua

Incorporates facilities common to most procedural languages – control structures (whiles, ifs, etc.), assignments, subroutines, and infix operators – but abstracts out any facilities specific to any particular domain

Page 11: Lua: The Programming Language

An Overview of Lua

Lua is not a stand-alone language thus it needs to be initialized and calledfrom another language like C and C++

In its design, the creation of a few meta mechanisms allow programmers to implement dynamic associative arrays, reflexive facilities, and fallbacks

Page 12: Lua: The Programming Language

Dynamic Associative Arrays

Directly implement a multitude of data types like ordinary arrays, records, and sets

Lever the data description power of Lua by means of constructors

Page 13: Lua: The Programming Language

Reflexive Facilities

Allow the creation of highly polymorphic parts

Persistence and multiple name spaces are not present in Lua, but can be easily implemented using these

Page 14: Lua: The Programming Language

Fallbacks

Extend the meaning of many syntactical constructions

e.g. fallbacks can be used to implement different kinds of inheritance, a feature not present in Lua

Page 15: Lua: The Programming Language

History of Lua

Lua was raised by three people who call themselves collectively as a committee: Roberto Ierusalimschy, , Luiz Henrique de Figueiredo, Waldemar Celes Filho

It was made with modest goals in mind and was finally ‘released’ in 1993

Page 16: Lua: The Programming Language

More on Lua’s History

PETROBRAS, a Brazilian petroleum company, needed a program for data entry and asked TeCGraf to do it for them

For this, the ‘committee’ created DEL

Page 17: Lua: The Programming Language

Continuing…

After some time, users demanded more features from DEL and at about the same time, the three were working on a configurable report generator for lithology files: SOL

Page 18: Lua: The Programming Language

Moving On…

By mid-1993, the authors of DEL and SOL realized that the two programming languages can be combined into one simpler language

And because this language was a development of SOL (sun) they named it Lua (moon in Portugese)

Page 19: Lua: The Programming Language

General Characteristics of Lua

Simple

Fast

Portable

Page 20: Lua: The Programming Language

Features of Lua

Inherited SOL’s syntax

Inherited Sol’s concept of being implemented as library

Borrowed Modula’s while, if, and repeat until commands

Used CLU’s multiple assignments and multiple returns

Page 21: Lua: The Programming Language

More Features…

Adopted C++’s concept of allowing local variable declaration

Used ‘..’ instead of the usual ‘+’ for string concatenation

Optional semicolons:

Page 22: Lua: The Programming Language

Lua Languages Six Types

Numbers

Strings

Associative Tables

nil

Userdata

Functions

Page 23: Lua: The Programming Language

Lua Versions

1.1 faster compiler (just-in-time compiler)New opcodes for contructorsReleased in 1994

Page 24: Lua: The Programming Language

Lua version 2

2.1Dropped @ from constructorsFallbacks were introduced

Allowed user-defined functions Several kinds of inheritance (including cross-

inheritance) Allowed support for object-oriented programming

Released in 1994

Page 25: Lua: The Programming Language

Lua version 2

2.4Main feature of this release was an external

compiler: luac Pre-complies Lua codes and saves bytecode and

string tables to a binary file Programs can avoid parsing and code generation

at run-time, which can be costly

Released in 1996

Page 26: Lua: The Programming Language

Lua version 3

3.0Replaced fallbacks with tag methods

Essentially fallbacks that are selected according to the tag of the operator

Different tables may now have different fallbacks for their operations

A number that represents a new typeSupport for conditional compilationReleased in 1997

Page 27: Lua: The Programming Language

Lua version 4

4.0Application Program Interface (API) include

explicit states of Lua and is now easier to use and is more efficient

For loopReleased in 2000

Page 28: Lua: The Programming Language

Applications made with Lua

LucasArts’ Escape from Monkey Island and Grim Fandango

PUC-Rio’s general aperture program (simulate the effects on incident photon stream of physical obstructions)

Performance Technologies’ command line interface of CPC4400 (a hot swappable ethernet switch)

Tollgrade’s DigiTest (telephony network testing)

Page 29: Lua: The Programming Language

Lua Examples

A very simple configuration file:

width = 420

height = width*3/2 -- ensures 3/2 aspect ratio

color = "blue"

Page 30: Lua: The Programming Language

Another Example

A configuration file using Functions:

function Bound (w, h)if w < 20 then w = 20elseif w > 500 then w = 500endlocal minH = w*3/2 -- local variable

if h < minH then h = minH endreturn w, h

end width, height = Bound(420, 500) if monochrome then color = "black" else color = "blue" end

Page 31: Lua: The Programming Language

A Question that need to be Answered

How does Lua apply the new configurations to the original program / application?

Page 32: Lua: The Programming Language

The Answer…

Lua at runtime, calls out the C and C++ functions of the original programming language used and uses those functions to apply the new configurations

Page 33: Lua: The Programming Language

For More Information…

http://www.lua.org

Page 34: Lua: The Programming Language

The End

At last… ;)