javascript - Run java script file created by Emscripten, from another java script file -
here task: want run .js
file witch created emscripten
.cpp
file, .js
file.
i.e.: have ping.cpp
file, witch display text "ping"
. use emscripten create ping.js
it, type em++ ping.cpp
, here - ping.js
.
can run using node ping.js
, want run second .js
file witch called init.js
, cant understand how should it. because ping.js doesnt have main function wicth display "ping" , witch can call .js file or example .html file, instead of has 68500 lines of code.
so, there chance me run ping.js init.js?
thanks help.
p.s. sorry english, not mother tongue.
you should load ping.js file script tag in html file, other script. trick make sure make functions want use accessible other scripts load. so, need set exported_functions compilation flag indicate function names want preserve. specifically
em++ -s exported_functions="['_ping']" ping.cpp -o ping.js
note underscore ('_') needed added in front of function name compensate name mangling.
in other js file want use ping, need set up. make sure compiled script loads first, , do:
ping = module.cwrap('ping', 'null', ['string']);
this allow use ping, assuming has void return type (hence null) , single c-style string argument (hence ['string']).
if want load javascript file, see answer: how include javascript file in javascript file?
Comments
Post a Comment