Collaboration diagram for An example which shows how to use a Lua script to create a new data type in a port:This example demonstrates how to use the port monitor carrier to substitute a data type with another one. The port '/write' from 'yarp write' module is connected to the '/read' port of 'yarp read' using a portmonitor plugged into the receiver side. The portmoniotr loads a Lua script ('type_modifier.lua') which expects to see a command such as 'random N' (where N is an integer number). The command is, then, completely substituted with a vector of N random values which will be delivered to the 'yarp read'. The port monitor also checks for the validity of the command
$ yarpserver
$ cd $YARP_ROOT/example/portmonitor/type_modification $ yarp read /read
$ yarp write /write
$ yarp connect /write /read tcp+recv.portmonitor+type.lua+file.type_modifier
Now if you write a valid command in the 'sender' terminal (e.g., random 3), you will see the command is completely substituted by a vector of 3 random values. For example:
[sender terminal] random 3
[receiver terminal] 0.513401 0.95223 0.916195