Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Begin Lua-scripting [closed]

Tags:

scripting

lua

I'm at a stage where I am forced to learn Lua, so do you have any suggestions on how I do this? I don't have a lot of experience with any other scripting languages than PHP.

So, some suggestions on "head start Lua"-pages?

EDIT

As an addition to the wonderful tutorial pages, could you please suggest any "programs" I could make that will help me learn Lua? Imagine I would want to learn Pointers in C++, I'd make a Linked List. I want to touch the basics in Lua but meanwhile be open to pretty advanced stuff.

like image 206
Filip Ekberg Avatar asked Feb 24 '09 09:02

Filip Ekberg


People also ask

How do I start Lua scripting?

A good place to start learning Lua is the book Programming in Lua, available in paperback and as an e-book. The first edition is freely available online. See also course notes based on this book. The official definition of the Lua language is given in the reference manual.

How do I exit a Lua script?

To exit the interactive mode and the interpreter, just type end-of-file ( ctrl-D in Unix, ctrl-Z in DOS/Windows), or call the exit function, from the Operating System library (you have to type os. exit()<enter> ).

Does Lua have closure?

In Lua, any function is a closure. In a narrower sense, a closure is an anonymous function like the returned function in your example. Closures are first-class: they can be assigned to variables, passed to functions and returned from them. They can be both keys and values in Lua tables.

How do you break a function in Lua?

Use os. exit() or just return from some "main" function if your script is embedded.


1 Answers

First of all work your way through the Programming in Lua, it should take you a day or two to get the gist of Lua.

However I can tell you right away on your first time through ignore coroutines and metatables, they are very powerful, but take a while to grasp. First learn the syntax, scoping (same as PHP luckily for you) and the standard libraries.

After that go back to coroutines and metatables, read them try them and by the third time through you might get it. Unless you have a very good CS background these are complex topics

Edit: The book is free online == website. Besides it is the best tutorial out there on Lua, everyone learns Lua with it.

Also: If you're purpose is Lua for World of Warcraft (probably not but just in case) you can check out this tutorial

And: Here is a tips and tricks thread on StackOverflow, might help give you some ideas of what to expect from Lua

Suggested Programs/Exercises:

Since you're initially looking at Lua for web development try to understand and improve the Data Description example in PIL. It'll give you a few good ideas and a nice feel for the power or Lua.

Then you might want to try out playing with the Data Structures chapter, although Lua has a single complex data-type, the Table, that chapter will show you Lua-like ways to make a table do anything you need.

Finally once you begin to grok metatables you should design a class system (yes with Lua you decide how your class system works). I'm sure everyone that knows Lua has made a dozen class systems, a good chapter to get you started on a class system is Object-Oriented Programming

And if you got time and know C or something like that (C# and Java included) try extending an application with Lua, but that'll take a week or two to do

like image 149
Robert Gould Avatar answered Oct 07 '22 23:10

Robert Gould