LuaTest - A Tool for Testing Scene Lua Code

Does this still work with the latest UI7. Looking for some method to test our Lua code and the built in stuff does not cut it.

It may do. I was a huge fan of this, but now use AltUI, which is (a) fantastically better interface than UI7, and (b) is great for testing Lua code because the print statement works.

Yes, it did last time I used it.
The other option you may wish to investigate include AltUI and
https://studio.zerobrane.com/vera.html

Seems like Vera would have allot more people doing development work if they had a tools like the ZeroBrane one.

It works on UI7. Been using it quite extensively myself.

Sharing some personal modifications I made to 1.6 in case others find it useful. I’ve been using this in UI7:

  • Added CodeMirror lua syntax highlighting editor support.
  • Test results are now displayed in an iframe on the same page as the editor.

See gist: RBLuaTest.lua Modifications (1.7) [Works in UI7 v1.7.3015] · GitHub

[Edit: attached screenshot]

Hi

I?m a big user of LuaTest

Is there any reason why this should not work on UI5 too ?

Update : Answering my own question it seems to work fine in UI5 too

Hi @cgmartin

Ive noticed something strange with this version. I am a trying to save this line of code

local result = data:match "S(%d+)E" or "error"

But the plus (+) sign is removed each time ?

local result = data:match "S(%d )E" or "error"

Any ideas ?

Hi @parkerc,

I was also able to reproduce that issue from your sample code.

I found some lines from v1.6 that encode the plus “+” character into “%0F” before submitting, but weren’t being decoded correctly upon receiving the request. The manual encoding seems unnecessary since the browser will urlencode the value just fine - maybe there was a bug in luup with it not urldecoding the params properly? Not sure what the history is there.

I’ve removed the lines doing the “+” encoding/decoding and it seems to be working better. The code has been updated in the gist link. You can also see the diff of the changes I made.

The following example is saving correctly for me now:

local data = "ZS123456EZ"
local result = data:match "S(%d+)E" or "error"
print(result)

Hi

I copied down the new file and installed it however now, when I try to save some code it adds a plus (+) into every space? E.g

If I enter this.

local code = "add anything for now"

After hitting save it goes to this…

local+code+=+"add+anything+for+now"

Is it doing that for you too ?

Is it doing that for you too ?

It’s not - It is working in my tests.

This seems like a bug in UI5 that was patched in UI7 (what I’m running, version “1.7.3015”), and explains some of that code I tried removing in the previous post.

But I’m failing to understand why the original version I posted was causing your other issue. Between 1.6 and 1.7 it should be doing the same type of encoding of the plus sign for UI5.

I don’t have a way to test on UI5. You could try this modification of the original version I published, which does the extra “+” encoding and adds a debug log line to try and narrow down the issue. If you can try that, send me the full URL it generates in the browser address bar and the output from the log - I’ll try to help.

Feel free to direct message me - we can move this out of the public forum while debugging. There will probably be a bit of back and forth.

Hi @cgmartin

Thanks for assisting with this.

An interesting observation when I look in the logs is that the code being sent/tested is not showing up ?

Test code

[code]local status, ip = luup.inet.wget(“http://checkip.dyndns.org”)

print (ip: match “%d+%.%d+%.%d+%.%d+”)
print(string.sub(ip, -15))
print(string.sub(ip, 21))
print (ip: match “%d+%.%d+%.%d+%.%d+”)
print(" ")[/code]

Will return print statements in the LuaTest UI, but nothing is in the logs to show that the code has been processed on vera? …

[b]Results[/b] No errors Runtime: 100.8 ms Code returned: nil

Print output

/body>

urrent IP CheckCurrent IP Address: XXX.XXX.XXX.XXX

However the Vera luup log just shows this…

04 10/08/17 11:10:56.784 <0x2c1d7680> 50 10/08/17 11:11:11.014 luup_log:0: LuaTest No errors Runtime: 100.8 ms Code returned: nil <0x3053b680>

I may also have contributed to the ?+? issues as the code I was testing at the time was the following? Not sure as I?m still new to programming.

[code]function my_escape (s)
s = string.gsub(s, " ", “+”)
return s
end

function my_prowl (appl, event, description)
local prowl_url = “https://api.prowlapp.com/publicapi/add?apikey=
… “yourwouldputyourapikeyhere”
… “&application=” … my_escape(appl)
… “&event=” … my_escape(event)
… “&description=” … my_escape(description)
… “&priority=-1”
luup.inet.wget(prowl_url)
end

– my_prowl (appl, event, description)
my_prowl (“Vera Home Controller”, “Testing code”, “this could any description”)

– luup.inet.wget(“http://www.prowlapp.com/publicapi/add?apikey=yourapikeyinhere&application=DSC+Security+Event&event=Armed+Notification&description=The+DSC+alarm+system+has+been+armed&priority=1”)[/code]

@parkerc

nothing is in the logs to show that the code has been processed on vera

It should log only when the “save” button is used. Your log levels seem good since you are seeing other LuaTest logs. I’m out of ideas why the log wouldn’t show up.

I may also have contributed to the ?+? issues as the code I was testing at the time was the following...

That code you were testing shouldn’t affect the behavior of LuaTest.

Hi

Im not sure whats changed - maybe it?s the recent firmware updated but Ive starting to get the following Handler error when trying to access the LuaTest Url (192.168.1.183:3480/data_request?id=lr_LuaTest)

No handler

I?ve checked the start up code is still there and I have reloaded and reuploaded the RBLuatest.lua file, but still get the error? I?ve tried a reboot but no luck there either…

Does anyone have any idea what could be causing this and how to fix it?

Does your startup lua still have the code to register the handler as noted in the first post of this thread? Maybe that got lost?

Hi

Yes the code in lua start up is still there…

-- lua testing code

local rblt = require("RBLuaTest")
rbLuaTest = rblt.rbLuaTest
luup.register_handler("rbLuaTest","LuaTest")

And running this

http://192.168.1.183:3480/data_request?id=lr_LuaTest

sadly still give me a No Handler error ?

Do you see anything in the log during the start up that indicates a problem with the code you list?

Good point (many thanks)

And yes checking the logs there is a huge long list of red, starting with this.

01 11/14/17 16:30:32.251 LuaInterface::LoadCode: [string "function scene_2()..."]:588: '' expected near 'end' <0x77457320> 01 11/14/17 16:30:32.379 JobHandler_LuaUPnP::Run cannot start lua with code: function scene_2() local host = "192.

I removed the offending code (in a scene) and it is working now, (thanks) although Im surprised I did not get any errors messages via the UI ??

I did not realise that all the lua code i have added - e.g for the start up and the scenes is loaded at once (in bulk) I assumed it was split so you would get an error if either had an issue ?

Need someone else to answer this - I’m not familiar with the detail of the startup sequence. I just take it for what it is and hunt down errors that I see and fix them…

Hi Parker,

I think the vera runs by all scene conditions on startup looking at the log file, so if you have LUA in a scene it will probably get loaded at startup. Other code is indeed loaded when needed.

Cheers Rene