* non-complex table on the fly.

Writing and using plugins for Version 5 and above.
Post Reply
User avatar
Ron Melby
Superstar
Posts: 467
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

non-complex table on the fly.

Post by Ron Melby » 22 Apr 2019 16:27

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: 17127
Joined: 25 May 2010 11:00
Family Historian: V6.2
Location: Torbay, Devon, UK
Contact:

Re: non-complex table on the fly.

Post by tatewise » 22 Apr 2019 16:45

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
Superstar
Posts: 467
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: non-complex table on the fly.

Post by Ron Melby » 22 Apr 2019 16:50

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