Skip to content
Branch: master
Find file History
Latest commit 3ac181c Oct 4, 2018

rticonnextdds-connector: Lua/C Integration

For the native code lovers, we have header files so you can call the Connector API directly in your C application; that's how Prototyper is implemented. The Lua version used is 5.1.

Installation and platform support

To compile this example, you will need to clone this repository. You can do that by executing:

git clone --depth=1

We provide example makefiles in the make directory and a Windows solution in the win directory. To compile the example, you need a copy of RTI Connext DDS. If you are on a Unix-like system, you can compile your example using make:

cd example\lua_c_integration
make -f make/Makefile.x64Darwin12clang4.1

After you compile, set the library path and run the executable.

On Linux:

export LD_LIBRARY_PATH=../../lib/x64Darwin12clang4.1/

On OS X (Mac):

export DYLD_LIBRARY_PATH=../../lib/x64Darwin12clang4.1/

Available example

In this directory, you can find an example on how to use the Lua RTI Connector from your C application. See the file main.c and Alert.lua, and look at the overview below.


The Lua API used in the example, Alert.lua, is available in the Prototyper Getting Started Guide.


Include the Connector library

If you want to use the lua rticonnextdds-connector from your C application, include the following header file:

#include "lua_binding/lua_binding_ddsConnector.h"

Instantiate a new Connector

To create a new Connector, you have to pass an XML file and a configuration name. For more information on the XML format, see the XML Application Creation Getting Started Guide or have a look to the Simple.xml file included in this directory.

struct RTIDDSConnector *connector = NULL;
connector = RTIDDSConnector_new(
        "./Simple.xml", NULL);

Assert the Lua script that will be executed

Once Connector has been created, you have to assert what Lua code will be executed. To do so, use the RTIDDSConnector_assertCode API. This API gets a pointer to Connector, an optional string (which can be NULL) containing the Lua script and an optional string (which can be NULL) with a path to a file containing a Lua script. If both strings are NULL, Connector will not execute any Lua code.

The last parameter is the interval, in seconds, during which the Lua script is checked for changes. A negative value disables reloads.


Pass parameters from C to Lua

Connector offers an API to allow C programs to set values in a Lua table called CONTEXT. All you have to do is call the RTIDDSConnector_set[Number|String|Boolean]IntoContext API:

RTIDDSConnector_setNumberIntoContext(connector,"temp", temp);

Execute the Lua script

When ready, your C loop can execute the Lua script asserted before just by calling RTIDDSConnector_execute:


RTIDDSConnector_execute will return once the script execution is finished.

Delete a Connector

To destroy all the DDS entities that belong to a Connector previously created, call the RTIDDSConnector_delete function.


Threading considerations

Connector is not thread safe. If you wish to call Connector APIs from different threads, you will have to protect those calls yourself.

You can’t perform that action at this time.