Hello,
I do not entirely understand what s not working correctly. Basically, you have a c++ CoppeliaSim plugin, and want to call one function inside of that plugin, from within a CoppeliaSim script.
There are 2 different ways of doing this: the
old way and the
new way. The old way is easier to understand and set up, for small projects. The new way is a bit more difficult to initially set up, butmore flexible and easier to maintain.
From your code, you are using the old way. There are several things in your plugin that are missing, not sure if this is intended to simplify your post. Have a look at the skeleton plugin from the old way, but basically you will need a callback function. e.g.:
Code: Select all
// --------------------------------------------------------------------------------------
// simExtSkeleton_getData: an example of custom Lua command
// --------------------------------------------------------------------------------------
#define LUA_GETDATA_COMMAND "simSkeleton.getData" // the name of the new Lua command
void LUA_GETDATA_CALLBACK(SScriptCallBack* p)
{ // the callback function of the new Lua command ("simExtSkeleton_getData")
int stack=p->stackID;
CStackArray inArguments;
inArguments.buildFromStack(stack);
if ( (inArguments.getSize()>=2)&&inArguments.isString(0)&&inArguments.isMap(1) )
{ // we expect at least 2 arguments: a string and a map
CStackMap* map=inArguments.getMap(1);
std::string tmp("we received a string (");
tmp+=inArguments.getString(0).c_str();
tmp+=") and following message in the map: ";
tmp+=map->getString("message").c_str();
simAddLog("PluginSkeleton",sim_verbosity_msgs,tmp.c_str());
}
else
simSetLastError(LUA_GETDATA_COMMAND,"Not enough arguments or wrong arguments.");
// Now return a string and a map:
CStackArray outArguments;
outArguments.pushString("Hello World");
CStackMap* map=new CStackMap();
map->setBool("operational",true);
CStackArray* pos=new CStackArray();
double _pos[3]={0.0,1.0,2.0};
pos->setDoubleArray(_pos,3);
map->setArray("position",pos);
outArguments.pushMap(map);
outArguments.buildOntoStack(stack);
}
// --------------------------------------------------------------------------------------
Then you need to make sure that you have the 3 required entry function to your plugin:
Code: Select all
SIM_DLLEXPORT unsigned char simStart(void* reservedPointer,int reservedInt)
SIM_DLLEXPORT void simEnd()
SIM_DLLEXPORT void* simMessage(int message,int* auxiliaryData,void* customData,int* replyData)
Inside of the simStart function, you will have to register your callback function, e.g.:
Code: Select all
simRegisterScriptCallbackFunction(strConCat(LUA_GETDATA_COMMAND,"@","PluginSkeleton"),strConCat("...=",LUA_GETDATA_COMMAND,"(string data1,map data2)"),LUA_GETDATA_CALLBACK);
Cheers