A Brief Introduction to Lua Scripting

The First Step to World of Warcraft's Interface Customization

© Mark Alexander Bain

Jun 24, 2009
A Brief Introduction to Lua Scripting, Mark Alexander Bain
Lua (portuguese for "Moon") is the scripting language used for World of Warcraft's interface customization. It's light, fast, portable, embeddable and very easy to learn

The most interesting thing about the Lua scripting languages is not that:

  • Lua is free to download, install and use
  • Lua is open source
  • Lua is small and fast
  • Lua is portable
  • Lua is embeddable
  • Tiobe reports that Lua is the 20th most used programming language (as of June 2009) with 0.557% of programmers using it
  • Lua is Portuguese for “Moon”

No, the most interesting thing about Lua is that it is used by more people than there are living in Belgium, and they don't even realize it.

How can the Number of Lua Users be Greater than the Population of Belgium?

One reason for Lua's success is that it is used as part of the interface customization for World of Warcraft (WoW), and it's an interesting fact that:

  • the current population of Belgium is 10, 403, 951
  • the current population of World of WarCraft (WoW) is 11 million

As well as World of Warcraft, Lua is used in (to name but a few):

  • Adobe Photo Lightshop
  • Apache
  • Baldur's Gate
  • Damn Small Linux
  • Heroes of Might and Magic
  • MySQL
  • SciTE
  • Supreme Commander

So, obviously Lua must be very complicated to use? Well, no, it's not. And that is why Lua is so powerful – it can be used as easily in a small scale development in Windows as a complex application targeted for a Playstation or a GameCube.

Installing Lua

The Lua installation application can be downloaded directly from the a href='http://www.lua.org'>Lua web site. It's worth noting that Lua requires the Microsoft Visual C++ 2005 SP1 redistributable to be installed as well (although the installation process will attempt to do that if the redistributable is missing and the user's computer is connected to the Internet).

A Simple Lua Script

Lua comes with its own command line interface, and so, once Lua has been installed the programmer can click the desktop shortcut to Lua, or start a command prompt and then type 'lua'. It's then just a matter of trying out some scripting (as can be seen in figure 1 at the bottom of this article):

print ('Hello World')

Once the obligatory 'Hello World' has been tried out then it can be turned into a function:

function hello ()
print ('Hello World')
end

Which can then be called by typing:

hello()

And, of course, the programmer will then want the function to accept inputs:

function hello (name)
print ('Hello ' .. name)
end

This is run by typing:

hello ('Me')

If this code is now saved to a file (for example c:\lua\hello) then it can run from any command prompt (as shown in figure 2) by typing:

lua c:\lua\hello

At this point the programmer can relax with a nice cup of Moca, look at WoW and say “I know how that all works”. Well, maybe not, but at least they'll have taken their first steps down that road.


The copyright of the article A Brief Introduction to Lua Scripting in Computer Programming Languages is owned by Mark Alexander Bain. Permission to republish A Brief Introduction to Lua Scripting in print or online must be granted by the author in writing.


A Brief Introduction to Lua Scripting, Mark Alexander Bain
Figure 1: The Lua Command Line Interface, Mark Alexander Bain
Figure 2: Running a Lua Script, Mark Alexander Bain
Figure 2: Running a Lua Script, Mark Alexander Bain
 


Post this Article to facebook Add this Article to del.icio.us! Digg this Article furl this Article Add this Article to Reddit Add this Article to Technorati Add this Article to Newsvine Add this Article to Windows Live Add this Article to Yahoo Add this Article to StumbleUpon Add this Article to BlinkLists Add this Article to Spurl Add this Article to Google Add this Article to Ask Add this Article to Squidoo