Page 1 of 1

Lua advice wanted

Posted: 30 Jun 2021 18:08
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?

Re: Lua advice wanted

Posted: 30 Jun 2021 18:20
by ColeValleyGirl
The help file for writing plugins has some advice as does Writing and Maintaining Plugins Compatible with Versions 5, 6 & 7.

Re: Lua advice wanted

Posted: 30 Jun 2021 18:58
by laz_gen
Helen

That works perfectly.

Thank you

Re: Lua advice wanted

Posted: 01 Jul 2021 18:14
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.

Re: Lua advice wanted

Posted: 01 Jul 2021 21:21
by laz_gen
Interesting. I will explore that.

Thanks