For the first question, you could use a getter/setter e.g.
    .property("format", +[](const foo& a) {
      return a.format;
    },
    +[](foo& a, Format value) {
      a.format = value;
    })

For the second, char arrays are not currently bindable. Depending on what 
you're trying to do you can use either: std:string, a vector of chars 
(register_vector), or a memory_view. 

On Friday, May 17, 2024 at 7:46:42 PM UTC-7 キャロウ マーク wrote:

> I have 2 issues. Despite much time poring over embind.html 
> <https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html#>
>  and bind.h 
> <https://github.com/emscripten-core/emscripten/blob/main/system/include/emscripten/bind.h>
>  I’ve 
> been unable to find a solution.
>
> I have a struct in c that contains a uint32_t field that is set from 
> values in an enum.
>
> typedef struct {
>    uint32_t format;
>     …
> } foo;
>
> enum Format { A = 5, B = 6};
>
> In my EMSCRIPTEN_BINDINGS block I have
>
>   enum_<Format>("Format")
>       .value(“A", A)
>       .value(“B", B)
>   ;
>
>   emscripten::class_<foo>(“foo")
>     .constructor<>()
>     .property(“format", &foo::format)
>     ...
>   ;
>
>
> In JS I have
>
> var foo = new foo();
>
> …
>
> foo.format = Format.A;
>
>
>
> format is always set to zero. To get it set to the correct value I have to 
> write
>
> foo.format = Format.A.value;
>
>
> I don’t want users of my API to need to know they have to do this. Is 
> there a way to avoid it, by modifying the declaration of the .property, by 
> using something other than an enum_<> to declare the possible values or 
> some other way? I don’t want to modify the underlying c API.
>
>
>
> The second issue is that in a separate Params struct I have a field that 
> is 
>
> char swizzle[4];
>
>
> With
>
> .property(“swizzle", &Params::swizzle)
>
>
> in the class binding, I get 
>
> /emsdk/upstream/emscripten/cache/sysroot/include/emscripten/wire.h:349:16: 
> error: array 'new' cannot have initialization arguments
>   349 |         return new T(v);
>
>
> How do I properly declare this property?
>
> Regards
>
>     -Mark
>
>

-- 
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/6cc7e432-fbfc-47ad-9989-ade6acb25a75n%40googlegroups.com.

Reply via email to