I’m not sure how other people cope, but when using an IDE for development, they tend to like the concept of “filetype → language”, ie if it’s .lua - then its lua, .xml it’s xml etc etc.
My request is that the code is removed from the xml (with perhaps just a hook?) such that I can upload code outside xml, making IDEs a lot happier, able to do stuff like intelligent formatting, auto-identification of class methods etc.
Next request is the ability to upload files without using the web gui (how do people do this ? scp with private / public keys ?)
I have two scripts in each of my projects (which are developed on a Mac). The first is “[tt]pushit[/tt]”, the second is “[tt]compressit[/tt]”.
The first runs an SCP command, with a pattern, to copy all my device’s source files to Vera’s cmh-ludl area. It also copies the “[tt]compressit[/tt]” script over (executes it, then deletes it)
Since it’s SCP, this prompts for a password once per execution (I’m too lazy to est SSH Keys) during the copy.
The [tt]compressit[/tt] script, which is “exec” on Vera, runs [tt]pluto-lzo[/tt] on the files so they come out compressed on Vera (as would be the case if you used the UI)
Each is only a few lines, and if you’re used to [tt]sshkeytool[/tt] (etc), I’m sure you can work out what they look like
You can put your Lua code in a separate Lua file since firmware version 1.1.1171.
Here’s how to do it:
- Make the Lua file a module:
module ("L_filename", package.seeall)
I usually put a run function in the module, which will be the entry point.
(equivalent to the main function in C/C++)
- Include the module in the startup function defined in the XML file:
[code]function plugin_startup (deviceId)
– Load the module.
package.path = package.path … “;/etc/cmh-ludl/?.lua”
package.loaded.L_filename = nil
local plugin = require (“L_filename”)
-- Here we declare the callback functions (those used in luup.call_timer, luup.variable_watch, etc.).
-- It is necessary to do this because the callback functions need be in the global namespace.
function1 = plugin.function1
function2 = plugin.function2
-- Run the code.
Hope this helps.
Is there a reason that MiOS doesn’t set LUA_PATH (or equivalent) env prior to startup? This would avoid us needing to add this:
package.path = package.path .. ";/etc/cmh-ludl/?.lua"
With multiple plugins each doing this, that string is going to get quite long…
The package.path variable is instanced for every device, so this won’t happen.
Edit: Done. Next firmware we’ll come with this fix.
For the impatient I attached the file:
Thanks all for your comments on this - all hints / tips gratefully received