Lua Language

www.lua.org is the official homepage, and contains a good overview.

See also lua-users wiki: lua-users.org and the tutorial lua-users.org .

I like Lua for the same reason I like Wiki: it's clean, simple, and light. The authors had a pure vision and left out the right things. Lua is the best extension language I've seen. It has a simple Cee Language Application Programming Interface, and a simple build process, and simple mechanisms for moving data in and out of the scripting subsystem. I was able to extend my application with Lua in the first day of use. -- Ashley Fryer

Lua 5 is built on a Non Recursive Interpreter, which allows it to directly support Co Routines.

Lua seems to have found a major killer application in game UI modification. World of Warcraft is the premier example, with a public-facing API for rewriting the interface. Rift, Age of Conan, Lord of the Rings Online, Warhammer Online, Runes of Magic and probably others have followed suit in recent years. Minecraft has an add-on, Computercraft, that allows you to write Lua scripts that interact with the Minecraft virtual world.


Simplified Wrapper And Interface Generator (SWIG) can be used to make calls to Cee Language or Cee Plus Plus code.


Lua also have a Just In Time Virtual Machine: www.luajit.org (LuaJIT2 is very fast!)


Lua 5.2

Lua 5.2 is (as in Nov 2011) in beta. This release will add (quoting the manual) yieldable pcall and metamethods, new lexical scheme for globals, ephemeron tables, new library for bitwise operations, light C functions, emergency garbage collector, goto statement, and finalizers for tables.

As of June 2012, Lua 5.2.1 is the current most stable release. Now that setfenv is gone, a lot of people are feeling empty inside, but the capabilities provided by _ENV are intriguing. They do pretty much everything setfenv did, except they lie closer to the code in the language, as opposed to being outsourced to a magic function. Not that Lua didn't work perfectly fine with magic function boxes that flip things about in amusing ways, but now that environments are controlled via a lexically scopable variable, you can make some amusing constructions, provided you know what you're doing... Perhaps that was the goal all along: to make sure we knew what we were doing when we referred to our magic environment-changing box.


Lua 5.1

Lua 5.1 was released in 2006 and it is the current stable language version. Quoting the release text, it adds "a new module system, incremental garbage collection, new mechanism for varargs, new syntax for long strings and comments, mod and length operators, metatables for all types, new configuration scheme via luaconf.h, and a fully reentrant parser".


Lua 5.0

Lua 5.0 was released on 11 Apr 2003. The main new features in Lua 5.0 are collaborative multithreading via Lua coroutines, full Lexical Scoping instead of upvalues, and metatables instead of tags and tag methods. Lua 5.0 also introduces booleans, Proper Tail Calls, and weak tables. Other features are better support for packages, new API for loading Lua chunks, new error handling protocol, better error messages, and much more. Lua 5.0 is the first version to be released under the new license.

With Version 5.0, Lua now uses a register-based instead of stack-based Virtual Machine.


Following are official announcements about the 4.0 alpha and beta of Lua, sent in the Lua mailing list. I've rearranged them in reverse chronological order.

I'm happy with the usual direction the Lua authors have taken the language in the 4.0 beta - they made it even smaller and faster than before. But the new C API is going to be a problem. I and others where I work invested a significant effort in extending Lua for our application, and now all that code will have to be revisited. It's too bad they couldn't come up with some sort of compatibility macros to make the transition easier, but it just wasn't possible with these changes.

Oh well, such is progress...


Lua 4.0 (beta) is now available for downloading at

ftp://ftp.tecgraf.puc-rio.br/lua/lua-4.0-beta.tar.gz

ftp://csg.uwaterloo.ca/pub/lhf/lua/lua.tar.gz

The other mirrors will be updated soon, hopefully.

The distribution includes an updated reference manual in HTML. The Post Script and PDF versions in the site are still for version 3.2.

New in version 4.0 (beta)

new API:
fully re-entrant, simpler, and more efficient.

new "break" and "for" statements (both numerical and for tables).

cleaner virtual machine -- at least 20% faster.

uniform treatment of globals:
globals are now stored in a Lua table.

improved error messages.

no more '$debug':
full speed *and* full debug information.

reduced memory usage.

non-recursive garbage-collector algorithm.

code now compiles unmodified as both ANSI C and C++.

improved support for 16-bit machines (we hope).

and more!

