We have moved at community.getvera.com

Author Topic: Lua comment, not a comment?  (Read 2686 times)

Offline Snotneus

  • Jr. Member
  • **
  • Posts: 52
  • Karma: +1/-0
Lua comment, not a comment?
« on: June 18, 2011, 12:35:14 pm »
Hi,

In one of my plug-ins I encountered a strange problem which I want to share.
From the plug-in I have to send data over IP to another device on my home network.

Therefore I used the following code in the Vera device implementation file (I_xxx.xml):

local http = require("socket.http");
local strCmd = http.request("http://10.0.0.155/command/invoke\?swid=/Tussenweid/Publiek/statusLampen&command=manualSet&arg=" .. tostring(newStatus));

The above long line is actually only one line.
If I paste this code into the "Test Luup code (Lua)" it just runs fine.

Same code pasted into the I_xxx.xml causes Vera not to run this code.

While debugging my code, I commented out the long line, expecting lua to jump over this line, because it now is only a comment.
However, this seems not to be true, because lua still recognizes the ? and the & and refuses to run the program.

Changing the ? into \063 and & into \038 cures the problem.

Strange however, that even when commented out, using --, causes failure.

Regards.

Offline Henk

  • Hero Member
  • *****
  • Posts: 820
  • Karma: +3/-0
Re: Lua comment, not a comment?
« Reply #1 on: June 18, 2011, 12:53:14 pm »
Hi,

In one of my plug-ins I encountered a strange problem which I want to share.
From the plug-in I have to send data over IP to another device on my home network.

Therefore I used the following code in the Vera device implementation file (I_xxx.xml):

local http = require("socket.http");
local strCmd = http.request("http://10.0.0.155/command/invoke\?swid=/Tussenweid/Publiek/statusLampen&command=manualSet&arg=" .. tostring(newStatus));

The above long line is actually only one line.
If I paste this code into the "Test Luup code (Lua)" it just runs fine.

Same code pasted into the I_xxx.xml causes Vera not to run this code.

While debugging my code, I commented out the long line, expecting lua to jump over this line, because it now is only a comment.
However, this seems not to be true, because lua still recognizes the ? and the & and refuses to run the program.

Changing the ? into \063 and & into \038 cures the problem.

Strange however, that even when commented out, using --, causes failure.

Regards.

@snotneus

I have encountered issues with special characters as well. LUA seems to have issues with it.
You might try to use escape characters (for instance space = %20) to work around this.

Let us know if that helped
| Vera2 @ UI4 1.1.1350 / 3.20 | Vera Lite @ UI5 | Vera 3 @ UI5 | 2x Merten  504519 | 1x Duewi  064374 | 1x Everspring SM103 doorbell mod |1 Y-cam IP cam | various LUUP plugins |

Offline Snotneus

  • Jr. Member
  • **
  • Posts: 52
  • Karma: +1/-0
Re: Lua comment, not a comment?
« Reply #2 on: June 18, 2011, 01:01:08 pm »
Henk,

As decribed in my first post, using escape characters does cure the problem.

But to me it is very strange, that if the line is commented out using --, the special characters still cause problems.

Regards.

Offline Henk

  • Hero Member
  • *****
  • Posts: 820
  • Karma: +3/-0
Re: Lua comment, not a comment?
« Reply #3 on: June 18, 2011, 01:06:40 pm »
Henk,

As decribed in my first post, using escape characters does cure the problem.

But to me it is very strange, that if the line is commented out using --, the special characters still cause problems.

Regards.

Did you check line breaks (cr/lf or others?)
Maybe theres a linebreak detected somewhere making your single line of code being split into more?

If not... im out of options...
| Vera2 @ UI4 1.1.1350 / 3.20 | Vera Lite @ UI5 | Vera 3 @ UI5 | 2x Merten  504519 | 1x Duewi  064374 | 1x Everspring SM103 doorbell mod |1 Y-cam IP cam | various LUUP plugins |

Offline guessed

  • Community Beta
  • Master Member
  • ******
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Lua comment, not a comment?
« Reply #4 on: June 18, 2011, 02:41:39 pm »
Device declaration and implementation files must be valid XML documents.

The & character, along with the < character, must be [XML] escaped to ensure that the XML document remains valid.  In this case the following type of substitutions need to be made:

   & -> &amp;
   < -> &lt;

Also note that you can use luup.inet.wget() to do the same thing you're doing with LuaSocket:
    http://wiki.micasaverde.com/index.php/Luup_Lua_extensions#function:_wget