* non-complex table on the fly.

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
Ron Melby
Megastar
Posts: 928
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

non-complex table on the fly.

Post by Ron Melby »

Code: Select all

 rmn = string.sub(fhGetTag(ptrWork), 1, 1)
  table.insert(tblRMN, rmn)

This is a slice of my matCEM function...It does a lot of stuff. Many times, one may only need a table or two out of its many tables.

so, I know I have seen tatewise do this when perusing his code and never understood it, and I cannot find it now when I need it, and cant find the example online.

rather than declare all these tables at the beginning of code before the functions as I have been doing, I would like to create them on the fly if they are not defined, I remember it looks something like:

table.insert(tblRMN, rmn) or {}
the questions are is that the correct statement, and on the first issuance of this, will rmn be inserted into the table or do I have to do some other check and insert it?
FH V.6.2.7 Win 10 64 bit
User avatar
tatewise
Megastar
Posts: 28413
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: non-complex table on the fly.

Post by tatewise »

I think what you are looking for is:
tblRMN = tblRMN or {}
which tests if tblRMN is defined or simply nil and in the letter case defines it as a table {}.
So if tblRMN is defined then it performs the self-assignment tblRMN = tblRMN that does nothing.
Otherwise, when tblRMN is undefined, it defines the empty table tblRMN = {}.

Then all table operations should be used as normal:
table.insert(tblRMN, rmn)
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
Ron Melby
Megastar
Posts: 928
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: non-complex table on the fly.

Post by Ron Melby »

great, thought I saw it all in one, but that statement is trivial it can go up in there with my cwcem = cwcem or 0 statements.
FH V.6.2.7 Win 10 64 bit
Post Reply