Lua 4.0 is a major new version (4.0 beta is a field test; we don't expect to make any visible changes from 4.0 beta to 4.0 final).

The language itself changed only a little ("break" and "for" statements and new semantics for forwarding the return values of functions are the major changes), but the C API and the implementation have changed a lot, with a new, simpler C-Lua protocol, a new, better code generator and a new, faster virtual machine. Also, the built-in functions are now in the standard library, and so Lua's core is even smaller (and faster)!

Those that program only in Lua should quickly adapt to Lua 4.0: many uses of

"while", "foreach" and "foreachvar" can now be rewritten using "for" in a much cleaner way. Also, global variables are now stored in an ordinary Lua table, making the treatment of globals and table fields more uniform.

Lua programmers will also welcome the improved error messages and the presence of full debug information without '$debug' (which paid a speed penalty in 3.2). Lua programs now run at full speed *and* errors are now reported fully (name of variable or field that caused the error, along with line numbers in the stack traceback).

Unfortunately, those that use the C API will have to change their code. First, all functions now require an explicit Lua state as the first argument, because the API is now fully re-entrant. Second, the C-Lua protocol has changed to be a simpler, stack-based protocol. lua_Objects have vanished and have been replaced by indices into the stack. This new protocol is simpler to use and understand and is more efficient. Hopefully, doubts about why the stack may overflow (as in a recent posting) will be a thing of the past. :-)

Also, the old API cannot be mapped easily into the new API, and so lua.h no longer contains compatibility macros. We are sorry about this, but we think that this is the time to adapt your C code, once and for all.

Moreover, libraries generated by tools such as tolua and the Simplified Wrapper And Interface Generator will be automatically updated once these tools have been updated to 4.0. tolua should be ready when we release Lua 4.0 (final).

Please report any problems to lua@tecgraf.puc-rio.br.

Thanks.

-- lhf

The support for reentrancy is a big deal as now Lua can be used concurrently from multiple threads. There was a mutant version of Lua available that also offered reentrancy, but this is now supported by the language designers. Lua was pretty fast before, but now it is noticably faster. -- John Passaniti


Here's a note from one of the Lua developers received today (August 28th, 2000) about the beta release of Lua 4.0.

About Lua 4.0:

The good news is that we are finishing the last modifications to release a beta version. The bad news is that those are somewhat big modifications. ;-) Mainly, we are redesigning the C API (more about that later).

Although we will release the next version as beta, we intend it to be as final as possible. But as there are many changes, we prefer to call it beta, and wait a little longer before releasing a final version. But we promise not to change any visible part of Lua from the beta version to the final 4.0 version, unless someone finds something very weird.

We hope to release Lua 4.0 beta by mid-September.

The news in the new version are:

new API:
(much) simpler, smaller, and (a little) faster. (more about that later ;-):

table of globals:
all globals are now stored in a regular table; you can change that table, so that you change all globals with a single (and fast operation.

`for' statement for tables:
?for k,v in t do ... end? * no more '$debug': full speed *and* full debug information. (Actually, no more pragmas at all.)

improved error messages; examples:

> foo() error: attempt to call global `foo' (a nil value)

> local a; print(a..1) error: attempt to concat local `a' (a nil value)

improved support for 16-bit machines (we hope)

improved treatment for memory allocation errors

non-recursive garbage-collector algorithm

About the new API: the current API between Lua and C is quite simple for simple things, but too much complex for non-trivial tasks. For instance, very few people really understands why/when/how to use beginblock/endblock. So, we are replacing the current design (with two structures lua2C/C2lua) by a simpler one with only one stack. We get rid of beginblock/endblock, lua_Object, and getparam/getresult. All objects are created on the top of the stack. lua_is* and other queries have direct access to any element on the stack. When a C function is called, its parameters are on the stack. When it returns, the results are also on the stack. To separate them, the function returns (in C) the number of results it is returning (in Lua). The auxlib remains mainly unchanged, so for many simple functions the only change is this "return int". For instance, the `sin' function in mathlib now will be

static int math_sin (lua_State *L) { lua_pushnumber(L, sin(TORAD(luaL_check_number(L, 1)))); return 1; /* <<<< Tells Lua it is returning one result */ }

As we said, this new API is much simpler to explain, it is much easier to implement, and it is faster and smaller. Although it is not difficult to change (by hand) a program with the old API to the new one, we are afraid we won't be able to provide a "compatibility module" that simulates the old API over the new one.

We feel that most C libraries are either small or are generated automatically with tools like Simplified Wrapper And Interface Generator for Lua and tolua. We intend to update tolua as soon as possible to generate code for 4.0, and we are willing to help the writers of others tools to adapt their code, if necessary.


Related:


Discussion moved to Lua Language Discussion. See also To Lua Description.


See original on c2.com