Judging by the fact that you have stumbled upon this document, I doubt you are actually wondering.
However, to quote the official definition:
Lua is a powerful, fast, lightweight, embeddable scripting language.
We'll just assume that the reader is competent enough to actually start Lua. Finding, Downloading, and Installing the Lua package is an excersize that will be left to the readers.
TODO: Download Lua for Windows (Google is your friend)
Lua is an interpreted language. This means that everything written in Lua is ran inside an interpreter.
To access this interpreter, simply run cmdlua and you should see the following show up.
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
If everything's alright, then congratulations, you have sucessfully installed Lua onto your computer.
Contrary to what hardcore "coders" tell you, notepad is not your ideal development environment. The purpose of a "coder" is to find the fastest way to solve the problem, or the problems. To this end, it's always a good idea to have an IDE on hand. The IDE that comes with the package is called SciTE. The IDE comes with built in syntax coloring and auto-indent. It also auto-configures the lua interpretor so you don't always have to go to the command line to run your code.
Let's try out our fancy new Lua installation. As always, it's ritualistic to start off learning a new language by writing a
Hello World program where we just print out the words Hello and World for no apparent reason. Yeah... we're not going to do that.
Instead, we will begin by printing out the frustrated response of a diagnostician.
Lupus is an auto immune disease. We will start off our life on the moon by printing out this quote.
print("It's Never Lupus!")
It's Never Lupus!
As you may have guessed, the statement
print("blah blah blah") will print out blah blah blah. Indeed, print is a function.
We will talk more about the properties of functions in a later chapter, but for practical purposes, we invoke or activate a function by
typing in its name followed by a set of parenthesis, that is (). "print" is the name of the function that prints out the text, () invokes it,
and the text within the parenthesis are the parameters that will be printed out.
To finish off with our introduction, I will present a sample program that will demonstrate other features of Lua. It's always easier to read code than to write them so I hope you won't have any trouble figuring out what it does
for i=1,10 do print("Maybe it's Auto Immune...") end print("House: If someone says Auto Immune, you're fired! ")
Maybe it's Auto Immune... Maybe it's Auto Immune... Maybe it's Auto Immune... Maybe it's Auto Immune... Maybe it's Auto Immune... Maybe it's Auto Immune... Maybe it's Auto Immune... Maybe it's Auto Immune... Maybe it's Auto Immune... Maybe it's Auto Immune... House: If someone says Auto Immune, you're fired!
The for keyword specifies that we're going into a loop. For each time that we go through the loop, the value of i, which is declared in the i=1 portion of the first line, is increased by 1, until the value of i reaches the value after the first comma, which in this case is 10. In each of these iterations, Lua will execute the code that is enclosed between the do and the end keywords, which is called a chunk or a block.
Other properties of for-loops will be discussed in later chapters.blog comments powered by Disqus