2016-12-15 3 views
0

私はここに完全な例を置いて、これが正しい方法であるかどうかわかりません! comple:Emscriptenとjqueryクリックコールバック、問題?

emcc jquery001.cpp -o jquery001.js -s EXPORTED_FUNCTIONS="['_x_click','_webmain']" 

すべてが常に最後のprintfないだけでなく、ほかのプログラムの仕事ですが... printf関数 ショーと思われますが

初期出力前:

pre-main prep time: 11 ms 
jquery001.js:143 
jquery001.js:143 enter webmain 
jquery001.js:143 webmain <> 

終了ウェブをmainはmissigです:printf( "\ n exit webmain");

その要素の例に 'クリック' と表示されます。

exit webmain 
jquery001.js:143 enter x_click 
jquery001.js:143 x_click event <x1> 

をprintfのメイン...ではなくprintfの出口ウェブ( "\ nの出口x_click");

何が問題なのですか。時点でその文字列が改行に達するまでprintfに渡される引数をバッファリングして出力するとともに

[jquery001.html]

<!DOCTYPE html> 
<html> 
<head> 
<title>emcc & jquery</title> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
</head> 
<body> 
<label id="x1" class="x" >emscripten1</label> 
<label id="x2" class="x" >emscripten2</label> 
</body> 
<script src="jquery001.js"></script> 
<script> 
Module.ccall('webmain', 'number', ['string'],['']); 
</script> 
</html> 

[jquery001.cpp]

#include <stdio.h> 
#include <stdlib.h> 
#include <emscripten.h> 
#include <string.h> 

#include <string> 

extern "C" 
{ 
    int x_click( char *s) 
    { 
     printf ("\n enter x_click"); 
     printf ("\n x_click event <%s>",s); 
     printf ("\n exit x_click"); 
     return 0 ; 
    } 


    int webmain(char *s) 
    { 
     printf ("\n enter webmain");  
     printf ("\n webmain <%s>",s); 

     int x = EM_ASM_INT({ 

     $('.x').click(function(e) 
     { 
      Module.ccall('x_click', 'number', ['string'],[e.target.id]); 

     }); 


      return 0; 
     }, NULL); 

     printf ("\n exit webmain");  

     return 0 ; 
    } 

} 


int main (void) 
{ 

    return 0 ; 
} 

答えて

1

Emscripten割引、出力の表示を扱うModule.print()メソッドに渡されます。この結末は、文字列が改行で終わらないprintfに渡された場合、それは印刷されないということです。

これはstdoutはCにバッファリングされる方法と似ていますが、Emscriptenとの違い(私がテストした少なくともバージョン1.36)がfflush(NULL)を呼び出すと、バッファをフラッシュしないことであり、stderrが同じようにバッファリングされていますstdout。あなたの問題を是正

は簡単です、あなたは自分の最後の文字列、すなわちの最後に改行を追加することにより、バッファをフラッシュする必要があります。

printf("\n exit x_click\n"); 

printf("\n exit webmain\n"); 
+1

あなたが示すよう完璧に動作私に(私が評判の15に達すると+1)! –