Created
January 1, 2013 18:19
-
-
Save xxuejie/4429121 to your computer and use it in GitHub Desktop.
js->c calling bugs in ASM_JS mode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <emscripten/emscripten.h> | |
void EMSCRIPTEN_KEEPALIVE c_func_calling_from_js() { | |
printf("This is a c function calling from js!"); | |
} | |
extern void js_func(); | |
int main(int argc, char *argv[]) | |
{ | |
js_func(); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mergeInto(LibraryManager.library, { | |
js_func: function() { | |
Module.print("Now we are in js side, let's call back to c side!"); | |
_c_func_calling_from_js(); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ emcc --js-library asmjs-test.js asmjs-test.c -s ASM_JS=1 | |
$ node a.out.js | |
Now we are in js side, let's call back to c side! | |
/Users/rafael/develop/tmp/asmjs/a.out.js:1928 | |
_c_func_calling_from_js(); | |
^ | |
ReferenceError: _c_func_calling_from_js is not defined | |
at _js_func (/Users/rafael/develop/tmp/asmjs/a.out.js:1928:7) | |
at Object._main (/Users/rafael/develop/tmp/asmjs/a.out.js:2444:8) | |
at Object.callMain (/Users/rafael/develop/tmp/asmjs/a.out.js:2530:25) | |
at doRun (/Users/rafael/develop/tmp/asmjs/a.out.js:2562:20) | |
at run (/Users/rafael/develop/tmp/asmjs/a.out.js:2586:12) | |
at /Users/rafael/develop/tmp/asmjs/a.out.js:2608:13 | |
at Object.<anonymous> (/Users/rafael/develop/tmp/asmjs/a.out.js:2625:4) | |
at Module._compile (module.js:449:26) | |
at Object.Module._extensions..js (module.js:467:10) | |
at Module.load (module.js:356:32) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ emcc --js-library asmjs-test.js asmjs-test.c | |
$ node a.out.js | |
Now we are in js side, let's call back to c side! | |
This is a c function calling from js! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment