Author Topic: Plea - seperation of code from xml files.  (Read 3007 times)

Offline ragmondo

  • Jr. Member
  • **
  • Posts: 51
  • Karma: +0/-0
Plea - seperation of code from xml files.
« on: March 16, 2011, 07:33:55 am »
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 ?)

Thanks !

Richard.

Offline guessed

  • Master Member
  • *******
  • Posts: 5294
  • Karma: +90/-22
  • Release compat is not a bolted-on afterthought
Re: Plea - seperation of code from xml files.
« Reply #1 on: March 16, 2011, 08:43:06 am »
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 "pushit", the second is "compressit".

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 "compressit" 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 compressit script, which is "exec" on Vera, runs pluto-lzo 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 sshkeytool (etc), I'm sure you can work out what they look like ;)

Offline mcvflorin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1755
  • Karma: +11/-3
Re: Plea - seperation of code from xml files.
« Reply #2 on: March 16, 2011, 08:46:06 am »
You can put your Lua code in a separate Lua file since firmware version 1.1.1171.
Here's how to do it:

1. Make the Lua file a module:
Code: [Select]
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++)

2. Include the module in the startup function defined in the XML file:
Code: [Select]
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.
    plugin.run(deviceId)
end

Hope this helps.

Offline guessed

  • Master Member
  • *******
  • Posts: 5294
  • Karma: +90/-22
  • Release compat is not a bolted-on afterthought
Re: Plea - seperation of code from xml files.
« Reply #3 on: March 16, 2011, 09:02:42 am »
@mcvflorin,
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:

Code: [Select]
        package.path = package.path .. ";/etc/cmh-ludl/?.lua"
With multiple plugins each doing this, that string is going to get quite long....

Offline mcvflorin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1755
  • Karma: +11/-3
Re: Plea - seperation of code from xml files.
« Reply #4 on: March 16, 2011, 09:48:22 am »
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.

Is there a reason that MiOS doesn't set LUA_PATH (or equivalent) env prior to startup?

Edit: Done. Next firmware we'll come with this fix.

For the impatient I attached the file:
/usr/bin/Start_LuaUPnP.sh
« Last Edit: March 16, 2011, 11:06:35 am by mcvflorin »

Offline ragmondo

  • Jr. Member
  • **
  • Posts: 51
  • Karma: +0/-0
Re: Plea - seperation of code from xml files.
« Reply #5 on: March 17, 2011, 06:05:16 am »
Thanks all for your comments on this - all hints / tips gratefully received