You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Best bet is to have a look at src/jwrap_*.c - there are loads of functions in there that work the same way. Basically in the comment at the start you describe what the arguments are. I guess you'll either want int32 (a 32 bit integer) or JsVar (a JavaScript variable, that might be something like an array).

    Actually unpacking something like an array into a C array is a bit more painful though - you'd probably want to see something like this as an example

    /*JSON{
      "type" : "staticmethod",
      "class" : "Crypto",
      "name" : "aescbc",
      "generate" : "jswrap_crypto_aescbc",
      "params" : [
        ["key","int32","A description for users"],
        ["iv","int32","A description for users"],
        ["hashKey","int32","A description for users"],
        ["data","JsVar","A description for users"]
       ]
    }*/
    void jswrap_crypto_aescbc(int key, int iv, int hashkey, JsVar *data)
    {
      if (!jsvIsIterable(data)) {
        jsExceptionHere(JSET_ERROR, "Expecting an array/string for 4th argument, got %t", data);
        return;
      }
    
      char data[128];
      JsvIterator it;
      jsvIteratorNew(&it, data);
      unsigned int i = 0;
      while (jsvIteratorHasElement(&it) && i<sizeof(data)) {
        data[i++] = (char)jsvIteratorGetIntegerValue(&it);
        jsvIteratorNext(&it);
      }
      jsvIteratorFree(&it);    
    
      // do stuff
    
      // write result back
      jsvIteratorNew(&it, data);
      i=0;
      while (jsvIteratorHasElement(&it) && i<sizeof(data)) {
        jsvUnLock(jsvIteratorSetValue(&it, jsvNewFromInteger(data[i++])));
        jsvIteratorNext(&it);
      }
      jsvIteratorFree(&it);
    }
    

    I haven't actually tested that, but it should work...

About

Avatar for Gordon @Gordon started