Lua Tutorial [1] 01-26-2013, 08:56 PM
#1
Lua Tutorial 1
Hello everyone, this is my first tutorial. I have been seeing lots of threads about Python, and other languages, and not enough about this wonderful language so I thought I would write this myself.
What is Lua? ( Lua, not LUA, not lua, but Lua )
http://www.lua.org/
Lua is a fast, powerful language, that is embeddable. This means that it can be used with other languages such as C, C++, or even Java. Compared to Python, Lua's standard lib is much much smaller, but this is one of the things that makes Lua great.
If you have something that you need, code it yourself, your way. No need to use someone else version. If it is too big, then most likely it has already been written and you can find it via Google.
Why use Lua?
The answer to this is partly in the definition of Lua. Lua is very small compared to other popular scripting languages such as Python. Lua is also faster. ( This is not to start an argument, but if you disagree please post a benchmark
)
Lua is also very easy to learn. Since it is not all that big, learning it will take little time.
Let's now get to actually learning about Lua's syntax.
First of all, go download the Lua interpreter. Explaining what an interpreter is, is not in the scope of this thread. Please Google it. You can get the interpreter from the link above.
Windows users, look into LuaforWindows. http://code.google.com/p/luaforwindows/
Go into terminal, or command prompt, and type "lua"... This should bring up an interpreter... Then type..
( also, you can run lua programs by changing directories of the one of the program, in terminal, and type lua programname.lua )
Now let's learn about variables. Variables store data. If you are familiar with other languages then this should make total sense. If not, I apologize.
This shows you a couple new things. First off, '..' is used for separating data inside the print statement. You can also use ','.
To declare a variable, just type in the holder, then make it equal to anything you'de like. The same goes with booleans.
Go ahead and mess with what you just learned a little bit, change things up, and research things if I did not explain them enough.
Now let's learn about Tables. Tables hold information, just like a variable. If you are familiar what an array is, you can say that Tables hold arrays of information. For example...
Functions
To create a function in Lua, you can do something similar to this...
For more information please check http://lua-users.org/wiki/FunctionsTutorial
This sums up this tutorial pretty nicely. I did not go into great detail about much, because I only wanted to give you an introduction. I hope that you will do the research yourself, and learn the language if you want to.
Here are some good resources for learning Lua...
http://lua-users.org/wiki/LuaDirectory
http://www.lua.org/pil/
http://www.google.com
If after this, you are wondering "Who actually uses Lua?" then here you go...
http://www.lua.org/uses.html
Any specific help PM me. I am always happy to help.
Hello everyone, this is my first tutorial. I have been seeing lots of threads about Python, and other languages, and not enough about this wonderful language so I thought I would write this myself.
What is Lua? ( Lua, not LUA, not lua, but Lua )
http://www.lua.org/
Lua is a fast, powerful language, that is embeddable. This means that it can be used with other languages such as C, C++, or even Java. Compared to Python, Lua's standard lib is much much smaller, but this is one of the things that makes Lua great.
If you have something that you need, code it yourself, your way. No need to use someone else version. If it is too big, then most likely it has already been written and you can find it via Google.
Why use Lua?
The answer to this is partly in the definition of Lua. Lua is very small compared to other popular scripting languages such as Python. Lua is also faster. ( This is not to start an argument, but if you disagree please post a benchmark
)Lua is also very easy to learn. Since it is not all that big, learning it will take little time.
Let's now get to actually learning about Lua's syntax.
First of all, go download the Lua interpreter. Explaining what an interpreter is, is not in the scope of this thread. Please Google it. You can get the interpreter from the link above.
Windows users, look into LuaforWindows. http://code.google.com/p/luaforwindows/
Go into terminal, or command prompt, and type "lua"... This should bring up an interpreter... Then type..
( also, you can run lua programs by changing directories of the one of the program, in terminal, and type lua programname.lua )
Quote:print("hello world")As you can see, this will display 'hello world' on the screen. Do this a few more times, and see how it works.
Now let's learn about variables. Variables store data. If you are familiar with other languages then this should make total sense. If not, I apologize.
Quote:x = 1
y = 2
print("X = " .. x)
print("X = " .. y)
z = x + y
print("Z = " .. z)
This shows you a couple new things. First off, '..' is used for separating data inside the print statement. You can also use ','.
To declare a variable, just type in the holder, then make it equal to anything you'de like. The same goes with booleans.
Quote:am_I_alive = true
sittingDown = true
standingUp = false
Go ahead and mess with what you just learned a little bit, change things up, and research things if I did not explain them enough.
Now let's learn about Tables. Tables hold information, just like a variable. If you are familiar what an array is, you can say that Tables hold arrays of information. For example...
Quote:table_1 = { "cat", "dog", "soup" }http://lua-users.org/wiki/TablesTutorial -- This site will teach you about tables more into depth.
Functions
To create a function in Lua, you can do something similar to this...
Quote:function saySomething()
print("Something")
end
OR
function saySomething(argument1)
print(argument1)
end
For more information please check http://lua-users.org/wiki/FunctionsTutorial
This sums up this tutorial pretty nicely. I did not go into great detail about much, because I only wanted to give you an introduction. I hope that you will do the research yourself, and learn the language if you want to.
Here are some good resources for learning Lua...
http://lua-users.org/wiki/LuaDirectory
http://www.lua.org/pil/
http://www.google.com
If after this, you are wondering "Who actually uses Lua?" then here you go...
http://www.lua.org/uses.html
Any specific help PM me. I am always happy to help.
Follow me on Twitter @jessehorne27 

![[+]](https://sinister.li/images/modern/collapse_collapsed.png)


![[Image: 9i8hs6.png]](http://i49.tinypic.com/9i8hs6.png)


miling:
![[Image: Need-ASP.Net-Expert-with-C2.jpg]](http://axtongroup.com/asp.net-developer/wp-content/uploads/2013/02/Need-ASP.Net-Expert-with-C2.jpg)