JSON comments format in module files

Posted on
  • What is the significance of the below jswrapper connect section, with type = init. Although Event and static method definitions are pretty much fine.

    I am not able to find much information but this Espruino documentation page

    This part looks like comment only. But there is a nice script in the background, scanning for comments like this. As we can see, there is some data in JSON format. And this is translated into one more C-file. At the end, this generated file is the connection between Javascript file and the compiled C-function.
    When and from where it will be called and

      "type" : "init",
      "generate" : "jswrap_xxx_init"

    EDIT: Similarly Type: kill/idle

  • There's some rough documentation at https://github.com/espruino/Espruino/blo­b/master/scripts/common.py#L61 and https://github.com/espruino/Espruino/blo­b/master/README_BuildProcess.md#wrapper-­files-

    Basically if you write an extension they are functions that hook into Espruino itself.

    • init runs when the JS environment starts (eg. power on, reset, load)
    • kill is when is shuts down
    • idle is basically once every time around the event loop
  • Thanks @Gordon for your comment. This is what I am looking for.

  • Just one more thing about firing the events from the lib, like Bangle.on('mag'...)

    I guess events are triggering "type" : "idle", where the associated 'C' method [like jswrap_puck_idle(), jswrap_banglejs_idle() ]checks if any event is available once every time around the event loop and call * jsiQueueObjectCallbacks();*.

    Or there is something more or else that I am missing.

  • No, that's about it. jswrap_puck_idle basically checks/queues/even performs any events that are needed.

    It'll return true if the device shouldn't sleep after that iteration of the loop (eg maybe there is a queues event that should be executed)

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

JSON comments format in module files

Posted by Avatar for Abhigkar @Abhigkar