diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-03-10 17:54:56 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-03-10 17:54:56 -0800 |
commit | a78a13dc7bee141afc6be2a68e6b19912f2a260c (patch) | |
tree | be6840c31fd039b74c88e297a22c0ce0eb02083f | |
parent | b1f86a1fb9323c9106d5d99a6afc52e1f6a1145e (diff) |
allow Module.stdin,out,err to provide defaults for streams
-rw-r--r-- | src/library.js | 5 | ||||
-rwxr-xr-x | tests/runner.py | 27 |
2 files changed, 32 insertions, 0 deletions
diff --git a/src/library.js b/src/library.js index 86897f11..598838a0 100644 --- a/src/library.js +++ b/src/library.js @@ -309,6 +309,11 @@ LibraryManager.library = { FS.ensureRoot(); + // Allow Module.stdin etc. to provide defaults, if none explicitly passed to us here + input = input || Module['stdin']; + output = output || Module['stdout']; + error = error || Module['stderr']; + // Default handlers. if (!input) input = function() { if (!input.cache || !input.cache.length) { diff --git a/tests/runner.py b/tests/runner.py index b8641d9a..b43fdfd7 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -3695,6 +3695,33 @@ def process(filename): self.do_run(src, 'size: 7\ndata: 100,-56,50,25,10,77,123\nloop: 100 -56 50 25 10 77 123 \ninput:hi there!\ntexto\ntexte\n$\n5 : 10,30,20,11,88\nother=some data.\nseeked=me da.\nseeked=ata.\nseeked=ta.\nfscanfed: 10 - hello\n', post_build=post, extra_emscripten_args=['-H', 'libc/fcntl.h']) + def test_files_m(self): + # Test for Module.stdin etc. + + post = ''' +def process(filename): + src = \'\'\' + var data = [10, 20, 40, 30]; + var Module = { + stdin: function() { return data.pop() || null }, + stdout: function(x) { print('got: ' + x) } + }; + \'\'\' + open(filename, 'r').read() + open(filename, 'w').write(src) +''' + src = r''' + #include <stdio.h> + + int main () { + char c; + while ((c = fgetc(stdin)) != EOF) { + putc(c+5, stdout); + } + return 0; + } + ''' + self.do_run(src, 'got: 35\ngot: 45\ngot: 25\ngot: 15\n', post_build=post) + def test_folders(self): add_pre_run = ''' def process(filename): |