lua-users home
lua-l archive

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


Hi Dietmar,

look at the description of table.sort. You may give a function as parameter that does the decision how to sort.

maybe like table.sort( vAdressen, function (a,b) return a.City < b.City end )

--
Oliver

Am 19.10.2016 um 18:53 schrieb Dietmar Segbert:
Hello,

i am new to lua. My Milestone 312 ACE, a Daisy-Player, Mp3-Player,
Audiorecorder, from Bones
  http://www.bones.ch

becomes in the next Firmware a lua-interface.

I can test the beta of that fw and so i want to program a little
adressbook.

Now i have a question to table.sort()

i have a list

local vAdressen = {}
local vAdr = {}
local vAdr.Name = ""
local vAdr.City = ""
...

I read the fields for the vAdr from a csv-file and store them  in

vAdressen[1] = vAdr
...
vAdressen[n] = vAdr

so that i have all my adress-datasets in vAdressen

Now  i want to sort the table vAdressen for name odr city or ...

If i do

print(vAdressen[1].Name]

the name of my first dataset will be printed

What st the correct syntax for the table.sort() function to sort for name
or city?

Thanks for your help.

Best regards

Dietmar Segbert