sorry, the struct should contain floats:

typedef struct {
    float a,b,c;
}myStruct,*myStructPtr; 

Dieter Weidenbrück schrieb am Dienstag, 8. November 2022 um 17:09:47 UTC+1:

> Hi,
>
> I am using this method:
>
> on the JS side allocate a buffer to store things
>
> export class Central {
>     constructor(app){
>         this.mApp    = app;
>         this.trainBuf    = malloc(2048); //or whatever you need
>     }
>
> //a function to fill the buffer
> sendData(a,b,c){
>         let i = this.trainBuf >> 2;
>         HEAPF32[ i + 0]  = a;
>         HEAPF32[ i + 1]  = b;
>         HEAPF32[ i + 2]  = c;
>      //sendMessage neds to exist on the C side, too
>     sendMessage(this.trainBuf); //inform you c code that data has been sent
>     }
> };
>
> Then in the c code you accept the event like this:
>
> typedef struct {
>     int a,b,c;
> }myStruct,*myStructPtr;
>
> myStruct    d;
>
> int sendMessage(void* param){
>     myStructPtr    p = (myStructPtr)param;
>
>     d.a    = p->a;
>     d.b    = p->b;
>     d.c    = p->c;
> }
>
> ale2...@gmail.com schrieb am Dienstag, 8. November 2022 um 16:16:49 UTC+1:
>
>> Hello, 
>> I want define some data struct as message and send from emscripten to 
>> javascript and viceversa, because i need to comunicate between opengl 
>> canvas (on c++ side) to html gui.
>> What's the best way to do that?
>>
>

-- 
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 emscripten-discuss+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/emscripten-discuss/e2298a2a-f687-4653-9834-c4e895841bban%40googlegroups.com.

Reply via email to