* Writing Plugins Compatible with Versions 5, 6 & 7

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
ColeValleyGirl
Megastar
Posts: 4854
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Writing Plugins Compatible with Versions 5, 6 & 7

Post by ColeValleyGirl » 14 Dec 2020 10:39

I've created a KnowledgeBase article on Writing Plugins Compatible with Versions 5, 6 & 7 if anyone would care to review it.

It's not intended to be exhaustive, but to cover the points that many plugin authors will come across and provide advice for how to tackle less common scenarios.

avatar
shoshk
Famous
Posts: 242
Joined: 13 May 2015 16:28
Family Historian: V7
Location: Mitzpe Jericho, Israel

Re: Writing Plugins Compatible with Versions 5, 6 & 7

Post by shoshk » 14 Dec 2020 12:44

Looks good to me.

Shosh
Shosh Kalson

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

Re: Writing Plugins Compatible with Versions 5, 6 & 7

Post by tatewise » 14 Dec 2020 18:34

Looks reasonably comprehensive.

I think the body of function table.getn(t) can simply be return #t

Code: Select all

function table.getn(t)
	return #t
end
Regarding other Lua changes, is it worth mentioning the formatting of numbers.
i.e. string.format("%d",number) won't work if number is not an integer.
It needs string.format("%d",math.floor(number)) or similar to ensure the parameter is an integer.
That solution works for all Lua versions.

The iup.SetGlobal("CUSTOMQUITMESSAGE","YES") seems OK in all IUP versions so doesn't need to be conditional.

Regarding IUP a popular simple dialogue involves iup.GetParam(..) but a bug prevents the button labels being changed from OK and Cancel. The workaround is:

Code: Select all

function paramAction(iupDialog,intIndex)
	if intIndex == iup.GETPARAM_MAP then		-- Correct button labels needed for IUP 3.28 bug
		iupDialog.Button1.Title = "Edit"	-- Otherwise remain as OK and Cancel
		iupDialog.Button2.Title = "Exit"
	end
	return 1
end
local isAns,strAns = iup.GetParam("Test",paramAction,"%u[Edit,Exit]")	-- Displays dialogue with buttons Edit and Exit
and to add a Help button:

Code: Select all

function paramAction(iupDialog,intIndex)
	if intIndex == iup.GETPARAM_MAP then		-- Correct button labels needed for IUP 3.28 bug
		iupDialog.Button1.Title = "Apply Rules"
		iupDialog.Button2.Title = "Cancel Plugin"
	elseif intIndex == (iup.GETPARAM_HELP or -4) then	-- FH V5 needs -4
		fhShellExecute("https://pluginstore.family-historian.co.uk/page/help/main-help-page","","","open")
	end
	return 1
end -- function paramAction
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

Post Reply