• In a C native module, I want to call other jswrap functions and asign my C function as the callback.

    How to do that?
    For example,
    void mycallback();

    void mycallback(){
        jsiConsolePrint("Hello world");
    }
    jswrap_net_connect(JsVar *options, JsVar *callback, SocketType socketType); // here I want asign mycallback( ) as the callback
    
  • You need to do something like this: https://github.com/espruino/Espruino/blo¬≠b/master/src/jswrap_promise.c#L83

    Note the JSWAT_* enums determine what arguments the function takes. Just use JSWAT_VOID in your case.

  • @Gordon
    Thanks.

    Is there a document which explains the usage of jsvLock and jsvUlock?

    Or, some documets describe the mechanism of native code?

  • Not really, no. You'd need to look at other code, or there are some good threads on this forum. Also worth looking at http://www.espruino.com/Internals

    However, I can't assist you - especially as you're not using one of the official Espruino boards. If you're doing this for a company and they need assistance then I can do consultancy work.

  • @Gordon
    Thanks a lot.

    I'm making a toy for my kid. I like javascript. Espruino makes it easy to write JS code for MCU. It's a wonderful platform.

    Thanks again.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

How to use a native C function as callback function in jswrap functions?

Posted by Avatar for Aifer @Aifer

Actions