Page 1 of 1
require in plugins
Posted: 29 Oct 2021 00:49
by Ron Melby
as you may or may not know, I make extensive use of requires. mine are """"""non-standard"""""" but any program of any usefulness will need some requires, lfs, iup, luacom, something.
almost universally, I put them at the top lines of my plugin so the first thing a plugin does is "bind" the required "stuff'
For you prolific plugin authors, is there anyone who late binds requires, that is rather than declare them first thing, bury them in functions or even mainline code after it has started executing, and if so, can you give me some of the names of those plugins?
This has a point.
I am making a profiler, and 'late binding' requires has very large implications in my code complexity, and real execution times.
So, thanks in advance for your replies.
Re: require in plugins
Posted: 29 Oct 2021 07:55
by Mark1834
The CP house style and recommendation to plugin authors is to put all requires at the top of the script as global variables, so I always follow that.
Re: require in plugins
Posted: 29 Oct 2021 11:29
by tatewise
The majority of my Plugins do not require all the library modules initially.
My large Plugins that include my 'standard library' of functions often only invoke the require needed within each function.
e.g.
Adjust AKA Names for Reports
Ancestral Sources Data Entry
Backup and Restore Family Historian Settings
Change Any Fact Tag
Export Gedcom File
Find Duplicate Individuals
Improve Website or CD DVD HTML
Lookup Missing BMD Records
Lookup Missing Census Facts
Map Life Facts
Search and Replace
Show Project Statistics
Some smaller Plugins only need a function or two that invokes the require when needed.
They may have some global require statements but not for all the libraries that might be needed.
e.g.
All Pool Relatives Except Partner Ancestors
Convert Legacy Places
Flexible CSV Importer
Install Library Modules
Move Local Media to Media Records
Where Used Record Links
Re: require in plugins
Posted: 30 Oct 2021 00:30
by Ron Melby
uff da. ok, thanks, we go the long route.
Re: require in plugins
Posted: 03 Nov 2021 23:24
by Ron Melby
the first part relatively painless, I have hit a surprising road block, and it is compounded by the fact that you cant really debug a program that does debug.
I hope I have enough here that you can follow what is occuring and see my problem.
_etbl entry:
_etbl is an enumeration of _G
(entry under discussion)
["matADR"] =
{
["cfn"] = "_STD_GPS.matADR",
["name"] = "matADR",
["pkg"] = "_STD_GPS.",
["lvl"] = 1,
},
here is the setup oc information coming into the function
send to rtv_dbg_rcd
depth: 3
ccwhat: Lua
ccnamewhat: global
ccname: matADR
clldfn: 305
cccln: 398
ccendl: 407
ccnups: 0
ccsrc: @C:\ProgramData\Calico Pie\Family Historian\Plugins\_STD_GPS.lua
ccssrc: ...ata\Calico Pie\Family Historian\Plugins\_STD_GPS.lua
>>XXXXXXXXXX<<
this is the function in question
arguements:
func is the hexidecimal 'value' of the function (it will be abandoned it is an ephemeral value and not useful as a handle)
force is always 1
info is the debug.getinfo(depth) table as above
function rtv_dbg_rcd(func, force, info)
-- func = mat_fn_name(func)
-- ** Find the function ref for 'func' (if not present, create one)
if info then
if info.name
or info.what then
this is inoperative at the moment and not at issue
end
end
local _fnrcd = _dbgrcd[func]
if not _fnrcd then
if force ~= 1 then
print('no force') -- never executeo
return
else
-- Build a new _fnrcd entry
print('****new record****')
_fnrcd =
{
func = func,
info = (info or ''),
children = {},
children_time = {},
anon_child_time = 0,
named_child_time = 0,
count = 0,
time = 0,
}
I am building a table with other profiling information for this record
print('from record: ', _fnrcd['info']['name'])
if _etbl[_fnrcd['info']['name']] then
print('inside') this never executes
_fnrcd['info']['short_src'] = _etbl[_fnrcd['info']['name']]['cfn']
else
print('*error*') this always executes
end
this executes
_fnrcd['info']['short_src'] = _fnrcd['info']['short_src']:gsub('.*[/\\]', ''):gsub('%..*', '')
print('--function rtv_dbg_rcd--')
print('what: ', _fnrcd['info']['what'])
print('namewhat:', _fnrcd['info']['namewhat'])
print('name: ', _fnrcd['info']['name'])
print('src: ', _fnrcd['info']['source'])
print('ssrc: ', _fnrcd['info']['short_src'])
_dbgrcd[func] = _fnrcd
end
end
this is the log of what happened
****new record**** not a _dbgrcd so build one
from record: matADR I have a matADR entry in info from the _fnrcd
*error*
--function rtv_dbg_rcd--
what: Lua
namewhat: global
name: matADR
src: @C:\ProgramData\Calico Pie\Family Historian\Plugins\_STD_GPS.lua ****this errors I expect to get STD_GPS.matADR from _etbl[...resolved to matADR... as above.[ [cfn] record
ssrc: _STD_GPS ***this works
I have been beating around with this for weeks, it must be staring me in the face, but I do not see how it is not working.
What is obvious to the rest of the world, that is not obvious to me?
Re: require in plugins
Posted: 04 Nov 2021 11:00
by tatewise
What has this got to do with require statements?
The simple answer to your question is that _etbl["matADR"] does not exist.
Try replacing the print('from record: ', _fnrcd['info']['name']) statement with the following:
local index = _fnrcd['info']['name']
print( 'from record: ', index, type(index) )
print( '_etbl[index]: ', _etbl[index] )
That tells you the data type of matADR which you suggest is a string, but is that true?
Re: require in plugins
Posted: 04 Nov 2021 11:23
by Ron Melby
it has a great deal to to with the placement of require statements in code I do not write, since this bit of code is seminal to the actual problem of profiling code, and when I should enumerate _G, and what to do if the function is not found in _G, and determining if this is lua internal or fh internal or some other C/C++ code that executes lua framework (for generators, main, etc). lua is run on C/C++ so it has to have a main, for instance.
As you might remember, you helped me with a _G enumerator, and looked askance at my deriving a hex value from a function name. Silly me, I thought they would be handles, they are not. So, I have to revamp that.
my future problem might be if there is such a thing as say:
string.rep
and
join.rep
this situation based on the debugger returns appears to be indiscernable.
Re: require in plugins
Posted: 04 Nov 2021 11:48
by Ron Melby
for k, v in pairs(_etbl) do
print(k, ' ', type(k))
end
results in:
matADR string
****new record****
index from record: matADR string
_etbl[index]: nil
from record: matADR
*error*
--function rtv_info_rcd--
info_rcd what: Lua
info_rcd namewhat: global
info_rcd name: matADR
info_rcd src: @C:\ProgramData\Calico Pie\Family Historian\Plugins\_STD_GPS.lua
info_rcd ssrc: _STD_GPS
they both appear to be strings, so I am still not following what is wrong,
Re: require in plugins
Posted: 04 Nov 2021 13:52
by tatewise
I assume that the print( ) statement output you have posted is copied directly from the FH debug screen.
On close examination, matADR is followed by varying numbers of space characters.
So although they all look much the same they are actually different strings.
So in the print( ) statements include some #k and #index items to show the length of the string.
I suspect in different cases they have varying trailing space characters, i.e. more than 6 characters long.