* Learning LUA

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
David2416
Superstar
Posts: 378
Joined: 12 Nov 2017 16:37
Family Historian: V7
Location: Suffolk UK

Learning LUA

Post by David2416 » 03 Nov 2022 15:36

I have been looking at The Finished Example (https://fhug.org.uk/kb/kb-article/iup-g ... -and-tips/)

It's not quite finished as these two lines need adding:
1. require("iuplua");
2. iup.SetGlobal("CUSTOMQUITMESSAGE","YES");

I have two/three questions:
1. If line two is omitted, then when run from the Run command it crashes FH. Is it known why?

2. dlg = iup.dialog followed by dlg:show() is used to get user input whereas in Norman's Probate plugin
local r = fh.getParam is used. I guess that this is using the fhUtils library. What are the implications of each approach?

Or perhaps where can I find guidance on this?

Thanks

David

User avatar
ColeValleyGirl
Megastar
Posts: 4850
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: Learning LUA

Post by ColeValleyGirl » 03 Nov 2022 15:48

David2416 wrote:
03 Nov 2022 15:36
1. If line two is omitted, then when run from the Run command it crashes FH. Is it known why?
It's an interaction between FH and IUP -- the standard IUP behaviour causes problems for FH.
David2416 wrote:
03 Nov 2022 15:36
2. dlg = iup.dialog followed by dlg:show() is used to get user input whereas in Norman's Probate plugin
local r = fh.getParam is used. I guess that this is using the fhUtils library. What are the implications of each approach?
fh.getParam question (19055) is relevant. My summary there:
ColeValleyGirl wrote:
07 Mar 2021 13:24
Joop, in V6 fhUtils didn't exist and many of us got used to the idiosyncrasies of iup, but it has always been a royal pain in the backside to use, even for simple purposes. fh.getParam is a way of hiding the complexity (once you've done the initialisation step) and creating simple table-driven interfaces.

If you need a more complex dialog, you'll probably need to get to grips with it at some point, but for people who are writing simple plugins, fhGetparams allows them to focus on the logic of what they're trying to achieve, not jumping through the iup hoops. I've found it an enormous timesaver when writing DEAs, and I've generated some pretty complex interfaces in the past.

User avatar
David2416
Superstar
Posts: 378
Joined: 12 Nov 2017 16:37
Family Historian: V7
Location: Suffolk UK

Re: Learning LUA

Post by David2416 » 03 Nov 2022 17:26

Helen, thank you for your reply. Gives me some insight.

User avatar
David2416
Superstar
Posts: 378
Joined: 12 Nov 2017 16:37
Family Historian: V7
Location: Suffolk UK

Re: Learning LUA

Post by David2416 » 07 Nov 2022 17:33

I am endeavouring to create a rich text hyperlink to a source note.
Currently I am coding

AddInfo(sourcePtr,"NOTE2","<web=\""..fld.."\">")

This generates a note as required
Screenshot 2022-11-07 075812.jpg
To get it to show as rich text I have to check the box in the screen below
Screenshot 2022-11-07 172536.jpg
I am clearly missing something; I have tried richTextRecordLink (ptr, text) and richTextReplace (s, old, new) in the FHUtils.lua file and also at Mike Tate's Move Note URL to Rich Text Web Link and tried fhSetValueAsRichText failing to get the desired result. I cannot find any documentation for fhSetValueAsRichText?

I would very much appreciate some guidance, please.

Thank you

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

Re: Learning LUA

Post by tatewise » 07 Nov 2022 18:26

All the relevant advice is in the How to Write Plugins help pages.

Under The Family Historian API > Function Index, you'll find fhSetValueAsRichText among the other fhSetValueAs... functions and is crucial in creating a Rich Text Note instead of a plain text Note.

Under The Family Historian API > Rich Text Syntax there are examples of creating Rich Text.

Presumably, AddInfo(...) is a function you have created as it is not a standard API function, which internally needs to create a Rich Text Object and use fhSetValueAsRichText. It would help to see the script of that function to give detailed advice. I suspect you are using fhSetValueAsText and maybe not even creating a Rich Text Object.
richTextRecordLink(...) and richTextReplace(...) are nothing to do with rich text web links.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
David2416
Superstar
Posts: 378
Joined: 12 Nov 2017 16:37
Family Historian: V7
Location: Suffolk UK

Re: Learning LUA

Post by David2416 » 07 Nov 2022 21:08

Thank you Mike for that guidance , I will look at those references and how I get on. I quite enjoy the challenge of getting things working.
As you suspectedAddInfo is using fhSetValueAsText. Clearly not a Rich Text Object 🙄

The next step is to add a Media Record, but one step at a time.

User avatar
David2416
Superstar
Posts: 378
Joined: 12 Nov 2017 16:37
Family Historian: V7
Location: Suffolk UK

Re: Learning LUA

Post by David2416 » 08 Nov 2022 09:27

tatewise wrote:
07 Nov 2022 18:26
All the relevant advice is in the How to Write Plugins help pages.

Under The Family Historian API > Function Index, you'll find fhSetValueAsRichText among the other fhSetValueAs... functions and is crucial in creating a Rich Text Note instead of a plain text Note.

Under The Family Historian API > Rich Text Syntax there are examples of creating Rich Text.
Now I have found that, it's obvious; I first Googled "The Family Historian API" which led me to https://www.family-historian.co.uk/help ... pi/api.htm.

Now I have also found it by Clicking "How to Write Plugins" in the Plugin Screen right at the end of the first page. And the Context and Index tabs.

Thank you again for pointing it out to me.

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

Re: Learning LUA

Post by tatewise » 08 Nov 2022 09:45

Also, when editing a Plugin script, use the Help menu that links to the same Plugin Help & API as well as Lua and IUP guides.

The available Help is also identified in the FHUG KB advice on Getting Started Writing Plugins.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
David2416
Superstar
Posts: 378
Joined: 12 Nov 2017 16:37
Family Historian: V7
Location: Suffolk UK

Re: Learning LUA

Post by David2416 » 08 Nov 2022 10:15

Brilliant, Thanks again.
Progress made, working link with preamble and postscript:
Screenshot 2022-11-08 100848.jpg
Still work to do to capture "Website Note Date Accessed" the "Further info section"

... and then the Image for Media tab, and error checking and etc. etc.

It is actually usable

Post Reply