embind will need something similar when asm.js support is added. Each function 
pointer will need to be passed with a signature object, probably derived with a 
template from the C function signature. What are the valid signature types in 
asm.js? void, int (including pointer), and double?

Sent from my iPhone

> On Dec 16, 2013, at 9:47 PM, Lu Wang <[email protected]> wrote:
> 
> Hello,
> 
>   When building vim.js (http://coolwanglu.github.io/vim.js/web/vim.html), I 
> tried to analyze the output of emscripten, and do some dirty work for async 
> functions.
> 
>   The dirty work is quite simple, just to insert a new arg in the beginning 
> of the function argument list and call it, In C the function pointer is 
> forced casted into a pointer to a function with the same number of (void*) 
> parameters.
>   
>   For example: 
> 
> // in C
>    int (*fp) (int a, int b);
> 
>    async_call(*fp, 1, 2);
> 
> // in JS 
>    function _async_call (func) {
>       var new_args = argument.slice(0);
>       new_args[0] = FAKE_ARG
>       FUNCTION_TABLE[func].apply(null, new_args);
>    }
>   
> 
>    Right now I'm thinking about enable ASM_JS to improve the performance, As 
> stated in the wiki, when ASM_JS is enabled, functions are stored into 
> different tables for optimizations, so given only a fuction pointer (sent 
> from C), JS code can no longer find the correct function since it does not 
> know the type of the function.
> 
>   Is there an easy way to achieve this without defining functions for each 
> type of function? Hopefully some information can be passed into js, something 
> like this:
> 
> // in C
>    async_call(EM_GET_FUNC_TABLE(fp), fp, 1,2)
> 
> // in JS
>  
>    function _async_call(tbl, func) {
>       tbl[func].apply ...
>    }
> 
>    Maybe a more `natural` way is to deref it in C, such that js would get the 
> raw function, but it might not make as much as sense as I had thought of:
> 
>   // in C
>    async_call(*fp, 1, 2);
>   // in JS
>    _async_call(func) {
>       func.apply... // no deref
>    }
>   
> 
>   Could any one please advise?
> 
>   Thanks!
> 
> 
>  
>   regards,
>   - Lu
> -- 
> You received this message because you are subscribed to the Google Groups 
> "emscripten-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to