gre.send_event_data

gre.send_event_data(
    event_name,
    format_string,
    data,
    [channel]
)
            

Send an event with custom data to the application or to a Storyboard IO channel. The data parameter is a Lua table where the indexes match the values from the format string. channel is an optional parameter.

Special consideration is required for sending data that is to be formatted as an array (i.e., N[suf]M where M is greater than 0). In this case the data entry should be provided as a Lua table and not as a raw value parameter.

Data parameters must be sent in order of descending alignment requirements. Example: 4u1 4u1 2u1 1s0 is good, 2u1 4u1 4u1 1s0 is not


Parameters:

        event_name    A string containing the event to send
        format_string A string format of the event data payload
        data          A table whose keys match up with the keys specified in the format_string
        channel       An optional Storyboard IO channel to send the event on, if not specified the
                      event is added directly into the current Storyboard application event queue
                      if neither the environment variable or global GREIONAME variable are set.
                      
Returns:

        true for success, false for failure and error message string, e.g. "Can't open greio channel my_channel"                       
                      
Example:
            

-- Send a 'int32_update' event with a 32bit signed integer (int32_t)
-- payload to the 'controller' channel
function send_integer(value)
    local  format = "4s1 value"
    local data = {}
    data["value"] = value
    local success, error = gre.send_event_data("int32_update", format,
    data, "controller")
    if(success == false) then
        print(error)
        --handle error
    end
end

-- Send a 'int16_update' event with two 16bit signed integers (int16_t)
-- payload to the 'controller' channel
function send_two_integers(value1, value2)
    local  format = "2s1 first 2s1 second"
    local data = {}
    data["first"] = value1
    data["second"] = value2
    local success, error = gre.send_event_data("int16_update", format, 
    data, "controller")
    if(success == false) then
        print(error)
        --handle error
    end
end

-- Send an 'array_update' event with an array of int32_t numbers (provided
-- as a table) to the client
function send_integer_array(values)
    -- Generate the format string dynamically based on the number of entries
    local count = #values
    local format = string.format("4s%d values", count)
    local data = {}
    data["values"] = values
    local success, error = gre.send_event_data("array_update", format, 
    data, "controller")
    if(success == false) then
        print(error)
        --handle error
    end
end

send_integer(12)
send_two_integers(10, 20)
send_integer_array({10, 20, 30, 40})