Page 1 of 1

Writing Plugins Compatible with Versions 5, 6 & 7

Posted: 14 Dec 2020 10:39
by ColeValleyGirl
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.

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

Posted: 14 Dec 2020 12:44
by shoshk
Looks good to me.

Shosh

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

Posted: 14 Dec 2020 18:34
by tatewise
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