emscripten-core / emscripten-core/emscripten
Add support for (const) char* type to Embind?
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
Hi,
I noticed that Embind does not have support for `char*` strings, i.e. this code
```cpp
// C++
#include
using namespace emscripten;
const char* hello() {
return "Hello, World";
}
EMSCRIPTEN_BINDINGS(my_module) {
function("hello", &hello, allow_raw_pointers());
}
```
```js
// JS
import main from '/emscripten/build/main.js';
main({
locateFile: f => "/emscripten/build/main.wasm"
}).then(m => {
console.log(m.hello());
});
```
produces this error: `Cannot call hello due to unbound types: PKc`
------
On the other hand, if I use `ccall` or `cwrap`, handling char* strings seems to be no problem:
```cpp
// C++
extern "C" {
const char* hello() {
return "Hello, World";
}
}
```
```js
// JS
import main from '/emscripten/build/main.js';
main({
locateFile: f => "/emscripten/build/main.wasm"
}).then(m => {
const hello = m.cwrap("hello", "string", []);
console.log(hello());
});
```
This outputs: `Hello, World`, as expected.
Is there a reason for this difference? From a usage standpoint, I would strongly prefer if Embind would handle char* strings equally nice :slightly_smiling_face:.
Contributor guide
Assessment
This issue has not been assessed yet.