Ejemplo n.º 1
0
PerlStack PerlInterface::sub(const char* functionName){
	PERL_SET_CONTEXT(my_perl);

	dSP;

	ENTER;
    SAVETMPS;

    PUSHMARK(SP);//remember the stack pointer

    while(!isEmpty()){
    	XPUSHs(sv_2mortal(getSV()));
    }

	PUTBACK;

	unsigned numberOfReturns = call_pv(functionName, G_ARRAY);
	SPAGAIN;

	PerlStack returnStack(perlManager);

	for(unsigned i=0; i < numberOfReturns; ++i){
		returnStack.pushFront(POPs);//get SV returned from the sub and push it to the stack
	}

	PUTBACK;
	FREETMPS; //free the return values
	LEAVE;

	return returnStack;
}
Ejemplo n.º 2
0
///////////////////////////////////////////////////////////////////////////////
/// Replace reference information in message.
/// E.g. #r1365# by variable name and ## by # in message
/// copies the result to buffer
///
///\param msg 
///\param buffer
///\param nBuffer
///\param fmu FMU
///////////////////////////////////////////////////////////////////////////////
static void replaceRefsInMessage(const char* msg, char* buffer, int nBuffer, FMU* fmu){
  int i=0; // position in msg
  int k=0; // position in buffer
  int n;
  char c = msg[i];
  while (c!='\0' && k < nBuffer) {
    if (c!='#') {
      buffer[k++]=c;
      i++;
      c = msg[i];
    }
    else {
      char* end = strchr(msg+i+1, '#');
      if (!end) {
        printf("unmatched '#' in '%s'\n", msg);
        buffer[k++]='#';
        break;
      }
      n = end - (msg+i);
      if (n==1) {
        // ## detected, output #
        buffer[k++]='#';
        i += 2;
        c = msg[i];
      }
      else {
        char type = msg[i+1]; // one of ribs
        fmiValueReference vr;
        int nvr = sscanf(msg+i+2, "%u", &vr);
        if (nvr==1) {
          // vr of type detected, e.g. #r12#
          ScalarVariable* sv = getSV(fmu, type, vr);
          const char* name = sv ? getName(sv) : "?";
          sprintf(buffer+k, "%s", name);
          k += strlen(name);
          i += (n+1);
          c = msg[i]; 
        }
        else {
          // could not parse the number
          printf("illegal value reference at position %d in '%s'\n", i+2, msg);
          buffer[k++]='#';
          break;
        }
      }
    }
  } // while
  buffer[k] = '\0';
}