Introducing Lua
Lua, WTF?
Lua is a powerful, fast, lightweight, embeddable scripting language. It’s name comes from the Portuguese word lua meaning “moon”. 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 Lua can be used?
Lua is intended for use as an extension or scripting language, and is compact enough to fit on a variety of host platforms. It is widely used as a scripting language by game programmers (in Blizzard’s World of Warcraft for instance), perhaps owing to how easy it is to embed, its fast execution speed, and its small learning curve. Besides, Lua used in Adobe Photoshop Lightroom for user interface, in MySQL Workbench for extension and add-ons, in VLC media player to provide scripting support and in many other products (list of products that uses Lua on it’s official site and Wikipedia list).
How to get started with Lua?
First you need to download and install Lua for your system. Lua distributed in source code, already compiled binaries and special “Lua for Windows” version. I’ve tried Windows version which include command line Lua interpreter and Lua IDE (“SciTE”) with syntax coloring, debugging, etc.
If you don’t want to install anything and just wanna play with Lua you can try online Demo interpreter.
Lua Basics
The most recent version is 5.1 – released in 2006 (5.2 still under development). Lua written in ANSI C so it’s very fast. Lua has a simple and well documented API that allows strong integration with code written in other languages. It is easy to extend Lua with libraries written in other languages. It is also easy to extend programs written in other languages with Lua. Lua has been used to extend programs written not only in C and C++, but also in Java, C#, Smalltalk, Fortran, Ada, Erlang, and even in other scripting languages, such as Perl and Ruby.
Lua’s syntax is very easy, so it shouldn’t be a problem for any developer to understand it. Two dashes introduce comments. An end statement delimits control structures (if, for, while). All variables are global unless explicitly declared local. Lua’s fundamental data types include numbers (typically represented as double-precision floating-point values), strings, and Booleans. Lua has true and false as keywords; any expression that does not evaluate to nil is true. Note that 0 and arithmetic expressions that evaluate to 0 do not evaluate to nil. Thus Lua considers them as true when you use them as part of a conditional statement.
Usual “Hello World” example looks like this:
Let say “Hello” three times:
print("Hello World")
end
Cool, isn’t it?
I would like to recommend you great Lua tutorial by Lee Gao - The.Lua.Tutorial to quickly get started with Lua syntax. If you’re interested to get more information about Lua please check last section with recommended links.
Further reading
Official site: Lua – the programming language
Embeddable scripting with Lua – at IBM developerWorks
Introducing Lua – at O’Reilly OnLamp
TweetTagged as lua, scripting
-
http://www.surgeforward.com Web Development