Skip to content

Instantly share code, notes, and snippets.

@xxuejie
Created January 1, 2013 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xxuejie/4429121 to your computer and use it in GitHub Desktop.
Save xxuejie/4429121 to your computer and use it in GitHub Desktop.
js->c calling bugs in ASM_JS mode
#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;
}
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();
}
});
$ 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)
$ 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