610 likes | 1.08k Views
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
E N D
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 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 Kernel VS Configuration
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
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
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
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
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
An Overview of Lua • An extensible procedural language with data description facilities • It is used to extend programs written in a full 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
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
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
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
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
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
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
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
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)
General Characteristics of Lua • Simple • Fast • Portable
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 Features of Lua
Adopted C++’s concept of allowing local variable declaration Used ‘..’ instead of the usual ‘+’ for string concatenation Optional semicolons: More Features…
Numbers Strings Associative Tables nil Userdata Functions Lua Languages Six Types
Lua Versions • 1.1 • faster compiler (just-in-time compiler) • New opcodes for contructors • Released in 1994
Lua version 2 • 2.1 • Dropped @ from constructors • Fallbacks were introduced • Allowed user-defined functions • Several kinds of inheritance (including cross-inheritance) • Allowed support for object-oriented programming • Released in 1994
Lua version 2 • 2.4 • Main 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
Lua version 3 • 3.0 • Replaced 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 type • Support for conditional compilation • Released in 1997
Lua version 4 • 4.0 • Application Program Interface (API) include explicit states of Lua and is now easier to use and is more efficient • For loop • Released in 2000
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) Applications made with Lua
Lua Examples • A very simple configuration file: width = 420 height = width*3/2 -- ensures 3/2 aspect ratio color = "blue"
Another Example • A configuration file using Functions: function Bound (w, h) if w < 20 then w = 20 elseif w > 500 then w = 500 end local minH = w*3/2 -- local variable if h < minH then h = minH end return w, h end width, height = Bound(420, 500) if monochrome then color = "black" else color = "blue" end
A Question that need to be Answered How does Lua apply the new configurations to the original program / application?
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
For More Information… • http://www.lua.org
The End At last… ;)