Appel d'un pointeur de fonction avec Emscripten

Avec Emscripten, est-il possible d'appeler un pointeur de fonction (donc un nombre) de JavaScript?
La signature de la fonction est variable, donc je ne peux pas écrire un assistant et être fait.

Pour illustrer un exemple, j'ai une fonction comme celle-ci:

// Returns a function pointer to call, with the appropiate // arguments, to initialize the demanded feature. void* get_feature_activator(feature_t feat); 

Vous êtes censé l'utiliser comme suit:

 // Initialize the speaker void* activator = get_feature_activator(FEATURE_SPEAKER); // We know this function needs one float, so we cast and call it ((void(*)(float))activator) (3.0); 

Pour faire de même avec JavaScript:

 var activator = _get_feature_activator(constants.FEATURE_SPEAKER); // TODO: Need to call this pointer with one float 

Vous pouvez appeler un pointeur de fonction C de JS en utilisant Runtime.dynCall . Voir par exemple

https://github.com/kripken/emscripten/blob/ee17f05c0a45cad728ce0f215f2d2ffcdd75434b/src/library_browser.js#L715

Les arguments sont (type signature, pointer, array of arguments) . Par exemple, le type 'vi' signifie retourner vide, recevoir un paramètre entier. Ceci correspond à FUNCTION_TABLE_vi que vous pouvez voir dans le code généré.

Je créerais une fonction C:

 void call_feature_activator(int activator, float in_val) { ((void(*)(float))activator) (in_val); } 

Vous pouvez alors appeler la fonction du côté JavaScript pour déclencher votre appel d'activation et il sera chargé de lancer un pointeur de fonction et l'appeler.