* Lua advice wanted

For users to report plugin bugs and request plugin enhancements; and for authors to test new/new versions of plugins, and to discuss plugin development (in the Programming Technicalities sub-forum). If you want advice on choosing or using a plugin, please ask in General Usage or an appropriate sub-forum.
Post Reply
User avatar
laz_gen
Famous
Posts: 177
Joined: 03 Apr 2018 14:02
Family Historian: V7
Contact:

Lua advice wanted

Post by laz_gen »

Trying to update a plugin to run in FH7 and would welcome some advice.

The plugin used the "table.maxn" function and is now generating an error as that function has been deprecated.

The plugin looked through my FH database seeking a particular fact and if found it copied the 4 elements of the fact to a table.

I used the table.maxn function to determine the table size i.e. if the loop search failed to find any facts then the result would be just the headings I placed in the table at the beginning of the loop.

The plugin runs OK with these few lines commented out and it only use was to report (in the exported text file) if no facts were found.

Code: Select all

if table.maxn(tblFile) < 4 then
	table.insert(tblFile, "To Do Facts on record: 0")
end
So, my question is there a alternative and simple way to replicate the table.maxn function?
User avatar
ColeValleyGirl
Megastar
Posts: 5499
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: Lua advice wanted

Post by ColeValleyGirl »

The help file for writing plugins has some advice as does Writing and Maintaining Plugins Compatible with Versions 5, 6 & 7.
User avatar
laz_gen
Famous
Posts: 177
Joined: 03 Apr 2018 14:02
Family Historian: V7
Contact:

Re: Lua advice wanted

Post by laz_gen »

Helen

That works perfectly.

Thank you
User avatar
tatewise
Megastar
Posts: 28410
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Lua advice wanted

Post by tatewise »

Since you are using table.insert(tblFile,...) the table index values will start at [1] and be consecutive up to [4].
The size of such tables can be obtained using the length operator #, i.e. if #tblFile < 4 then
That works in FH v5, v6 & v7 with both versions of Lua.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
laz_gen
Famous
Posts: 177
Joined: 03 Apr 2018 14:02
Family Historian: V7
Contact:

Re: Lua advice wanted

Post by laz_gen »

Interesting. I will explore that.

Thanks
Post Reply