[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Lua 4.0
- From: Roberto Ierusalimschy <roberto@...>
- Date: Fri, 25 Aug 2000 18:10:14 -0300
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 SWIGLua 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.
-- Roberto