%in Midrand+277-882-255-28 abortion pills for sale in midrand
Lua - Programming Language
1. 1
TERM PAPER
On
Title: Lua
Submitted to
Amity school of Engineering and Technology
AMITY UNIVERSITY UTTAR PRADESH
GAUTAM BUDDHA NAGAR
Guided By - Submitted By –
Guided by: Ms Rashmi Dubey Varun Sharma
Asst. prof. Computer science Dept. 3CS-5x
A2305213337
2013-17
2. 2
DECLARATION
I, Varun Sharma, student of B-TECH (CSE) hereby declare that project titled "Lua" which is
submitted by me to the department of Computer Science and Engineering, Amity school of
Engineering and Technology, Amity University Uttar Pradesh, Noida, in partial fulfillment of
requirement for the award of the degree of Bachelor of Technology in Computer Science and
Engineering, has not been previously formed the basis for the award of any degree, diploma, or other
similar title or recognition
The Author attests that permission has been obtained for the use of any copy righted material
appearing in the Dissertation/Project report other than brief excerpts requiring only proper
acknowledgement in scholarly writing and all such use is acknowledged.
Signature
Noida
Date Varun Sharma
3. 3
CERTIFICATE
This is to certify that Mr. Varun Sharma, student of B-Tech in Computer Science and
Engineering has carried out the work presented in the project entitled “Lua” as a part of first year
program of Bachelor of Technology in Computer Science and Engineering from Amity School of
Engineering and Technology, Amity University, Noida, Uttar Pradesh under my supervision.
Ms. Rashmi Dubey
Amity School of Engineering and Technology
Amity University, Noida, UP
4. 4
Index
1. Preface…………………………………………………………………………..……………………..5
2. Prerequisites…………………………………………………………………..……………………....6
2.1 Programming Paradigms……………………………………………….….…………………….6
2.2 Important Terms……………………………………………………….…….……………………7
3. Introduction………………………………………………………………….…….…………………...8
4. History……………………………………………………………………….…….……………………9
5. Benefits…………………………...………………………………………..……….……………..…..10
6. Evolution…………………………………………...……………………..………….….…………….12
7. Programming in Lua……………………………………..……………...………………….………..14
7.1 Lua VS Other Scripting Languages…………………………..…………..…………..…….....17
8. Discussion & Conclusion……………………………………………...….……………………..…….19
9. References………………………………………………………………...……………..……………..20
5. 5
1. Preface
In this term paper, my main motive will be to know about Lua and how and where it fits in
today’s scenario of software development. Starting with some basic knowledge, I will begin with the
History of Lua and then talk about the benefits it provides and then analyze various versions which
have been released and ultimately go towards the programming in Lua. After all that is said and done,
I will compare Lua’s execution timings with that of other scripting languages.
Throughout this term paper, my objective have been to gather as much as relevant
knowledge as possible and produce it in a concise yet informative matter. Excluding all the
unnecessary information and focusing on that main idea behind the language and what ways it can be
used.
6. 6
2. Prerequisites
2.1 Programming Paradigms
A programming paradigm is the basic style of programing for computers, a procedure of building
various elements and structures in a computer program. Even though there are numerous types of
programing paradigms available, we would only restrict ourselves to those used in Lua.
Scripting Languages
A Language which supports scripts, which are actually interpreted by an interpreter rather
than compiled and automate the execution of various tasks which could be executed by a
human operator one by one are called scripting languages [1]. They are also called
extension languages as they can provide extensions to already built programs (Such as
Add-ons for web browsers). They also sometimes referred to as very high-level
languages as they have a very high level of abstraction.
As stated earlier, they are interpreted and not compiled, which makes it easier for
programmers to de-bug the program or add new features without any need of re-building
the entire software. And since, Lua is dynamic in nature, programs written in it can be
dynamically altered during runtime.
Functional Programming
It is a programing paradigm which views programs with a mathematical approach and
avoids mutable data. It emphasizes more on functions which gives out same results for
same inputs, i.e. – the output does not matter upon the program state but the values input
so that if same value in entered twice at different points of time, same result is obtained.
Procedural, prototype-based Object Oriented
Lua is a Procedural, prototype-based Object Oriented language, which particularly means
– OOP concepts (Like - classes, etc.) are not ‘actually’ embedded within the language but
can be faked through ‘tables’. Procedural means the language tells the computer the step
by step process of what to do and when to do it, prototype-based means that inheritance
is achieved by cloning or duplicating the existing objects and use them as ‘prototypes’ [2]
[3].
7. 7
2.2 Important Terms
Interpreted Language
A programming language which is not pre-compiled using a compiler but is interpreted during
runtime by an interpreter which translates each of the given statement in a program into one
or more predefined procedures or subroutines which already are compiled into the machine is
known as an interpreted language [4]. Lua is one good example of it.
Subroutine
A subroutine is a succession of instructions to a program that performs a certain task which is
packaged as a single entity/unit [5].
Dynamically Typed Language
This simply means that the variables in the language does not have any ‘data types’, only the
values associated with them do and language does not have any type definitions.
Multi-Paradigm Programming Language
A programming language is called “Multi-Paradigm” if it supports more than one paradigms
for programming.
Prototype-Based Programming
It is a style of OOP in which inheritance is achieved through duplication of the objects which
then serves as prototype.
8. 8
3. Introduction
Lua is a scripting language designed by a small team of three developers - Roberto
Ierusalimschy, Waldemar Celes and Luiz Henrique de Figueiredo; at Pontifical Catholic University
(Situated in Rio de Janeiro) in 1993. It is known to be extremely lightweight (with Lua interpreter being
only about 182KB in size!), fast with less overhead, easily embeddable and powerful. Since it is
written in ANSI C, it is extensively cross-platform and able to run on virtually anything.
It have achieved an honorable place in the Gaming as well as other Industries and has been
used in various famous Softwares and Games, such as Angry Birds, Word of Warcraft, Baldur's Gate,
Apache HTTP server, Firefox Web Browser and many more! The main reason being, it can be easily
used to extend the capabilities of an existing program without any need of re-building the software. In
gaming industry, it is mainly used for scripting the AI logic. Another advantage of Lua is that - it is a
free open-source software, which is distributed under the MIT license, allowing it to be used for
virtually any purpose (commercial or non-commercial) at no cost at all!
The name Lua (Not “LUA”) is a Portuguese word meaning moon [6]. The latest version being 5.2, Lua
have had various additions to its features and implementations. However, being an open source
language, users are free to pursue using any version they wish to use for as long as they like.
9. 9
4. History
Lua was created in 1993 by a team of 3 developers from the team TecGraf, Roberto,
Waldemar Celes and Luiz Henrique at Pontific Catholic University situated in Rio de Janeiro city of
Brazil. Brazil had a really strict trade policy known as market reserve from 1977 until 1992 for
computer software and hardware. So in that scenario, it was a matter of affordability for TechGraf’s
clients which prevented from being able to buy custom-made softwares from other part of the world.
And all this lead TechGraf to build the basic tools it required from the beginning [7].
Lua’s predecessors which can also be considered its “father and mother” where the
TechGraf’s data-configuration/description languages - data-entry language (DEL) and SOL (Simple
Object Language). Both of these languages were developed independently by TechGraf during 1992-
1993 to attain additional freedom in two individual projects which they were doing for Petrobras.
Since, there was absence of flow-control structures in both DEL as well as SOL and Petrobras felt
need for addition of more programming power to their programs.
In 1993, Tcl was the only real contender as it was designed to be embedded into applications
but it had a very queer syntax, there was not much support in terms of data-description and moreover,
it ran exclusively on Unix platform. And since their clients had a diverse range of computer platforms,
it was more logical for them to create their own scripting language keeping the diversity of computer
platforms in mind and maintaining a simple syntax as their clients where not professional
programmers. As they expected their future products to also have a need to embed a scripting
language and it went with their do-it-yourself approach which they had back then, they went on to
create their own scripting language to fulfill their need for more programming power and simple syntax
for the potential users. They went on and used ANSI C to make it cross-platform and created Lua, a
successor for DEL and SOL (Which means Sun in Portuguese, so you know where Lua/Moon came
from).
10. 10
5. Benefits
It’s popular
Many industrial languages have used Lua to achieve better user experience and increase
functionality via plugins (One such example being - Adobe's Photoshop Lightroom), with
extensive focus on embedded systems (Such as the Ginga middleware, designed for digital
TV in Brazil) as well as games (Including Angry Birds, Civilization V and World of Warcraft).
As of today, Lua is the most used language in games, having multiple game Engines using it.
There have been several books published about Lua and it have a simple and detailed
manual written by its developers.
Lua is fast
When it comes to performance, Lua is amongst fastest scripting languages. Quite a lot of
tests and comparisons of execution time of Lua with other scripting languages reveal Lua as
the fastest language in the category. It is fast, not only in synthetic benchmarks but in real
world performance too, wide chunks of large applications have been written in Lua.
Additional speed can be achieved with and independent implementation of the language,
namely - LuaJit, which uses just-in-time compiler.
Lua is cross-platform
Distribution of Lua is in small packages and it is built out of the box on any platform which
comes with ANSI C library. Lua runs on various operating systems such as Windows, UNIX,
mobile platforms such as – Symbian, iOS, BREW, Windows Phone and android with support
with many mobile processors such as ARM and even on IBM mainframes, etc.
Lua is embeddable
Lua has a very small over-head and can be embedded into any application with ease. It
allows strong integration with other programming languages through its well documented and
easy to use API and its functioning can be easily extended by libraries written in various other
languages as well. Lua has not just been utilized to extend programs coded using C and C++
but also other programming languages such as C#, Ada, Java and also various scripting
languages namely Ruby and Perl.
11. 11
Lua is powerful (yet simple)
The primary concept behind the design of Lua is to offer meta-mechanisms for
implementation of various features, in place of supplying a cluster of features straight in the
language. For instance, even Lua is not really a pure OOP language, implementation of
classes and inheritance can be done through meta-mechanisms such as tables. The meta-
mechanisms present in Lua bring an economy of concepts as well as keep the language
small and provide all this while permitting extension of semantics in unconventional ways.
Lua is small
Lua’s tarball (Version 5.2.3) which comprises of both the documentation as well as the source
code, occupies only 246KB of space when compressed and 960KB when Uncompressed. So,
it does not really inflate the size of application in which it is implemented. The original source
code of only of around 20,000 lines of code in C. The Lua interpreter occupies around 182KB
when built along with all the standard libraries and the Lua library occupies around 244KB.
It’s Free!
Being an open-source software with MIT license, Lua can be used for any purpose, be it
academic or commercial at not costs at all!
12. 12
6. Evolution
Features 1.0 1.1 2.1 2.2 2.4 2.5 3.0 3.1 3.2 4.0 5.0 5.1
Constructors Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes
Garbage Collection Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes
Extensible Semantics Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes
Support for OOP Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes
Long Strings Yes Yes Yes Yes Yes Yes Yes Yes Yes
Debug API Yes Yes Yes Yes Yes Yes Yes Yes Yes
External Compiler Yes Yes Yes Yes Yes Yes Yes Yes
vararg Function Yes Yes Yes Yes Yes Yes Yes
Pattern Matching Yes Yes Yes Yes Yes Yes Yes
Conditional
Compilation
Yes Yes Yes
Anonymous Functions,
Closures
Yes Yes Yes Yes Yes
Debug Library Yes Yes Yes Yes
Multi-state API Yes Yes Yes
for Statement Yes Yes Yes
Long Comments Yes Yes
Full Lexical Scoping Yes Yes
Booleans Yes Yes
Co-Routines Yes Yes
Incremental Garbage
Collection
Yes
Module System Yes
Since its creation in 1993, Lua have seen various drastic improvements and changes. Version 1.0
was never publically available and the first public release of Lua began with 1.1 which was released
on 1994, 8 July and was free for academic purposes and any commercial use had to be negotiated
but it never was. In Feb 1995, Lua 2.1 came to the scene with support for OOP and this time, it was
freely available for all purposes. Same year, in November, version 2.2 got released with support for
long strings and a couple more features. 2.3 was never released publically and only existed in beta.
And in the next few years, various versions came in with multiple improvements, additions and bug
fixes. On April 2003, Lua 5.0 came with new MIT license having new features such as full lexical
support, Co-Routines for collaborative multi-threading and metatables. The current version of Lua is
5.2, which was released on Dec. 16, 2012 with new key features, such as – finalizers for tables, an
13. 13
emergency garbage collector, a brand new library for bitwise tables, light C functions and goto
statement support. Its latest release is 5.2.3 which was released on Dec. 07, 2013. The work for Lua
5.3 has already been initiated and beta version is available, however no release date is available for
the final version as of 23 June 2014. [8]
14. 14
7. Programming in Lua
Lua is a multi-paradigm language. It does not really have any classes but it does support the
concept of OOP by ‘faking’ classes through tables and achieving inheritance through prototype-based
programming [9]. Unlike other languages such as C, there is no need to declare any variable.
Variables can be used whenever required and they don’t require any declaration first. Moreover,
variables have no data types, only values do.
There are basically eight types present in Lua – table, userdata, nil, thread, string, Boolean,
function and number.
Table – The type tables is used for implementation of associative arrays, which means arrays
can be indexed with not just numbers but any type available in Lua apart from Nil and Nan
(Not a Number, it is used for representation of unpresentable results, for example – 0//0).
Userdata – It is utilized to store any C data into a Lua variable. Its value is actually a pointer
which points to a block of raw memory. Userdata can be further sub-divided into two different
types –
o Full userdata – In it, the management of block memory is performed by Lua.
o Light userdara – The management of memory block is handled by the host.
Nil – Its main characteristic is to be different from all the values and it signifies the absence of
useful value.
Thread – Threads are used to implement coroutines, they signify individual threads of
execution. They are different from the threads present in operating systems and Lua also
have support for threads on operating systems which do not have them.
String – A string is used for representation of immutable sequence of bytes.
Boolean – It holds value in either true or false.
Function – Lua support the functionality to call and manipulate functions which have been
written in Lua as well as C.
Number – it is used for representation of real numbers with double floating point precision.
15. 15
A simple “Hello world!” program can be as short as one line of code in Lua –
For swapping two numbers, a temporary variable is required to store the value and then copy
or mathematical addition and subtraction algorithm is required. However, it is built into Lua –
This line of code swaps the value of ‘a’ with that of ‘b’ and the value of ‘b’ with that of ‘a’.
While loop syntax in Lua –
This program will print ‘Hi’ three times.
print(“Hello world!”)
a,b = b,a
a = 5
while a>2 do
print(“Hi”)
a = a – 1
end
16. 16
An example of class in Lua –
function Gold_Reserve:new (o)
0 = 0 or
Setmetatable(o, self)
return 0
end
function Gold_Reserve:Deposit (v)
self.Existing = self.Existing + v
end
function Gold_Reserve:Retrieve (v)
if v > self.Existing then error “insufficient gold
available” end
self.Existing = self.Existing – v
end
17. 17
7.1 Lua VS Other Scripting Languages
Lua VS Ruby [10]–
18. 18
Lua VS Python [11]–
So in these benchmarks, it can be seen that Lua is a lot faster than its competing languages.
However, it needs to be noted that it is fast in terms of scripting languages, however if we compare it
with other languages such as C, it will be slower.
19. 19
8. Discussion & Conclusion
Lua is a scripting language which started as a project of a small group for their personal
projects but eventually became famous amongst programmers due to its ease of use, power, speed
of execution of commands, portability as well as small size and little over-head. Lua provides
incredible integration with other leading languages though its API libraries and have become a really
good extension language due to that fact. Many famous programs, games and game engines have
adopted it. It is really useful for game developers as it is a very secretive industry and having Lua in
their game allows modding community to mod the games without even knowing the source code of
the actual game which in turn increases the lifetime of that game, web browsers use Lua for
extensions and plugins, video games use Lua for their AI logic.
Languages like Lua gives people with no programming background an easier way to get
themselves into the field of programming without much investment of time and need of knowing the
actual background processes and provides them with a platform to begin their programming career.
All this, comes along with multiple merits and uses which not many languages are able to seize.
20. 20
9. References
[1] L. Wall, "Programming is Hard, Let's Go Scripting...," 06 12 2007. [Online]. Available:
http://www.perl.com/pub/2007/12/06/soto-11.html. [Accessed 21 05 2014].
[2] j. noble, A. Taivalsaari and I. Moore, Prototype-Based Programming: Concepts, Languages and
Applications, Springer, 1999.
[3] B. C. Pierce, "What is Object-Oriented Programming?," in Types and Programming Languages.,
MIT Press, 2002.
[4] "Interpreted Languages," 06 08 2004. [Online]. Available:
https://earthsci.stanford.edu/computing/unix/programming/interpreted/. [Accessed 03 05
2014].
[5] "Subroutine," [Online]. Available: http://www.computerhope.com/jargon/r/routine.htm.
[Accessed 03 05 2014].
[6] "About, Lua.org," [Online]. Available: http://www.lua.org/about.html#name. [Accessed 06 05
2014].
[7] R. Ierusalimschy, L. H. d. Figueiredo and W. Celes, "Prehistory," in HOPL III Proceedings of the
third ACM SIGPLAN conference on History of programming languages, Rio-d Janeiro, 2007.
[8] "Version History, Lua.Org," [Online]. Available: http://www.lua.org/versions.html. [Accessed 10
06 2014].
[9] K. Jung and A. Brown, Beginning Lua Programming, Wiley Publishing, Inc., 2007.
[10] "Ruby VS Lua," [Online]. Available:
http://benchmarksgame.alioth.debian.org/u64/benchmark.php?test=all&lang=lua&lang2=yarv
&data=u64. [Accessed 15 06 2014].
[11] "Lua VS Phython 3," [Online]. Available:
http://benchmarksgame.alioth.debian.org/u64/benchmark.php?test=all&lang=lua&lang2=pyth
on3&data=u64. [Accessed 15 06 2014].