* require issue.

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

require issue.

Post by Ron Melby »

I have rounded up many of my routines and put them in a single fh_lua source.

then in writing the script at the top, before anything else, I have:

local fh = {} -- Local environment table
package.seeall(fh) -- Enable all globals
-- module(..., package.seeall) -- Create matching module name
setfenv(1, fh) -- All public names are added to local fh table

require '_STDfn'

of course stolen from some of Mikes code somewhere, and I dont understand it all yet, and have shopped around in the 'manual'...
I have module commented out because I am not sure how to load it, and as is, it gives me an error.

anyway, the gravamen of the issue is that while it sees all my STDfn code, and uses it. I cannot see it in the debugger, so if an error occurs, I get a line number in the require but it would be very handy to debug it actively. is there a way enable that?

I have about 20 or so programs I have written, and now that I have these STDfns I can probably reduce that to 10.

Interestingly enough, I have one function that I have done everywhichwayfromsundaytodeath, and thought it was bulletproof. DATES stuff ( -2010) ( - ) (1900 - ) and so on, the code which you all have seen 100 or more times. Once it went into a require though, it did create an error. I swear I have not changed anything in that program chunk and have run it hundreds of times inline (and I checked it with a file compare utility, and it is indeed the same.) and I have looked at programs where I havent stuck the require in instead of a copy and it runs fine, but looking at it with hindsight, HOW DID THAT EVER RUN? in any case, it would be very handy to debug the require is it possible?
FH V.6.2.7 Win 10 64 bit
User avatar
tatewise
Megastar
Posts: 28341
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: require issue.

Post by tatewise »

I have to admit the whole 'require' mechanism is a bit mysterious to me. :?
My reusable library modules are 'require' compatible in the hope that Calico Pie will offer a user library feature one day.
However, until then, all my modules are explicitly incorporated inline within every Plugin that needs them.
That has the drawback that when a module is updated it must be copied into every such Plugin. :(

I suspect there is no workaround for the debug of 'require' modules, unless some expert knows different.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
ColeValleyGirl
Megastar
Posts: 5465
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: require issue.

Post by ColeValleyGirl »

I'm in the same position as Mike -- I put my "modules" inline, for the same reason (although I don't explicitly code them as modules as there's no benefit if they're inline.) I don't expect that Calico Pie will ever allow a user library feature -- too much scope for name clashes, and too much work involved in deciding which modules to admit.

As an aside, the module function is deprecated now: http://lua-users.org/wiki/ModulesTutorial
User avatar
Ron Melby
Megastar
Posts: 917
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: require issue.

Post by Ron Melby »

well my worst of all worlds method now is:

since LUA is nice enough to tell you the line I go thru the error in FH. Stop. Goto ZeroBrane copy the 'module' out of the _STDfn.lua and put it inline in the program. Switch to FH. stick a debug on the copied in module (since no overloading in LUA) it will chose the second one defined every time....

then I can debug it. go back into ZB put the fix in update STDfn copy it into the fh plugin and rerun it insuring it works, and if so, go to ZB remove the inline copy update and done.

I am sort of ok with flipping back and forth between FH and ZB but it would be nice to find the fh....modules so that I dont get the 49000000000000000 warnings of unknown global function fhyaddayaddayadda messages when I analyze the code.
FH V.6.2.7 Win 10 64 bit
User avatar
tatewise
Megastar
Posts: 28341
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: require issue.

Post by tatewise »

I hope I am answering your question, but all Lua modules are in C:\ProgramData\Calico Pie\Family Historian\Plugins\ in a subfolder with the module name.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
Jane
Site Admin
Posts: 8508
Joined: 01 Nov 2002 15:00
Family Historian: V7
Location: Somerset, England
Contact:

Re: require issue.

Post by Jane »

The FH lua functions are only available when running lua within Family Historian, as they are apis to the parent program.

if you really wanted to I suppose you could write a dummy module to use in zb.

Personally I would never move anything to a module until it's fully tested.
Jane
My Family History : My Photography "Knowledge is knowing that a tomato is a fruit. Wisdom is not putting it in a fruit salad."
User avatar
ColeValleyGirl
Megastar
Posts: 5465
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: require issue.

Post by ColeValleyGirl »

I agree with Jane about 'fully tested'. However, most of my 'modules' are needed for published plugins, so can't be real modules.
User avatar
Ron Melby
Megastar
Posts: 917
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: require issue.

Post by Ron Melby »

fully tested, yaaaaaaaaaaaaaaaas.

I 'fully test' my modules, I have them in about 20 scripts and run them constantly. I have run them hundreds if not thousands of times.

microsoft, ubuntu, you name it fully test gabillions of times, over much more massive environments, and still have bugs.

fully tested is relative to space-time and eye of the beholder.

why? all you guys want to use my programs on your data, then send me the gedcoms and the errors so I can fix them? (they still will have a bug, or a feature you dont like), right off the bat, my FaG processing would be useless to every one of you. But it takes processing time, because it requires a source and cooks on each INDI.
FH V.6.2.7 Win 10 64 bit
User avatar
Ron Melby
Megastar
Posts: 917
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: require issue.

Post by Ron Melby »

C:\ProgramData\Calico Pie\Family Historian\Plugins\_hrelations.fh_lua:260: first use of unknown global function 'fhOutputResultSetTitles'
C:\ProgramData\Calico Pie\Family Historian\Plugins\_hrelations.fh_lua:261: first use of unknown global function 'fhOutputResultSetColumn'

ie.
FH V.6.2.7 Win 10 64 bit
User avatar
ColeValleyGirl
Megastar
Posts: 5465
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: require issue.

Post by ColeValleyGirl »

If you're not running Lua from within FH, the FH API isn't available. So ZeroBrane will throw that message up during Analyze.

Re fully tested, depends how complex your 'modules' are -- mine tend to consist of very atomic functions so I can (and do) construct detailed test scripts that include all edge cases for each function. Yes, there can still be problems (I used to run a Quality Management team, and also a Testing team that took the outputs from developers, wrote black box tests and chucked the code back for fixing as required) but -- as I expect you know -- just running something a gazillion-squared times is not testing it.
User avatar
Ron Melby
Megastar
Posts: 917
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: require issue.

Post by Ron Melby »

I used to write software, testing was another group. I beat it as best I could, thought of all the cases I could, and found from my end was to write chunks that were doing one job, one in one out, in the rather narrow domains, like this one, and the telephone system in America, dont know how the lash up in the UK is done that is how the testing is done, by beating on it a gazillion times.

very incremental refinements.

doesnt matter, the error was there, and it was a trivial fix, dont know why it didnt show up inline. I have other spurious issues, and am not sure that the problem is mine. for example, once in a million times insert at line so and so #1 parm table expected is nil.

function matNAME(iptr)
local thisPTR = iptr:Clone()

tblName = tblName or {}
cwnam = cwnam or 0

tblINDI = tblINDI or {}
cwptr = 0

local Name = ''
local NameSfx = ''
Name = fhGetItemText(thisPTR,'~.NAME:SURNAME_FIRST')
NameSfx = fhGetItemText(thisPTR,'~.NAME.NSFX')
Name = (Name .. NameSfx)
table.insert(tblName, Name)
cwnam = math.max(cwnam, #Name)
table.insert(tblINDI, thisPTR:Clone())
return
end -- fn matNAME

there is the code where it happened
FH V.6.2.7 Win 10 64 bit
Post Reply