1. I would just call require('fs') normally, avoiding storing anything on
Module. Note btw that emscripten's output will itself define these:

  var nodeFS = require('fs');
  var nodePath = require('path');

so you could just use them.

2. Yes, you can use EM_ASM_INT and _DOUBLE to return values from an EM_ASM,
see
http://kripken.github.io/emscripten-site/docs/api_reference/emscripten.h.html?#c.EM_ASM_INT


On Thu, Sep 24, 2015 at 11:06 AM, Erik Rantapaa <[email protected]> wrote:

> I'm using empscripten with nodejs.
>
> Questions:
>
> 1. What's the best way to access require('fs') in js library code?
> 2. Is there something like EM_ASM() which can return a value?
> 3. Is there a better way to do what I'm trying to do (see code below).
>
> Here is the js library code I want to use:
>
> mergeInto(LibraryManager.library, {
>   readch: function() {
>             var fs = Module.fs;
>             var buf = Buffer(10);
>             var fd = fs.openSync('/dev/stdin', 'rs')
>             var nread = fs.readSync(fd, buf, 0, 1, null);
>             if (nread > 0) {
>               return buf[0];
>             } else {
>               return 0;
>             }
>           }
>   }
> )
>
> Note that it accesses Module.fs which is not normally defined. To get it
> to work I hack the a.out.js file to include the assignment around line 52:
>
> Module['fs'] = nodeFS;
>
> Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups
> "emscripten-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to