lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


There seems to be an inconsistance with table_getn/table_setn
semantics when LUA_COMPAT_GETN is defined. In Lua 5.0.2, table size
was stored in either a table field 'n' or an inaccessible array in the
registry (checked in that order). Seems like this was changed in lua
5.1-rc in such a way that the internal array is used always in
table_setn, and internal array or 'n' used in table_getn (in that
order). This results in an inconsistent behavior for a feature whose
sole purpose is to provide backward compatibility (unless I
misunderstood).

Here is an example:

Lua 5.0.2  Copyright (C) 1994-2004 Tecgraf, PUC-Rio
> a = { n = 0 }
> table.insert(a, 'one')
> table.insert(a, 'two')
> =a.n, table.getn(a)
2	2
> table.setn(a, 3)
> =a.n, table.getn(a)
3	3

 Lua 5.1  Copyright (C) 1994-2006 Lua.org, PUC-Rio
> a = { n = 0 }
> table.insert(a, 'one')
> table.insert(a, 'two')
> =a.n, table.getn(a)
0	2
> table.setn(a, 3)
> =a.n, table.getn(a)
0	3

Is the change intentional or a bug?

Thanks,
Varol Kaptan

On 1/12/06, Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> wrote:
> Lua 5.1 (final,rc) is now available for testing at
>        http://www.lua.org/work/lua-5.1-rc.tar.gz
>
> This is a pre-release. Unless major problems appear, it will be frozen
> in 10 days or so. The tarball will then be renamed and moved to the
> official download area.
>
> In addition to many little details and fixes, the tarball contains a
> revised and updated reference manual and revamped Makefiles following
> suggestions by Mike Pall and others.
>
> Please take a look and send us your comments or post them here.
>
> Enjoy.
> --lhf
>