[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANNOUNCE] Lua 5.0 (work0)
- From: Roberto Ierusalimschy <roberto@...>
- Date: Thu, 06 Jun 2002 11:49:17 -0300
Here is a list of changes in 5.0w0. Probably I will forget some of them,
or list some which were already present in 4.1w4...
- the biggest change is the packing of the standard libraries into tables.
We changed the names of some of them ('string', 'table'), but we could
not think of good long names for the 'io' and the 'os' libraries...
- all "tag method" names are prefixed with '__'
- As several people complained about the global statement (saying it was
too complex, the worst sin for us ;-), we removed it. We are thinking
now in a much simpler mechanism (not yet implemented). It would be more
or less equivalent to
global in exp
That is, each function can have its "own" global table. When several
functions share the same global table we have a namespace. With
that mechanism, it is much easier to apply tag methods to those
tables, as they only affect the respective module, and not the whole
program. Therefore, each module could decide whether it wants forced
declarations, declarations only for writing, what to import, etc.
- we introduced a new tag method, __newindex, called when we insert a
new key into a table (that is, when we do "t[x]=y" and the old value of
"t[x]" was nil).
- we did some changes in the way chunks are loaded. The core now has only
one "lua_load" function, that gets a "reader" function as argument. Then
auxlib defines the usual luaL_loadfile and luaL_loadbuffer. As a result,
the core now does not use "stdio.h" for anything, except for a single
use of sprintf to convert numbers to strings. (Yes, we also removed all
other uses of sprintf, as now Lua has its own simplified version of
sprintf, where we don't have to worry about memory.)
- we introduced the lightweight userdata, a simple "void *" without
a metatable.
- we are changing some things in error handling. Now, errors are not
printed, but returned, so the caller decides what to do with them. The
"call" function is being replaced by "pcall" (protected call):
"pcall(f, a, b, c)" calls "f(a,b,c)", and returns true plus all returns
from f, or in case of any error, false plus the error message.
(Actually the error value, as the error "message" don't have to be
a string.) The details are still fluid, particularly about the
_ERRORMESSAGE (its work cannot be done after the function returns,
as by then the stack is gone).
- we changed the generic for, so that now it handles a state.
for var_1, ..., var_n in explist do block end
is equivalent to
do
local _f, _s, var_1 = explist
local var_2, ..., var_n
while 1 do
var_1, ..., var_n = _f(_s, var_1)
if var_1 == nil then break end
block
end
end
So, a call like
for i,k in nexti{'a','b','c'} do print(k) end
creates no objects. (The name 'nexti' is weird, but the function shows
the idea.) The "usual" for is simply
for k,v in next,t do ... end
although the old "for k,v in t do ... end" still works.
- we introduced "block comments", --[[ ... ]]
- lua.c now runs the environment variable LUA_INIT, if present. It can
be "@filename", to run a file, or the chunk itself.
-- Roberto