diff options
-rw-r--r-- | system/include/emscripten/emscripten.h | 14 | ||||
-rw-r--r-- | tests/core/test_inlinejs3.in | 1 | ||||
-rw-r--r-- | tests/core/test_inlinejs3.out | 1 |
3 files changed, 12 insertions, 4 deletions
diff --git a/system/include/emscripten/emscripten.h b/system/include/emscripten/emscripten.h index b92d920c..852a8e0d 100644 --- a/system/include/emscripten/emscripten.h +++ b/system/include/emscripten/emscripten.h @@ -40,10 +40,15 @@ extern "C" { #define EM_ASM(...) emscripten_asm_const(#__VA_ARGS__) /* - * Input-output versions of EM_ASM. EM_ASM_INT receives arguments of - * either int or double type and returns an int; EM_ASM_DOUBLE - * receives similar arguments (int or double) but returns a double. - * Arguments arrive as $0, $1 etc; output value should be returned: + * Input-output versions of EM_ASM. + * + * EM_ASM_ (an extra _ is added) allows sending values (ints + * or doubles) into the code. If you also want a return value, + * EM_ASM_INT receives arguments (of int or double type) + * and returns an int; EM_ASM_DOUBLE does the same and returns + * a double. + * + * Arguments arrive as $0, $1 etc. The output value should be returned: * * int x = EM_ASM_INT({ * console.log('I received: ' + [$0, $1]); @@ -54,6 +59,7 @@ extern "C" { * (int or double) but *not* to pass any values, you can use * EM_ASM_INT_V and EM_ASM_DOUBLE_V respectively. */ +#define EM_ASM_(code, ...) emscripten_asm_const_int(#code, __VA_ARGS__) #define EM_ASM_INT(code, ...) emscripten_asm_const_int(#code, __VA_ARGS__) #define EM_ASM_DOUBLE(code, ...) emscripten_asm_const_double(#code, __VA_ARGS__) #define EM_ASM_INT_V(code) emscripten_asm_const_int(#code) diff --git a/tests/core/test_inlinejs3.in b/tests/core/test_inlinejs3.in index 9ddd5907..12e31007 100644 --- a/tests/core/test_inlinejs3.in +++ b/tests/core/test_inlinejs3.in @@ -7,6 +7,7 @@ int main(int argc, char **argv) { for (int i = 0; i < 3; i++) { EM_ASM(Module.print('hello dere3'); Module.print('hello dere' + 4);); } + EM_ASM_({ Module.print('hello input ' + $0) }, 123); int sum = 0; for (int i = 0; i < argc * 3; i++) { sum += EM_ASM_INT({ diff --git a/tests/core/test_inlinejs3.out b/tests/core/test_inlinejs3.out index c293e80b..1f64a89a 100644 --- a/tests/core/test_inlinejs3.out +++ b/tests/core/test_inlinejs3.out @@ -6,6 +6,7 @@ hello dere3 hello dere4 hello dere3 hello dere4 +hello input 123 i: 0,0.00 i: 1,0.08 i: 2,0.17 |