PDA

View Full Version : Accessing Girder LUA functions and variables from NetRemote



kanebullen
September 20th, 2007, 05:07 PM
Hi all,

This may seem like a silly question, but I've been trying to trawl the forums for an answer with not much luck. I'm a relative newcomer to LUA/girder/netremote, but am getting some things up and running quite quickly, which is great.

Anyway, I have girder running on one PC, and have written a LUA function that retrieves a value (mm of rainfall recorded today) from a SQL Server database. This works fine in Girder - I can call this function to retrieve the value.

But, I can't seem to figure out a way to call this LUA function from NetRemote (on another PC), so that I can display the rainfall within NetRemote.

I can obviously use the Girder plugin to send an eventstring to Girder, but cannot figure out how to retrieve a Girder variable, or grab the result of a LUA function that returns a value.

Obviously, from the Girder side, I can use the Netremote->Set Variable action. But that's not really the way I want to do it (I'd prefer to only have to retrieve the value on request)

Hopefully I've provided enough information - if not, please let me know!

Thanks heaps,

Kane

Rob H
September 20th, 2007, 11:22 PM
I can obviously use the Girder plugin to send an eventstring to Girder, but cannot figure out how to retrieve a Girder variable, or grab the result of a LUA function that returns a value.

Obviously, from the Girder side, I can use the Netremote->Set Variable action. But that's not really the way I want to do it (I'd prefer to only have to retrieve the value on request)

Okay, you have the two pieces of the puzzle right there - NetRemote will send an event string to Girder and Girder will use either the NetRemote|Set Variable action or a direct call to NetRemote.SetVariable from a bit of Lua script. The simplest way is probably to use a Scripting action to call your Lua function to retrieve the value from the SQL database and then use NetRemote.SetVariable to send that value back to NetRemote.

If there's something I missed then let me know.

kanebullen
September 20th, 2007, 11:28 PM
Okay, you have the two pieces of the puzzle right there - NetRemote will send an event string to Girder and Girder will use either the NetRemote|Set Variable action or a direct call to NetRemote.SetVariable from a bit of Lua script. The simplest way is probably to use a Scripting action to call your Lua function to retrieve the value from the SQL database and then use NetRemote.SetVariable to send that value back to NetRemote.

If there's something I missed then let me know.

Why didn't I think of that!! That makes a lot of sense, now that it's been pointed out to me!

Although I suppose it would be much cleaner if I could simply call the LUA function directly from NetRemote, but oh well!

Thanks heaps - much appreciated.

Kane

Rob H
September 20th, 2007, 11:39 PM
I'm fairly sure that RunLua isn't implemented from NR to Girder although it does work the other way around i.e. you can run arbitrary Lua code on NR from Girder. But I wouldn't really recommend it unless you absolutely have to do it.