You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • I'm afraid there isn't anything at the moment - it'd just be a matter of having a static variable, of multiple functions if you wanted to allow multiple instantiation...

    Also, there's no need for jsvNewNativeFunction... you can just do:

    void gotInterrupt(int n, ... ){ jsWarn("got it %j",n); }
    void jswrap_Gesture_scan(JsVar *parent){
      JsGesture gest;
      if(!getFromVar(&gest,parent)) return;
      IOEventFlags exti = EV_NONE;
      if (!jsiIsWatchingPin(gest.data.echo))
        exti = jshPinWatch(gest.data.echo, true);
        // disable event callbacks by default
      if (exti) {
        jshSetEventCallback(exti, (JshEventCallbackCallback)gotInterrupt);­
      }
    }
    

    So I guess a multi-function might look like:

    JsVar *parents[4]  {0,0,0,0};
    void gotInterrupt1(int n, ... ){ /* parents[0] */ }
    void gotInterrupt2(int n, ... ){ /* parents[1] */ }
    void gotInterrupt3(int n, ... ){ /* parents[2] */ }
    void gotInterrupt4(int n, ... ){ /* parents[3] */ }
    const JshEventCallbackCallback gotInterrupts[4] = { gotInterrupt1, gotInterrupt2, gotInterrupt3, gotInterrupt4 };
    
    void jswrap_Gesture_scan(JsVar *parent){
      JsGesture gest;
      if(!getFromVar(&gest,parent)) return;
      IOEventFlags exti = EV_NONE;
      if (!jsiIsWatchingPin(gest.data.echo))
        exti = jshPinWatch(gest.data.echo, true);
      if (exti) {
        int n = 0;
        while (parents[n]) n++;
        if (n>3) {
         jsExceptionHere(JSET_ERROR, "Too many watches!");
         return;
        }
        jsvUnLock(parents[n]);
        parents[n] = jsvLockAgain(parent);
        jshSetEventCallback(exti, (JshEventCallbackCallback)gotInterrupts[­n]);
      }
    }
    
About

Avatar for Gordon @Gordon started