diff options
author | tim.dawborn <tim.dawborn@gmail.com> | 2011-06-23 13:50:19 +1000 |
---|---|---|
committer | tim.dawborn <tim.dawborn@gmail.com> | 2011-06-23 13:50:19 +1000 |
commit | 89ecb3e21c105df110a3c62a2d3366864fc5fe3c (patch) | |
tree | 787cede07897558a047b8da4295f35ba2d6c1b76 | |
parent | 68b06527633437767bbeaeb7cdf6a122db78ef56 (diff) |
* propogated return value from main back to the return value from Module.run
* improved the behaviour of ungetc
* added optional argument to intArrayFromString to not add the trailing NULL -- useful when adding JS strings as the data in the virtual file system
-rw-r--r-- | src/library.js | 5 | ||||
-rw-r--r-- | src/postamble.js | 6 | ||||
-rw-r--r-- | src/preamble.js | 5 |
3 files changed, 12 insertions, 4 deletions
diff --git a/src/library.js b/src/library.js index 97f7f61e..4875c7dc 100644 --- a/src/library.js +++ b/src/library.js @@ -476,6 +476,11 @@ var Library = { _IO_getc: 'getc', ungetc: function(chr, stream) { + var f = STDIO.streams[stream]; + if (!f) + return -1; // EOF + if (!f.interactiveInput) + f.position--; return chr; }, diff --git a/src/postamble.js b/src/postamble.js index 98d8f578..9b61c0a7 100644 --- a/src/postamble.js +++ b/src/postamble.js @@ -17,7 +17,7 @@ Module.callMain = function callMain(args) { argv.push(0); argv = Pointer_make(argv, null, ALLOC_STATIC, 'i32'); - _main(argc, argv, 0); + return _main(argc, argv, 0); } function run(args) { @@ -29,10 +29,12 @@ function run(args) { __globalConstructor__(); + var ret = null; if (Module['_main']) { - Module.callMain(args); + ret = Module.callMain(args); __shutdownRuntime__(); } + return ret; } Module['run'] = run; diff --git a/src/preamble.js b/src/preamble.js index e7cbcce6..cfab022e 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -549,7 +549,7 @@ function jrint(label, obj) { // XXX manual debugging // This processes a JS string into a C-line array of numbers, 0-terminated. // For LLVM-originating strings, see parser.js:parseLLVMString function -function intArrayFromString(stringy) { +function intArrayFromString(stringy, dontAddNull) { var ret = []; var t; var i = 0; @@ -557,7 +557,8 @@ function intArrayFromString(stringy) { ret.push(stringy.charCodeAt(i)); i = i + 1; } - ret.push(0); + if (!dontAddNull) + ret.push(0); return ret; } Module['intArrayFromString'] = intArrayFromString; |