COOPY » Guide
version 0.6.5
|
00001 #include <stdio.h> 00002 #include <coopy/Diff.h> 00003 00004 #include <emscripten.h> 00005 #include <string> 00006 00007 using namespace coopy::app; 00008 using namespace std; 00009 00010 std::string emcc_result; 00011 00012 extern "C" const char *get_message() { 00013 return (const char *)emcc_result.c_str(); 00014 } 00015 00016 extern "C" void process_message(const char *msg) { 00017 if (msg[0]=='\0') return; 00018 emcc_result = std::string("I GOT ") + msg; 00019 emscripten_run_script("js_get_message = cwrap('get_message', 'string', []);"); 00020 emscripten_run_script("postMessage(js_get_message());"); 00021 } 00022 00023 int main(int argc, char *argv[]) { 00024 process_message(get_message()); 00025 process_message(""); 00026 if (argc==1) { 00027 emscripten_run_script("if (typeof postMessage !== 'undefined') { postMessage('hello from worker 3!') }"); 00028 emscripten_run_script("js_process_message = cwrap('process_message', 'void', ['string']);"); 00029 emscripten_run_script("onmessage = function(e){ js_process_message(e.data); };"); 00030 return 0; 00031 } 00032 00033 Options opt("ssdiff"); 00034 int r = opt.apply(argc,argv); 00035 if (r!=0) return r; 00036 00037 Diff diff; 00038 return diff.apply(opt); 00039 } 00040