Tuesday, September 4, 2012

LUA

What is Lua?

Lua is a powerful, fast, lightweight, embeddable scripting language.
Lua combines simple procedural syntax with powerful data description constructs based on associative arrays and extensible semantics. Lua is dynamically typed, runs by interpreting bytecode for a register-based virtual machine, and has automatic memory management with incremental garbage collection, making it ideal for configuration, scripting, and rapid prototyping.


Where does Lua come from?

Lua is a scripting language born in 1993 at PUC-Rio, the Pontiļ¬cal Catholic University of Rio de Janeiro in Brazil.
Since then, Lua has evolved to become widely used in all kinds of industrial applications, such as robotics, literate programming, distributed business, image processing, extensible text editors, Ethernet switches, bioinformatics, finite element packages, web development, and more. In particular, Lua is one of the leading scripting languages in game development.


What's in a name?

"Lua" (pronounced LOO-ah) means "Moon" in Portuguese. As such, it is neither an acronym nor an abbreviation, but a noun. More specifically, "Lua" is a name, the name of the Earth's moon and the name of the language. Like most names, it should be written in lower case with an initial capital, that is, "Lua". Please do not write it as "LUA", which is both ugly and confusing, because then it becomes an acronym with different meanings for different people. So, please, write "Lua" right!
Why choose Lua?

  • PROVEN, ROBUST language
  • FAST   
  • PORTABLE.
  • EMBEDDABLE.
  • POWERFUL (but SIMPLE)
  • SMALL
  • FREE
  • EXPRESSIVE

One-on-One:

  • Lua Vs Python


Lua 's not whitespace sensitive. While this has its downsides when compared with Python, there is no need to worry about automatic editor space-to-tab conversion or vice versa. When using a proportional width font, Lua allows use of as much indentation as necessary to make the code easy to read.


Python is extremely high performance numeric computing (ala scientific and graphics) is possible with an add-on module that implements true multidimensional arrays. Strictly speaking, Lua has no arrays and must use a table structure for them.



When it comes to OO models, Python dictates a specific model for object-oriented programming. It has rich OO capabilities, including metaclasses, multiple inheritance, and so on. Lua does not dictate any particular OO system. Instead you can build your own (using meta-methods) and tailor it to your needs.
  • Lua Vs Perl
Memory Management:

 Lua 5.1 has an incremental garbage collector. Perl uses a simple but efficient reference-based garbage collection that will leak on cycles.


Stability: 

Very few bugs can be found in Lua. The code is small, highly stable, and extensively reviewed. The Perl core is larger, does more, and is much more complex, so naturally it would be harder to ensure validity. That said, Perl is widely used and tested, and the core is generally quite stable. If one includes non-core modules, then Perl may be more stable/mature in general. 

  • Lua Vs Go
Types:
Go has a larger number of built-in types (e.g. integers of various sizes and signedness), whereas Lua code normally just uses the number type (typically floating point).
Multiple  return values are supported by both languages. Strings are immutable in Go and Lua. 
Pointers:
Go has pointers but no pointer arithmetic, for safety. Lua has no pointers.
  • Lua Vs Ruby                                Lua  already had a very good VM which allows Lua programs to be compiled and also to execute a lot faster than Ruby(x2 in most case).

SAMPLE PROGRAMS:

  • Hello World!






  • Factorial



Strings in Lua are subject to automatic memory management, like all Lua objects. That means that you do not have to worry about allocation and deallocation of strings; Lua handles this for you. A string may contain a single letter or an entire book. Lua handles long strings quite efficiently. Programs that manipulate strings with 100K or 1M characters are not unusual in Lua!!!

There is a function called "dofile" which is very useful when you are testing a piece of code. You can work with two windows: One of them is a text editor with your program (in a file prog.lua, say) and the other is a console running Lua in interactive mode. After saving a modification that you make to your program, you execute dofile("prog.lua") in the Lua console to load the new code; then you can exercise the new code, calling its functions and printing the results.



QUOTEs:

“Lua is a brilliant, tiny powerhouse.” 
Lucas Ackerman, in rec.games.roguelike.development (2003).

“Lua - The most useful piece of truly free software I've ever used.” 
David Jeske, in his list of recommended products (2000?).
“This fine, little, free scripting engine is one of the most reusable parts in software industry I ever found. I could not imagine any better way of incorporating a scripting system into a game engine than this one.” 
Harald Nowak, in the Station 5 web site.
“If you compare Scheme and Lua for the things you'd want in a game console scripting language, I think Lua will come out ahead. It's smaller, portable, uses less memory, and is faster.”Steve Dekorte, in comp.lang.objective-c (1997).
“Learn it at once. It's lovely.”
Rob Kendrick, in comp.sys.acorn.programmer (2000).


Heart to Heart :">

"I thought that Lua is just like a child of python but when you read more about it, you'll discover that it offers more. =) It's more readable and writable compare to other PLs. Small but terrible...fast and easy to extend." 
-Vice Ganda 2010-41749 T-9L
 "I think it's cool. But the name sucks." -Zukee 2010-57236    T-9L
Installer for Windows: Lua For Windows
Programming in LuaCode Examples

References:


http://www.lua.org/pil/1.1.html
http://www.lua.org/quotes.html




CMSC 124 LUA MEMBERS:
2010-41749 Vice Ganda
2010-57236 Zukee


1 comment: