You can probably use embind or the webidl binder, wrapping those structs as
if there were C++ classes, but that's likely overkill. If that's the entire
API, I'd suggest just writing some simple C wrappers that convert between
the struct and simple types, like

ADYLibraryResult register_app_wrapper(char* merchant_account, char
*user_id, [..] ,  void (*callback_function)(register_app_response *, void
*), void * echo_struct) {
  // create a struct from those fields,
  // then call register_app
}

You may also need to make getters/setters like

char* get_merchant_account(struct register_app_request* s) {
  return s->merchant_account;
}

And then you can just use ccall or cwrap to call those simple C methods (as
they can handle char*, void* and so forth, it's just arbitrary C structs
that they can't).

On Wed, Jul 19, 2017 at 6:05 AM, Sebastiaan Pierrot <
[email protected]> wrote:

> Hello All,
>
> First off: Emscripten is wonderful product, i was able to compile without
> too many problems my c-library to JavaScript. and have a demo app run with
> it.
>
> Next off I wanted to provide JavaScript bindings for my library.
> I saw there were quite a few options for C++ bindings, but could not
> directly find any C bindings.
> I am hoping you could help me further when I explain the details of my API
>
> typedef struct {
> char *merchant_account;
> char *user_id;
> char *password;
> char *app_id;
> } register_app_request;
>
> typedef struct {
>     int AppRegisteredForOfflineUsage; // offline storage was a success ,
> will return 0 also if loaded offline
> RESULT parsed_result;
> } register_app_response;
>
> // register the device
> ADYLibraryResult register_app(register_app_request*
> register_app_request_ptr, void (*callback_function)(register_app_response
> *, void *), void * echo_struct);
> register_app_request * register_app_allocate();
>
> Basically the "register_app_allocate()" function returns a structure which
> the user should fill
> Then the user calls "register_app()" with the structure and a callback
> function.
>
> I am wondering how to expose the structure part to javascript and how I
> can provide an javascript callback function to the "register_app" call
> itself.
>
> Kind regards,
>
> Sebastiaan Pierrot
>
>
> --
> 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/d/optout.
>

-- 
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/d/optout.

Reply via email to