luaFunctionData.cpp
Go to the documentation of this file.
1 // Copyright 2006-2016 Coppelia Robotics GmbH. All rights reserved.
2 // marc@coppeliarobotics.com
3 // www.coppeliarobotics.com
4 //
5 // -------------------------------------------------------------------
6 // THIS FILE IS DISTRIBUTED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
7 // WARRANTY. THE USER WILL USE IT AT HIS/HER OWN RISK. THE ORIGINAL
8 // AUTHORS AND COPPELIA ROBOTICS GMBH WILL NOT BE LIABLE FOR DATA LOSS,
9 // DAMAGES, LOSS OF PROFITS OR ANY OTHER KIND OF LOSS WHILE USING OR
10 // MISUSING THIS SOFTWARE.
11 //
12 // You are free to use/modify/distribute this file for whatever purpose!
13 // -------------------------------------------------------------------
14 //
15 // This file was automatically created for V-REP release V3.3.2 on August 29th 2016
16 
17 #include "luaFunctionData.h"
18 #include <sstream>
19 #include <cstring>
20 
22 {
23 }
24 
26 {
27 }
28 
29 void CLuaFunctionData::getInputDataForFunctionRegistration(const int* dat,std::vector<int>& outDat)
30 {
31  outDat.clear();
32  outDat.push_back(dat[0]);
33  for (int i=0;i<dat[0];i++)
34  outDat.push_back((dat[1+2*i+0]|SIM_LUA_ARG_NIL_ALLOWED)-SIM_LUA_ARG_NIL_ALLOWED);
35 }
36 
37 std::vector<CLuaFunctionDataItem>* CLuaFunctionData::getInDataPtr()
38 { // use this when reading data from Lua from inside of a custom Lua function call
39  return(&_inData);
40 }
41 
42 std::vector<CLuaFunctionDataItem>* CLuaFunctionData::getOutDataPtr_luaFunctionCall()
43 { // use this when reading data returned from a Lua function call from a plugin
44  return(&_outData);
45 }
46 
47 bool CLuaFunctionData::readDataFromLua(const SLuaCallBack* p,const int* expectedArguments,int requiredArgumentCount,const char* functionName)
48 {
49  // use this when reading data from Lua from inside of a custom Lua function call
50  _inData.clear();
51  int argCnt=p->inputArgCount;
52  if (argCnt<requiredArgumentCount)
53  {
54  simSetLastError(functionName,"Not enough arguments.");
55  return(false);
56  }
57 
58  int boolArgInd=0;
59  int intArgInd=0;
60  int floatArgInd=0;
61  int doubleArgInd=0;
62  int charArgInd=0;
63  int charBuffArgInd=0;
64 
65  for (int i=0;i<argCnt;i++)
66  {
67  if (i>=expectedArguments[0])
68  break;
69  bool done=false;
70  if (p->inputArgTypeAndSize[i*2+0]==sim_lua_arg_nil)
71  {
72  // is nil explicitely allowed?
73  if (expectedArguments[1+i*2+0]&SIM_LUA_ARG_NIL_ALLOWED)
74  { // yes. This is for an argument that can optionally also be nil.
76  _inData.push_back(dat);
77  done=true;
78  }
79  else
80  { // no
81  if (int(_inData.size())<requiredArgumentCount)
82  {
83  std::ostringstream str;
84  str << "Argument " << i+1 << " is not correct.";
85  simSetLastError(functionName,str.str().c_str());
86  return(false);
87  }
88  break; // this argument is nil, so it is like inexistant. But we also won't explore any more arguments, we have enough.
89  }
90  }
91  if (!done)
92  {
93  if (p->inputArgTypeAndSize[i*2+0]!=((expectedArguments[1+i*2+0]|SIM_LUA_ARG_NIL_ALLOWED)-SIM_LUA_ARG_NIL_ALLOWED))
94  {
95  std::ostringstream str;
96  str << "Argument " << i+1 << " is not correct.";
97  simSetLastError(functionName,str.str().c_str());
98  return(false);
99  }
101  { // we have a table
102  if ( (p->inputArgTypeAndSize[i*2+1]<expectedArguments[1+i*2+1])&&(expectedArguments[1+i*2+1]!=0) )
103  {
104  std::ostringstream str;
105  str << "Argument " << i+1 << " is not correct (wrong table size).";
106  simSetLastError(functionName,str.str().c_str());
107  return(false);
108  }
109  else
110  {
111  int t=p->inputArgTypeAndSize[i*2+0]-sim_lua_arg_table;
112  int itemCnt=p->inputArgTypeAndSize[i*2+1];
113 
114  if (t==sim_lua_arg_nil)
115  {
117  a->setNilTable(itemCnt);
119  dat.setNilTable(itemCnt);
120  _inData.push_back(dat);
121  }
122  if (t==sim_lua_arg_bool)
123  {
124  std::vector<bool> vect;
125  for (int j=0;j<itemCnt;j++)
126  vect.push_back(p->inputBool[boolArgInd++]!=0);
127  CLuaFunctionDataItem dat(vect);
128  _inData.push_back(dat);
129  }
130  if (t==sim_lua_arg_int)
131  {
132  std::vector<int> vect;
133  for (int j=0;j<itemCnt;j++)
134  vect.push_back(p->inputInt[intArgInd++]);
135  CLuaFunctionDataItem dat(vect);
136  _inData.push_back(dat);
137  }
138  if (t==sim_lua_arg_float)
139  {
140  std::vector<float> vect;
141  for (int j=0;j<itemCnt;j++)
142  vect.push_back(p->inputFloat[floatArgInd++]);
143  CLuaFunctionDataItem dat(vect);
144  _inData.push_back(dat);
145  }
146  if (t==sim_lua_arg_double)
147  {
148  std::vector<double> vect;
149  for (int j=0;j<itemCnt;j++)
150  vect.push_back(p->inputDouble[doubleArgInd++]);
151  CLuaFunctionDataItem dat(vect);
152  _inData.push_back(dat);
153  }
154  if (t==sim_lua_arg_string)
155  {
156  std::vector<std::string> vect;
157  for (int j=0;j<itemCnt;j++)
158  {
159  std::string str(p->inputChar+charArgInd);
160  vect.push_back(str);
161  charArgInd+=int(strlen(p->inputChar+charArgInd))+1;
162  }
163  CLuaFunctionDataItem dat(vect);
164  _inData.push_back(dat);
165  }
166  if (t==sim_lua_arg_charbuff)
167  {
168  std::ostringstream str;
169  str << "Argument " << i+1 << " cannot be a table.";
170  simSetLastError(functionName,str.str().c_str());
171  return(false);
172  }
173  }
174  }
175  else
176  { // we do not have a table
177  int t=p->inputArgTypeAndSize[i*2+0];
178  if (t==sim_lua_arg_nil)
179  {
181  _inData.push_back(dat);
182  }
183  if (t==sim_lua_arg_bool)
184  {
185  CLuaFunctionDataItem dat(p->inputBool[boolArgInd++]!=0);
186  _inData.push_back(dat);
187  }
188  if (t==sim_lua_arg_int)
189  {
190  CLuaFunctionDataItem dat(p->inputInt[intArgInd++]);
191  _inData.push_back(dat);
192  }
193  if (t==sim_lua_arg_float)
194  {
195  CLuaFunctionDataItem dat(p->inputFloat[floatArgInd++]);
196  _inData.push_back(dat);
197  }
198  if (t==sim_lua_arg_double)
199  {
200  CLuaFunctionDataItem dat(p->inputDouble[doubleArgInd++]);
201  _inData.push_back(dat);
202  }
203  if (t==sim_lua_arg_string)
204  {
205  CLuaFunctionDataItem dat(std::string(p->inputChar+charArgInd));
206  charArgInd+=int(strlen(p->inputChar+charArgInd))+1;
207  _inData.push_back(dat);
208  }
209  if (t==sim_lua_arg_charbuff)
210  {
211  if ( (p->inputArgTypeAndSize[i*2+1]<expectedArguments[1+i*2+1])&&(expectedArguments[1+i*2+1]!=0) )
212  {
213  std::ostringstream str;
214  str << "Argument " << i+1 << " is not correct (wrong buffer size).";
215  simSetLastError(functionName,str.str().c_str());
216  return(false);
217  }
218  else
219  {
220  CLuaFunctionDataItem dat(p->inputCharBuff+charBuffArgInd,p->inputArgTypeAndSize[i*2+1]);
221  charBuffArgInd+=p->inputArgTypeAndSize[i*2+1];
222  _inData.push_back(dat);
223  }
224  }
225  }
226  }
227  }
228  return(true);
229 }
230 
231 bool CLuaFunctionData::readDataFromLua_luaFunctionCall(const SLuaCallBack* p,const int* expectedArguments,int requiredArgumentCount,const char* functionName)
232 {
233  // use this when reading data returned from a Lua function call from a plugin
234  _outData.clear();
235  int argCnt=p->outputArgCount;
236  if (argCnt<requiredArgumentCount)
237  {
238  simSetLastError(functionName,"Not enough return arguments.");
239  return(false);
240  }
241 
242  int boolArgInd=0;
243  int intArgInd=0;
244  int floatArgInd=0;
245  int doubleArgInd=0;
246  int charArgInd=0;
247  int charBuffArgInd=0;
248 
249  for (int i=0;i<argCnt;i++)
250  {
251  if (i>=expectedArguments[0])
252  break;
253  bool done=false;
254  if (p->outputArgTypeAndSize[i*2+0]==sim_lua_arg_nil)
255  {
256  // is nil explicitely allowed?
257  if (expectedArguments[1+i*2+0]&SIM_LUA_ARG_NIL_ALLOWED)
258  { // yes. This is for an argument that can optionally also be nil.
260  _outData.push_back(dat);
261  done=true;
262  }
263  else
264  { // no
265  if (int(_outData.size())<requiredArgumentCount)
266  {
267  std::ostringstream str;
268  str << "Return argument " << i+1 << " is not correct.";
269  simSetLastError(functionName,str.str().c_str());
270  return(false);
271  }
272  break; // this argument is nil, so it is like inexistant. But we also won't explore any more arguments, we have enough.
273  }
274  }
275  if (!done)
276  {
277  if (p->outputArgTypeAndSize[i*2+0]!=((expectedArguments[1+i*2+0]|SIM_LUA_ARG_NIL_ALLOWED)-SIM_LUA_ARG_NIL_ALLOWED))
278  {
279  std::ostringstream str;
280  str << "Return argument " << i+1 << " is not correct.";
281  simSetLastError(functionName,str.str().c_str());
282  return(false);
283  }
285  { // we have a table
286  if ( (p->outputArgTypeAndSize[i*2+1]<expectedArguments[1+i*2+1])&&(expectedArguments[1+i*2+1]!=0) )
287  {
288  std::ostringstream str;
289  str << "Return argument " << i+1 << " is not correct (wrong table size).";
290  simSetLastError(functionName,str.str().c_str());
291  return(false);
292  }
293  else
294  {
295  int t=p->outputArgTypeAndSize[i*2+0]-sim_lua_arg_table;
296  int itemCnt=p->outputArgTypeAndSize[i*2+1];
297 
298  if (t==sim_lua_arg_nil)
299  {
301  a->setNilTable(itemCnt);
303  dat.setNilTable(itemCnt);
304  _outData.push_back(dat);
305  }
306  if (t==sim_lua_arg_bool)
307  {
308  std::vector<bool> vect;
309  for (int j=0;j<itemCnt;j++)
310  vect.push_back(p->outputBool[boolArgInd++]!=0);
311  CLuaFunctionDataItem dat(vect);
312  _outData.push_back(dat);
313  }
314  if (t==sim_lua_arg_int)
315  {
316  std::vector<int> vect;
317  for (int j=0;j<itemCnt;j++)
318  vect.push_back(p->outputInt[intArgInd++]);
319  CLuaFunctionDataItem dat(vect);
320  _outData.push_back(dat);
321  }
322  if (t==sim_lua_arg_float)
323  {
324  std::vector<float> vect;
325  for (int j=0;j<itemCnt;j++)
326  vect.push_back(p->outputFloat[floatArgInd++]);
327  CLuaFunctionDataItem dat(vect);
328  _outData.push_back(dat);
329  }
330  if (t==sim_lua_arg_double)
331  {
332  std::vector<double> vect;
333  for (int j=0;j<itemCnt;j++)
334  vect.push_back(p->outputDouble[doubleArgInd++]);
335  CLuaFunctionDataItem dat(vect);
336  _outData.push_back(dat);
337  }
338  if (t==sim_lua_arg_string)
339  {
340  std::vector<std::string> vect;
341  for (int j=0;j<itemCnt;j++)
342  {
343  std::string str(p->outputChar+charArgInd);
344  vect.push_back(str);
345  charArgInd+=int(strlen(p->outputChar+charArgInd))+1;
346  }
347  CLuaFunctionDataItem dat(vect);
348  _outData.push_back(dat);
349  }
350  if (t==sim_lua_arg_charbuff)
351  {
352  std::ostringstream str;
353  str << "Return argument " << i+1 << " cannot be a table.";
354  simSetLastError(functionName,str.str().c_str());
355  return(false);
356  }
357  }
358  }
359  else
360  { // we do not have a table
361  int t=p->outputArgTypeAndSize[i*2+0];
362  if (t==sim_lua_arg_nil)
363  {
365  _outData.push_back(dat);
366  }
367  if (t==sim_lua_arg_bool)
368  {
369  CLuaFunctionDataItem dat(p->outputBool[boolArgInd++]!=0);
370  _outData.push_back(dat);
371  }
372  if (t==sim_lua_arg_int)
373  {
374  CLuaFunctionDataItem dat(p->outputInt[intArgInd++]);
375  _outData.push_back(dat);
376  }
377  if (t==sim_lua_arg_float)
378  {
379  CLuaFunctionDataItem dat(p->outputFloat[floatArgInd++]);
380  _outData.push_back(dat);
381  }
382  if (t==sim_lua_arg_double)
383  {
384  CLuaFunctionDataItem dat(p->outputDouble[doubleArgInd++]);
385  _outData.push_back(dat);
386  }
387  if (t==sim_lua_arg_string)
388  {
389  CLuaFunctionDataItem dat(std::string(p->outputChar+charArgInd));
390  charArgInd+=int(strlen(p->outputChar+charArgInd))+1;
391  _outData.push_back(dat);
392  }
393  if (t==sim_lua_arg_charbuff)
394  {
395  if ( (p->outputArgTypeAndSize[i*2+1]<expectedArguments[1+i*2+1])&&(expectedArguments[1+i*2+1]!=0) )
396  {
397  std::ostringstream str;
398  str << "Return argument " << i+1 << " is not correct (wrong buffer size).";
399  simSetLastError(functionName,str.str().c_str());
400  return(false);
401  }
402  else
403  {
404  CLuaFunctionDataItem dat(p->outputCharBuff+charBuffArgInd,p->outputArgTypeAndSize[i*2+1]);
405  charBuffArgInd+=p->outputArgTypeAndSize[i*2+1];
406  _outData.push_back(dat);
407  }
408  }
409  }
410  }
411  }
412  return(true);
413 }
414 
416 { // use this when returning data from inside of a custom Lua function call
417  _outData.push_back(dataItem);
418 }
419 
421 { // use this when doing a Lua function call from a plugin
422  _inData.push_back(dataItem);
423 }
424 
426 {
427  // use this when returning data from inside of a custom Lua function call
428  p->outputArgCount=0;
429  int itemCnt=int(_outData.size());
430  if (itemCnt>0)
431  {
432  p->outputArgCount=itemCnt;
434 
435  int boolDataCnt=0;
436  int intDataCnt=0;
437  int floatDataCnt=0;
438  int doubleDataCnt=0;
439  int charDataCnt=0;
440  int charBuffDataCnt=0;
441 
442  for (int i=0;i<itemCnt;i++)
443  {
444  if (_outData[i].isTable())
445  { // table
446  if (_outData[i].getType()==-1)
447  {
449  p->outputArgTypeAndSize[i*2+1]=_outData[i].getNilTableSize();
450  }
451  if (_outData[i].getType()==0)
452  {
454  p->outputArgTypeAndSize[i*2+1]=int(_outData[i].boolData.size());
455  boolDataCnt+=p->outputArgTypeAndSize[i*2+1];
456  }
457  if (_outData[i].getType()==1)
458  {
460  p->outputArgTypeAndSize[i*2+1]=int(_outData[i].intData.size());
461  intDataCnt+=p->outputArgTypeAndSize[i*2+1];
462  }
463  if (_outData[i].getType()==2)
464  {
466  p->outputArgTypeAndSize[i*2+1]=int(_outData[i].floatData.size());
467  floatDataCnt+=p->outputArgTypeAndSize[i*2+1];
468  }
469  if (_outData[i].getType()==5)
470  {
472  p->outputArgTypeAndSize[i*2+1]=int(_outData[i].doubleData.size());
473  doubleDataCnt+=p->outputArgTypeAndSize[i*2+1];
474  }
475  if (_outData[i].getType()==3)
476  {
478  p->outputArgTypeAndSize[i*2+1]=int(_outData[i].stringData.size());
479  for (int j=0;j<int(_outData[i].stringData.size());j++)
480  charDataCnt+=int(_outData[i].stringData[j].length())+1;
481  }
482  }
483  else
484  {
485  if (_outData[i].getType()==-1)
486  {
487  p->outputArgTypeAndSize[i*2+1]=0;
489  }
490  if (_outData[i].getType()==0)
491  {
492  p->outputArgTypeAndSize[i*2+1]=0;
494  boolDataCnt++;
495  }
496  if (_outData[i].getType()==1)
497  {
498  p->outputArgTypeAndSize[i*2+1]=0;
500  intDataCnt++;
501  }
502  if (_outData[i].getType()==2)
503  {
504  p->outputArgTypeAndSize[i*2+1]=0;
506  floatDataCnt++;
507  }
508  if (_outData[i].getType()==5)
509  {
510  p->outputArgTypeAndSize[i*2+1]=0;
512  doubleDataCnt++;
513  }
514  if (_outData[i].getType()==3)
515  {
516  p->outputArgTypeAndSize[i*2+1]=0;
518  charDataCnt+=int(_outData[i].stringData[0].length())+1;
519  }
520  if (_outData[i].getType()==4)
521  {
522  p->outputArgTypeAndSize[i*2+1]=int(_outData[i].stringData[0].length());
524  charBuffDataCnt+=int(_outData[i].stringData[0].length());
525  }
526  }
527  }
528 
529  // Now create the buffers:
530  p->outputBool=(simBool*)simCreateBuffer(boolDataCnt*sizeof(simBool));
531  p->outputInt=(simInt*)simCreateBuffer(intDataCnt*sizeof(simInt));
532  p->outputFloat=(simFloat*)simCreateBuffer(floatDataCnt*sizeof(simFloat));
533  p->outputDouble=(simDouble*)simCreateBuffer(doubleDataCnt*sizeof(simDouble));
534  p->outputChar=(simChar*)simCreateBuffer(charDataCnt*sizeof(simChar));
535  p->outputCharBuff=(simChar*)simCreateBuffer(charBuffDataCnt*sizeof(simChar));
536 
537  // Now populate the buffers:
538  int boolDataOff=0;
539  int intDataOff=0;
540  int floatDataOff=0;
541  int doubleDataOff=0;
542  int charDataOff=0;
543  int charBuffDataOff=0;
544 
545  for (int i=0;i<itemCnt;i++)
546  {
547  if (_outData[i].isTable())
548  { // table
549  if (_outData[i].getType()==0)
550  {
551  for (int j=0;j<int(_outData[i].boolData.size());j++)
552  p->outputBool[boolDataOff++]=_outData[i].boolData[j];
553  }
554  if (_outData[i].getType()==1)
555  {
556  for (int j=0;j<int(_outData[i].intData.size());j++)
557  p->outputInt[intDataOff++]=_outData[i].intData[j];
558  }
559  if (_outData[i].getType()==2)
560  {
561  for (int j=0;j<int(_outData[i].floatData.size());j++)
562  p->outputFloat[floatDataOff++]=_outData[i].floatData[j];
563  }
564  if (_outData[i].getType()==5)
565  {
566  for (int j=0;j<int(_outData[i].doubleData.size());j++)
567  p->outputDouble[doubleDataOff++]=_outData[i].doubleData[j];
568  }
569  if (_outData[i].getType()==3)
570  {
571  for (int j=0;j<int(_outData[i].stringData.size());j++)
572  {
573  for (int k=0;k<int(_outData[i].stringData[j].length());k++)
574  p->outputChar[charDataOff++]=_outData[i].stringData[j][k];
575  p->outputChar[charDataOff++]=0;
576  }
577  }
578  }
579  else
580  {
581  if (_outData[i].getType()==0)
582  p->outputBool[boolDataOff++]=_outData[i].boolData[0];
583  if (_outData[i].getType()==1)
584  p->outputInt[intDataOff++]=_outData[i].intData[0];
585  if (_outData[i].getType()==2)
586  p->outputFloat[floatDataOff++]=_outData[i].floatData[0];
587  if (_outData[i].getType()==5)
588  p->outputDouble[doubleDataOff++]=_outData[i].doubleData[0];
589  if (_outData[i].getType()==3)
590  {
591  for (int j=0;j<int(_outData[i].stringData[0].length());j++)
592  p->outputChar[charDataOff++]=_outData[i].stringData[0][j];
593  p->outputChar[charDataOff++]=0;
594  }
595  if (_outData[i].getType()==4)
596  {
597  for (int j=0;j<int(_outData[i].stringData[0].length());j++)
598  p->outputCharBuff[charBuffDataOff++]=_outData[i].stringData[0][j];
599  }
600  }
601  }
602  }
603 }
604 
606 {
607  // use this when doing a Lua function call from a plugin
608  p->objectID=-1; // added this on 23/2/2016, to avoid conflicts (even if chances are very small) with new way of calling simCallScriptFunction
609  p->inputArgCount=0;
610  p->inputBool=NULL;
611  p->inputInt=NULL;
612  p->inputFloat=NULL;
613  p->inputDouble=NULL;
614  p->inputChar=NULL;
615  p->inputCharBuff=NULL;
616  p->inputArgTypeAndSize=NULL;
617 
618  p->outputArgCount=expectedArguments[0];
619  p->outputBool=NULL;
620  p->outputInt=NULL;
621  p->outputFloat=NULL;
622  p->outputDouble=NULL;
623  p->outputChar=NULL;
624  p->outputCharBuff=NULL;
626  for (int i=0;i<p->outputArgCount*2;i++)
627  p->outputArgTypeAndSize[i]=expectedArguments[1+i];
628 
629  int itemCnt=int(_inData.size());
630  if (itemCnt>0)
631  {
632  p->inputArgCount=itemCnt;
634 
635  int boolDataCnt=0;
636  int intDataCnt=0;
637  int floatDataCnt=0;
638  int doubleDataCnt=0;
639  int charDataCnt=0;
640  int charBuffDataCnt=0;
641 
642  for (int i=0;i<itemCnt;i++)
643  {
644  if (_inData[i].isTable())
645  { // table
646  if (_inData[i].getType()==-1)
647  {
649  p->inputArgTypeAndSize[i*2+1]=_inData[i].getNilTableSize();
650  }
651  if (_inData[i].getType()==0)
652  {
654  p->inputArgTypeAndSize[i*2+1]=int(_inData[i].boolData.size());
655  boolDataCnt+=p->inputArgTypeAndSize[i*2+1];
656  }
657  if (_inData[i].getType()==1)
658  {
660  p->inputArgTypeAndSize[i*2+1]=int(_inData[i].intData.size());
661  intDataCnt+=p->inputArgTypeAndSize[i*2+1];
662  }
663  if (_inData[i].getType()==2)
664  {
666  p->inputArgTypeAndSize[i*2+1]=int(_inData[i].floatData.size());
667  floatDataCnt+=p->inputArgTypeAndSize[i*2+1];
668  }
669  if (_inData[i].getType()==5)
670  {
672  p->inputArgTypeAndSize[i*2+1]=int(_inData[i].doubleData.size());
673  doubleDataCnt+=p->inputArgTypeAndSize[i*2+1];
674  }
675  if (_inData[i].getType()==3)
676  {
678  p->inputArgTypeAndSize[i*2+1]=int(_inData[i].stringData.size());
679  for (int j=0;j<int(_inData[i].stringData.size());j++)
680  charDataCnt+=int(_inData[i].stringData[j].length())+1;
681  }
682  }
683  else
684  {
685  if (_inData[i].getType()==-1)
686  {
687  p->inputArgTypeAndSize[i*2+1]=0;
689  }
690  if (_inData[i].getType()==0)
691  {
692  p->inputArgTypeAndSize[i*2+1]=0;
694  boolDataCnt++;
695  }
696  if (_inData[i].getType()==1)
697  {
698  p->inputArgTypeAndSize[i*2+1]=0;
700  intDataCnt++;
701  }
702  if (_inData[i].getType()==2)
703  {
704  p->inputArgTypeAndSize[i*2+1]=0;
706  floatDataCnt++;
707  }
708  if (_inData[i].getType()==5)
709  {
710  p->inputArgTypeAndSize[i*2+1]=0;
712  doubleDataCnt++;
713  }
714  if (_inData[i].getType()==3)
715  {
716  p->inputArgTypeAndSize[i*2+1]=0;
718  charDataCnt+=int(_inData[i].stringData[0].length())+1;
719  }
720  if (_inData[i].getType()==4)
721  {
722  p->inputArgTypeAndSize[i*2+1]=int(_inData[i].stringData[0].length());
724  charBuffDataCnt+=int(_inData[i].stringData[0].length());
725  }
726  }
727  }
728 
729  // Now create the buffers:
730  p->inputBool=(simBool*)simCreateBuffer(boolDataCnt*sizeof(simBool));
731  p->inputInt=(simInt*)simCreateBuffer(intDataCnt*sizeof(simInt));
732  p->inputFloat=(simFloat*)simCreateBuffer(floatDataCnt*sizeof(simFloat));
733  p->inputDouble=(simDouble*)simCreateBuffer(doubleDataCnt*sizeof(simDouble));
734  p->inputChar=(simChar*)simCreateBuffer(charDataCnt*sizeof(simChar));
735  p->inputCharBuff=(simChar*)simCreateBuffer(charBuffDataCnt*sizeof(simChar));
736 
737  // Now populate the buffers:
738  int boolDataOff=0;
739  int intDataOff=0;
740  int floatDataOff=0;
741  int doubleDataOff=0;
742  int charDataOff=0;
743  int charBuffDataOff=0;
744 
745  for (int i=0;i<itemCnt;i++)
746  {
747  if (_inData[i].isTable())
748  { // table
749  if (_inData[i].getType()==0)
750  {
751  for (int j=0;j<int(_inData[i].boolData.size());j++)
752  p->inputBool[boolDataOff++]=_inData[i].boolData[j];
753  }
754  if (_inData[i].getType()==1)
755  {
756  for (int j=0;j<int(_inData[i].intData.size());j++)
757  p->inputInt[intDataOff++]=_inData[i].intData[j];
758  }
759  if (_inData[i].getType()==2)
760  {
761  for (int j=0;j<int(_inData[i].floatData.size());j++)
762  p->inputFloat[floatDataOff++]=_inData[i].floatData[j];
763  }
764  if (_inData[i].getType()==5)
765  {
766  for (int j=0;j<int(_inData[i].doubleData.size());j++)
767  p->inputDouble[doubleDataOff++]=_inData[i].doubleData[j];
768  }
769  if (_inData[i].getType()==3)
770  {
771  for (int j=0;j<int(_inData[i].stringData.size());j++)
772  {
773  for (int k=0;k<int(_inData[i].stringData[j].length());k++)
774  p->inputChar[charDataOff++]=_inData[i].stringData[j][k];
775  p->inputChar[charDataOff++]=0;
776  }
777  }
778  }
779  else
780  {
781  if (_inData[i].getType()==0)
782  p->inputBool[boolDataOff++]=_inData[i].boolData[0];
783  if (_inData[i].getType()==1)
784  p->inputInt[intDataOff++]=_inData[i].intData[0];
785  if (_inData[i].getType()==2)
786  p->inputFloat[floatDataOff++]=_inData[i].floatData[0];
787  if (_inData[i].getType()==5)
788  p->inputDouble[doubleDataOff++]=_inData[i].doubleData[0];
789  if (_inData[i].getType()==3)
790  {
791  for (int j=0;j<int(_inData[i].stringData[0].length());j++)
792  p->inputChar[charDataOff++]=_inData[i].stringData[0][j];
793  p->inputChar[charDataOff++]=0;
794  }
795  if (_inData[i].getType()==4)
796  {
797  for (int j=0;j<int(_inData[i].stringData[0].length());j++)
798  p->inputCharBuff[charBuffDataOff++]=_inData[i].stringData[0][j];
799  }
800  }
801  }
802  }
803 }
804 
806 { // this is the old version. Use instead 'releaseBuffers_scriptFunctionCall'
807  // use this you finished with a Lua function call from a plugin
808  simReleaseBuffer((char*)p->inputBool);
809  p->inputBool=NULL;
810  simReleaseBuffer((char*)p->inputInt);
811  p->inputInt=NULL;
812  simReleaseBuffer((char*)p->inputFloat);
813  p->inputFloat=NULL;
814  simReleaseBuffer((char*)p->inputDouble);
815  p->inputDouble=NULL;
816  simReleaseBuffer((char*)p->inputChar);
817  p->inputChar=NULL;
818  simReleaseBuffer((char*)p->inputCharBuff);
819  p->inputCharBuff=NULL;
821  p->inputArgTypeAndSize=NULL;
822 
823  simReleaseBuffer((char*)p->outputBool);
824  p->outputBool=NULL;
825  simReleaseBuffer((char*)p->outputInt);
826  p->outputInt=NULL;
827  simReleaseBuffer((char*)p->outputFloat);
828  p->outputFloat=NULL;
829  simReleaseBuffer((char*)p->outputDouble);
830  p->outputDouble=NULL;
831  simReleaseBuffer((char*)p->outputChar);
832  p->outputChar=NULL;
833  simReleaseBuffer((char*)p->outputCharBuff);
834  p->outputCharBuff=NULL;
836  p->outputArgTypeAndSize=NULL;
837 }
#define SIM_LUA_ARG_NIL_ALLOWED
std::vector< CLuaFunctionDataItem > * getOutDataPtr_luaFunctionCall()
double simDouble
Definition: v_repTypes.h:40
ptrSimCreateBuffer simCreateBuffer
Definition: v_repLib.cpp:171
bool readDataFromLua(const SLuaCallBack *p, const int *expectedArguments, int requiredArgumentCount, const char *functionName)
simDouble * inputDouble
Definition: v_repTypes.h:74
simDouble * outputDouble
Definition: v_repTypes.h:75
simBool * inputBool
Definition: v_repTypes.h:58
simChar * inputCharBuff
Definition: v_repTypes.h:71
simInt * outputArgTypeAndSize
Definition: v_repTypes.h:69
simFloat * outputFloat
Definition: v_repTypes.h:66
bool readDataFromLua_luaFunctionCall(const SLuaCallBack *p, const int *expectedArguments, int requiredArgumentCount, const char *functionName)
void pushOutData(const CLuaFunctionDataItem &dataItem)
void writeDataToLua(SLuaCallBack *p)
simInt * outputInt
Definition: v_repTypes.h:65
simInt * inputArgTypeAndSize
Definition: v_repTypes.h:63
simFloat * inputFloat
Definition: v_repTypes.h:60
virtual ~CLuaFunctionData()
char simChar
Definition: v_repTypes.h:37
std::vector< CLuaFunctionDataItem > _outData
ptrSimReleaseBuffer simReleaseBuffer
Definition: v_repLib.cpp:172
simChar * outputCharBuff
Definition: v_repTypes.h:72
simInt outputArgCount
Definition: v_repTypes.h:68
simBool * outputBool
Definition: v_repTypes.h:64
simInt * inputInt
Definition: v_repTypes.h:59
int simInt
Definition: v_repTypes.h:38
void writeDataToLua_luaFunctionCall(SLuaCallBack *p, const int *expectedArguments)
simInt objectID
Definition: v_repTypes.h:57
if(EXISTS "${PROJECT_DOC_DIR}/CMakeLists.txt") option(BUILD_DOCUMENTATION "Request build and/or installation of documentation." OFF) endif() if(EXISTS "$
static void getInputDataForFunctionRegistration(const int *dat, std::vector< int > &outDat)
float simFloat
Definition: v_repTypes.h:39
simChar * outputChar
Definition: v_repTypes.h:67
unsigned char simBool
Definition: v_repTypes.h:36
ptrSimSetLastError simSetLastError
Definition: v_repLib.cpp:197
simInt inputArgCount
Definition: v_repTypes.h:62
std::vector< CLuaFunctionDataItem > _inData
void pushOutData_luaFunctionCall(const CLuaFunctionDataItem &dataItem)
void releaseBuffers_luaFunctionCall(SLuaCallBack *p)
std::vector< CLuaFunctionDataItem > * getInDataPtr()
simChar * inputChar
Definition: v_repTypes.h:61