This is a thread about the development of a contacts plugin written in LUA, FS#11989.
The following post was a previous help request over a problem I solved myself (my programming skills are
very good as you can think) and its original content is kept here just for reference.
Hi everyone!
I'm writing a contacts plugin in LUA for Rockbox. I already have lots of code (with the current code, the plugin should be able to view the contacts on its database, add contacts to its DB, save and load the DB from a file), but not I ran into a problem I can't solve so I'm asking here for help...
The problem is as follows: With an earlier version of the plugin, which the only thing it did was automatically add some example contacts to the database and save it, I added some contacts to my debug DB (located at the root of the player, named contacts.txt). These contacts created by the old code were stores on the database file as follows:
return {
-- Table: {1}
{
{2},
{3},
{4},
{5}
},
-- Table: {2}
{
["department"]="",
["last"]="Last Name",
["company"]="SC, Co.",
["worktel"]="40304399",
["first"]="Joe",
["middle"]="Middle",
["jobtitle"]="",
},
-- Table: {3}
{
["department"]="",
["last"]="last",
["company"]="a company",
["worktel"]="9845641254",
["first"]="some first",
["middle"]="",
["jobtitle"]="dr.",
},
-- Table: {4}
{
["department"]="",
["last"]="test last",
["company"]="companiiis",
["worktel"]="53981330",
["first"]="test first",
["middle"]="test middle",
["jobtitle"]="",
},
-- Table: {5}
{
["department"]="",
["last"]="Exex",
["company"]="Mirdalha",
["worktel"]="560928028",
["first"]="Joe",
["middle"]="Coco",
["jobtitle"]="",
},
}
And these ones are successfully loaded into the actual plugin when it opens (successfully means they are added to the entry count and their first, middle and last names are displayed in the menu).
However (and here comes the problem), I don't know what changes I made to the function that adds a contact to the DB, I just added code to be able to identify each table entry by a "unique ID", that in this case is the first name, plus the middle and last name, without spaces in between. Now, contacts are stored this way:
return {
-- Table: {1}
{
[98989]={2},
["aabbbcccc"]={3},
},
-- Table: {2}
{
["department"]="",
["last"]="HHH",
["company"]="",
["worktel"]="",
["first"]="dddggg",
["email"]="",
["workfax"]="",
["im"]="",
["jobtitle"]="",
["workaddr"]="",
["middle"]="vvv",
["mobiletel"]="",
},
-- Table: {3}
{
["department"]="",
["last"]="cccc",
["company"]="",
["worktel"]="",
["first"]="aa",
["email"]="",
["workfax"]="",
["im"]="",
["jobtitle"]="",
["workaddr"]="",
["middle"]="bbb",
["mobiletel"]="",
},
}
And these new ones, with " ["aabbbcccc"]={3}" instead of just " {3}" are not recognized. I mean, they are added to the total entry count (that means the "for" loop "sees" them), but their names are not shown in the main menu. On the simpler ones, without the unique ID, are still displayed.
Sorry for all this ramble, perhaps if you understand LUA it's easier to look at the code and run on your player to understand what happens. The script file goes attached as "contacts.lua.txt" (change its name to "contacts.lua") and an example database with both of the "modern" and "old" contact table formats is attached as "contacts.txt" (put it on the root of your player).
The code is well commented (at least in my opinion), if you have more questions feel free to ask.
Any suggestion you may give is useful

A contacts plugin is something I sometimes miss on Rockbox, and I think it's something simple enough to code in LUA (no need to have another C plugin). I have thought of features like exporting and importing vCards as well as contact photo, which I'll try to implement when (if) I complete the basic part of the plugin.
PS: perhaps it's a very obvious bug, but I've looked at the code for three days and tried different configurations and no result. So I came here...