For example I want to have function to send email which can be used from any scene but without necesarity to dublicate function definition in every scene
I’ve tried a search but it not able to find an answer
For example I want to have function to send email which can be used from any scene but without necesarity to dublicate function definition in every scene
I’ve tried a search but it not able to find an answer
I achieved that via the “Mios Developers”, “Edit Startup LUA” & defined my function(s) there. I also decided to use that location as the place where I define labels for the device IDs (simplifies my luup in scenes further).
Do wish there could be a slightly cleaner way to achieve this and the device ID abstraction, but it works as is.
Thank you for sharing expirience.
I also thought about using startup Lua but not sure because I saw no referencies from the forum to it.
Do I need to restart Lua somehow for changes to take effect?
You probably need to restart the Luup Engine, by going to the Luup Files tab of Mios Developers and going to the bottom of that tab clicking the checkbox to restart after upload and click upload (without any files selected in the browse fields). This will restart the Luup Engine.
By my current practice with latest beta there is no need to restart Lua, just need to press Go button on “Edit Startup Lua” tab
You can also put your common stuff into a “[tt].lua[/tt]” file, like “[tt]shared.lua[/tt]”, and upload it via the standard MiOS developers UI, as you would with Plugin files.
Then, in your code, you place the following construct at the top:
[tt] require(“shared.lua”)[/tt]
and it’ll load that library in, and it’s functions will become available for you to use. This will work “as-is” on the newest MiOS releases
On older MiOS releases, the “right” directories weren’t setup, so uploaded .lua wouldn’t be seen. In this case, you’ll likely have to add the explicit path, something along the lines of:
[tt] require(“/etc/cmh-ludl/shared.lua”)[/tt]
as the “[tt]/etc/cmh-ludl/[/tt]” directory is where the UI uploads files to on the Vera box. On earlier versions, if you didn’t put in the full path information, you’d get an error in the Vera logs along the lines of:
[tt]01 xx/xx/11 xx:xx:xx.133 LuaInterface::StartEngine failed run: 0 [string “x = require(“test1”)”]:1: module ‘test1’ not found:
no field package.preload[‘test1’]
no file ‘./test1.lua’
no file ‘/usr/share/lua/test1.lua’
no file ‘/usr/share/lua/test1/init.lua’
no file ‘/usr/lib/lua/test1.lua’
no file ‘/usr/lib/lua/test1/init.lua’
no file ‘./test1.so’
no file ‘/usr/lib/lua/test1.so’
no file ‘/usr/lib/lua/loadall.so’ <0x2c0c>
01 xx/xx/xx xx:xx:xx.134 JobHandler_LuaUPnP::RunLua failed: x = require(“test1”) <0x2c0c>[/tt]
For reference, the details of this are here:
Programming in Lua : 8.1
[quote=“guessed, post:6, topic:168356”]You can also put your common stuff into a “[tt].lua[/tt]” file, like “[tt]shared.lua[/tt]”, and upload it via the standard MiOS developers UI, as you would with Plugin files.
Then, in your code, you place the following construct at the top:
[tt] require(“shared.lua”)[/tt]
and it’ll load that library in, and it’s functions will become available for you to use. This will work “as-is” on the newest MiOS releases
On older MiOS releases, the “right” directories weren’t setup, so uploaded .lua wouldn’t be seen. In this case, you’ll likely have to add the explicit path, something along the lines of:
[tt] require(“/etc/cmh-ludl/shared.lua”)[/tt]
as the “[tt]/etc/cmh-ludl/[/tt]” directory is where the UI uploads files to on the Vera box. On earlier versions, if you didn’t put in the full path information, you’d get an error in the Vera logs along the lines of:
[tt]01 xx/xx/11 xx:xx:xx.133 LuaInterface::StartEngine failed run: 0 [string “x = require(“test1”)”]:1: module ‘test1’ not found:
no field package.preload[‘test1’]
no file ‘./test1.lua’
no file ‘/usr/share/lua/test1.lua’
no file ‘/usr/share/lua/test1/init.lua’
no file ‘/usr/lib/lua/test1.lua’
no file ‘/usr/lib/lua/test1/init.lua’
no file ‘./test1.so’
no file ‘/usr/lib/lua/test1.so’
no file ‘/usr/lib/lua/loadall.so’ <0x2c0c>
01 xx/xx/xx xx:xx:xx.134 JobHandler_LuaUPnP::RunLua failed: x = require(“test1”) <0x2c0c>[/tt]
For reference, the details of this are here:
http://www.lua.org/pil/8.1.html[/quote]
Looks like a page for the How To Wiki?
@Henk,
Likely so, let’s wait a little while though so that people have an opportunity to thrash it out in the Forums (test in various scenarios).
I’ve only tested the technique with the “Test Lua” dialog, and I’m sure folks will find nuances and post-back here in the Forums.
Best Home Automation shopping experience. Shop at Ezlo!
© 2022 Ezlo Innovation, All Rights Reserved. Terms of Use | Privacy Policy | Forum Rules