* LUA_PATH environment variable.

For plugin authors to discuss plugin programming
Post Reply
User avatar
Ron Melby
Megastar
Posts: 928
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

LUA_PATH environment variable.

Post by Ron Melby »

I am back after the crash (after a fashion).
I have a windows 11 computer, and have installed fh 6.7.2
I got most of my customizations back, but some I had to do by hand.
I am cleaning up my data a bit in a move to getting fh 7 in the near future.
I havent changed my profile here, because I also have a windows 10 computer that I am setting up to keep 6.7.2 for awhile as backup, and checking differences in things. Now; to business...

LUA_PATH environment variable....
there was none on my computer, but in fh, an os.getenv('LUA_PATH') filled one out.
C:\ProgramData\Calico Pie\Family Historian\Plugins\?.fh_lua;C:\ProgramData\Calico Pie\Family Historian\Plugins\?.lua;

I wanted to change that so the package.path is :C:\ProgramData\Calico Pie\Family Historian\Plugins\.bin\?.lua; (<**add, obvs this bit is not in the string) C:\ProgramData\Calico Pie\Family Historian\Plugins\?.fh_lua;C:\ProgramData\Calico Pie\Family Historian\Plugins\?.lua;

however when I install them in system and user environment variables, the path is the same, without my additions, when I check it in fh.

the package.path and the LUA_PATH revert to the original. Am I missing something or is fh trashing my paths?
FH V.6.2.7 Win 10 64 bit
User avatar
tatewise
Megastar
Posts: 28423
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: LUA_PATH environment variable.

Post by tatewise »

Why don't you keep backups of your customisations by using the Backup and Restore FH Settings plugins?

I think you mean FH v6.2.7 not 6.7.2

I suspect LUA_PATH is not a system variable but a user variable.
User variables take precedence over system variables of the same name.
I guess FH is setting the LUA_PATH variable each time it runs, so you cannot adjust it.
See https://www.baeldung.com/cs/user-vs-system-variables.

I recommend you do not meddle with the FH global folder structure.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
Ron Melby
Megastar
Posts: 928
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: LUA_PATH environment variable.

Post by Ron Melby »

I have added LUA_PATH to user and system with no change.

I have 13 (at present) "require" modules, packages, whatever...
around 4 of them are universal.

the rest are one-off and are used depending on the plugin's focus.

in my quest for speed and memory reduction (to do more and bigger) I posit:
since I cant debug a require,
since all my requires have messaging for known errors,
since they are all old friends and I know every line and function in them,
since they rarely change,

I would like to compile them with luac and also strip out debug info
according to Lua itself, the 'run unit' knows whether they are compiled or source,
I could save time and memory by having them in binary format
since I can neither add a folder, nor change extension, since fh will pick up niether, the issue is how to accomplish this.
FH V.6.2.7 Win 10 64 bit
User avatar
tatewise
Megastar
Posts: 28423
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: LUA_PATH environment variable.

Post by tatewise »

Sorry, that is way beyond my pay grade :D
Perhaps somebody else can help...
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
ColeValleyGirl
Megastar
Posts: 5504
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: LUA_PATH environment variable.

Post by ColeValleyGirl »

Why not just put them in into the C:\ProgramData\Calico Pie\Family Historian\Plugins folder? Or even a subdirectpry of it. I have no idea if it will work but worth a try.
User avatar
Ron Melby
Megastar
Posts: 928
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: LUA_PATH environment variable.

Post by Ron Melby »

I have the executables in a subdirectory, it doesnt work. in that it is not visible to package.path
I have switched around the situation such that I will put the source in a subdirectory and the executable in plugins.
I will have to make some changes to the compiler plugin, and try that out.

this is typical of my plugins:

--[[
@title: .allCem
@author: Ron Melby
@lastupdated: 25 Dec 2019
@version: 1.0.0
@description: all cemetery records
*TODO:
]]

--[[Import Section:]]
local require = require
require 'QSYS'
require 'QSYS_MAT'
require 'QSYS_PRT'
require 'QSYS_SLT'

starting at the first require they need to be the executables:
QSYS.lua (so it doesnt show up in the plugins window) will need to be taken from some other folder, in plugins(I use ZeroBrane and it needs to be visible there....)
So ....

... .... /Plugins/QSRC will have source for the QSYS
the compiler will get from QSRC/QSYS.lua, and compile into ... ... /Plugins/QSYS.lua

unless I just make another require to be first in the list changing the package.path, but dont think that will work, because I would expect package.path is loaded at fire up, or at least every time it hits a require (in case that was changed in a require) and it requires a great deal of changes to my runnable plugins.
FH V.6.2.7 Win 10 64 bit
User avatar
tatewise
Megastar
Posts: 28423
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: LUA_PATH environment variable.

Post by tatewise »

Perhaps try asking CP for advice on how to achieve your package objectives.
They know the internals of the FH Lua subsystem and maybe can suggest a workaround.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
Ron Melby
Megastar
Posts: 928
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: LUA_PATH environment variable.

Post by Ron Melby »

this works --- this is from my compiler which will need the sources, because it might be one of the QSYS_*.lua that I am compiling.

package.path = ('%s;%s'):format('C:/ProgramData/Calico Pie/Family Historian/Plugins/qsrc/?.lua', package.path)

require 'QSYS'
require 'QSYS_SLT'
FH V.6.2.7 Win 10 64 bit
Post Reply