Configuring path for require()

Moderator: leecollings

Post Reply
PVuser
Posts: 33
Joined: Monday 30 March 2020 19:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: DE
Contact:

Configuring path for require()

Post 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
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Configuring path for require()

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest