diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler.js | 6 | ||||
-rw-r--r-- | src/shell.html | 16 | ||||
-rw-r--r-- | src/shell.js | 9 |
3 files changed, 12 insertions, 19 deletions
diff --git a/src/compiler.js b/src/compiler.js index 33f0e1fb..655fd9a6 100644 --- a/src/compiler.js +++ b/src/compiler.js @@ -52,11 +52,7 @@ if (ENVIRONMENT_IS_NODE) { } } else if (ENVIRONMENT_IS_WEB) { - // Warning: We do not override print here, so that you can define it before - // this code runs. However, if you do not define it and it is actually - // called, it will try to print to a printer, and/or give odd errors. - - printErr = function(x) { + print = printErr = function(x) { console.log(x); }; diff --git a/src/shell.html b/src/shell.html index 87c285ea..c096a314 100644 --- a/src/shell.html +++ b/src/shell.html @@ -9,23 +9,21 @@ <div id='output'></div> <hr> <script type='text/javascript'> - // implement print - var print = (function() { - var element = document.getElementById('output'); - return function(text) { - element.innerHTML += text.replace('\n', '<br>', 'g') + '<br>'; - }; - })(); - // connect to canvas var Module = { + print: (function() { + var element = document.getElementById('output'); + return function(text) { + element.innerHTML += text.replace('\n', '<br>', 'g') + '<br>'; + }; + })(), canvas: document.getElementById('canvas') }; try { Module.ctx2D = Module.canvas.getContext('2d'); if (!Module.ctx2D) throw 'Could not create canvas :('; } catch (e) { - print('(canvas not available)'); + Module.print('(canvas not available)'); } // The compiled code diff --git a/src/shell.js b/src/shell.js index 850dfd81..d67cc45a 100644 --- a/src/shell.js +++ b/src/shell.js @@ -44,11 +44,7 @@ if (ENVIRONMENT_IS_NODE) { } } else if (ENVIRONMENT_IS_WEB) { - // Warning: We do not override print here, so that you can define it before - // this code runs. However, if you do not define it and it is actually - // called, it will try to print to a printer, and/or give odd errors. - - printErr = function(x) { + print = printErr = function(x) { console.log(x); }; @@ -99,6 +95,9 @@ try { if (!Module.arguments) { Module.arguments = arguments_; } +if (Module.print) { + print = Module.print; +} {{BODY}} |