aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-11-21 20:26:26 +0100
committerAlon Zakai <alonzakai@gmail.com>2012-11-21 20:26:26 +0100
commitb074f4241b87a097bf25e09cda7766b55a88a81b (patch)
tree08e354f63988b6db439710c55c72847edc3c6938
parent25912c4c7e019aaa9a9ce1066c6b3cfe945c5bbc (diff)
emscripten_run_script_string
-rw-r--r--src/library.js12
-rw-r--r--system/include/emscripten/emscripten.h1
-rwxr-xr-xtests/runner.py3
3 files changed, 15 insertions, 1 deletions
diff --git a/src/library.js b/src/library.js
index 837ed71d..4acf021b 100644
--- a/src/library.js
+++ b/src/library.js
@@ -6909,6 +6909,18 @@ LibraryManager.library = {
return eval(Pointer_stringify(ptr));
},
+ emscripten_run_script_string: function(ptr) {
+ var s = eval(Pointer_stringify(ptr));
+ var me = _emscripten_run_script_string;
+ if (!me.bufferSize || me.bufferSize < s.length+1) {
+ if (me.bufferSize) _free(me.buffer);
+ me.bufferSize = s.length+1;
+ me.buffer = _malloc(me.bufferSize);
+ }
+ writeStringToMemory(s, me.buffer);
+ return me.buffer;
+ },
+
emscripten_random: function() {
return Math.random();
},
diff --git a/system/include/emscripten/emscripten.h b/system/include/emscripten/emscripten.h
index 871a7162..3eefe0b8 100644
--- a/system/include/emscripten/emscripten.h
+++ b/system/include/emscripten/emscripten.h
@@ -31,6 +31,7 @@ extern "C" {
*/
extern void emscripten_run_script(const char *script);
extern int emscripten_run_script_int(const char *script);
+extern char *emscripten_run_script_string(const char *script); // uses a single buffer - shared between calls!
extern void emscripten_async_run_script(const char *script, int millis);
/*
diff --git a/tests/runner.py b/tests/runner.py
index 6404a211..8ffc759a 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -2777,6 +2777,7 @@ c5,de,15,8a
// EMSCRIPTEN_COMMENT("hello from the source");
emscripten_run_script("Module.print('hello world' + '!')");
printf("*%d*\n", emscripten_run_script_int("5*20"));
+ printf("*%s*\n", emscripten_run_script_string("'five'+'six'"));
emscripten_run_script("_save_me_aimee()");
return 0;
}
@@ -2788,7 +2789,7 @@ def process(filename):
# TODO: restore this (see comment in emscripten.h) assert '// hello from the source' in src
'''
- self.do_run(src, 'hello world!\n*100*\nmann\n', post_build=check)
+ self.do_run(src, 'hello world!\n*100*\n*fivesix*\nmann\n', post_build=check)
def test_inlinejs(self):
src = r'''