30

I read something about Lua today, and I was wondering what it was.

I did a Google and Wikipedia search, I understood it until they began talking about C and API. I still don't understand it.

What is Lua and are there any tutorials for beginners?

Universal Link
  • 307
  • 1
  • 14

10 Answers10

44

Lua is a lightweight interpreted programming language developed in Brazil with a focus on embedding.

It is written in Pure ANSI C which means high portability, even as C++ code.

Here is an example:

print("Hello World!")

Wikipedia Summary

Official Site

Unknown
  • 45,913
  • 27
  • 138
  • 182
44

I'm surprised everyone is getting this one wrong.

Lua is the Hawaiian word for "toilet".

piotrek1543
  • 19,130
  • 7
  • 81
  • 94
Kip
  • 107,154
  • 87
  • 232
  • 265
34

Lua is a scripting language for C and C++. It allows to use the simpler syntax of Lua and execute these scripts in your C/C++ application. Therefore you don't have to compile the program on each change, but simply deliver a new script version.

For tutorials just use google, you'll find enough to keep you busy the next days.

DaClown
  • 4,171
  • 6
  • 31
  • 31
  • I'dd add to that that it allows to quite easily invoke the C code (don't know about C++, never did it myself, so maybe) from your Lua script. Also it's tiny and quite fast. Which makes it an ideal "glue" for an application. Oh, and it is a perfect config file parser (if you don't import any functions into the interpreter context that you use for parsing the config files). – Andrew Y Aug 13 '09 at 23:42
  • 19
    It's not only for C/C++. The Lua runtime can be used from other languages as well, and there are implementations other than the official one. Lua itself is technically not bound to C or C++. – OregonGhost Mar 05 '10 at 17:10
26

Lua is a simple lightweight highly portable dynamically typed embeddable and extendable multi-paradigm scripting language. The "vanilla" (some would say official) implementation of it is made purely on ANSI C and has an awesome (simple yet powerful) C API that you can use to both embed Lua on your app or extend the behavior of the language itself. It is developed at the Informatics Department of the Pontifical Catholic University of Rio de Janeiro (PUC-Rio).

Thought it was not primarily designed for that, Lua found a big niche in game scripting, with big names such as "Grim Fandango" and "World of Warcraft". Nonetheless, because of its speed, simplicity and portability, it is also heavily used in embedded systems (see, for example, eLua project) and graphic computing.

Its philosophy is to be minimalistic, i.e its core libraries are very small with only minimum functionality (quite like C's standard libraries), though through the C API it is very simple to add features that wouldn't be possible through the pure core library, such as sockets, GUIs etc. In fact, Lua is so minimalistic that its main -and only- structured data type are 'tables', that could be described as associative arrays on 'roids.

Lua is procedural in its essence, but also supports multiple paradigms such as functional programming and object orientation.

Though Lua is not the fastest scripting language around (probably javascript's V8 project wins the prize) it is very fast (faster than vanilla Python or Ruby, for instance) and also features a non-official just-in-time implementation called LuaJIT.

In the end, Lua is actually no more than a fun language to play with, which I recommend!. =)

About tutorials, I'd recommend the article about that on the lua-users wiki.

I hope I helped! =)

PS: I couldn't post all the links because I'm new on stack overflow, but it shouldn't be hard to find everything on Google. Sorry. =(

om-nom-nom
  • 62,329
  • 13
  • 183
  • 228
etandel
  • 381
  • 3
  • 4
  • 1
    There are benchmarks floating around, which show the fastest JIT implementation is LuaJIT. Apparently, LuaJIT has even performed over V8. – J. M. Becker Nov 28 '11 at 20:57
15

Lua is a scripting language. Link is to lua.org. It is heavily used in game development, most notably (to me) World of Warcraft.

Paul Williams
  • 16,585
  • 5
  • 47
  • 82
  • 7
    I wonder if someone thought I worked for Blizzard. I do not. I just played and enjoyed the game for a long, long time. On the other hand, quitting has been the best thing for my life. /shrug – Paul Williams Aug 26 '09 at 22:40
  • I gave you +1 for the awesomeness of your answer! – Mark Dec 05 '09 at 09:30
10

Lua is a lightweight, embeddable scripting language. It's garnered a lot of popularity partly due to it's use in many popular games. A good example of this is World of Warcraft which uses an embedded version of lua to drive the behavior of the UI elements in the game.

A good intro to the language can be found here: http://computer-programming-languages.suite101.com/article.cfm/a_brief_introduction_to_lua_scripting

And the official online reference for the language can be found here: http://www.lua.org/manual/5.1/

Dan Rigby
  • 17,133
  • 6
  • 43
  • 60
8

It's a scripting language that is designed to work with C (and C++). It is designed to be embedded into C/C++ programs. Which means unlike a lot of other scripting languages, it makes no use of global variables and such, this means you can easily thread lua scripting engines.

It also makes claims about being the fastest dynamic scripting language.

I've made use of it in PC based C++ application for creating a plugin scripting interface, and also used it as a embedded scripting language. Its quite versitile, nice and small.

as a general purpose scripting language? Its not quite in the same league as your ruby/python/perl type stuff. It doesn't have as many libraries and the user community is pretty small.

But for extending C++/C apps? its awesome.

Keith Nicholas
  • 43,549
  • 15
  • 93
  • 156
3

Lua is a SCRIPTING language written in C and is commonly used in game development because of its power and flexibility. Lua is also cross-platform so it can be used anywhere on any platform. Lua can also be used as a programming language with a handy program I use called AutoPlay Media Studio which allows you to create fully fledged applications for the Windows platform. I hope this clears things up for you.

Website: http://www.lua.org.
AutoPlay Media Studio: http://www.indigorose.com.

prapin
  • 6,395
  • 5
  • 26
  • 44
3

The C API, which looks to be the part that confused you, is designed to make it very easy for you to take existing C code (or new C code) and control it with a Lua script. This is what is meant by embedding. Via embedding, you can get a lightweight, programmable, interactive, text-based interface to any C code, for very little effort. Even if you don't embed things yourself, Lua is a very nice little scripting language.

My favorite example is that a nice person put a great many POSIX system calls into Lua. When I want something that is like a shell script but is more sophisticated, I can just use this library. Likewise with the MD5 library and with many others.

When learning Lua you can ignore the C API completely—just benefit from other people's work with the API—and if you ever need to embed your own code, you can come back to it later.

Norman Ramsey
  • 198,648
  • 61
  • 360
  • 533
2

Lua is a powerful, fast, lightweight, embeddable scripting language.

Lua combines simple procedural syntax with powerful data description constructs based on associative arrays and extensible semantics. Lua is dynamically typed, runs by interpreting bytecode for a register-based virtual machine, and has automatic memory management with incremental garbage collection, making it ideal for configuration, scripting, and rapid prototyping.

for more you can read here