Page 1 of 1

Configuring path for require()

Posted: Friday 17 April 2020 16:56
by PVuser
How can I config the path to modules I want to include with "require()"?

The only hint I found in the forum is:
package.path = package.path .. ';' .. '/home/pi/domoticz/scripts/lua/?.lua'

but that's I have to do for every script!?

Another way seems to put it in /usr/local/lib/lua/5.3, but than it is
- in a different directory
- not easy to handle, because in the normal way (saving from an editor) permisson is not allowed. You need admin rights!

So what is a usabel way.? Perhaps I would prefer to store it in /home/pi/domoticz/scripts/lua/lib so all scripts are in the same directory environment. Bad idea? And how to say domoticz to laod modules from therre in a general way?

I have little linux know how and starting with domoticz and lua. Is there a tutorial or complete documentation using lua in domoticz? I only found the wiki and the workbook. But there are things like this not described.
Thanks

Re: Configuring path for require()

Posted: Friday 17 April 2020 17:34
by waaren
PVuser wrote: Friday 17 April 2020 16:56 How can I config the path to modules I want to include with "require()"?
So what is a usable way.? Perhaps I would prefer to store it in /home/pi/domoticz/scripts/lua/lib so all scripts are in the same directory environment. Bad idea? And how to say domoticz to load modules from there in a general way?

I have little Linux know how and starting with domoticz and Lua. Is there a tutorial or complete documentation using Lua in domoticz? I only found the wiki and the workbook. But there are things like this not described.
Thanks
Any specific module you want to include ? (user module or external library)
In dzVents (100% Lua) user modules are to be stored in <domoticz dir>/scripts/dzVents/scripts/modules/ to allow a require with the need to specify complete path.
Furthermore most functionality is already available in dzVents without the need for external modules.

dzVents is documented here
For generic Lua stuf look at the official Lua site
For Lua in domoticz: this would be a good starting point.