Is there a way to use the name of the current script in LUA, so I can use it in logging?
I know I can do it "hard coded", but it would be more elegant if there is a way to pull it...
can I find script name in LUA code?
Moderator: leecollings
-
- Posts: 748
- Joined: Saturday 27 February 2016 12:49
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Location: NL
- Contact:
Re: can I find script name in LUA code?
any ideas? Is there a simple way to use the script name in the LUA code?
Hans
-
- Posts: 660
- Joined: Thursday 10 November 2016 9:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: can I find script name in LUA code?
Hello,
A quick search shows this possibility using a Lua debug module, if available in Lua interpreter build included with Domoticz?
https://stackoverflow.com/questions/214 ... rrent-file
But looks there is no luck as $0 in bash, __FILE in python or __FILE__ etc even here in good old C. Lua just misses this common feature builtin.
-
- Posts: 147
- Joined: Friday 31 July 2015 21:02
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Sint-Oedenrode, Netherlands
- Contact:
Re: can I find script name in LUA code?
I use: in all my scripts.
Code: Select all
local SCRIPT_NAME = string.gsub(string.match(debug.getinfo(1, 'S').short_src, "[^/]+$"), '.lua', '')
Mark: Domoticz Beta on Raspberry Pi 4 running Debian Bookworm - Z-Stick 7 - RFXCom - P1 - MySensors - SolarEdge - Dahua - Philips Hue - Docker - Zigbee2mqtt (plugin) - Zwave-js-ui - dzVents - Nodered
-
- Posts: 218
- Joined: Friday 04 November 2016 12:33
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: France
- Contact:
Re: can I find script name in LUA code?
Excellent find !Doler wrote: ↑Monday 06 February 2023 13:21 I use:in all my scripts.Code: Select all
local SCRIPT_NAME = string.gsub(string.match(debug.getinfo(1, 'S').short_src, "[^/]+$"), '.lua', '')
-
- Posts: 748
- Joined: Saturday 27 February 2016 12:49
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Location: NL
- Contact:
Re: can I find script name in LUA code?
Yes...lost wrote: ↑Monday 06 February 2023 11:31Hello,
A quick search shows this possibility using a Lua debug module, if available in Lua interpreter build included with Domoticz?
https://stackoverflow.com/questions/214 ... rrent-file
But looks there is no luck as $0 in bash, __FILE in python or __FILE__ etc even here in good old C. Lua just misses this common feature builtin.
Hans
-
- Posts: 748
- Joined: Saturday 27 February 2016 12:49
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Location: NL
- Contact:
Re: can I find script name in LUA code?
Good tip, thank you. Although it does not really give me the actual name of the script, but rather the contents of the very first line of the script.Doler wrote: ↑Monday 06 February 2023 13:21 I use:in all my scripts.Code: Select all
local SCRIPT_NAME = string.gsub(string.match(debug.getinfo(1, 'S').short_src, "[^/]+$"), '.lua', '')
I could add your line of code to each script, but I might as well hard code the name as first LUA statement into SCRIPT_NAME.
Anyway, it gives me a way forward. Thanks.
Hans
Who is online
Users browsing this forum: No registered users and 1 guest