• @Robin, now I understand why it goes side-ways for you:

    On Writing and Submitting Modules (or changes), it says:

    To test out your module, we'd suggest that you copy it verbatim into the right-hand side of the Web IDE, with the line var exports={}; at the top, and at the bottom, where you use the module, write exports.myfunction() instead of require('MOD123').myfunction().

    which means something else in regard to the ...between... you paraphrase it. Try to read it this way:

    To test out your module, we'd suggest that you copy it verbatim into the right-hand side of the Web IDE, with the line var exports={}; at the top. *( Fullstop - that is dealing with the top before the module code - then: )*At the bottom, where you use thje module, write exports.myfunction() INSTEAD of require('MOD123').myfunction();.

    This reading (interpretation) is corroborated by the code example just above this text.

    For your example, the working code reads:

    // testingInlineCompiledCInModule.js
    
    var exports={};
    var c = E.compiledC(`
    // double lookup(int)
    double lut[8] = {
      41,42,43,44,45,46,47,48
    };
    double lookup(unsigned int x)
    {
      return lut[x&7];
    }
    `);
    exports = c;
    
    // usage (require) of the module with inline, compiled C:
    // var lookup = require("lookup.js"); // commented and instead using:
    var lookup = exports;
    
    // usage (invocation) of the module with inline, compiled C:
    function callLookup() {
      console.log(lookup(13)); // shows 5 in console
    }
    
    function onInit() {
      callLookup();
    }
    
    setTimeout(onInit,1000); // convenience; while developing...
    

    Take a shot at it (...cannot guarantee for the C part... ;) )

    Now we have the between out of the way, let's look what it actually did: The 2nd var exports = {}; just killed what was setup for exports just before. So even if you (would) have used the module correctly, it would never be there, because c was just an empty object again.

    It is not about insisting on being as complete and detailed as possible in the forum. It is for everyone on the forum who wants to help, understand the issue and how come the issue in order to find a solution to overcome what ever road blocks. Everyone works out of their context and sometimes this context is more fare from than close to common, especially when coming from all walks of IT.. So please accept your questioning as the expression of being helpless to provide help... ;-)

    Every issue is an opportunity... and in this case better phrasing and may be providing the example literally would prevented the rabbit trail with hole as trap at end.

    Looking forward to more conversations from you. - aO

  • Mon 2018.09.24

    @allObjects, not having any issue with the development of a module running in the IDE. It's the deployment part. Gordon understood what the issue is.

    Thought the title 'in deployed module' was explicit enough. Thanks for the clarification however. Incidentally, works either with or without the second occurrence.

    and, . . . who would have guessed we would have had so much fun over a comma!!? ROTFLOL

About

Avatar for allObjects @allObjects started