mrousavy / nitro

🔥 Insanely fast native C++, Swift or Kotlin modules with a statically compiled binding layer to JSI
https://nitro.margelo.com
MIT License
665 stars 22 forks source link

fix: Fix optional bools in JNI structs #283

Closed mrousavy closed 3 weeks ago

mrousavy commented 3 weeks ago

Fixes an error where structs that contain optional bools where not properly converted from Java to C++.

interface SomeStruct {
  someBool?: boolean
}

The reason this failed is because a Java boolean is not the same as a C++ boolean in JNI. It is an unsigned char, whereas a C++ boolean is a bool. This cannot be implicitly converted, so we have to wrap booleans with static_cast<bool>(value) in order for it to work. This is what this PR now does.

And it adds the code to the example so it doesn't break in the future anymore.

vercel[bot] commented 3 weeks ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment | Name | Status | Preview | Comments | Updated (UTC) | | :--- | :----- | :------ | :------- | :------ | | **nitro-docs** | ⬜️ Skipped ([Inspect](https://vercel.com/margelo/nitro-docs/ZoUcE9EDe33MeZdKanMKfs7KcyMu)) | | | Nov 5, 2024 10:08am |