Sinisterly
Lua Tutorial [1] - Printable Version

+- Sinisterly (https://sinister.li)
+-- Forum: Coding (https://sinister.li/Forum-Coding)
+--- Forum: Coding (https://sinister.li/Forum-Coding--71)
+--- Thread: Lua Tutorial [1] (/Thread-Lua-Tutorial-1)

Pages: 1 2 3


Lua Tutorial [1] - JesseH - 01-26-2013

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 Smile )
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.


RE: Lua Tutorial [1] - Guxi - 01-26-2013

It's great that you came up with idea for Lua tutorial.. It would be nice if you could update this later, to go more further.

Thanks!


RE: Lua Tutorial [1] - JesseH - 01-26-2013

Hey,
I am not that good with tutorials, but I will make it better in the future, and continue it on once I plan it out a bit more. Smile

JesseH


RE: Lua Tutorial [1] - bluedog.tar.gz - 01-26-2013

I wanted to get into Lua duo gmod supporting it.

Anyhow I must say that its a well written tutorial.
You made good use of colors and the [code ] tags.

Keep it up Wink


RE: Lua Tutorial [1] - Ex094 - 01-26-2013

A nicely written tutorial Smile Thank you for your efforts, I'll look more into this language Smile


RE: Lua Tutorial [1] - JesseH - 01-26-2013

Hey,
Thank you all for the support. Maybe my future tutorials will go into more depth. Smile

JesseH


RE: Lua Tutorial [1] - narc0tics - 01-26-2013

Oh, this brings back memories... LUA scripting on Counter-Strike Source - making people angry at the age of twelve.

Thank you, based God. Thank you for this thread.


RE: Lua Tutorial [1] - Dark_Sunrise - 01-26-2013

Thanks! I've been meaning to learn Lua (I see it used everywhere). This tut is great thanks Smile

Quote:to go more further.

hahaha Guxi Wink Try "to go further"


RE: Lua Tutorial [1] - asitkumar - 04-15-2013

Wow!

I program tools for myself in Lua because it is much faster than Perl/Python, takes little space on disk and has a very small memory footprint. Cool

It is a rising language and I am a great fan of it. I liked your post a lot for spreading Lua awareness among new coders Biggrin

Thanks for this tutorial Confusedmiling:


RE: Lua Tutorial [1] - asitkumar - 04-15-2013

Wow!

I program tools for myself in Lua because it is much faster than Perl/Python, takes little space on disk and has a very small memory footprint. Cool

It is a rising language and I am a great fan of it. I liked your post a lot for spreading Lua awareness among new coders Biggrin

Thanks for this tutorial Confusedmiling: