Results 1 to 5 of 5

Thread: Can NetRemote send LUA code to Girder?

  1. #1
    Join Date
    Nov 2006
    Posts
    116

    Default Can NetRemote start LUA calls in Girder

    Hi,

    I am looking for a solution to call a lua function in Girder, but from a NetRemote client. What I need is to handover the function call including parameters. The function itself is running in Girder.

    So for example Girder has loaded a luascript that offers the function "switch_light_on(parameters)" and I want to call it directly from NetRemote without using the eventmanagement etc.

    Is it possible?

    Thanks,
    Marc
    Last edited by Marquis; June 11th, 2007 at 05:25 AM.

  2. #2
    Join Date
    Mar 2005
    Location
    Los Angeles, CA
    Posts
    1,001

    Default

    While the technique I'm about to describe DOES use the event manager, hopefully it accomplishes what you're looking for:

    1. Create the script that you want to execute in Girder
    2. Set up a raw communication server event with a convenient name ("NR.Test", for example) to trigger the script you just created.
    3. From NetRemote, make the following call:
    Code:
    NetRemote.ExecuteAction( -1, 0, 1, "NR.Test("..param1.."|"..param2..")" );
    4. At the beginning of your Girder function which will be triggered by the "NR.Test" event, insert the following code to extract the passed parameters:
    Code:
    local p1, p2;
    
    -- Parse the payload into two strings
    _, _, p1, p2 = string.find( pld3, "(%w+)%|(.+)" );
    You have now set up a mechanism to trigger a Girder function from NetRemote, passing two parameters. The pld3 variable is a global Girder variable which contains the raw text of what was passed from NetRemote. After step 4 above, the p1 and p2 variables will contain param1 and param2 from NetRemote (note that these are now strings, so you might use tonumber() if you need to do numeric comparisons with them). It is possible to scale this parameter passing approach to handle more parameters, or to pass a table instead.

    Cheers,
    Tim

  3. #3
    Join Date
    May 2004
    Location
    Dallas, TX
    Posts
    1,032

    Default

    I use the same method described however I use the following to parse the parameters

    Code:
    local parms = string.Split(pld3, '|')
    this way you can pass in varying number of parms.
    Rick

    Girder 5.0 - Elk M1 Gold - JRMC 11.1 w/ M-Audio Delta 410 - NetRemote 2.0 - Panasonic KX-TA624 Phone System - ZoneMinder DVR
    Girder 5 Plugins - Elk M1/EZ8, Email Manager, Girder Backup, Ocelot, xAP Speedfan, xAP Ping, xAP Zoneminder and many more.


    Visit My Showcase

  4. #4
    Join Date
    Mar 2005
    Location
    Los Angeles, CA
    Posts
    1,001

    Default

    Good point! Assuming you've added a string.split function, that's a more elegant approach . You can find a number of string.split examples with a Google search (but I don't think it's part of the base LUA distribution, at least as far as I know).

    Cheers,
    Tim

  5. #5
    Join Date
    May 2004
    Location
    Dallas, TX
    Posts
    1,032

    Default

    It was recently added by Mike, I use it quite frequently.
    Rick

    Girder 5.0 - Elk M1 Gold - JRMC 11.1 w/ M-Audio Delta 410 - NetRemote 2.0 - Panasonic KX-TA624 Phone System - ZoneMinder DVR
    Girder 5 Plugins - Elk M1/EZ8, Email Manager, Girder Backup, Ocelot, xAP Speedfan, xAP Ping, xAP Zoneminder and many more.


    Visit My Showcase

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •