lua-users home
lua-l archive

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


Nutria Seawolf implements a PHP Array emulator, give it a tray: http://gitorious.org/nutria

Blessings.

---- On Tue, 23 Feb 2010 16:37:54 -0800 Klaus Ripke <paul-lua@malete.org> wrote ----

On Tue, Feb 23, 2010 at 09:14:51PM -0300, Luiz Henrique de Figueiredo wrote:
> What do you expect from a sorted table with string keys?
> That pairs will list the entries in order?
> That is not possible: a table is a bag of pairs, not ordered in any way.

unfortunately PHP arrays "work" that way, sort of,
and their asort, arsort, ksort etc hell is an ugly mess *shudder*

Valerio, in Lua it's more like e.g. Perl,
table.sort only works on plain arrays,
i.e. tables indexed by integers 1..n.
"Most functions in the table library assume that the table
represents an array or a list."
http://www.lua.org/manual/5.1/manual.html#5.5

To list a hash sorted by key values,
get the list of keys as plain list, sort that,
and print the hash accordingly as you would in Perl.
for (sort keys %h) { print $_, " -> ", $h{$_}, "\n"; }

well it requires a few more lines in Lua


cheers