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 https://github.com/rticommunity/rticonnextdds-connector.git
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.
export LD_LIBRARY_PATH=../../lib/x64Darwin12clang4.1/ ./objs/x64Darwin12clang4.1/main
On OS X (Mac):
export DYLD_LIBRARY_PATH=../../lib/x64Darwin12clang4.1/ ./objs/x64Darwin12clang4.1/main
Include the Connector library
If you want to use the
lua rticonnextdds-connector from your C application, include the following header file:
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( "MyParticipantLibrary::Zero", "./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
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
Execute the Lua script
When ready, your C loop can execute the Lua script asserted before just by calling
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
Connector is not thread safe. If you wish to call Connector APIs from different threads, you will have to protect those calls yourself.