Lua in JavaScript

Could anybody provide an example of how to call lua on the vera from within a java script?

Lets say I want to rund the lua code “luup.log(“TEST”)” from within a java script. What is the best wa to do this? Any good ideas?

What you can do is very limited:

  • getting the value of a device (state)variable
  • calling a callback

Running lua code like in your example is I think not possible.

In a typical plugin lua/luup scripts run on Vera and JavaScript runs on your pc/laptop/tablet/smart phone …

The luup.XXX functions are MCV’s extension to a normal lua interpreter and only run on Vera (unless you have cloned these functions).

There is no way to call luup.log(‘Test’) from JavaScript in this environment.
You can send a message in JavaScript from the Web Browser to the Vera to have a receiving agent in Vera call that function for you. I do not believe one exists at this time … but you could add one …

Welcome to the world of distributed processing.

Using Firebug, or any browser that lets you see the URL calls made, run the built in Test Lua UI.

You’ll see it effectively runs the [tt]RunLua[/tt] action, which (minimally) lets you invoke an arbitrary bit of Lua code from the browser… This is also how we do the old reboot trick.

No data can come back from it, so you’ll need other calls to get back stateVars etc.

…and yes, it’s a huge security hole…

Hm, too bad, was hoping for bether news.

An example for what I am doing at the moment to save variables from javascript to vera variables:
Function

function sendhttp(device, varname, varvalue) { var xmlHttp = null; xmlHttp = new XMLHttpRequest(); xmlHttp.open( "GET", ''+ipaddress+'id=lu_action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunLua&Code=luup.variable_set("'+HC_SID+'","'+varname+'","'+varvalue+'",'+device+')', false ); xmlHttp.send( null ); }

Call:

sendhttp(device, varname, varvalue)

What do you think about this, is this a proper approach?

I don’t get where to see an example of “RunLua”. Could anybody provide an example of RunLua action?